/* Glottle — a small language field guide: paper, ink, rules, and one green
   accent. The tree is the interface; the surrounding UI should stay quiet. */
:root {
  --paper:  #e8f0f2;
  --paper2: #f7fbfb;
  --card:   #ffffff;
  --ink:    #172c35;
  --ink-soft:#62777e;
  --frame:  #d5e1e4;
  --frame2: #9fb7bd;
  --leaf:   #147866;
  --gold:   #c28726;   /* the target's revealed lineage */
  --gold-ink:#76500e;
  /* warmth ramp: cold(blue) -> hot(red), solved = leaf-green */
  --w0:#9aa3ad; --w1:#5b8def; --w2:#1aa39c; --w3:#e0a52e;
  --w4:#ec7a30; --w5:#db4b3f; --w6:#3aa757;
  --shadow: 0 12px 32px #23444d12;
}
* { box-sizing: border-box; }
/* The palette above is a deliberate single light theme. Declare it, so a
   browser in dark mode does not auto-invert form controls against it. */
html { color-scheme: light; }
html, body { margin: 0; }

/* Visible to screen readers only — used for the guess input's label. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
body {
  background:
    radial-gradient(circle at 8% -12%, #b5ded5 0, transparent 32%),
    radial-gradient(circle at 100% 20%, #cfdeee 0, transparent 28%),
    linear-gradient(145deg, #e5eff2 0%, #f4f8f7 52%, #e1ecec 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--leaf); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { font-family: "Fredoka", system-ui, sans-serif; margin: 0; }
.wrap { max-width: 980px; margin-inline: auto; padding: 28px 22px 46px; }

/* ---- header ---- */
.top { display: grid; grid-template-columns: minmax(220px, 1fr) auto;
  grid-template-areas: "brand controls" "tag controls"; align-items: center;
  column-gap: 36px; row-gap: 2px; }
.brand { grid-area: brand; display: inline-flex; align-items: center; gap: 10px; }
.brand .mark { display: block; width: 40px; height: 40px; flex: none; }
.brand h1 { font-size: 38px; font-weight: 700; letter-spacing: -1.2px; color: var(--ink); }
.streak-chip { font-size: 12px; font-weight: 800; color: var(--w4);
  background: #fbe4d2; background: color-mix(in srgb, var(--w4) 18%, var(--card));
  border: 1px solid var(--w4); border-radius: 999px; padding: 2px 9px;
  white-space: nowrap; }
.tag { grid-area: tag; margin: 0; max-width: 38ch; color: var(--ink-soft); font-size: 14px; text-wrap: balance; }
.controls { grid-area: controls; display: flex; align-items: end; justify-content: flex-end;
  gap: 14px; flex-wrap: wrap; }
.selector-block { display: flex; flex-direction: column; gap: 5px; }
/* Puzzle-day is a niche control, so on narrow screens it folds away (the
   script closes the details); desktop shows the seg outright. */
.fold > summary { cursor: pointer; list-style: none; user-select: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: " ▸"; }
.fold[open] > summary::after { content: " ▾"; }
@media (min-width: 761px) {
  .fold > summary { display: none; }
}
.selector-label { color: var(--ink-soft); font-size: 10px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase; }
.seg { display: inline-flex; gap: 2px; padding: 3px; background: #ffffffaa;
  border: 1px solid var(--frame); border-radius: 8px; box-shadow: 0 3px 10px #23444d0a; }
/* An author `display` beats the UA's `[hidden] { display: none }`, so every
   element this stylesheet gives a `display` to and the script toggles `hidden`
   on needs a rule like this one. */
.seg[hidden] { display: none; }
.seg-btn { min-height: 34px; font-family: "Nunito"; font-weight: 800; font-size: 13px;
  cursor: pointer; border: 0; background: transparent; color: var(--ink-soft);
  padding: 4px 11px; border-radius: 6px; white-space: nowrap; }
.seg.small .seg-btn { font-size: 12px; }
.seg-btn:hover { color: var(--ink); background: #dcece9; }
.seg-btn.active { color: #fff; background: var(--leaf); box-shadow: 0 2px 5px #14786640; }

/* ---- play bar ---- */
.playbar { display: flex; gap: 12px; align-items: center; margin-top: 30px; }
.ac-wrap { position: relative; flex: 1; }
#guess-input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  font-family: "Nunito"; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--frame2); border-radius: 8px;
  box-shadow: inset 0 1px 2px #0000000c;
}
#guess-input::placeholder { color: #a99f8c; font-weight: 400; }
#guess-input:focus { outline: none; border-color: var(--leaf);
  box-shadow: inset 0 1px 2px #0000000c, 0 0 0 3px #14786659;
  box-shadow: inset 0 1px 2px #0000000c, 0 0 0 3px color-mix(in srgb, var(--leaf) 35%, transparent); }
.count { font-family: "Nunito"; font-weight: 800; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 15px; }

.ac-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px); margin: 0;
  list-style: none; padding: 6px; background: var(--card);
  border: 2px solid var(--frame2); border-radius: 14px; max-height: 340px; overflow: auto;
  box-shadow: 0 18px 40px #3a2f1626;
}
.ac-list li { padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-weight: 700; }
.ac-list li:hover, .ac-list li.sel { background: var(--leaf); color: #fff; }
.ac-fam { color: var(--ink-soft); font-size: 12px; font-weight: 400; }
.ac-list li:hover .ac-fam, .ac-list li.sel .ac-fam { color: #eaf6f1; }

/* ---- feedback line (reacts to last guess) ---- */
.feedback { margin: 14px 0 8px; padding: 0; border: 0; border-radius: 0;
  background: none; font-size: 15px; font-weight: 700; text-align: left; text-wrap: balance; }
.feedback b { font-weight: 800; }
.feedback.w5, .feedback.w6 { color: var(--leaf); }

.banner { margin-top: 12px; padding: 12px 0; border-top: 1px solid var(--frame2);
  border-bottom: 1px solid var(--frame2); font-size: 16px; text-align: left; font-weight: 700; }
/* Winning is the moment that drives sharing — it should look like one. */
.banner.won { background: #e3f2ec; background: color-mix(in srgb, var(--leaf) 10%, var(--card));
  border: 1.5px solid var(--leaf); border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 8px 24px #14786622; }
.banner .muted { color: var(--ink-soft); font-weight: 400; }

/* ---- the tree: the hero ---- */
.board { margin-top: 18px; background: var(--card); border: 1px solid var(--frame);
  border-radius: 14px; padding: 9px 9px 5px; box-shadow: var(--shadow); }
.board-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px;
  padding: 8px 12px 6px; }
.board-head h2 { font-size: 18px; font-weight: 500; }
/* status and the reveal button ride together on the right of the heading */
.board-head .status { margin-left: auto; }
#reveal-btn { flex: none; align-self: center; }
.legend-strip { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0 12px 8px;
  color: var(--ink-soft); font-size: 11.5px; font-weight: 700; }
.legend-strip span { display: inline-flex; align-items: center; gap: 5px; }
.legend-strip .dot { width: 9px; height: 9px; transform: none; }
.pan-hint { margin-left: auto; color: var(--frame2); font-weight: 800; }
.status { color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.tree-scroll { position: relative; overflow: auto; min-height: 300px; max-height: 540px;
  border-radius: 8px; background: var(--paper2); }
.tree { display: block; }
.tree-empty { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: var(--ink-soft); font-weight: 700; font-size: 15px; }
.tree-empty[hidden] { display: none; }
.edge { fill: none; stroke: var(--frame2); stroke-width: 2; }
.edge.on { stroke: var(--gold); stroke-width: 2.8;
  /* gold sits close to the warm oranges for deuteranopes, so the revealed
     lineage is dashed as well as coloured — pattern, not hue alone */
  stroke-dasharray: 7 4; }
.cnode { fill: var(--frame2); }
.cnode.on { fill: var(--gold); stroke: var(--card); stroke-width: 1.5; }
.clade-label { fill: var(--ink-soft); font-family: "Nunito"; font-style: italic; font-size: 12px; }
.clade-label.on { fill: var(--gold-ink); font-style: normal; font-weight: 800; }
.chip { stroke-width: 2; }
.chip-label { font-family: "Nunito"; font-weight: 800; font-size: 14.5px; fill: var(--ink); }
.chip.warm-0 { fill: color-mix(in srgb, var(--w0) 20%, var(--card)); stroke: var(--w0); }
.chip.warm-1 { fill: color-mix(in srgb, var(--w1) 18%, var(--card)); stroke: var(--w1); }
.chip.warm-2 { fill: color-mix(in srgb, var(--w2) 18%, var(--card)); stroke: var(--w2); }
.chip.warm-3 { fill: color-mix(in srgb, var(--w3) 22%, var(--card)); stroke: var(--w3); }
.chip.warm-4 { fill: color-mix(in srgb, var(--w4) 22%, var(--card)); stroke: var(--w4); }
.chip.warm-5 { fill: color-mix(in srgb, var(--w5) 22%, var(--card)); stroke: var(--w5); }
.chip.warm-6 { fill: color-mix(in srgb, var(--w6) 24%, var(--card)); stroke: var(--w6); }
.chip.target { fill: color-mix(in srgb, var(--gold) 22%, var(--card)); stroke: var(--gold);
  stroke-dasharray: 5 4; }
.chip-label.target { fill: var(--gold-ink); }

/* ---- lower: guesses + hints ---- */
.lower { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 22px; }
.card { background: #ffffffc9; border: 1px solid var(--frame); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 500; }

.guesses { display: flex; flex-direction: column; gap: 9px; }
.guesses:empty::after { content: "No guesses yet."; color: var(--ink-soft); font-size: 14px; }
.guess { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px;
  border: 0; border-bottom: 1px solid var(--frame); border-left: 3px solid var(--gm);
  border-radius: 0; padding: 9px 0 9px 10px; background: none; }
.g-main { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.g-name { font-weight: 800; font-size: 15.5px; }
.language-link { color: inherit; text-decoration: underline; text-decoration-color: var(--frame2); }
.language-link:hover { color: var(--leaf); text-decoration-color: currentColor; }
.g-band { font-size: 12.5px; font-weight: 800; color: var(--gm); }
.g-sub { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; margin-top: 0;
  font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.g-geo { white-space: nowrap; }
.meter { grid-column: 1 / -1; height: 3px; background: #00000010; border-radius: 0; margin-top: 5px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 0; background: var(--gm); }
.gm-0{--gm:var(--w0);} .gm-1{--gm:var(--w1);} .gm-2{--gm:var(--w2);} .gm-3{--gm:var(--w3);}
.gm-4{--gm:var(--w4);} .gm-5{--gm:var(--w5);} .gm-6{--gm:var(--w6);}

.hints { display: flex; flex-direction: column; gap: 8px; }
.hints:empty::after { content: "Tap “Reveal a hint” for a clue about the mystery language.";
  color: var(--ink-soft); font-size: 14px; }
.hint { display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 9px 0; border-radius: 0; background: none;
  border: 0; border-bottom: 1px solid var(--frame); animation: pop .18s ease; }
.hint .h-l { color: var(--ink-soft); font-weight: 700; font-size: 13.5px; }
.hint .h-v { font-weight: 800; text-align: right; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } to { transform: none; opacity: 1; } }
/* solved tree: chips pop in, the revealed lineage marches twice, then rests */
.tree.celebrate .chip { animation: pop .35s ease backwards;
  transform-box: fill-box; transform-origin: center; }
.tree.celebrate .edge.on { animation: march 1.1s linear 2; }
@keyframes march { to { stroke-dashoffset: -22; } }
@media (prefers-reduced-motion: reduce) {
  .tree.celebrate .chip, .tree.celebrate .edge.on { animation: none; }
}
@media (prefers-reduced-motion: reduce) { .hint { animation: none; } }

/* ---- buttons ---- */
.pill-btn { font-family: "Nunito"; font-weight: 800; font-size: 13.5px; cursor: pointer;
  border: 1px solid var(--frame2); background: transparent; color: var(--ink);
  border-radius: 8px; padding: 6px 11px; }
.pill-btn:hover { border-color: var(--leaf); color: var(--leaf); }
.pill-btn:disabled { opacity: .5; cursor: default; border-color: var(--frame2); color: var(--ink-soft); }
.pill-btn.primary { background: var(--leaf); color: #fff; border-color: var(--leaf); }
.pill-btn.primary:hover { filter: brightness(1.05); color: #fff; }
/* the 404 page uses a link where the game uses a button */
a.pill-btn { display: inline-block; text-decoration: none; }
a.pill-btn:hover { text-decoration: none; }
.text-btn { font-family: "Nunito"; font-weight: 700; font-size: 14px; cursor: pointer;
  background: none; border: 0; color: var(--ink-soft); text-decoration: underline; padding: 8px; }
.text-btn:hover { color: var(--w5); }
.foot-actions { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 20px; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--leaf) 55%, transparent); outline-offset: 2px; }
footer { margin-top: 22px; text-align: center; color: var(--ink-soft); font-size: 12.5px; line-height: 1.9; }

/* ---- transient messages ----------------------------------------------------
   Its own element rather than the status line: overwriting the status with
   "Already guessed" used to leave the player with no way back to knowing which
   puzzle they were on. */
.toast {
  margin-top: 14px; padding: 10px 14px; border-radius: 14px; text-align: center;
  font-size: 14px; font-weight: 700; color: var(--gold-ink);
  background: #f4e8d3; background: color-mix(in srgb, var(--gold) 12%, var(--card));
  border: 1.5px solid #dcbb85; border: 1.5px solid color-mix(in srgb, var(--gold) 45%, var(--card));
  animation: pop .18s ease;
}
.toast[hidden] { display: none; }

/* ---- end-of-game stats + countdown ---------------------------------------- */
.stats { display: flex; justify-content: center; gap: 22px; margin-top: 12px;
  padding-top: 12px; border-top: 1px solid var(--frame2); }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.stat b { font-family: "Fredoka", system-ui, sans-serif; font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .06em; }
.countdown { margin-top: 10px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.countdown b { font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---- how-to-play ---------------------------------------------------------- */
.help {
  max-width: 520px; width: calc(100% - 32px); padding: 24px;
  border: 1px solid var(--frame2); border-radius: 14px;
  background: var(--card); color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif; font-size: 14.5px; line-height: 1.6;
  box-shadow: 0 24px 60px #3a2f1633;
}
.help::backdrop { background: #34303a66; }
.help h2 { font-size: 24px; font-weight: 600; margin-bottom: 10px; }
.help p { margin: 0 0 12px; }
.help .legend { list-style: none; padding: 0; margin: 0 0 14px; }
.help .legend li { display: flex; align-items: baseline; gap: 9px; padding: 3px 0; }
.dot { flex: none; display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  transform: translateY(1px); }
.dot.w0 { background: var(--w0); } .dot.w1 { background: var(--w1); }
.dot.w2 { background: var(--w2); } .dot.w3 { background: var(--w3); }
.dot.w4 { background: var(--w4); } .dot.w5 { background: var(--w5); }
.help form { margin-top: 6px; text-align: right; }

/* The tree is scrollable and focusable, so it needs a visible focus ring. */
.tree-scroll:focus-visible { outline-offset: -3px; }

@media (max-width: 760px) {
  .wrap { padding: 22px 16px 36px; }
  .top { grid-template-columns: 1fr; grid-template-areas: "brand" "tag" "controls";
    row-gap: 4px; }
  .tag { max-width: 48ch; }
  .controls { justify-content: flex-start; align-items: stretch; margin-top: 10px; gap: 10px; }
  .selector-block { flex: 1 1 210px; }
  .controls > .pill-btn { align-self: end; min-height: 40px; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding-inline: 7px; }
}

@media (max-width: 560px) {
  .wrap { padding: 16px 12px 36px; }
  .brand h1 { font-size: 28px; }
  .brand .mark { width: 32px; height: 32px; }
  .tag { font-size: 13px; }
  /* row, not a stack: the input and the tree should own the first screen */
  .controls { flex-direction: row; flex-wrap: wrap; align-items: end; gap: 8px; }
  .selector-block { flex: 1 1 150px; width: auto; }
  .controls > .pill-btn { width: auto; min-height: 40px; flex: none; }
  .playbar { flex-wrap: wrap; margin-top: 22px; }
  .ac-wrap { flex-basis: 100%; }
  .count { margin-left: auto; }
  .board { margin-top: 14px; padding: 7px 7px 4px; }
  .board-head { display: block; padding-inline: 8px; }
  .status { display: block; margin-top: 2px; }
  #reveal-btn { margin-top: 8px; }
  .tree-scroll { min-height: 260px; max-height: 430px; }
  .lower { grid-template-columns: 1fr; gap: 14px; margin-top: 16px; }
  .card { padding: 14px; }
  .g-main { gap: 6px; }
  .g-band { text-align: right; }
  .g-sub { flex-wrap: wrap; }
  .hint .h-v { max-width: 58%; }
  .foot-actions { flex-wrap: wrap; gap: 8px; }
  footer { margin-top: 18px; }
}
