:root {
  --bg: #14161c;
  --panel: #1e212b;
  --panel-2: #262a37;
  --line: #343a4b;
  --ink: #eef1f7;
  --muted: #99a1b5;
  --accent: #7cc4ff;
  --accent-ink: #0d1017;
  --good: #58d68d;
  --bad: #f1746b;
  --hover: rgba(124, 196, 255, .08);
  /* Dark-theme logo: black and dark blue would vanish, so the same three steps, lightened. */
  --logo-th: #eef1f7;
  --logo-wo: #4f95dd;
  --logo-p: #9aa3b2;
  --field: #262a37;
  --field-line: #4a5268;
  --go: #eef1f7;
  --go-ink: #0d1017;
  --gauge-track: #3a4050;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa;
    --panel: #ffffff;
    --panel-2: #eef0f6;
    --line: #d5d9e4;
    --ink: #151923;
    --muted: #5d6579;
    --accent: #1f6fbf;
    --accent-ink: #ffffff;
    --good: #1e8e4f;
    --bad: #c8382d;
    --hover: rgba(31, 111, 191, .07);
    --logo-th: #111418;
    --logo-wo: #1d4f8a;
    --logo-p: #6b7280;
    --field: #ffffff;
    --field-line: #b9bfcc;
    --go: #151923;
    --go-ink: #ffffff;
    --gauge-track: #d3d7df;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  padding: .75rem .75rem 2rem;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 760px; margin: 0 auto; }
a { color: var(--accent); }

header.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.brand {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
  text-decoration: none;
}
/* TH-WO-P: THree WOrd Puzzle */
.brand .th { color: var(--logo-th); }
.brand .wo { color: var(--logo-wo); }
.brand .p { color: var(--logo-p); }
.icon { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
.icon .dot { stroke-width: 3; }
/* Each header control has a ~44px touch target (icon plus padding); the negative margin keeps
   the visual spacing, and the gap is wider than two paddings so the targets never overlap. */
header.top nav { display: flex; align-items: center; gap: 1.5rem; }
a.icon-link { display: block; padding: .55rem; margin: -.55rem; color: var(--muted); }
a.icon-link:hover { color: var(--accent); }
button.icon-btn { display: block; padding: .55rem; margin: -.55rem; border: 0; background: none; color: var(--muted); }
button.icon-btn:hover { color: var(--accent); background: none; }
button.icon-btn .icon, a.icon-link .icon { width: 1.7rem; height: 1.7rem; stroke-width: 2.2; }

/* Difficulty gauge and its pop-up list */
.gauge { width: 1.9rem; height: 1.45rem; display: block; fill: none; stroke-linecap: round; }
button.icon-btn .gauge { width: 2.3rem; height: 1.75rem; }
.gauge .track { stroke: var(--gauge-track); stroke-width: 3.6; }
.gauge .level { stroke-width: 3.6; }
.gauge.easy .level { stroke: #4cae67; }
.gauge.medium .level { stroke: #e9b90e; }
.gauge.hard .level { stroke: #e0524a; }
.gauge .needle { stroke: var(--muted); stroke-width: 1.8; }
.gauge .hub { fill: var(--muted); }
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: -4rem;
  top: calc(100% + .5rem);
  z-index: 10;
  min-width: 11rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  padding: .4rem;
}
.menu-title { font-size: .8rem; color: var(--muted); padding: .25rem .5rem .35rem; }
button.menu-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ink);
  padding: .45rem .5rem;
  font-weight: 600;
  text-align: left;
}
button.menu-item:hover { background: var(--hover); }
button.menu-item.current { background: var(--panel-2); box-shadow: inset 0 0 0 1.5px var(--accent); }
.menu-icon { display: block; }
h1.page-title { font-size: 1.2rem; margin: 0 0 .75rem; }

p.lede { margin: 0 0 1.25rem; color: var(--muted); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card > :first-child { margin-top: 0; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }

/* ---- Play area: no surrounding box, so the grid gets the full width on phones ---- */
form.play { margin-bottom: .35rem; }
.clue-row { display: flex; gap: .5rem; margin: 5px 0 .75rem; }
.clue-row input[type=text] { flex: 1; min-width: 0; font-size: 16px; /* 16px stops iOS zooming on focus */ background: var(--field); border-color: var(--field-line); }
.clue-row button { flex: none; }
/* Puzzle page: the clue box sits where the clue field is on the create page, with Submit
   beside it; once Submit is hidden the box takes the full width. */
.clue-row .clue-box { flex: 1; min-width: 0; margin: 0; }
.clue-box.stacked { display: block; padding: .35rem .75rem .4rem; }
.clue-box.stacked .label { font-size: .68rem; line-height: 1.3; }
.clue-box.stacked .clue { font-size: 1.45rem; line-height: 1.15; }
.define .bad { color: var(--bad); font-weight: 600; }
form.play .feedback { margin: 0 0 .6rem; font-size: .92rem; }
form.play .feedback:empty { display: none; }
p.how { color: var(--muted); font-size: .9rem; margin: 1.25rem 0 0; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem; }

/* ---- Word grid: three lists side by side, hidden radios inside clickable cells ---- */
.lists { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; margin-bottom: .8rem; min-height: 9.6rem; }
.listgroup { border: 0; margin: 0; padding: 0; min-width: 0; }
/* The legend is for screen readers; the columns speak for themselves visually. */
.listgroup legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.wordlist {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.word { display: block; position: relative; cursor: pointer; }
.word + .word { border-top: 1px solid var(--line); }
.word input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.word .text {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 3.1rem;
  padding: .3rem .3rem;
  font-size: 1rem;
  line-height: 1.2;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: anywhere;
}
.word .text.long { font-size: .88rem; }
.word .text.longer { font-size: .78rem; }
@media (hover: hover) { .word:hover { background: var(--hover); } }
.word:has(input:checked) { background: var(--accent); }
.word:has(input:checked) .text { color: var(--accent-ink); font-weight: 700; }
.word:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent); }

.listgroup.locked .wordlist { border-color: var(--good); }
.listgroup.locked .word:has(input:checked) { background: var(--good); }
.listgroup.locked .word:not(:has(input:checked)) .text { opacity: .45; }
.listgroup.locked .word { cursor: default; }
.listgroup.wrong .wordlist { border-color: var(--bad); animation: shake .35s; }
.listgroup.answer .word:has(input:checked) { background: var(--good); }
@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
@media (prefers-reduced-motion: reduce) { .listgroup.wrong .wordlist { animation: none; } }

.define:empty { display: none; }
.define {
  font-size: .92rem;
  line-height: 1.4;
  margin-bottom: .5rem;
}
.define strong { color: var(--accent); }
.define a { white-space: nowrap; }

/* ---- Clue ---- */
.clue-box {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem .8rem;
  margin-bottom: .6rem;
}
.label {
  font-size: .75rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.clue { font-size: 1.6rem; font-weight: 800; color: var(--accent); overflow-wrap: anywhere; line-height: 1.2; }

/* ---- Controls ---- */
label.field { display: block; margin-bottom: .4rem; font-weight: 600; }
input[type=text], input[type=email] {
  width: 100%;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .75rem;
  font: inherit;
}
input[type=text]:focus, input[type=email]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .5rem;
  font: inherit;
}
button, a.btn {
  display: inline-block;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: .65rem 1.2rem;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button.go { background: var(--go); color: var(--go-ink); border-color: var(--go); font-weight: 700; }
button.go:hover { background: var(--go); }
button.primary, a.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
button:hover, a.btn:hover { filter: brightness(1.08); background-color: var(--hover); }
button.primary:hover, a.btn.primary:hover { background: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font-weight: 400;
  text-decoration: underline;
}
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .75rem; }
.toolbar { display: flex; gap: .6rem; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
.toolbar label { display: inline-flex; gap: .4rem; align-items: center; }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.feedback { min-height: 1.5em; margin: 0; font-weight: 600; }
.feedback.bad { color: var(--bad); }
.feedback.good { color: var(--good); }
.error {
  background: rgba(241, 116, 107, .12);
  border: 1px solid var(--bad);
  border-radius: 8px;
  padding: .75rem 1rem;
  margin: 0 0 1rem;
}
.verdict { font-size: 1.4rem; font-weight: 800; margin: 0 0 .75rem; }
.verdict.win { color: var(--good); }
.link-out {
  display: block;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .75rem;
  font: .9rem/1.4 ui-monospace, "Cascadia Code", Consolas, monospace;
  word-break: break-all;
  text-decoration: none;
}
pre.result {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem 1rem;
  white-space: pre-wrap;
  font: inherit;
  margin: 0;
}
.identify { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.identify .row { margin-top: .5rem; }
.identify label.field { font-size: .95rem; font-weight: 600; }
.identify .name-line { margin: 0; }
.identify input { flex: 1 1 12rem; width: auto; }

/* ---- History ---- */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
table.list tr.detail td { background: var(--panel-2); }
table.list td.date { white-space: nowrap; }
table.list .toggle-cell { width: 2rem; padding-left: 0; padding-right: 0; text-align: center; }
table.list th.toggle-cell .icon { width: 1rem; height: 1rem; fill: var(--muted); vertical-align: middle; }
button.toggle {
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  line-height: 1;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 6px;
}
.empty { color: var(--muted); }
.muted { color: var(--muted); }

footer { color: var(--muted); font-size: .8rem; margin-top: 2rem; text-align: center; }
footer a { color: var(--muted); }
.prose p, .prose li { color: var(--ink); }
.prose h1 { font-size: 1.5rem; margin-top: 0; }
[hidden] { display: none !important; }

/* Panels shown after creating/solving sit on the page like the play area. */
#after { margin-bottom: 1rem; }
#after > :first-child { margin-top: 0; }
#after .row { margin-top: .6rem; }

/* On phones, boxes around content cost two sets of margins; drop them. */
@media (max-width: 560px) {
  .card { background: none; border: 0; border-radius: 0; padding: 0; margin-bottom: 1.5rem; }
  button, a.btn { padding: .55rem .75rem; font-size: .95rem; }
  /* Four buttons (Share, Copy link, Email, New Thwop) on one line even at 360px. */
  .share-row { gap: .4rem; }
  .share-row button, .share-row a.btn { padding: .5rem .6rem; font-size: .9rem; }
}

/* Instructions and footer sit at the bottom of the screen; the space above them takes a
   definition of any length. Normal flow (not position: fixed), so nothing is ever covered. */
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: .75rem; }
main { flex: 1; display: flex; flex-direction: column; width: 100%; }
main > footer { margin-top: auto; padding-top: 1.25rem; }
/* The instructions start just under the play area. Once the definition line is in use
   (main.defined, set by app.js) they move down to sit on the footer. */
main > p.how { margin-top: .25rem; }
main.defined > p.how { margin-top: auto; }
main.defined > p.how:not([hidden]) ~ footer { margin-top: 0; padding-top: .75rem; }

/* A box (puzzle link or result) with a copy button tucked into its top-right corner. */
.copy-box { position: relative; }
.copy-box .link-out, .copy-box pre.result { padding-right: 2.8rem; }
button.copy-btn {
  position: absolute;
  top: .3rem;
  right: .3rem;
  padding: .3rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
}
button.copy-btn:hover { color: var(--accent); background: var(--hover); }
button.copy-btn.done { color: var(--good); }
button.copy-btn .icon { width: 1.2rem; height: 1.2rem; }
.share-row { justify-content: space-between; }
.share-row .next { margin-left: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

