@font-face {
  font-family: "Fredoka";
  src: url("fonts/Fredoka.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}

:root, [data-swatch="classic"] {
  --night: #241a44;
  --night-2: #33265e;
  --night-3: #45357a;
  --ink: #fff8ec;
  --ink-2: #d9cff5;
  --paper: #fff8ec;
  --paper-ink: #2c2050;
  --paper-line: #b9a9ec;
  --hit: #1f9d63;        /* right spot: green + star */
  --hit-ink: #ffffff;
  --near: #f5b935;       /* in the word: gold + arrows */
  --near-ink: #33240a;
  --miss: #6e6790;       /* not in it: plain grey-violet */
  --miss-ink: #f1edff;
  --accent: #ffd166;
  --pink: #ff8fc7;
  /* theme tokens: these are "classic" (the night sky); the other sets are under Themes at the end */
  --key: #d9d0fa; --key-shadow: #9d8fd6; --go-shadow: #c39a2c; --hit-shadow: #146b43; --near-shadow: #b5831a;
  --key-miss: #4c4570; --key-miss-ink: #b7b0d6; --key-miss-shadow: #332d52;
  --btn: #6c4ef2; --btn-ink: #fff; --btn-shadow: #4b33b8; --title: #5a3fd1; --soft: #6a5c99;
  --near-line: #a5730d; --star: #fff6b0; --arrows: #5a3d00; --ghost: #ffffff38; --backdrop: #120c26b0;
  --sky:
    radial-gradient(2px 2px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(2px 2px at 82% 12%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 66% 30%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 24% 62%, #fff5 50%, transparent 51%),
    radial-gradient(2px 2px at 90% 70%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 86%, #fff5 50%, transparent 51%),
    radial-gradient(60% 40% at 50% 0%, #4b3a8a 0%, transparent 70%),
    radial-gradient(50% 35% at 100% 100%, #3b2a6a 0%, transparent 70%),
    linear-gradient(#2a1f50, #1d1538);
  --tile: min(60px, 15vw);   /* game.js fits it to the screen */
  --key-h: clamp(46px, 7.4dvh, 60px);
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* a still night sky: soft glows and a few painted stars, no motion */
.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--sky);
}

.app {
  max-width: 520px; margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

.top { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top-right { display: flex; gap: 6px; }
.logo { margin: 0; display: flex; align-items: center; gap: 8px; font-size: clamp(24px, 6.4vw, 32px); font-weight: 700; letter-spacing: .01em; color: var(--accent); }
.logo-hat { width: 1.5em; height: 1.5em; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--night-3);
  background: var(--night-2); font-size: 20px; font-weight: 700; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--night-3); }

.modes { display: flex; gap: 4px; background: var(--night-2); padding: 4px; border-radius: 999px; }
.mode { border: 0; background: none; padding: 8px 16px; min-height: 44px; border-radius: 999px; cursor: pointer; font-size: 16px; font-weight: 600; color: var(--ink-2); }
.mode.on { background: var(--accent); color: var(--paper-ink); }

.clue {
  display: flex; align-items: center; gap: 12px; width: 100%; max-width: 380px;
  background: var(--night-2); border: 2px dashed var(--night-3); border-radius: var(--radius); padding: 8px 14px;
}
.clue-pic { font-size: 38px; line-height: 1; }
.clue-text { margin: 0; font-size: 17px; line-height: 1.3; color: var(--ink); }

.hintline { display: flex; gap: 6px; align-items: center; font-size: 15px; color: var(--ink-2); }
.hintline .hl { width: 30px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; font-size: 18px; background: var(--night-2); border: 2px dashed var(--night-3); text-transform: uppercase; }
.hintline .hl.got { background: var(--hit); color: var(--hit-ink); border: 2px solid var(--hit); }

/* the board */
.board { display: grid; grid-template-rows: repeat(6, var(--tile)); gap: 7px; margin-top: 2px; }
.row { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: 7px; }
.row.nudge { animation: nudge .5s ease; }
@keyframes nudge { 50% { transform: scale(1.03); filter: brightness(1.15); } }

.tile {
  position: relative; width: var(--tile); height: var(--tile);
  display: grid; place-items: center;
  border-radius: 12px; border: 3px solid var(--night-3);
  background: color-mix(in srgb, var(--night-2) 70%, transparent);
  font-size: calc(var(--tile) * .56); font-weight: 700; text-transform: uppercase; line-height: 1;
  user-select: none;
}
.tile.filled { background: var(--paper); color: var(--paper-ink); border-color: var(--paper-line); animation: pop .12s ease; }
@keyframes pop { 50% { transform: scale(1.07); } }
.tile.ghost::before { content: attr(data-ghost); position: absolute; inset: 0; display: grid; place-items: center; color: var(--ghost); }

.tile.hit  { background: var(--hit);  color: var(--hit-ink);  border-color: var(--hit); }
.tile.near { background: var(--near); color: var(--near-ink); border-color: var(--near); border-style: dashed; border-color: var(--near-line); }
.tile.miss { background: var(--miss); color: var(--miss-ink); border-color: var(--miss); }
/* the second cue, so colour isn't the only signal: a star for the right spot, arrows for "somewhere else" */
.tile.hit::after, .tile.near::after {
  position: absolute; top: 3px; right: 4px; font-size: max(11px, calc(var(--tile) * .24)); line-height: 1;
}
.tile.hit::after  { content: "★"; color: var(--star); }
.tile.near::after { content: "⇄"; color: var(--arrows); }
.tile.mini { --tile: 40px; display: inline-grid; flex: none; animation: none; }

.tile.flip-in { animation: flip-in .2s ease-in both; }
.tile.flip-out { animation: flip-out .22s ease-out both; }
@keyframes flip-in { to { transform: rotateX(90deg); } }
@keyframes flip-out { from { transform: rotateX(90deg); } to { transform: rotateX(0); } }
.tile.hop { animation: hop .5s ease both; }
@keyframes hop { 40% { transform: translateY(-10px); } 100% { transform: translateY(0); } }

.msg { min-height: 1.4em; margin: 0; text-align: center; font-size: 17px; color: var(--ink); max-width: 420px; }

.tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill {
  border: 2px solid var(--night-3); background: var(--night-2); border-radius: 999px;
  padding: 8px 16px; font-size: 16px; font-weight: 600; cursor: pointer; min-height: 44px;
}
.pill:hover:not(:disabled) { background: var(--night-3); }
.pill:disabled { opacity: .45; cursor: default; }
.pill[aria-pressed="true"] { border-color: var(--accent); }

/* the end card: a friendly panel, never a "game over" screen */
.end {
  width: 100%; max-width: 400px; text-align: center;
  background: var(--paper); color: var(--paper-ink); border-radius: 22px; padding: 16px 18px 14px;
  box-shadow: 0 10px 30px #0006; animation: rise .4s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.end-pic { font-size: 44px; line-height: 1; }
.end-title { margin: 4px 0 2px; font-size: 26px; color: var(--title); }
.end-text { margin: 0 0 8px; font-size: 17px; line-height: 1.35; }
.end-word { display: flex; justify-content: center; gap: 5px; margin-bottom: 12px; }
.end-word .tile { --tile: 42px; }
.end-count { margin: 8px 0 0; font-size: 14px; color: var(--soft); }
.big-btn {
  border: 0; border-radius: 16px; padding: 12px 22px; min-height: 52px; cursor: pointer;
  background: var(--btn); color: var(--btn-ink); font-size: 19px; font-weight: 700; box-shadow: 0 4px 0 var(--btn-shadow);
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--btn-shadow); }

/* the on-screen keyboard: big, touch-first */
.keys { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 7px; margin-top: auto; padding-top: 4px; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  position: relative; flex: 1 1 0; max-width: 46px; height: var(--key-h);
  border: 0; border-radius: 10px; cursor: pointer;
  background: var(--key); color: var(--paper-ink); font-size: 21px; font-weight: 700; text-transform: uppercase;
  box-shadow: 0 3px 0 var(--key-shadow); user-select: none;
}
.key:active, .key.down { transform: translateY(2px); box-shadow: 0 1px 0 var(--key-shadow); }
.key.wide { max-width: 76px; flex-grow: 1.6; font-size: 17px; }
.key.go { background: var(--accent); box-shadow: 0 3px 0 var(--go-shadow); }
.key.hit  { background: var(--hit);  color: var(--hit-ink);  box-shadow: 0 3px 0 var(--hit-shadow); }
.key.near { background: var(--near); color: var(--near-ink); box-shadow: 0 3px 0 var(--near-shadow); }
.key.miss { background: var(--key-miss); color: var(--key-miss-ink); box-shadow: 0 3px 0 var(--key-miss-shadow); }
.key.hit::after, .key.near::after { position: absolute; top: 2px; right: 4px; font-size: 11px; }
.key.hit::after  { content: "★"; color: var(--star); }
.key.near::after { content: "⇄"; color: var(--arrows); }

/* win sparkles: a few stars drift up and fade */
.sparkles { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.spark { position: absolute; font-size: 22px; animation: drift 1.8s ease-out forwards; opacity: 0; }
@keyframes drift {
  0% { opacity: 0; transform: translate(0, 0) scale(.6); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), -180px) scale(1); }
}

.sheet {
  border: 0; border-radius: 22px; padding: 20px 22px; max-width: min(420px, calc(100vw - 32px));
  background: var(--paper); color: var(--paper-ink); font-size: 17px; line-height: 1.4;
}
.sheet::backdrop { background: var(--backdrop); }
.sheet h2 { margin: 0 0 8px; color: var(--title); }
.sheet form { margin-top: 14px; text-align: center; }
.legend { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 10px; }
.legend li { display: flex; align-items: center; gap: 12px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-size: 18px; cursor: pointer; }
.toggle input { width: 26px; height: 26px; accent-color: var(--btn); }
.small { font-size: 14px; color: var(--soft); }

/* calm mode and reduced motion: nothing moves */
.calm *, .calm *::before, .calm *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-height: 640px) {
  :root { --key-h: 44px; }
  .clue-pic { font-size: 28px; }
  .clue { padding: 4px 10px; }
}

/* Phones on their side: the board on the left, everything else (and the keys) on the right, so it all fits */
@media (orientation: landscape) and (max-height: 540px) {
  .app {
    max-width: 940px; display: grid; grid-template-columns: auto minmax(330px, 1fr); column-gap: 24px; row-gap: 6px;
    align-content: center; justify-content: center;
    padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .app > * { grid-column: 2; justify-self: center; }
  .app > .board { grid-column: 1; grid-row: 1 / span 8; align-self: center; margin-top: 0; }
  .app > .top, .app > .keys { justify-self: stretch; }
  .keys { margin-top: 2px; padding-top: 0; gap: 6px; }
  :root { --key-h: 42px; }
  .logo { font-size: 22px; white-space: nowrap; }
  .logo-hat { display: none; }
  .icon-btn { width: 44px; height: 44px; }
  .tools { flex-wrap: nowrap; }
  .pill { font-size: 15px; padding: 6px 12px; white-space: nowrap; }
  .msg { min-height: 1.2em; font-size: 16px; }
  .end { padding: 10px 14px; }
  .end-pic { font-size: 32px; }
}

/* ---------- Themes ----------
   Colour sets on <html data-theme="...">, picked in Settings and remembered on this device. Green with a star is
   always "right spot", gold with arrows "in the word", plain "not in it", in every theme. */
[data-swatch] { --hit: #1f9d63; --hit-ink: #fff; --near: #f5b935; --near-line: #a5730d; --miss-ink: #f1edff; }
:root[data-theme="sunny"], [data-swatch="sunny"] {
  color-scheme: light;
  --night: #fff3c9; --night-2: #ffffff; --night-3: #f0c34a; --ink: #3b2a12; --ink-2: #6b4f1d;
  --paper: #ffffff; --paper-ink: #3b2a12; --paper-line: #e0b84a; --accent: #ff9a4d;
  --hit: #1a8f58; --near: #f5b935; --miss: #8a8698; --miss-ink: #ffffff;
  --key: #ffffff; --key-shadow: #e3c46a; --go-shadow: #c96a22; --key-miss: #d6d0bf; --key-miss-ink: #5c5646; --key-miss-shadow: #b3ab95;
  --btn: #d4501c; --btn-shadow: #8f3410; --title: #b8460f; --soft: #7a5a2a; --ghost: #3b2a1240; --backdrop: #5a4210a0;
  --sky: radial-gradient(40% 30% at 85% 4%, #ffe27a 0%, transparent 70%), radial-gradient(50% 35% at 0% 100%, #ffd9a8 0%, transparent 70%), linear-gradient(#fff7da, #ffe9b0);
}
:root[data-theme="ocean"], [data-swatch="ocean"] {
  --night: #0b3a5c; --night-2: #11507a; --night-3: #2a78a8; --ink: #f2fbff; --ink-2: #cfeaff;
  --paper: #f2fbff; --paper-ink: #0b3a5c; --paper-line: #8cc8ea; --accent: #ffd166;
  --miss: #5e7d93; --miss-ink: #f2fbff;
  --key: #cdeeff; --key-shadow: #7fb7d6; --key-miss: #2f5873; --key-miss-ink: #b4d2e4; --key-miss-shadow: #1d3c52;
  --btn: #0f76ad; --btn-shadow: #0a5a85; --title: #0f6aa0; --soft: #3f6b88; --backdrop: #04192ab0;
  --sky: radial-gradient(1.5px 1.5px at 20% 30%, #fff6 50%, transparent 51%), radial-gradient(2px 2px at 80% 60%, #fff5 50%, transparent 51%),
    radial-gradient(60% 40% at 50% 0%, #2a7fb5 0%, transparent 70%), linear-gradient(#0f4a72, #082a44);
}
:root[data-theme="forest"], [data-swatch="forest"] {
  --night: #163a26; --night-2: #1f4d33; --night-3: #3a7a52; --ink: #f4fbef; --ink-2: #d2ecc8;
  --paper: #fbf7ea; --paper-ink: #22402c; --paper-line: #b5d39a; --accent: #ffcf5c;
  --hit: #1f9d63; --miss: #6f7d72; --miss-ink: #f4fbef;
  --key: #e2f3d4; --key-shadow: #9cc58a; --key-miss: #2e4a38; --key-miss-ink: #a9c2ad; --key-miss-shadow: #1c3123;
  --btn: #c0561a; --btn-shadow: #8f3e10; --title: #2f7a4a; --soft: #4f6f57; --backdrop: #0b1f12b0;
  --sky: radial-gradient(2px 2px at 14% 20%, #fff7 50%, transparent 51%), radial-gradient(1.5px 1.5px at 78% 14%, #fff6 50%, transparent 51%),
    radial-gradient(60% 40% at 50% 0%, #2f6b45 0%, transparent 70%), linear-gradient(#1c4a30, #0f2919);
}
:root[data-theme="candy"], [data-swatch="candy"] {
  color-scheme: light;
  --night: #fdeef6; --night-2: #ffffff; --night-3: #efb3d6; --ink: #4a2a5e; --ink-2: #6b4a80;
  --paper: #ffffff; --paper-ink: #4a2a5e; --paper-line: #e3b5f0; --accent: #ffd36e;
  --hit: #1f9d63; --near: #f7b733; --miss: #a99cbc; --miss-ink: #2e1a3c;
  --key: #f3e3ff; --key-shadow: #cdb1e6; --go-shadow: #d9a63a; --key-miss: #ddd5e6; --key-miss-ink: #6e6280; --key-miss-shadow: #bfb3cc;
  --btn: #a24fca; --btn-shadow: #7d3aa0; --title: #9a3f96; --soft: #7a5a8a; --ghost: #4a2a5e40; --backdrop: #4a2a5e90;
  --sky: radial-gradient(50% 40% at 10% 0%, #ffd6ec 0%, transparent 70%), radial-gradient(50% 40% at 90% 100%, #d8f5ec 0%, transparent 70%), linear-gradient(#fff3fa, #f3e8ff);
}
:root[data-theme="arcade"], [data-swatch="arcade"] {
  --night: #0a0620; --night-2: #170e35; --night-3: #5a2ad8; --ink: #ffffff; --ink-2: #d9ccff;
  --paper: #ffffff; --paper-ink: #170e35; --paper-line: #2af5d2; --accent: #2af5d2;
  --hit: #12c46f; --hit-ink: #04140b; --near: #ffd23f; --miss: #4a4470; --miss-ink: #ffffff;
  --key: #e6dcff; --key-shadow: #ff3fd4; --go-shadow: #0f8f7a; --hit-shadow: #08713f; --near-shadow: #b8901a;
  --key-miss: #2a2350; --key-miss-ink: #9a92c4; --key-miss-shadow: #15102e;
  --btn: #ff3fd4; --btn-ink: #1a0430; --btn-shadow: #a0168a; --title: #a8108a; --soft: #6a3a8a; --star: #ffffff; --backdrop: #05030fc0;
  --sky: radial-gradient(50% 35% at 15% 0%, rgba(255, 63, 212, .35) 0%, transparent 70%), radial-gradient(50% 35% at 90% 100%, rgba(42, 245, 210, .25) 0%, transparent 70%), linear-gradient(#0d0726, #05030f);
}
:root[data-theme="contrast"], [data-swatch="contrast"] {
  --night: #000; --night-2: #000; --night-3: #fff; --ink: #fff; --ink-2: #fff;
  --paper: #fff; --paper-ink: #000; --paper-line: #000; --accent: #ffe500;
  --hit: #007a33; --hit-ink: #fff; --near: #ffe500; --near-ink: #000; --miss: #3a3a3a; --miss-ink: #fff;
  --key: #fff; --key-shadow: #8a8a8a; --go-shadow: #8a7c00; --hit-shadow: #003d19; --near-shadow: #8a7c00;
  --key-miss: #3a3a3a; --key-miss-ink: #fff; --key-miss-shadow: #000;
  --btn: #000; --btn-ink: #fff; --btn-shadow: #555; --title: #000; --soft: #222;
  --near-line: #000; --star: #fff; --arrows: #000; --ghost: #ffffff80; --backdrop: #000000d0; --sky: linear-gradient(#000, #000);
}
:root[data-theme="contrast"] .tile, :root[data-theme="contrast"] .pill, :root[data-theme="contrast"] .icon-btn { border-color: #fff; }
:root[data-theme="contrast"] .tile.filled { border-color: #000; box-shadow: 0 0 0 2px #fff; }

/* the picker in Settings: three little tiles on each theme's own background */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin: 6px 0 4px; }
.themes button { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 76px; padding: 8px 6px;
  border-radius: 14px; border: 3px solid transparent; background: #eee6ff; color: var(--paper-ink); font-size: 15px; font-weight: 600; cursor: pointer; }
.themes button[aria-pressed="true"] { border-color: #6c4ef2; }
.themes .sw { display: flex; gap: 4px; padding: 6px 8px; border-radius: 10px; background: var(--sky); }
.themes .sw .tile { --tile: 22px; border-width: 2px; border-radius: 6px; font-size: 0; }
.themes .sw .tile::after { display: none; }
.label-s { font-weight: 600; margin: 10px 0 0; }
