:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --text-dim: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #8b7bff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --maxw: 960px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.12);
  --shadow-md: 0 12px 32px rgba(0,0,0,.16);
  --control-height: 44px;
  color-scheme: dark;
  font-synthesis: none;
}

/* Default to the OS preference when the user hasn't picked a theme. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --bg-elev: #ffffff;
    --bg-elev-2: #f0f2f6;
    --border: #e2e6ee;
    --text: #1a1f29;
    --text-dim: #5b6472;
    --accent: #2563eb;
    --accent-2: #7c3aed;
  }
}

/* Explicit user choice overrides the OS preference. Higher specificity than
   the :root / media-query rules above so it always wins. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --text-dim: #9aa3b2;
  --accent: #6ea8fe;
  --accent-2: #8b7bff;
}
:root[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f2f6;
  --border: #e2e6ee;
  --text: #1a1f29;
  --text-dim: #5b6472;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
html { scroll-behavior: smooth; }
body { min-width: 280px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.skip-link { position: fixed; left: 12px; top: 8px; z-index: 1000; transform: translateY(-160%); background: var(--accent); color: #07111f; padding: 9px 14px; border-radius: 8px; font-weight: 700; }
.skip-link:focus { transform: translateY(0); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}
#site-header .brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
#site-header .brand-mark { color: var(--accent); display: inline-flex; }
#site-header .brand-mark svg { display: block; width: 0.85em; height: 0.85em; }
#site-header nav { display: flex; gap: 18px; }
#site-header nav a { color: var(--text-dim); font-weight: 500; }
#site-header nav a:hover { color: var(--text); text-decoration: none; }
.theme-toggle {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 32px 24px 64px;
}
main > h1:first-child { margin: 0 0 6px; font-size: clamp(1.65rem, 4vw, 2.25rem); line-height: 1.15; letter-spacing: -.025em; }
.subtitle, .tool-desc { color: var(--text-dim); max-width: 72ch; margin: 0 0 24px; }
.tool-container, .tool-wrap { width: 100%; }

/* Consistent shell used by the large set of standalone tools. */
.input-section, .result-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 24px);
  box-shadow: var(--shadow-sm);
}
.input-section { display: grid; gap: 10px; margin: 20px 0; }
.input-section > label:not(:first-child) { margin-top: 6px; }
.result-section { margin-top: 16px; }
.result-section:empty { display: none; }
.result-row { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.result-row:first-child { padding-top: 0; }
.result-row:last-child { padding-bottom: 0; border-bottom: 0; }
.result-row > :last-child { text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.hero { margin-bottom: 28px; }
.hero h1 { font-size: 1.8rem; margin: 0 0 8px; }
.hero p { color: var(--text-dim); margin: 0; max-width: 60ch; }
.hero p.tool-count { margin-top: 8px; font-size: 0.9rem; color: var(--accent); font-weight: 500; }
.meme-badge { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; padding: 3px 10px; border-radius: 999px; background: transparent; border: 1px solid var(--border); font-size: 0.7rem; color: var(--text-dim); cursor: default; opacity: 0.7; }
.meme-badge:hover { opacity: 1; }
.meme-badge__emoji { font-size: 0.8rem; }
.meme-badge__text strong { color: var(--accent); }
.search-box { margin-top: 16px; max-width: 420px; }
.search-box input { width: 100%; }

.catalog-category { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 28px 0 12px; }

/* Homepage view tabs (All / Recently added) */
.view-tabs { display: flex; gap: 6px; margin: 4px 0 20px; }
.view-tab {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.view-tab:hover { color: var(--text); border-color: var(--accent); }
.view-tab.active { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }
.tool-card-added { margin-top: 8px; color: var(--text-dim); font-size: 0.78rem; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.tool-card {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--text);
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
}
.tool-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); background: var(--bg-elev-2); }
.tool-card-icon { font-size: 1.6rem; margin-bottom: 8px; }
.tool-card-name { font-weight: 600; margin-bottom: 4px; }
.tool-card-desc { color: var(--text-dim); font-size: 0.9rem; }

/* Tool page shell */
.tool-header { margin-bottom: 20px; }
.tool-header .back { color: var(--text-dim); font-size: 0.9rem; }
.tool-header h1 { margin: 6px 0 4px; font-size: 1.5rem; }
.tool-header p { color: var(--text-dim); margin: 0; font-size: 0.95rem; }

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

label { display: block; font-size: 0.85rem; color: var(--text-dim); margin: 0 0 6px; }
input:not([type]), input[type="text"], input[type="url"], input[type="number"],
input[type="email"], input[type="password"], input[type="search"],
input[type="tel"], input[type="date"], input[type="time"],
input[type="datetime-local"], input[type="month"], input[type="week"],
textarea, select {
  width: 100%;
  min-height: var(--control-height);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: .72; }
input[type="file"] { width: 100%; color: var(--text-dim); padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: var(--bg); }
input[type="file"]::file-selector-button { margin-right: 10px; border: 0; border-radius: 6px; padding: 7px 11px; background: var(--bg-elev-2); color: var(--text); cursor: pointer; }
textarea { min-height: 110px; resize: vertical; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 78%, white); outline-offset: 2px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

button {
  background: var(--accent);
  color: #0b0d12;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.spacer { height: 16px; }

.output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 1em;
}
.note { color: var(--text-dim); font-size: 0.85rem; margin-top: 10px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; font: inherit; font-size: 0.85rem; cursor: pointer; text-decoration: underline; }

.status-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.status-received { background: rgba(110,168,254,.18); color: var(--accent); }
.status-completed { background: rgba(74,222,128,.18); color: var(--ok); }
.status-rejected  { background: rgba(248,113,113,.18); color: var(--bad); }

.muted { color: var(--text-dim); }
code { background: var(--bg-elev-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
pre { max-width: 100%; overflow: auto; }
img, svg, canvas, video { max-width: 100%; }
table { width: 100%; max-width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--text-dim); font-size: .8rem; letter-spacing: .03em; }
details { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg-elev); }
summary { cursor: pointer; font-weight: 600; }

@media (max-width: 640px) {
  #site-header { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  #site-header nav { order: 3; width: 100%; overflow-x: auto; gap: 14px; padding-top: 2px; }
  main { padding: 24px 14px 48px; }
  .input-section, .result-section, .panel { padding: 16px; }
  .result-row { align-items: flex-start; flex-direction: column; gap: 3px; }
  .result-row > :last-child { text-align: left; }
  button { min-height: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.feedback-form .field { margin-bottom: 14px; }

/* Checkbox row (used by option toggles) */
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 0.9rem; margin: 0; cursor: pointer; }
label.check input { width: auto; margin: 0; }

/* Range slider */
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
/* Color picker */
input[type="color"] { width: 100%; height: 40px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.uuid-box { font-family: ui-monospace, monospace; font-size: 0.95rem; background: var(--bg); border:1px solid var(--border); border-radius:8px; padding:10px 12px; word-break: break-all; }

/* Regex Tester */
mark { background: rgba(110,168,254,.28); color: inherit; border-radius: 3px; padding: 0 1px; }
.regex-delim { font-family: ui-monospace, monospace; color: var(--text-dim); font-size: 1.1rem; padding: 0 2px; }

/* Contrast Checker */
.contrast-preview { border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-top: 12px; }
.contrast-preview .cp-large { font-size: 1.6rem; font-weight: 700; margin-bottom: 8px; }
.contrast-preview .cp-small { font-size: 1rem; }
.contrast-ratio { font-size: 2rem; font-weight: 800; font-family: ui-monospace, monospace; }
.contrast-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.92rem; }
.contrast-table th, .contrast-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.contrast-table th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.contrast-table td:last-child { text-align: right; }
.contrast-table .pass { color: var(--ok); font-weight: 700; }
.contrast-table .fail { color: var(--bad); font-weight: 700; }

/* Markdown Previewer */
.md-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .md-split { grid-template-columns: 1fr; } }
.md-split textarea { min-height: 360px; }
.md-preview { white-space: normal; word-break: normal; font-family: inherit; line-height: 1.6; }
.md-preview h1, .md-preview h2, .md-preview h3 { line-height: 1.25; margin: 1.2em 0 0.5em; }
.md-preview h1 { font-size: 1.6rem; }
.md-preview h2 { font-size: 1.35rem; }
.md-preview h3 { font-size: 1.15rem; }
.md-preview p { margin: 0.6em 0; }
.md-preview ul, .md-preview ol { margin: 0.6em 0; padding-left: 1.4em; }
.md-preview li { margin: 0.2em 0; }
.md-preview code { background: var(--bg-elev-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.md-preview pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; }
.md-preview pre code { background: none; padding: 0; }
.md-preview blockquote { margin: 0.6em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-dim); }
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md-preview a { color: var(--accent); }

/* Number Base Converter */
.base-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.base-table th, .base-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.base-table th { color: var(--text-dim); font-weight: 600; font-size: 0.85rem; width: 120px; }
.base-table td.mono { font-family: ui-monospace, monospace; font-size: 0.95rem; word-break: break-all; }
.base-table td:last-child { width: 60px; text-align: right; }

/* Word & Character Counter */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; font-family: ui-monospace, monospace; }
.stat-label { display: block; color: var(--text-dim); font-size: 0.8rem; margin-top: 2px; }

/* Image Converter & Resizer */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: var(--bg-elev-2); }
.dropzone .dropzone-hint { margin: 0; color: var(--text-dim); }
.dropzone .dropzone-name { margin: 6px 0 0; font-weight: 600; word-break: break-all; }
.image-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .image-split { grid-template-columns: 1fr; } }
.image-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 120px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.image-preview img { max-width: 100%; max-height: 320px; object-fit: contain; }

/* Text Diff */
.diff-stats { color: var(--text-dim); font-size: 0.85rem; margin: 10px 0; }
.diff-stats .added { color: var(--ok); font-weight: 600; }
.diff-stats .removed { color: var(--bad); font-weight: 600; }
.diff-view { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 70vh; }
.diff-line { display: flex; align-items: flex-start; }
.diff-line .mark { flex: 0 0 2ch; text-align: center; user-select: none; color: var(--text-dim); }
.diff-line .content { flex: 1; white-space: pre-wrap; word-break: break-word; }
.diff-line.eq .content { color: var(--text-dim); }
.diff-line.del { background: rgba(248,113,113,.10); }
.diff-line.del .mark { color: var(--bad); }
.diff-line.add { background: rgba(74,222,128,.10); }
.diff-line.add .mark { color: var(--ok); }
.diff-w-del { background: rgba(248,113,113,.35); border-radius: 2px; }
.diff-w-add { background: rgba(74,222,128,.35); border-radius: 2px; }
.diff-sbs .sbs-head, .diff-sbs .sbs-row { display: grid; grid-template-columns: 1fr 1fr; }
.diff-sbs .sbs-head .cell { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.diff-sbs .sbs-row .cell { padding: 0 8px; white-space: pre-wrap; word-break: break-word; min-height: 1.4em; }
.diff-sbs .sbs-row .cell:first-child { border-right: 1px solid var(--border); }
.diff-sbs .cell.eq { color: var(--text-dim); }
.diff-sbs .cell.del { background: rgba(248,113,113,.10); }
.diff-sbs .cell.add { background: rgba(74,222,128,.10); }
.diff-sbs .cell.empty { background: rgba(127,127,127,.04); }

/* Box-Shadow Generator */
.bs-stage { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.bs-stage-bar { padding: 6px 10px; background: var(--bg-elev-2); border-bottom: 1px solid var(--border); }
.bs-stage-canvas {
  min-height: 260px; display: flex; align-items: center; justify-content: center;
  padding: 36px; background: var(--bg);
}
.bs-stage-canvas.stage-light { background: #e9edf5; }
.bs-box {
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--text-dim); background: #fff;
  height: 120px; transition: box-shadow .1s ease, border-radius .1s ease, width .1s ease;
}
.bs-layer {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px; align-items: end;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 8px;
}
.bs-sm { display: block; font-size: 0.75rem; color: var(--text-dim); margin-bottom: 2px; }
.bs-val { display: block; font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; font-family: ui-monospace, monospace; }
.bs-layer input[type="range"] { width: 100%; }
.bs-layer input[type="color"] { width: 100%; height: 32px; padding: 2px; }
.bs-acts { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Color Palette Generator */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.swatch {
  position: relative; min-height: 96px; border-radius: 10px; padding: 10px;
  display: flex; align-items: flex-end; cursor: pointer; border: 1px solid var(--border);
  transition: transform .08s ease, box-shadow .12s ease;
}
.swatch:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.swatch-hex { font-family: ui-monospace, monospace; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.02em; }
.swatch-tag { position: absolute; top: 8px; left: 10px; font-size: 0.7rem; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.05em; }

/* Percentage Calculator */
.pct-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.pct-card label { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; margin: 0; }
.pct-card .pct-num { width: 100px; flex: 0 0 auto; margin: 0; }
.pct-result { margin-top: 10px; font-family: ui-monospace, monospace; font-size: 1.2rem; font-weight: 700; color: var(--text); }
@media (max-width: 560px) { .pct-card .pct-num { width: 80px; } }
