/* ==========================================================================
   ToolHex design system — mobile-first, no framework.
   "Workshop" palette: warm paper, ink, burnt orange, deep green accent.
   ========================================================================== */

:root {
  --bg: #faf7f2;          /* warm paper */
  --surface: #ffffff;
  --ink: #201d1a;         /* warm near-black */
  --muted: #6e675f;       /* warm gray */
  --faint: #a39e93;
  --brand: #c2410c;       /* burnt orange */
  --brand-dark: #9a3412;
  --brand-soft: #fbede3;  /* light orange tint */
  --green: #2e7d4f;       /* trust / success accent */
  --red: #b42318;
  --content: #403a33;
  --border: #e8e2d8;      /* warm hairline */
  --radius: 10px;
  --shadow: 0 1px 2px rgba(32, 29, 26, .07);
  --max: 1080px;
}

[data-theme="dark"] {
  --bg: #171512;          /* warm charcoal */
  --surface: #221f1c;
  --ink: #ece7df;
  --muted: #a8a097;
  --faint: #7d766c;
  --brand: #e86a33;       /* brighter orange for dark */
  --brand-dark: #f0875a;
  --brand-soft: #35231a;
  --green: #45b07a;
  --red: #e5654e;
  --content: #cfc9be;
  --border: #37322c;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

[data-theme="dark"] .content p, [data-theme="dark"] .content li { color: var(--content); }
[data-theme="dark"] .ad-slot {
  background: repeating-linear-gradient(45deg, #221f1c, #221f1c 10px, #2a2622 10px, #2a2622 20px);
}
[data-theme="dark"] .logo-mark .logo-hole { fill: var(--surface); }
.logo-mark .logo-hole { fill: #ffffff; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:active { transform: translateY(1px); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1 0 auto; }

.container {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 16px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.02em;
}
.logo em { font-style: normal; color: var(--brand); }
.logo:hover { text-decoration: none; }
.logo-mark { display: block; flex-shrink: 0; }
.site-nav { display: flex; gap: 18px; font-size: .95rem; }
.site-nav a { color: var(--muted); font-weight: 500; }
.site-nav a:hover { color: var(--brand); text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s ease, background .15s ease;
}
.theme-toggle:hover { color: var(--brand); background: var(--brand-soft); }

/* ---------- Tools drawer (hamburger menu) ---------- */
.menu-btn {
  background: none;
  border: 0;
  padding: 8px;
  margin-left: -8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: var(--ink);
  border-radius: 8px;
}
.menu-btn:hover { color: var(--brand); background: var(--brand-soft); }
@media (max-width: 720px) { .site-nav { display: none; } }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  max-width: 86vw;
  background: var(--surface);
  z-index: 50;
  transform: translateX(-102%);
  transition: transform .22s ease;
  box-shadow: 0 0 40px rgba(15, 23, 42, .18);
  overflow-y: auto;
  padding: 16px 20px 32px;
}
body.drawer-open .drawer { transform: none; }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
body.drawer-open { overflow: hidden; }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.drawer-title { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.drawer-close {
  background: none;
  border: 0;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.drawer-close:hover { color: var(--brand); background: var(--brand-soft); }
.drawer-home {
  display: block;
  padding: 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: .92rem;
}
.drawer-home:hover { background: var(--brand-soft); text-decoration: none; }
.drawer-section { margin-top: 12px; }
.drawer-section-name {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--faint);
  font-weight: 700;
}
.drawer-section-toggle {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  background: none;
  border: 0;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
}
.drawer-section-toggle:hover { background: var(--brand-soft); }
.drawer-section-toggle:hover .drawer-section-name,
.drawer-section-toggle:hover .drawer-chevron { color: var(--brand); }
.drawer-chevron { color: var(--faint); transition: transform .2s ease; flex-shrink: 0; }
.drawer-section-toggle[aria-expanded="true"] .drawer-chevron { transform: rotate(180deg); }
.drawer-links { padding: 2px 0 6px 6px; }
.drawer-section a {
  display: block;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 500;
  font-size: .95rem;
}
.drawer-section a:hover { background: var(--brand-soft); color: var(--brand); text-decoration: none; }
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-backdrop { transition: none; }
}

/* ---------- Page head ---------- */
.page-head { padding: 44px 0 8px; }
.page-head h1 {
  font-size: clamp(1.65rem, 4.5vw, 2.45rem);
  line-height: 1.15;
  margin: 0 0 10px;
  letter-spacing: -.025em;
}
.lead { color: var(--muted); font-size: 1.05rem; margin: 0; max-width: 62ch; }

/* ---------- Category sections (hub) ---------- */
.tool-section { margin-top: 36px; }
.tool-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 4px;
  font-size: 1.25rem;
  letter-spacing: -.015em;
}
.tool-section-title::before {
  content: "";
  width: 4px;
  height: 1.15em;
  border-radius: 2px;
  background: var(--brand);
}
.tool-section > p { color: var(--muted); margin: 0; font-size: .95rem; }

/* ---------- Cards & grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 24px 0 8px;
}
@media (min-width: 640px) { .tool-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .tool-grid { grid-template-columns: repeat(3, 1fr); } }

.tool-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.tool-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: var(--brand);
  box-shadow: 0 6px 16px rgba(32, 29, 26, .10);
}
.tool-card h2, .tool-card h3 { margin: 0 0 6px; font-size: 1.12rem; color: var(--ink); letter-spacing: -.01em; }
.tool-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.tool-card .badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--green);
  margin-bottom: 8px;
}
.tool-card .badge.soon { color: var(--faint); }

/* ---------- Tool UI ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.dropzone p { margin: 6px 0; }
.dropzone .hint { color: var(--faint); font-size: .85rem; }

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }

label { font-weight: 600; font-size: .95rem; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
select, input[type="number"], input[type="text"], textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  max-width: 100%;
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  color: var(--green);
  font-weight: 600;
}

/* ---------- Ad slot: fixed size, empty, no layout shift ---------- */
.ad-slot {
  min-height: 250px;
  margin: 32px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(45deg, #f3eee5, #f3eee5 10px, #ece6d9 10px, #ece6d9 20px);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--faint);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* ---------- Content (500+ word sections, FAQ) ---------- */
.content { max-width: 75ch; padding-bottom: 16px; }
.content h2 { font-size: 1.4rem; margin: 2rem 0 .5rem; letter-spacing: -.015em; }
.content h3 { font-size: 1.1rem; margin: 1.5rem 0 .25rem; }
.content p, .content li { color: var(--content); }
.content ul, .content ol { padding-left: 1.4rem; }

.faq details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 10px 0;
}
.faq summary { font-weight: 600; cursor: pointer; }
.faq details p { margin: 8px 0 2px; }

/* ---------- Tool controls & results ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 18px;
}
@media (min-width: 700px) { .controls { grid-template-columns: repeat(3, 1fr); align-items: end; } }
.control label { display: block; margin-bottom: 4px; }
.control select, .control input { width: 100%; }

.results { margin-top: 24px; }
.results-title { margin: 0 0 4px; font-size: 1.2rem; }
.results-summary { margin: 0 0 12px; color: var(--green); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.results-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.results-table th, .results-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.saved { color: var(--green); font-weight: 700; }
.larger { color: var(--red); font-weight: 700; }
.btn-small { padding: 6px 12px; font-size: .85rem; border-radius: 6px; }
.results-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Queue & progress (tool workflow) ---------- */
.queue { margin-top: 14px; }
.queue-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
.queue-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.queue-list li:last-child { border-bottom: 0; }
.queue-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg);
}
.queue-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .9rem;
}
.queue-size { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.queue-remove {
  background: none;
  border: 0;
  color: var(--faint);
  cursor: pointer;
  font-size: 1.15rem;
  padding: 4px 8px;
  line-height: 1;
}
.queue-remove:hover { color: var(--brand); }

.actions-row { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

.progress-wrap { margin-top: 16px; }
.progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width .2s ease;
}
.progress-status { font-size: .85rem; color: var(--muted); margin: 6px 0 0; }

/* Indeterminate progress (for blocking WASM jobs) — compositor-thread animation */
.progress-bar.indeterminate {
  width: 40%;
  transition: none;
  animation: indet-slide 1.1s ease-in-out infinite;
}
@keyframes indet-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(320%); }
}
@media (prefers-reduced-motion: reduce) {
  .progress-bar.indeterminate { animation: none; width: 100%; opacity: .4; }
}

/* ---------- Text tools ---------- */
.text-tool textarea {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  font: inherit;
  line-height: 1.55;
  padding: 12px 14px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat-num { display: block; font-size: 1.25rem; font-weight: 800; color: var(--brand); letter-spacing: -.02em; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.output-meta { color: var(--muted); font-size: .88rem; margin: 10px 0 0; }
.checkbox-row { display: flex; gap: 8px 20px; flex-wrap: wrap; margin-top: 12px; font-size: .92rem; }
.checkbox-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.checkbox-row input { accent-color: var(--brand); }
.field-row { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
@media (min-width: 640px) { .field-row { grid-template-columns: 1fr 1fr; } }
.field-row label { display: block; margin-bottom: 4px; }
.field-row input[type="text"] { width: 100%; }

/* ---------- Random tools (wheel / dice / coin) ---------- */
.wheel-layout { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 780px) { .wheel-layout { grid-template-columns: 1fr auto; } }
.wheel-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#wheel { max-width: 100%; height: auto; }
.winner-banner {
  background: var(--green);
  color: #fff;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 1.15rem;
  animation: pop-in .3s ease;
}
@keyframes pop-in {
  0% { transform: scale(.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.dice-stage {
  margin-top: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: radial-gradient(ellipse at 50% 25%, var(--surface), var(--bg));
  overflow: hidden;
}
.dice-stage:empty { display: none; }
.dice-stage canvas { max-width: 100%; display: block; }
.dice-results { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; min-height: 56px; }
.die {
  width: 56px;
  height: 56px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: die-tumble .45s ease backwards;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .18));
}
.die-6 { border-radius: 12px; }
.die-4 { clip-path: polygon(50% 2%, 2% 98%, 98% 98%); }            /* triangle */
.die-8 { clip-path: polygon(50% 2%, 98% 50%, 50% 98%, 2% 50%); }    /* diamond */
.die-10 { clip-path: polygon(50% 2%, 98% 38%, 82% 98%, 18% 98%, 2% 38%); } /* kite */
.die-12 { clip-path: polygon(50% 0, 98% 34%, 79% 90%, 21% 90%, 2% 34%); }  /* pentagon */
.die-20 { clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%); } /* hexagon */
.die-pips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 9px;
  gap: 2px;
}
.pip { width: 8px; height: 8px; border-radius: 50%; background: #fff; place-self: center; }
.result-chip {
  display: inline-flex;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 700;
  color: var(--ink);
  animation: pop-in .25s ease backwards;
}
@keyframes die-tumble {
  0% { transform: rotate(-28deg) scale(.4); opacity: 0; }
  60% { transform: rotate(8deg) scale(1.08); }
  100% { transform: rotate(0) scale(1); opacity: 1; }
}

/* 3D two-faced coin */
.coin3d { width: 130px; height: 130px; margin: 10px auto; perspective: 700px; }
.coin-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 1.1s cubic-bezier(.2, .8, .25, 1);
}
.coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  font-weight: 800;
  color: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  user-select: none;
}
.coin-face::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
}
.coin-heads { background: radial-gradient(circle at 35% 30%, #e0875a, #c2410c 70%); }
.coin-tails {
  background: radial-gradient(circle at 35% 30%, #8a8378, #57514a 70%);
  transform: rotateY(180deg);
}

/* ---------- Typing test ---------- */
.typing-sample {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 1.05rem;
  line-height: 1.9;
  letter-spacing: .01em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  margin-top: 14px;
  user-select: none;
}
.char-ok { color: var(--green); }
.char-bad { background: var(--red); color: #fff; border-radius: 3px; }
.char-cur { text-decoration: underline; text-decoration-color: var(--brand); text-decoration-thickness: 2px; }

/* ---------- Footer ---------- */
.site-footer {
  background: #1c1a17;
  color: #cfc9be;
  margin-top: 64px;
  padding: 32px 0;
  font-size: .9rem;
  flex-shrink: 0;
}
.site-footer a { color: #cfc9be; }
.site-footer a:hover { color: #fff; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 12px; }
.site-footer p { margin: 0; color: #8f887c; }
