/* WordTools — plain CSS, no preprocessor, no framework. */

:root {
  --green:  #6aaa64;
  --yellow: #c9b458;
  --gray:   #787c7e;

  --bg:       #ffffff;
  --bg-sunk:  #f4f5f7;
  --fg:       #1a1c1f;
  --fg-dim:   #6a7078;
  --line:     #d8dbe0;
  --line-soft:#e8eaee;
  --accent:   #2f6f4f;
  /* Focus must not be green/yellow/gray — those three already mean something here. */
  --focus:    #0b63ce;
  --danger-bg:#fdecea;
  --danger-fg:#8a2418;
  --danger-line:#f0b4ac;

  --tile:     3.1rem;
  --radius:   8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green:  #538d4e;
    --yellow: #b59f3b;
    --gray:   #3a3d40;

    --bg:       #14161a;
    --bg-sunk:  #1b1e23;
    --fg:       #e3e6ea;
    --fg-dim:   #939aa4;
    --line:     #2e333a;
    --line-soft:#23272d;
    --accent:   #7fc79b;
    --focus:    #7ab8ff;
    --danger-bg:#3a1f1c;
    --danger-fg:#ffb4a8;
    --danger-line:#6b3029;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

main { max-width: 46rem; margin: 0 auto; padding: 0 1rem 3rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  max-width: 46rem; margin: 0 auto; padding: 1rem;
}
.topbar h1 {
  font-size: 1.15rem; margin: 0; letter-spacing: -.01em; font-weight: 700;
}
.topbar h1 span { color: var(--fg-dim); font-weight: 400; }

.lengthctl { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.lengthctl > label { color: var(--fg-dim); font-size: .82rem; text-transform: uppercase;
                     letter-spacing: .05em; margin-right: .1rem; }
.lengthctl output {
  font-variant-numeric: tabular-nums; font-weight: 700; min-width: 2ch;
  text-align: center; font-size: 1.05rem;
}
.step {
  width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font-size: 1rem; line-height: 1; cursor: pointer;
}
.step:hover { border-color: var(--fg-dim); }
.ghostbtn {
  border: 1px solid var(--line); background: transparent;
  color: var(--fg-dim); border-radius: 999px; padding: .2rem .8rem;
  font-size: .85rem; cursor: pointer;
}
.ghostbtn:hover { color: var(--fg); border-color: var(--fg-dim); }

/* ---------------------------------------------------------------- board */
.board { margin-top: .5rem; }

/* One grid track per slot, capped at --tile but free to shrink below it, so a long
   word narrows its tiles instead of wrapping onto a second line. --n is set from
   ui.js; the not-here strip reads the same value, which is what keeps the two rows
   in step. minmax(0, ...) (not just var(--tile)) is what allows the shrink. */
.tiles, .nothere-row {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), minmax(0, var(--tile)));
  gap: .4rem;
}

/* The tile IS the colour control: clicking it advances gray -> yellow -> green,
   and also focuses it so you can retype straight away. */
/* min-width: 0 defeats the automatic minimum size a grid item gets from its
   content -- an <input> reports a ~20-character min-content width, which would
   push the row wide enough to overflow. container-type lets the letter size
   follow the tile (cqi = 1% of the tile's width) once the tiles start shrinking. */
.tile { min-width: 0; container-type: inline-size; }
.tile input {
  width: 100%; aspect-ratio: 1; cursor: pointer;
  font: 700 1.5rem/1 var(--mono); font-size: min(1.5rem, 52cqi);
  text-align: center; text-transform: uppercase;
  color: var(--fg); background: var(--bg-sunk);
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: 0; caret-color: transparent;
}
.tile input:focus { outline: none; border-color: var(--fg-dim); }
.tile input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tile input:hover { filter: brightness(1.06); }

.tile[data-color="green"]  input { background: var(--green);  border-color: var(--green);  color: #fff; }
.tile[data-color="yellow"] input { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.tile[data-color="gray"]   input { background: var(--gray);   border-color: var(--gray);   color: #fff; }

/* ------------------------------------------------------------ not here */
.nothere { margin-top: .85rem; }
.nhlabel {
  display: block; color: var(--fg-dim); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: .25rem;
}
.nh { min-width: 0; container-type: inline-size; }
.nh input {
  width: 100%; height: 1.7rem; text-align: center; text-transform: uppercase;
  font: 600 .8rem/1 var(--mono); font-size: min(.8rem, 30cqi); letter-spacing: .04em;
  color: var(--fg); background: var(--bg);
  border: 1px dashed var(--line); border-radius: 6px; padding: 0 .15rem;
}
.nh input:focus { outline: none; border-color: var(--fg-dim); border-style: solid; }
.nh .derived {
  display: block; text-align: center; color: var(--fg-dim); opacity: .75;
  font: 600 .62rem/1.5 var(--mono); font-size: min(.62rem, 24cqi);
  text-transform: uppercase; letter-spacing: .06em;
  min-height: 1.1em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.hint { color: var(--fg-dim); font-size: .82rem; margin: .85rem 0 0; }
.hint kbd {
  font: inherit; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 .3rem; background: var(--bg-sunk);
}
.c-green  { color: var(--green); }
.c-yellow { color: var(--yellow); }
.c-gray   { color: var(--fg-dim); }

/* ------------------------------------------------------- letter panel */
.panel {
  margin: 1.5rem 0 0; padding: .9rem .95rem 1rem;
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: var(--bg-sunk);
  display: grid; gap: .7rem;
}

.chiprow { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.chiprow > label {
  color: var(--fg-dim); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .06em; width: 7.5rem; flex: none;
}
.chips { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.chipnone { color: var(--fg-dim); opacity: .6; font-size: .82rem; font-style: italic; }
.chip {
  display: inline-flex; align-items: center; gap: .12rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
  padding: .1rem .1rem .1rem .55rem; font-size: .85rem;
}
.chip.req { border-color: var(--yellow); }
.chip.ban { border-color: var(--line); opacity: .85; }
.chip b { font: 700 .95rem var(--mono); text-transform: uppercase; }
.chip button {
  border: 0; background: transparent; color: var(--fg-dim); cursor: pointer;
  font: inherit; padding: .05rem .3rem; border-radius: 999px; line-height: 1;
}
.chip button:hover:not(:disabled) { background: var(--bg-sunk); color: var(--fg); }
.chip button:disabled { opacity: .3; cursor: default; }
.chip .cnt { font-variant-numeric: tabular-nums; color: var(--fg-dim);
             font-size: .78rem; margin: 0 .1rem 0 .15rem; }
/* Set apart from the -/+ steppers so "remove" is never hit by accident. */
.chip .kill {
  font-size: 1rem; margin-left: .2rem; padding-left: .35rem;
  border-left: 1px solid var(--line-soft); border-radius: 0 999px 999px 0;
}

.addletter {
  width: 2.1rem; height: 1.9rem; text-align: center; text-transform: uppercase;
  font: 700 .9rem var(--mono); color: var(--fg); background: var(--bg);
  border: 1px dashed var(--line); border-radius: 6px; padding: 0;
}
.addletter:focus { outline: none; border-style: solid; border-color: var(--fg-dim); }

/* minmax(0, 1fr), not 1fr: a plain 1fr track has an auto (content-based) minimum,
   which the aspect-ratio below inflates, overflowing the page on narrow screens. */
.keyboard { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: .25rem; }
.keyboard button {
  position: relative; aspect-ratio: 1 / 1.15; min-width: 0; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--bg); color: var(--fg);
  font: 700 .82rem var(--mono); text-transform: uppercase;
}
.keyboard button[data-state="req"] { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.keyboard button[data-state="ban"] { background: var(--gray); border-color: var(--gray); color: #fff; }
.keyboard .badge {
  position: absolute; top: 1px; right: 3px;
  font: 700 .58rem/1 system-ui, sans-serif; opacity: .9;
}
/* A dot for what the TILES say, so both layers are readable at once. */
.keyboard button[data-derived]:not([data-derived=""])::after {
  content: ""; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: .34rem; height: .34rem; border-radius: 50%;
}
.keyboard button[data-derived="green"]::after  { background: var(--green); }
.keyboard button[data-derived="yellow"]::after { background: var(--yellow); }
.keyboard button[data-derived="gray"]::after   { background: var(--fg-dim); opacity: .6; }
.keyboard button[data-state=""][data-derived="green"]  { border-color: var(--green); }
.keyboard button[data-state=""][data-derived="yellow"] { border-color: var(--yellow); }

/* --------------------------------------------------------------- banner */
.banner {
  margin: 1.25rem 0 0; padding: .7rem .9rem; border-radius: var(--radius);
  background: var(--danger-bg); color: var(--danger-fg);
  border: 1px solid var(--danger-line); font-size: .9rem;
}
.banner ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.banner strong { display: block; }

/* -------------------------------------------------------------- results */
.results { margin-top: 1.5rem; border-top: 1px solid var(--line-soft); padding-top: .9rem; }
.resulthead {
  display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem;
}
.resulthead h2 { font-size: 1rem; margin: 0; font-weight: 700; }
.resultopts { display: flex; align-items: center; gap: .6rem; margin-left: auto;
              flex-wrap: wrap; font-size: .85rem; color: var(--fg-dim); }
.resultopts select {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: .15rem 1.4rem .15rem .4rem;
}
.resultopts .check { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.resultopts input[disabled] + span, .check:has(input[disabled]) { opacity: .5; cursor: not-allowed; }

.words { display: flex; flex-wrap: wrap; gap: .3rem; }
.words button {
  font: 600 .95rem var(--mono); text-transform: uppercase; letter-spacing: .06em;
  border: 1px solid var(--line-soft); background: var(--bg-sunk); color: var(--fg);
  border-radius: 5px; padding: .22rem .5rem; cursor: pointer;
}
.words button:hover { border-color: var(--fg-dim); }
.words button.copied { background: var(--green); border-color: var(--green); color: #fff; }
.words .divider {
  flex: 1 0 100%; display: flex; align-items: center; gap: .6rem;
  color: var(--fg-dim); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .07em; margin: .7rem 0 .3rem;
}
.words .divider::before, .words .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line-soft);
}
.empty { color: var(--fg-dim); font-size: .9rem; }

.more { margin-top: .9rem; }
.more button {
  font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--bg);
  color: var(--fg); border-radius: 999px; padding: .3rem 1rem; cursor: pointer;
}

footer {
  max-width: 46rem; margin: 0 auto; padding: 0 1rem 2rem;
  display: flex; gap: 1rem; color: var(--fg-dim); font-size: .78rem;
}
footer a { color: inherit; }

/* ---------------------------------------------------------------- phone */
@media (max-width: 34rem) {
  :root { --tile: 2.75rem; }
  main { padding-bottom: 2rem; }
  .topbar { padding: .8rem 1rem; row-gap: .6rem; }
  .lengthctl { margin-left: auto; }
  .chiprow > label { width: 100%; }
  .keyboard { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .tiles, .nothere-row { gap: .3rem; }
  .resultopts { margin-left: 0; width: 100%; }
}

@media (max-width: 26rem) {
  :root { --tile: 2.4rem; }
  .tile input { font-size: min(1.25rem, 52cqi); }
}
