/* Layout and components: header, word-length modes, board, keyboard, dialogs, stats and groups. */

/* Header */
.top {
  width: 100%; max-width: 560px;
  display: grid; grid-template-columns: 88px 1fr 88px; align-items: center;
  padding: 12px 16px 6px;
}
.top-actions { display: flex; gap: 6px; justify-content: flex-end; }
.top-actions.start { justify-content: flex-start; }
.brand { text-align: center; }
.brand h1 {
  font-family: var(--serif); font-weight: 600; font-size: 30px; letter-spacing: .06em;
  margin: 0; font-variant: small-caps;
}
.tagline { margin: 0; font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 14px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-family: var(--serif); font-weight: 700; font-size: 18px;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn:hover { border-color: var(--muted); }
/* The theme button shows the current choice: half-filled circle for "match device", sun, or moon. */
.theme-btn svg { display: none; }
.theme-btn[data-choice="auto"] .if-auto, .theme-btn[data-choice="light"] .if-light, .theme-btn[data-choice="dark"] .if-dark { display: block; }
.theme-btn:not([data-choice]) .if-auto { display: block; }
.theme-btn .filled { fill: currentColor; stroke: none; }

/* Modes */
.modes {
  display: flex; gap: 4px; padding: 4px; margin: 8px 16px 4px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.modes button {
  border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; color: var(--muted);
  position: relative; white-space: nowrap;
}
.modes button[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-fill-ink); font-weight: 600; }
.modes button.done::after {
  content: ""; position: absolute; top: 5px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--hit-mark);
}
.modes button.done[aria-pressed="true"]::after { background: var(--accent-fill-ink); }

main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; padding: 4px 16px; }
.puzzle-meta { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 28px; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }
.hint { font-family: var(--serif); font-style: italic; color: var(--ink); }

/* Board */
.board {
  --n: 5;
  --gap: 6px;
  --size: min(58px, calc((100vw - 32px - (var(--n) - 1) * var(--gap)) / var(--n)), calc((100dvh - 360px) / 6 - var(--gap)));
  display: grid; gap: var(--gap);
}
.row { display: grid; grid-template-columns: repeat(var(--n), var(--size)); gap: var(--gap); }
.row.shake { animation: shake .4s; }
.tile {
  width: var(--size); height: var(--size); display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: calc(var(--size) * .52); text-transform: uppercase;
  border-radius: 10px; border: 2px solid var(--tile-line); background: var(--tile-bg); color: var(--ink);
  user-select: none;
}
.tile.filled { border-color: var(--ink); animation: press .12s; }
.tile.hit, .tile.near, .tile.miss { color: var(--mark-ink); border-color: transparent; }
.tile.hit { background: var(--hit); color: var(--hit-ink); }
.tile.near { background: var(--near); color: var(--near-ink); }
.tile.miss { background: var(--miss); color: var(--miss-ink); }
.tile.rise { animation: rise .5s both; }
.tile.sm { --size: 30px; display: inline-grid; font-size: 16px; border-radius: 6px; vertical-align: middle; }
.row.win .tile { animation: glow 1.2s ease-out both; }

@keyframes press { 50% { transform: scale(1.08); } }
@keyframes rise {
  0% { transform: translateY(0) scale(1); filter: brightness(1.4) saturate(0); }
  40% { transform: translateY(-8px) scale(1.06); }
  100% { transform: none; filter: none; }
}
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(192, 138, 38, .8); } 100% { box-shadow: 0 0 0 10px rgba(192, 138, 38, 0); } }

.after-game { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.after-game[hidden] { display: none; }

/* Keyboard */
/* touch-action stops iOS double-tap zoom when keys are tapped quickly. */
.keyboard { width: 100%; max-width: 520px; padding: 8px 8px max(12px, env(safe-area-inset-bottom)); user-select: none; touch-action: manipulation; }
.kb-row { display: flex; gap: 5px; justify-content: center; margin-bottom: 6px; }
.key {
  flex: 1; max-width: 44px; height: 54px; border: 0; border-radius: 8px; background: var(--key); color: var(--key-ink);
  font-weight: 600; font-size: 15px; display: grid; place-items: center; padding: 0;
}
.key.wide { max-width: 70px; flex: 1.5; font-size: 12px; letter-spacing: .04em; }
.key.hit { color: var(--hit-ink); }
.key.near { color: var(--near-ink); }
.key.hit { background: var(--hit); }
.key.near { background: var(--near); }
.key.miss { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--line); }
.key:active { transform: translateY(1px); }

/* Toast */
.toast {
  position: fixed; inset: 84px auto auto 50%; margin: 0; border: 0;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--toast-bg); color: var(--toast-ink); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
  width: min(440px, calc(100vw - 32px)); padding: 22px 22px 18px; box-shadow: var(--shadow);
  max-height: calc(100dvh - 32px);
}
dialog.wide { width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(23, 19, 15, .45); }
dialog h2 { font-family: var(--serif); margin: 0 0 12px; font-size: 24px; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
dialog p { line-height: 1.5; }
.dlg-close { position: absolute; top: 10px; right: 12px; margin: 0; }
.dlg-close button:focus:not(:focus-visible) { outline: none; }
.dlg-close button { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 4px 8px; }
dialog { position: fixed; }
.legend { list-style: none; padding: 0; }
.legend li { margin: 8px 0; display: flex; gap: 10px; align-items: center; }
.fine { font-size: 13px; color: var(--muted); }

.result-head { text-align: center; color: var(--muted); margin: 4px 0 0; font-size: 15px; }
.result-word { text-align: center; font-family: var(--serif); font-size: 36px; letter-spacing: .14em; font-weight: 700; margin: 4px 0 0; }
.result-cat { text-align: center; margin: 0 0 12px; color: var(--muted); font-style: italic; font-family: var(--serif); }
.verse {
  margin: 0; padding: 16px 18px; border-left: 4px solid var(--gold-line); background: var(--bg); border-radius: 4px 12px 12px 4px;
  font-family: var(--serif); font-size: 18px; line-height: 1.55;
}
.verse p { margin: 0 0 8px; }
.verse mark { background: none; color: var(--accent); font-weight: 700; }
.verse footer { font-family: var(--sans); font-size: 14px; color: var(--muted); }
.verse cite { font-style: normal; font-weight: 600; color: var(--ink); }
.kjv { font-size: 11px; letter-spacing: .08em; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; margin-left: 4px; }
.verse-link { text-align: right; margin: 6px 0 0; font-size: 14px; }
.verse-link a, .fs a { color: var(--accent); }
.result-actions { display: flex; gap: 10px; margin-top: 16px; }
.result-actions button { flex: 1; }
.next-word { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 0; }
.next-word span { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

.primary, .secondary {
  border-radius: 12px; padding: 11px 16px; font-weight: 600; font-size: 15px;
}
.primary { background: var(--accent-fill); color: var(--accent-fill-ink); border: 0; }
.secondary { background: none; border: 1.5px solid var(--line); }
.primary:disabled { opacity: .5; cursor: default; }

/* Stats */
.seg { display: flex; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 1px solid var(--line); background: none; border-radius: 8px; padding: 6px 0; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.stat-row b { display: block; font-family: var(--serif); font-size: 28px; }
.stat-row span { font-size: 12px; color: var(--muted); }
.dist { display: grid; gap: 4px; }
.dist div { display: grid; grid-template-columns: 14px 1fr; gap: 8px; align-items: center; font-size: 14px; }
.dist i { display: block; background: var(--miss); color: var(--miss-ink); font-style: normal; font-weight: 600; font-size: 13px; padding: 2px 8px; text-align: right; border-radius: 4px; min-width: 26px; }
.dist i.now { background: var(--hit); color: var(--hit-ink); }

/* Groups */
.fs label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.fs .inline { display: flex; gap: 8px; }
.fs input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
}
.fs input.code { text-transform: uppercase; letter-spacing: .2em; font-weight: 600; }
.fs .groups { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.fs .groups li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.fs .groups li b { flex: 1; }
.fs .groups li small { color: var(--muted); }
.fs .chip { font-size: 12px; letter-spacing: .15em; font-weight: 700; border: 1px dashed var(--muted); border-radius: 6px; padding: 3px 6px; background: none; }
.fs .me { color: var(--muted); font-size: 14px; }
.fs table { width: 100%; border-collapse: collapse; font-size: 14px; }
.fs th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.fs td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.fs td.num, .fs th.num { text-align: right; font-variant-numeric: tabular-nums; }
.fs tr.mine td { font-weight: 700; }
.fs .empty { color: var(--muted); font-style: italic; font-family: var(--serif); }
.fs .back { margin-bottom: 8px; }
.fs .board-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.fs .board-head h3 { margin-top: 4px; }

@media (max-width: 380px) {
  .top { padding-inline: 12px; }
  .brand h1 { font-size: 24px; }
  .modes button { padding: 7px 10px; font-size: 13px; }
  .key { height: 50px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Installed app: offline notice, new-version bar, install prompts, restore code */
.offline-note {
  margin: 6px 16px 0; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.offline-note[hidden] { display: none; }
.browser-tip {
  display: flex; align-items: center; gap: 10px; margin: 8px 16px 0; padding: 10px 12px; max-width: 528px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; line-height: 1.4;
}
.browser-tip[hidden] { display: none; }
.browser-tip p { margin: 0; flex: 1; }
.browser-tip .secondary { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.update-bar {
  display: none; position: fixed; inset: auto auto max(16px, env(safe-area-inset-bottom)) 50%; margin: 0;
  transform: translateX(-50%); width: max-content; max-width: calc(100vw - 24px);
  align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: 14px; z-index: 30;
}
.update-bar.show { display: flex; }
.update-bar .primary { padding: 7px 14px; font-size: 14px; }
.install-box { margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; }
.install-box[hidden] { display: none; }
.install-box p { margin: 0 0 8px; line-height: 1.45; }
.install-box p:last-child { margin-bottom: 0; }
.install-box .primary, .install-box .secondary { padding: 8px 14px; font-size: 14px; margin-right: 10px; }
.ios-share { width: 18px; height: 18px; vertical-align: -3px; fill: none; stroke: var(--hit-mark); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fs input.restore { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.restore-box { margin: 4px 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; }
.restore-box[hidden] { display: none; }
.restore-box p { margin: 0 0 8px; }
.restore-box code {
  flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 8px 10px; border-radius: 8px; background: var(--surface);
  border: 1px dashed var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; user-select: all;
}
