:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --fg: #1d1a16;
  --muted: #6d675d;
  --line: #ddd5c6;
  --tile: #e8d7b0;
  --accent: #1f6f5c;
  --accent-fg: #ffffff;
  --hook: #c2410c;
  --blank: #8b8378;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1d1b16;
    --fg: #f0ebe1;
    --muted: #9b948a;
    --line: #332f27;
    --tile: #3b3326;
    --accent: #3fb089;
    --accent-fg: #06120e;
    --hook: #f59e6b;
    --blank: #7c756a;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 ui-sans-serif, -apple-system, system-ui, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}

/* One column that fills the viewport; only .results scrolls, so the inputs
   stay put on a phone. Flex rather than fixed grid tracks because the tile
   panel comes and goes, and a track count that assumes it is there leaves the
   list stranded on the wrong row. */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.bar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* Tight vertical padding so the button can own a full tap target without
     making the header taller. */
  padding: 2px 12px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.02em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.ghost {
  min-height: var(--tap);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.panel {
  flex: none;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  max-height: 42dvh;
  overflow-y: auto;
}

.values {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.values li {
  background: var(--tile);
  border-radius: 4px;
  padding: 4px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

.values sup {
  font-size: 9px;
  font-weight: 400;
  margin-left: 1px;
}

.note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.note code {
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.keys {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 4px 6px;
  margin: 8px 0 0;
  font-size: 12px;
}

.keys dt {
  min-width: 18px;
  padding: 1px 0;
  background: var(--tile);
  border-radius: 3px;
  text-align: center;
  font-weight: 700;
}

.keys dd {
  margin: 0;
  color: var(--muted);
}

.inputs {
  display: grid;
  flex: none;
  gap: 6px;
  padding: 8px 12px;
}

/* The board field shares the row with the rack to buy back vertical space.
   The rack's share is whatever seven legible slots need. */
.pair {
  display: grid;
  grid-template-columns: 7fr auto 4fr;
  gap: 6px;
}

/* Sits on the input line rather than the label line above it. */
.clear {
  align-self: end;
  width: 30px;
  height: var(--tap);
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  padding: 0;
}

.clear:disabled {
  opacity: 0.35;
}

.field {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  /* A label that wraps makes its column taller and knocks the two inputs out
     of line with each other. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label em {
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
}

input[type="text"],
select {
  width: 100%;
  min-height: var(--tap);
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 17px; /* >=16px stops iOS Safari zooming on focus */
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

input::placeholder {
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  opacity: 0.7;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* A rack holds exactly seven tiles, so the field is seven slots rather than a
   text box of arbitrary width. The input sits on top, invisible, so the native
   keyboard and caret still work. */
.rack {
  position: relative;
  height: var(--tap);
}

.rack input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: transparent;
  caret-color: transparent;
  -webkit-text-fill-color: transparent;
}

.rack:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 6px;
}

.rack input:focus-visible {
  outline: none;
}

.slots {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  pointer-events: none;
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--tile);
  border-radius: 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.slot sup {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 8px;
  font-weight: 400;
  line-height: 1;
  opacity: 0.7;
}

.slot.blank {
  color: var(--blank);
}

.slot.empty {
  background: none;
  border: 1px dashed var(--line);
}

/* Where the next tile lands. */
.rack:focus-within .slot.next {
  border-style: solid;
  border-color: var(--accent);
}

.tiles span.blank {
  color: var(--blank);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: flex;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  flex: 1;
  min-height: var(--tap);
  background: none;
  border: 0;
  font-size: 14px;
  color: var(--muted);
}

.segmented button.on {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

.minlen {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.minlen select {
  width: auto;
  letter-spacing: 0;
  font-size: 16px;
  padding: 0 4px;
}

.status {
  flex: none;
  margin: 0;
  padding: 0 12px 6px;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.results {
  flex: 1;
  overflow-y: auto;
  /* Without this the flex item refuses to shrink below its content, so a long
     result list overflows the viewport instead of scrolling inside it. */
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}

.group {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

/* Starred plays sit above the list and outlive it, so they stay put while the
   rack changes underneath. */
.pinned {
  flex: none;
  max-height: 34dvh;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.pinned .row {
  box-shadow: inset 3px 0 0 var(--accent);
}

.row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  /* Tall enough that the star is a real target, since the whole row is one. */
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.star {
  flex: none;
  align-self: stretch;
  width: 26px;
  margin: -10px 0 -10px -4px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  opacity: 0.55;
}

.star.on {
  color: var(--accent);
  opacity: 1;
}

.row .word {
  flex: 1;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  word-break: break-all;
}

.row .word i {
  font-style: normal;
}

.row .word i.hook {
  color: var(--hook);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row .word i.blank {
  color: var(--blank);
}

.row .bingo {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.row .pts {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 700;
  min-width: 2.5ch;
  text-align: right;
}

.row .len {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  min-width: 3ch;
  text-align: right;
}

.more {
  display: block;
  width: 100%;
  min-height: var(--tap);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

.results .empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
