/* ---------- colours ----------
 * Every colour in the game comes from these variables, and the share picture uses them too.
 * The game follows the device's light/dark setting: dark mode is "Sky" (neutral greys with a
 * sky-blue accent), light mode is "Paper" (dark letter boxes on warm paper).
 * Green, orange and red are kept for right / later / wrong in both, so neither uses those
 * as its accent colour.
 */
:root {
  color-scheme: dark;     /* scrollbars and form controls match */
  --good: #35b779;
  --bad: #e5534b;
  --near: #f0a03a;
  --radius: 10px;

  --bg: #121315;          /* page */
  --bg-glow: #1d1e22;     /* soft light at the top of the page */
  --surface: #1a1b1f;     /* panels, dialog */
  --line: #2c2e34;        /* borders, empty boxes */
  --line-strong: #3d4048; /* the fading "more" box, ad outlines */
  --text: #eceef2;
  --text-soft: #cdd0d6;
  --muted: #8b8f99;
  --tile-bg: #eef1f5;     /* placed letters */
  --tile-text: #121315;
  --accent: #5cb8ff;      /* logo, active box, buttons, big score */
  --accent-glow: rgba(92, 184, 255, .18);
  --on-accent: #08121f;   /* text on accent buttons */
  --key: #26282e;
  --key-hover: #30333a;
  --key-active: #3b3e46;
  --wash: rgba(255, 255, 255, .02); /* faint fill for empty boxes */
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3eee3;
    --bg-glow: #fdfaf3;
    --surface: #fffdf8;
    --line: #d2c9b6;
    --line-strong: #bcb19a;
    --text: #1d1f27;
    --text-soft: #3d404b;
    --muted: #7a7566;
    --tile-bg: #232838;
    --tile-text: #f6f1e4;
    --accent: #3550c8;
    --accent-glow: rgba(53, 80, 200, .15);
    --on-accent: #ffffff;
    --key: #e4ddcd;
    --key-hover: #dad2c0;
    --key-active: #cfc6b2;
    --wash: rgba(0, 0, 0, .02);
  }
}

/* ---------- font ----------
 * Rubik, served from the fonts/ folder so players never connect to Google. One variable file
 * holds every weight from 400 to 800. The browser downloads the second file only if a page
 * shows an accented letter outside Western European (e.g. Ł, Ő, Ș). fonts/OFL.txt is Rubik's
 * licence and has to ship with the font files.
 */
@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/rubik-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/rubik-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background: radial-gradient(ellipse at top, var(--bg-glow) 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  /* one screen tall; the game page or end screen fills it */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

/* ---------- header & stats ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.logo {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.logo span { color: var(--accent); }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }
.top-actions { display: flex; gap: 8px; }
/* the Ko-fi cup: a link that looks like the "?" button */
a.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.cup-heart { fill: var(--accent); stroke: none; }

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-top: 16px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.stat-words { min-width: 96px; text-align: center; }

.stat-label {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: color .25s;
}

.meter {
  height: 6px;
  margin-top: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.meter-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  transition: width .25s ease, background-color .25s;
}

.stat.low .stat-value { color: var(--bad); }
.stat.low .meter-fill { background: var(--bad); }

.stat.bump .stat-value { animation: bump .5s ease-out; }

.minus {
  position: absolute;
  top: 12px;
  right: 14px;
  color: var(--bad);
  font-weight: 800;
  pointer-events: none;
  animation: float-up .8s ease-out forwards;
}
.minus.big { font-size: 20px; top: 8px; animation-duration: 1.1s; }

/* ---------- the word ---------- */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px 0;
}

.word-label {
  font-size: 12px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}

.board {
  --tile: 56px;
  --gap: 8px;
  display: flex;
  justify-content: center;
  gap: var(--gap);
  width: 100%;
  min-height: var(--tile);
}

.tile {
  position: relative;
  flex: none;
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  font-size: calc(var(--tile) * .52);
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
}

.tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.tile.active:empty::after {
  content: "";
  position: absolute;
  left: 30%;
  right: 30%;
  bottom: 18%;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}

.tile.filled {
  background: var(--tile-bg);
  border-color: var(--tile-bg);
  color: var(--tile-text);
}

.tile.missed {
  border-style: dashed;
  color: var(--muted);
}

.tile.pop { animation: pop .28s ease-out both; }
.tile.flash-right { animation: flash-right .55s ease-out; }
.tile.flash-later { animation: flash-later .7s ease-out; }
.tile.flash-wrong { animation: flash-wrong .45s ease-out forwards; }
.tile.flash-repeat { animation: flash-repeat .65s ease-out forwards; }
.tile.solved { animation: solved .7s ease-out both; }

/* "more letters": an inactive box that fades out to the right */
.more,
.mini.fade {
  border: 2px solid var(--line-strong);
  background: var(--wash);
  -webkit-mask-image: linear-gradient(to right, #000 10%, transparent 92%);
  mask-image: linear-gradient(to right, #000 10%, transparent 92%);
}
.more {
  flex: none;
  width: var(--tile);
  height: var(--tile);
  border-radius: 8px;
}

.toast {
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  line-height: 22px;
  letter-spacing: .08em;
  text-align: center;
  text-transform: uppercase;
  color: var(--good);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.bad.show { animation: nudge .4s ease-out; }

/* ---------- keyboard ---------- */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  user-select: none;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  flex: 0 0 calc((100% - 54px) / 10); /* every key the width of one in the 10-key top row */
  max-width: 48px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: var(--key);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s, background-color .12s;
}
.key:hover { background: var(--key-hover); }
.key:active, .key.pressed { transform: scale(.93); background: var(--key-active); }

/* ---------- ad placeholders ---------- */

.ad-slot {
  flex: none;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-inline: auto;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  background: var(--wash);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
}
.ad-slot b { text-transform: uppercase; letter-spacing: .14em; }
.ad-banner { width: 320px; height: 50px; margin-top: 12px; }
.ad-rect { width: 300px; height: 250px; margin-top: 24px; }

/* ---------- game over: a full-screen page ---------- */

.end {
  flex: 1;
  animation: rise .4s ease-out;
}
.end-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.end-logo { font-size: 18px; margin-bottom: 18px; }
.end-kicker {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--bad);
}
.end-count {
  margin: 4px 0 2px;
  font-size: 84px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}
.end-sub { font-size: 18px; }
.end-next {
  margin-top: 20px;
  font-size: 14px;
  color: var(--muted);
}

/* words drawn as rows of small letter boxes, like the board */
.end-words {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 18px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}
.end-words:empty { display: none; }
.word-tiles { display: flex; justify-content: center; gap: 3px; }
.word-tiles span {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: var(--tile-bg);
  color: var(--tile-text);
  font-size: 17px;
  font-weight: 800;
}
.word-tiles span.missed {
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--muted);
}
.end-last { margin-top: 20px; }
.end-label {
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.end-actions { width: 100%; max-width: 360px; margin-top: 18px; }
.end-actions .primary { margin-top: 0; }
.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.secondary {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.secondary:hover { color: var(--text); background: var(--wash); }

/* daily reminder, below Share */
.reminder-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.reminder-btn.on { color: var(--text-soft); }
.reminder-btn:disabled { opacity: .6; cursor: progress; }
.reminder-note {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.reminder-note:empty { display: none; }
.text-btn {
  margin-top: 4px;
  padding: 6px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}
.text-btn:hover { color: var(--text); }
/* tip link, below the buttons */
.tip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0 6px;
  margin: 26px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.tip a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.tip a:hover { text-decoration: underline; }
.tip svg { flex: none; }

/* the small "Privacy" link on the end screen and in the help */
.fine-print {
  margin: 14px 0 0;
  text-align: center;
  font-size: 13px;
}
.fine-print a { color: var(--muted); }
.fine-print a:hover { color: var(--text); }
.end-next strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- help dialog ---------- */

dialog {
  width: calc(100% - 32px);
  max-width: 420px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
dialog p { margin: 10px 0; color: var(--text-soft); }

.rules {
  margin: 14px 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}
.rules li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.mini {
  flex: none;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 6px;
  font-weight: 800;
  color: #fff;
}
.mini.good { background: var(--good); }
.mini.near { background: var(--near); }
.mini.bad { background: var(--bad); }

.primary {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.06); }

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

/* ---------- privacy page ---------- */

.doc {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 20px calc(40px + env(safe-area-inset-bottom));
  line-height: 1.6;
  color: var(--text-soft);
}
.doc .logo { color: var(--text); text-decoration: none; }
.doc h1 { margin: 28px 0 8px; font-size: 30px; color: var(--text); }
.doc h2 { margin: 30px 0 6px; font-size: 18px; color: var(--text); }
.doc p, .doc ul { margin: 8px 0; }
.doc ul { padding-left: 20px; }
.doc li + li { margin-top: 4px; }
.doc strong { color: var(--text); }
.doc a:not(.logo) { color: var(--accent); }
.doc-lead { font-size: 17px; color: var(--text); }
.doc-updated { margin-top: 32px; font-size: 13px; color: var(--muted); }
.doc-back a { font-weight: 700; }

/* ---------- animations ---------- */

@keyframes pop {
  0% { opacity: 0; transform: scale(.6); }
  100% { opacity: 1; transform: none; }
}

@keyframes flash-right {
  0%, 35% { background: var(--good); border-color: var(--good); color: #fff; transform: scale(1.1); }
  100% { transform: none; }
}

@keyframes flash-later {
  0% { background: var(--near); border-color: var(--near); color: #fff; transform: scale(.6); opacity: 0; }
  30% { background: var(--near); border-color: var(--near); color: #fff; transform: scale(1.12); opacity: 1; }
  55% { background: var(--near); border-color: var(--near); color: #fff; transform: none; }
  100% { transform: none; }
}

@keyframes flash-wrong {
  0% { background: var(--bad); border-color: var(--bad); color: #fff; transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-3px); }
  60% { background: var(--bad); border-color: var(--bad); color: #fff; transform: translateX(0); }
  100% { color: transparent; }
}

@keyframes flash-repeat {
  0% { background: var(--bad); border-color: #ffd5d2; color: #fff; transform: scale(1.12); }
  12% { transform: scale(1.12) translateX(-7px); }
  24% { transform: scale(1.12) translateX(7px); }
  36% { transform: scale(1.12) translateX(-5px); }
  48% { transform: scale(1.12) translateX(5px); }
  70% { background: var(--bad); border-color: #ffd5d2; color: #fff; transform: none; }
  100% { color: transparent; }
}

@keyframes nudge {
  0% { transform: scale(.85); }
  60% { transform: scale(1.06); }
  100% { transform: none; }
}

@keyframes solved {
  0% { transform: none; }
  35% { transform: translateY(-10px); background: var(--good); border-color: var(--good); color: #fff; }
  100% { transform: none; background: var(--good); border-color: var(--good); color: #fff; }
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes float-up {
  0% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-18px); }
}

@keyframes bump {
  40% { transform: scale(1.3); color: var(--good); }
}

@keyframes rise {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tile.active:empty::after { animation: none; }
}
