:root {
  --blue: #173d92;
  --blue-deep: #0f2c70;
  --navy: #0a1d4f;
  --ice: #cfdcff;
  --ice-2: #e3ebff;
  --muted: #6d89cf;
  --ghost: #4f73c7;
  --white: #ffffff;
  --line: rgba(255, 255, 255, 0.92);
  --wrong: #ff5a7a;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: 16px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--blue);
  color: var(--white);
  font-family: var(--font);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, .cell:focus-visible { outline: 2px solid var(--ice); outline-offset: 2px; }

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 8px var(--gutter) calc(48px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------ switcher */
.switcher {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: center;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: linear-gradient(var(--blue) 70%, rgba(23, 61, 146, 0));
}
.switcher__track {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  width: min(100%, 360px);
  padding: 4px; border-radius: 999px;
  background: var(--blue-deep);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.switcher__pill {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px); border-radius: 999px;
  background: var(--ice);
  transition: transform .45s var(--spring);
}
.switcher[data-active="scramble"] .switcher__pill { transform: translateX(100%); }
.switcher:not(.is-ready) .switcher__pill { transition: none; }
.switcher__btn {
  position: relative; z-index: 1;
  border: 0; background: none; padding: 9px 6px;
  font-weight: 800; font-stretch: 112%; font-size: clamp(10.5px, 3.3vw, 12px);
  letter-spacing: .07em; text-transform: uppercase; white-space: nowrap;
  color: var(--ice); transition: color .3s;
}
.switcher__btn[aria-selected="true"] { color: var(--navy); }

/* ------------------------------------------------------------ titles */
.game { animation: fadeUp .5s var(--ease-out) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.title { text-align: center; margin: 22px 0 18px; line-height: .82; }
.title__name, .title__game, .title__ghost {
  margin: 0; font-weight: 900; font-stretch: 125%;
  text-transform: uppercase; letter-spacing: -.01em;
}
.title__name { font-size: clamp(54px, 16vw, 104px); }
.title__game { font-size: clamp(33px, 9.6vw, 62px); margin-top: .18em; letter-spacing: .005em; }
.title__game--sm { font-size: clamp(25px, 7.4vw, 40px); margin-top: .04em; }
.title__ghost {
  font-size: clamp(25px, 7.4vw, 40px); color: var(--ghost); margin-top: .08em;
  font-variant-ligatures: none;
}
.title__ghost span { display: inline-block; transition: transform .5s var(--spring), opacity .3s; }

.lede { text-align: center; color: var(--ice-2); font-size: clamp(14px, 3.8vw, 17px); letter-spacing: .03em; margin: 0 auto 22px; max-width: 34em; }
.lede--sm { font-size: 13.5px; line-height: 1.5; margin: 18px auto; }
.rule {
  border: 0; height: 1px; width: 200px; margin: 0 auto;
  background: linear-gradient(90deg, transparent, rgba(207,220,255,.5), transparent);
}
.hint { text-align: center; color: var(--ice-2); font-size: clamp(13px, 3.6vw, 16px); letter-spacing: .03em; margin: 26px auto 22px; }

/* ------------------------------------------------------------ submit */
.submit {
  display: block; margin: 0 auto;
  min-width: 230px; padding: 18px 40px;
  border: 0; border-radius: 999px;
  background: var(--ice); color: var(--navy);
  font-weight: 900; font-stretch: 125%; font-size: 22px;
  text-transform: uppercase; letter-spacing: .01em;
  box-shadow: 0 8px 26px rgba(5, 18, 60, .35);
  transition: transform .2s var(--spring), background .3s, color .3s, box-shadow .3s;
}
.submit:not(:disabled):hover { transform: translateY(-2px); }
.submit:not(:disabled):active { transform: scale(.96); }
.submit:disabled { background: var(--navy); color: var(--muted); box-shadow: none; cursor: default; }
.submit.is-ready { animation: ready 2.4s ease-in-out infinite; }
@keyframes ready { 50% { box-shadow: 0 0 0 8px rgba(207,220,255,.18), 0 8px 26px rgba(5,18,60,.35); } }

/* ------------------------------------------------------------ crossword board */
.board-wrap { position: relative; width: min(100%, 620px); margin: 0 auto; }
.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), auto);
  user-select: none; -webkit-user-select: none;
}
.cell {
  position: relative; aspect-ratio: 1;
  border: 0; padding: 0; background: transparent;
  outline: 1.5px solid var(--line); outline-offset: -.75px;
  display: grid; place-items: center;
  transition: background-color .18s, color .18s;
  touch-action: manipulation;
}
.cell__num {
  position: absolute; top: 6%; left: 9%;
  font-size: max(6px, calc(100cqw / var(--cols) * .23));
  font-weight: 700; line-height: 1; color: var(--ice-2); pointer-events: none;
}
.cell__ch {
  font-weight: 800; font-stretch: 112%;
  font-size: calc(100cqw / var(--cols) * .56);
  line-height: 1; transform: translateY(6%); pointer-events: none;
}
.cell.in-word { background: rgba(207, 220, 255, .16); }
.cell.is-active { background: var(--ice); color: var(--navy); }
.cell.is-active .cell__num { color: var(--navy); }
.cell.is-wrong { color: var(--wrong); }
.cell.is-active.is-wrong { background: #ffd2dc; color: #c4123a; }
.cell.is-solved { background: var(--white); color: var(--navy); }
.cell.is-solved .cell__num { color: var(--blue); }
.cell.is-solved.is-active { background: var(--ice); }
.cell.shake { animation: shake .38s; }
.cell.pop { animation: pop .45s var(--spring) both; }
@keyframes shake { 20%,60% { transform: translateX(-12%); } 40%,80% { transform: translateX(12%); } }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); z-index: 2; } 100% { transform: scale(1); } }

/* phones: let the grid run nearly edge to edge so squares are as big as possible */
@media (max-width: 660px) {
  .board-wrap { width: calc(100% + 2 * var(--gutter) - 8px); margin: 0 calc(4px - var(--gutter)); }
  .cell__ch { font-size: calc(100cqw / var(--cols) * .62); }
  .cell__num { font-size: max(6.5px, calc(100cqw / var(--cols) * .26)); }
}

/* dock = clue bar (+ on-screen keyboard on touch devices) */
.dock {
  position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20;
  width: min(100%, 620px); margin: 18px auto 0;
}
.kb { display: none; }
.board-wrap.locked + .dock { display: none; }

html.is-touch .dock {
  position: fixed; left: 0; right: 0; bottom: 0; width: auto; margin: 0; z-index: 40;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: var(--navy);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 30px rgba(4, 14, 45, .45);
  transition: transform .35s var(--ease-out);
  /* touches on the keyboard panel never scroll or zoom the page */
  touch-action: none; overscroll-behavior: contain;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
html.is-touch .dock.is-hidden { transform: translateY(calc(100% + 20px)); }
html.is-touch .dock .cluebar { margin: 0 2px 8px; box-shadow: none; }
html.is-touch main { padding-bottom: calc(var(--dock-h, 250px) + 24px); }
html.is-touch .kb { display: grid; gap: 7px; }
.kb__row { display: flex; justify-content: center; gap: 5px; }
.kb__row:nth-child(2) { padding: 0 4.5%; }
.kb__key {
  flex: 1 1 0; max-width: 46px; height: 46px; padding: 0;
  border: 0; border-radius: 7px;
  background: rgba(207, 220, 255, .16); color: var(--white);
  font-weight: 800; font-stretch: 112%; font-size: 19px;
  display: grid; place-items: center;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: background .08s, transform .08s;
}
.kb__key--wide { flex: 1.7 1 0; max-width: 72px; }
.kb__key svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.kb__key.is-down { background: var(--ice); color: var(--navy); transform: scale(.94); }

/* clue bar */
.cluebar {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: stretch;
  background: var(--ice); color: var(--navy);
  border-radius: 16px; box-shadow: 0 10px 30px rgba(5, 18, 60, .4);
  overflow: hidden;
}
.cluebar__nav { border: 0; background: none; display: grid; place-items: center; }
.cluebar__nav svg { width: 20px; height: 20px; fill: none; stroke: var(--navy); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.cluebar__nav:active { background: rgba(10, 29, 79, .08); }
.cluebar__text {
  border: 0; background: none; text-align: left; padding: 11px 4px;
  font-size: 14px; line-height: 1.3; min-height: 58px;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 2px;
}
.cluebar__num { font-weight: 900; font-stretch: 118%; white-space: nowrap; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--blue); }
.cluebar__clue { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }


/* clue list */
.clues {
  margin: 34px auto 0; padding: 26px 18px 30px;
  background: var(--ice); color: var(--navy); border-radius: 30px;
}
.clues__title { text-align: center; margin: 0; font-weight: 900; font-stretch: 125%; font-size: clamp(36px, 10vw, 46px); text-transform: uppercase; line-height: 1; }
.clues__sub { text-align: center; margin: 10px 0 24px; font-size: 14px; letter-spacing: .02em; }
.clues__cols { display: grid; grid-template-columns: 1fr; gap: 10px 28px; }
@media (min-width: 620px) { .clues__cols { grid-template-columns: 1fr 1fr; } .clues { padding: 30px 26px 34px; } }
.clues h3 { text-align: center; margin: 8px 0 12px; font-weight: 900; font-stretch: 125%; font-size: 17px; text-transform: uppercase; letter-spacing: .02em; }
.clues ol { list-style: none; margin: 0; padding: 0; }
.clue {
  display: block; width: 100%; text-align: left;
  border: 0; background: none; padding: 9px 10px; margin: 0 -10px; width: calc(100% + 20px);
  border-radius: 10px; font-size: 14.5px; line-height: 1.4; letter-spacing: .01em;
  transition: background .2s;
}
.clue b { font-weight: 800; margin-right: 4px; }
.clue:hover { background: rgba(10, 29, 79, .06); }
.clue.is-active { background: var(--white); box-shadow: 0 2px 10px rgba(10,29,79,.08); }
.clue.is-solved { color: rgba(10, 29, 79, .5); }
.clue.is-solved b::after { content: " ✓"; color: var(--blue); }

/* ------------------------------------------------------------ scramble */
.scrambles { list-style: none; margin: 26px 0 30px; padding: 0; display: grid; gap: 30px; }
.scr { text-align: center; }
.scr__clue { margin: 0 auto 12px; font-size: 14px; color: var(--ice-2); letter-spacing: .02em; max-width: 36em; line-height: 1.4; }
.scr__clue .tick { display: inline-block; margin-left: 6px; color: var(--ice); transform: scale(0); transition: transform .4s var(--spring); }
.scr.is-solved .scr__clue .tick { transform: scale(1); }
.scr__meta { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 12px; margin: 12px 0 0; }
.scr__count { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ice-2); }
.scr__count .status { color: var(--ice); font-weight: 700; }
.scr__hint {
  border: 0; border-radius: 999px; padding: 5px 12px 5px 10px;
  background: rgba(207, 220, 255, .14); color: var(--ice);
  font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .2s, transform .15s;
}
.scr__hint::before { content: "💡"; font-size: 12px; letter-spacing: 0; }
.scr__hint:active { transform: scale(.94); background: rgba(207, 220, 255, .28); }
.scr__hint:disabled { opacity: .45; cursor: default; transform: none; }
.scr__hint:disabled::before { filter: grayscale(1); }
.scr.is-solved .scr__hint, .locked .scr__hint { display: none; }

/* hint-locked letters */
.tile.is-fixed { background: rgba(207, 220, 255, .9); color: var(--navy); cursor: not-allowed; }
.tile.is-fixed::after { box-shadow: inset 0 0 0 1.5px rgba(23, 61, 146, .3); }
.tile.pop-in { animation: pop .45s var(--spring); }

/* progress */
.progress { width: min(100%, 300px); margin: 0 auto 18px; text-align: center; }
.progress__bar { height: 6px; border-radius: 999px; background: rgba(207, 220, 255, .18); overflow: hidden; }
.progress__bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--ice); transition: width .6s var(--spring); }
.progress__label { margin: 8px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ice); }
.progress.is-done .progress__bar span { background: var(--white); box-shadow: 0 0 12px rgba(255,255,255,.6); }
#ws-progress { margin-top: 22px; }

/* mini progress under the tabs */
.switcher { flex-direction: column; align-items: center; }
.minibar {
  position: absolute; left: 50%; top: calc(100% - 6px);
  display: flex; align-items: center; gap: 10px;
  width: min(calc(100% - 2 * var(--gutter)), 260px); padding: 7px 14px;
  border-radius: 999px; background: var(--blue-deep);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 6px 18px rgba(4, 16, 55, .35);
  opacity: 0; pointer-events: none; transform: translate(-50%, -8px);
  transition: opacity .25s, transform .3s var(--ease-out);
}
.minibar.is-on { opacity: 1; transform: translate(-50%, 0); }
.minibar .progress__bar { flex: 1; height: 5px; }
.minibar__label { font-size: 10.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--ice); white-space: nowrap; }

/* first-visit tip */
.coach {
  position: relative; width: fit-content; max-width: 100%; margin: 0 auto 16px;
  padding: 10px 16px; border-radius: 14px;
  background: var(--white); color: var(--navy);
  font-size: 13.5px; font-weight: 700; line-height: 1.35; text-align: center;
  box-shadow: 0 8px 24px rgba(4, 16, 55, .35);
  animation: coachIn .5s var(--spring) both, bob 2.4s ease-in-out .6s infinite;
}
.coach::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px;
  background: var(--white); transform: translateX(-50%) rotate(45deg); border-radius: 2px;
}
.coach.is-leaving { animation: coachOut .3s ease both; }
/* inside the phone keyboard panel: arrow points up at the grid */
.dock .coach { margin: 2px auto 10px; font-size: 13px; padding: 9px 14px; }
.dock .coach::after { bottom: auto; top: -6px; }
@keyframes coachIn { from { opacity: 0; transform: translateY(8px) scale(.9); } }
@keyframes coachOut { to { opacity: 0; transform: translateY(-6px) scale(.95); } }
@keyframes bob { 50% { transform: translateY(-3px); } }

.tiles {
  --gap: 6px;
  container-type: inline-size;
  position: relative;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px var(--gap);
  margin: 0 auto; max-width: 680px;
}
.tile {
  --size: min(46px, calc((100cqw - (var(--n) - 1) * var(--gap)) / var(--n) - .5px));
  position: relative;
  width: var(--size); height: var(--size);
  display: grid; place-items: center;
  border-radius: 7px; border: 0;
  background: var(--blue);
  box-shadow: inset 0 0 0 2.5px var(--ice);
  color: var(--white);
  font-weight: 900; font-stretch: 125%;
  font-size: calc(var(--size) * .5);
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab;
  transition: background .25s, color .25s, box-shadow .25s;
}
.tile::after { /* inner ring like the design */
  content: ""; position: absolute; inset: 3.5px; border-radius: 4px;
  box-shadow: inset 0 0 0 1.5px rgba(207, 220, 255, .55);
  pointer-events: none;
}
.tile.is-selected { background: var(--ice); color: var(--navy); transform: translateY(-4px); transition: transform .2s var(--spring), background .2s, color .2s; }
.tile.is-dragging {
  z-index: 10; cursor: grabbing;
  background: var(--ice); color: var(--navy);
  box-shadow: inset 0 0 0 2.5px var(--white), 0 14px 26px rgba(4, 16, 55, .5);
  transition: none;
}
.tile.is-dropping { transition: transform .28s var(--spring), background .25s, color .25s, box-shadow .25s; }
.scr.is-solved .tile { background: var(--ice); color: var(--navy); cursor: default; box-shadow: inset 0 0 0 2.5px var(--white); animation: wave .6s var(--spring) both; animation-delay: calc(var(--i) * 45ms); }
.scr.is-solved .tile::after { box-shadow: inset 0 0 0 1.5px rgba(23, 61, 146, .35); }
@keyframes wave { 40% { transform: translateY(-9px) scale(1.06); } }
.scr.is-wrong .tile { box-shadow: inset 0 0 0 2.5px var(--wrong); }
.scr.shake .tiles { animation: rowshake .45s; }
@keyframes rowshake { 20%,60% { transform: translateX(-7px); } 40%,80% { transform: translateX(7px); } }
.locked .tile { cursor: default; }

/* solved: tiles merge into a single answer box */
.scr__word { display: none; }
.scr.is-merged .tiles { display: none; }
.scr.is-merged .scr__word {
  display: block; width: fit-content; min-width: min(100%, 330px); max-width: 100%;
  margin: 0 auto; padding: 9px 22px 8px;
  border-radius: 7px; box-shadow: inset 0 0 0 2.5px var(--ice);
  color: var(--ice); font-weight: 900; font-stretch: 125%;
  font-size: clamp(17px, 5.6vw, 26px); letter-spacing: .02em; line-height: 1.15;
  overflow-wrap: anywhere;
  animation: merge .55s var(--spring) both;
}
@keyframes merge { from { opacity: 0; transform: scale(.85, .7); } }

/* scramble Submit stays pinned to the bottom of the screen until you reach the end */
#ws-submit {
  position: sticky; z-index: 15;
  bottom: calc(14px + env(safe-area-inset-bottom));
  margin-top: 28px;
  box-shadow: 0 10px 30px rgba(4, 14, 45, .55), 0 0 0 6px var(--blue);
}
#ws-submit:disabled { box-shadow: 0 0 0 6px var(--blue); }

/* ------------------------------------------------------------ toast + modal */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--white); color: var(--navy);
  padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 14px;
  box-shadow: 0 10px 30px rgba(4, 16, 55, .45); width: max-content; max-width: calc(100vw - 32px);
  text-align: center; line-height: 1.35;
  transition: opacity .25s, transform .35s var(--spring);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { background: #ffe3e9; color: #b0102f; }

.modal {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: var(--gutter);
  background: rgba(6, 20, 62, .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .3s both;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal__card {
  width: min(100%, 420px); text-align: center;
  background: var(--blue); border-radius: 30px; padding: 34px 24px 26px;
  box-shadow: inset 0 0 0 1.5px rgba(207,220,255,.4), 0 30px 80px rgba(0,0,0,.4);
  animation: rise .5s var(--spring) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.94); } }
.modal__eyebrow { margin: 0 0 6px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--ice); }
.modal__title { margin: 0; font-weight: 900; font-stretch: 125%; text-transform: uppercase; font-size: clamp(34px, 10vw, 46px); line-height: .9; }
.modal__body { margin: 14px 0 0; color: var(--ice-2); font-size: 15px; line-height: 1.45; }
.modal__quote {
  margin: 16px auto 0; max-width: 20em;
  font-weight: 900; font-stretch: 112%; font-size: 15px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ice); line-height: 1.3;
}
.modal__quote[hidden] { display: none; }
.modal__actions { display: grid; gap: 10px; justify-items: center; margin-top: 24px; }
.submit--light { font-size: 17px; padding: 15px 28px; min-width: 0; width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.submit--light svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.submit--ghost {
  font-size: 15px; padding: 13px 24px; min-width: 0; width: 100%;
  background: transparent; color: var(--ice); box-shadow: inset 0 0 0 2px rgba(207, 220, 255, .55);
  text-decoration: none; text-align: center;
}
.modal [hidden] { display: none !important; }
.linkbtn { border: 0; background: none; color: var(--ice); font-size: 14px; letter-spacing: .04em; text-decoration: underline; text-underline-offset: 4px; padding: 8px; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 80; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* "Start over" under each game (tap twice to confirm) */
.restart { display: block; margin: 10px auto 0; font-size: 13px; opacity: .8; }
.restart.is-armed { opacity: 1; color: var(--wrong); }
