/* Useless Word of the Day: mobile-first, no external fonts. */
:root {
  --bg: #16131c; --fg: #f4f1f8; --muted: #a39cb0; --panel: #221d2b; --border: #3b3446;
  --tile-border: #3b3446; --tile-filled: #6f6880;
  --key: #6f6880; --key-fg: #fff;
  --correct: #56279a; --present: #2b70e0; --absent: #36303f;   /* purple / blue / gray; white text 9.8:1 / 4.7:1 / 12.7:1 */
  --accent: #ff2d92;                                          /* brand pink: links, focus ring, title */
  --tile: 52px; --gap: 5px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.light {
  --bg: #fff8ec; --fg: #1d1a22; --muted: #5e5768; --panel: #ffffff; --border: #ddd3c4;
  --tile-border: #ddd3c4; --tile-filled: #8a8294;
  --key: #e6dccb; --key-fg: #1d1a22; --absent: #403a4a; --accent: #c2185b;   /* absent: white text 10.9:1 */
}
body.contrast { --correct: #c9430e; --present: #1b72c6; }   /* white text 4.9:1 / 4.9:1 */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font);
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
#app {
  height: 100vh; height: 100dvh; max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font-family: inherit; color: inherit; }
a { color: var(--accent); }
.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; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Header */
.topbar { display: flex; align-items: center; gap: 2px; padding: 2px 4px; border-bottom: 1px solid var(--border); flex: none; }
.title-wrap { flex: 1; min-width: 0; text-align: center; }
h1 { margin: 0; color: var(--accent); font-size: clamp(15px, 4.6vw, 24px); font-weight: 800; letter-spacing: .02em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tagline { margin: 1px 0 0; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: 8px; cursor: pointer; padding: 0; font-size: 28px; line-height: 1;
}
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }
.icon-btn:hover { background: rgba(127,127,127,.15); }

/* Mode + language bar */
.subbar { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 4px 6px; flex: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { min-height: 44px; min-width: 44px; padding: 0 10px; border: 0; background: none; font-size: 14px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
/* language picker: native names in a select (Quality lang-dropdown M8). font set longhand: `inherit` is not valid inside the `font` shorthand */
.lang-select { min-height: 44px; max-width: 46vw; padding: 0 8px; font-family: inherit; font-size: 14px; font-weight: 700; line-height: 1; color: var(--fg); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.puzzle-label { font-size: 13px; color: var(--muted); text-align: center; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.practice-banner { margin: 0 8px 2px; padding: 4px 8px; border-radius: 6px; font-size: 12px; text-align: center; background: var(--accent); color: #1d1a22; font-weight: 700; flex: none; }
body.light .practice-banner { color: #fff; }

/* Board */
.board-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 4px 0; }
.board { display: grid; grid-template-rows: repeat(6, var(--tile)); gap: var(--gap); }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: var(--gap); }
.tile {
  width: var(--tile); height: var(--tile); border: 2px solid var(--tile-border);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--tile) * .55); font-weight: 800; text-transform: uppercase; user-select: none;
}
.tile.filled { border-color: var(--tile-filled); animation: pop .1s ease-in-out; }
.tile.correct, .tile.present, .tile.absent { border-color: transparent; color: #fff; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent { background: var(--absent); }
.tile.flip { animation: flip .5s ease forwards; }
.row.shake { animation: shake .45s; }
.tile.bounce { animation: bounce .6s ease; }
@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 10%,90% { transform: translateX(-2px); } 20%,80% { transform: translateX(4px); } 30%,50%,70% { transform: translateX(-6px); } 40%,60% { transform: translateX(6px); } }
@keyframes bounce { 0%,20% { transform: translateY(0); } 40% { transform: translateY(-24px); } 50% { transform: translateY(4px); } 60% { transform: translateY(-12px); } 80% { transform: translateY(2px); } 100% { transform: translateY(0); } }

.toasts { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 5; pointer-events: none; width: 92%; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-weight: 700; font-size: 14px; text-align: center; max-width: 100%; animation: fadein .15s; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }

/* Keyboard */
.keyboard { flex: none; padding: 0 4px 4px; user-select: none; }
.kb-row { display: flex; justify-content: center; margin-bottom: 6px; touch-action: manipulation; }
.key {
  flex: 1 1 0; min-width: 0; height: 54px; margin: 0 2px; border: 0; border-radius: 6px;
  background: var(--key); color: var(--key-fg); font-size: 15px; font-weight: 700; text-transform: uppercase;
  cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.key.wide { flex: 1.55 1 0; font-size: 12px; }
.key svg { width: 22px; height: 22px; fill: currentColor; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: #fff; opacity: .85; }
.key:active { filter: brightness(1.2); }
.kb-spacer { flex: .5 1 0; }

.footer { flex: none; display: flex; align-items: center; justify-content: center; gap: 2px; text-align: center; font-size: 12px; color: var(--muted); padding: 0 4px; min-height: 44px; }
.footer #credit { line-height: 1.25; }
.footer a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; vertical-align: middle; }
.credits-link { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 8px; font-size: 13px; }
.credits-wrap { text-align: center; margin: 4px 0 0; }
.dot { margin: 0 4px; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.modal[hidden] { display: none; }
.modal-card {
  position: relative; background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 440px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; padding: 18px 18px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.modal-close { position: absolute; top: 6px; right: 6px; }
.modal h2 { margin: 2px 44px 12px 0; font-size: 20px; text-transform: uppercase; letter-spacing: .04em; }
.modal h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 8px; }
.modal p { line-height: 1.45; font-size: 15px; }
.example { display: flex; gap: 4px; margin: 10px 0 4px; }
.example .tile { --tile: 36px; width: 36px; height: 36px; font-size: 20px; }
.result-msg { font-weight: 800; font-size: 17px !important; text-align: center; margin: 0 0 12px; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-num { font-size: 28px; font-weight: 800; }
.stat-lbl { font-size: 11px; color: var(--muted); }
.dist-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 14px; }
.dist-row .n { width: 12px; text-align: right; }
.dist-bar { background: var(--absent); color: #fff; padding: 2px 6px; text-align: right; font-weight: 700; min-width: 22px; border-radius: 3px; }
.dist-bar.hl { background: var(--correct); }
.no-stats { color: var(--muted); font-size: 14px; }
.stats-footer { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.stats-footer[hidden] { display: none; }
.countdown-box { flex: 1; text-align: center; border-right: 1px solid var(--border); padding-right: 8px; }
.countdown-label { font-size: 12px; color: var(--muted); }
.countdown { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.btn { min-height: 48px; padding: 0 18px; border-radius: 10px; border: 0; font-size: 16px; font-weight: 800; cursor: pointer; }
.btn.primary { background: var(--correct); color: #fff; flex: 1; }
.btn.secondary { background: transparent; border: 2px solid var(--border); color: var(--fg); }
.btn.wide { width: 100%; margin-top: 12px; }
.cross-sell { font-size: 13px !important; color: var(--muted); text-align: center; margin: 14px 0 0; font-style: italic; }
.small-credit { font-size: 12px !important; color: var(--muted); text-align: center; margin: 10px 0 0; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.setting-name { font-weight: 700; }
.setting-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch { position: relative; width: 52px; min-width: 52px; height: 44px; background: none; border: 0; cursor: pointer; padding: 0; }
.switch::before { content: ""; position: absolute; left: 4px; right: 4px; top: 10px; height: 24px; border-radius: 12px; background: var(--absent); transition: background .2s; }
.switch span { position: absolute; top: 13px; left: 7px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch[aria-checked="true"]::before { background: var(--correct); }
.switch[aria-checked="true"] span { transform: translateX(20px); }

@media (min-height: 760px) { .key { height: 58px; } }
@media (max-width: 359px) { .seg-btn { padding: 0 7px; font-size: 13px; } .key { margin: 0 1.5px; font-size: 14px; } .key.wide { font-size: 10px; } }
@media (prefers-reduced-motion: reduce) {
  .tile.flip, .tile.bounce, .row.shake, .tile.filled, .toast { animation: none !important; }
}
/* Narrow phones: two-line title, no tagline, wrapping footer, so nothing is cut off. */
@media (max-width: 420px) {
  .tagline { display: none; }
  h1 { white-space: normal; font-size: 16px; line-height: 1.12; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .footer { font-size: 11px; padding: 0 2px; }
  .footer a { padding: 0 6px; flex: none; }
  .footer .dot { display: none; }
  .footer #credit { text-align: left; font-size: 10.5px; min-width: 0; }
}
