:root {
  --bg: #212121;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-strong: rgba(255, 255, 255, 0.10);
  --border: #636363;
  --text: #f2f2f2;
  --muted: #a8a8a8;
  --gold: #e6d3b3;
  --gold-deep: #c9b38c;
  --gold-text: #2b2214;
  --accent: #9aa0a6;
  --bad: #ff6b81;
  /* Feetle-like: each tile ~18% of screen width, capped on big screens and short windows */
  --tile-w: clamp(40px, min(17.5vw, 9dvh), 76px);
  --tile-h: var(--tile-w);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* starfield */
.sky {
  display: none;
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 10% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 30% 70%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 55% 15%, #fffa, transparent),
    radial-gradient(1px 1px at 75% 40%, #fff7, transparent),
    radial-gradient(1px 1px at 90% 80%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 20% 90%, #fff8, transparent),
    radial-gradient(1px 1px at 65% 85%, #fff5, transparent),
    radial-gradient(1px 1px at 45% 50%, #fff4, transparent),
    radial-gradient(1.5px 1.5px at 85% 10%, #fff9, transparent),
    radial-gradient(1px 1px at 5% 55%, #fff6, transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .6; } to { opacity: 1; } }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9.6px 16px 3.2px; max-width: 416px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: 2px; font-weight: 800; }
.brand h1 .gold { color: var(--gold); }
.splash { width: 32px; height: 32px; flex: none; filter: drop-shadow(0 0 6px #ffffff55); }

.icon-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 14.4px; font-weight: 700; cursor: pointer;
}
.icon-btn:hover { background: var(--panel-strong); }

.modes {
  display: flex; gap: 4.8px; justify-content: center; padding: 6.4px 12.8px;
}
.modes button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 4.8px 11.2px; border-radius: 799.2px; font-size: 11.2px; cursor: pointer; font-weight: 600;
}
.modes button.active { background: var(--gold); color: var(--gold-text); border-color: var(--gold); }

main {
  flex: 1; min-height: 0; width: 100%; max-width: 416px; margin: 0 auto; padding: 0 16px;
  display: flex; flex-direction: column; align-items: center;
}
.tagline { color: var(--muted); margin: 4.8px 0 3.2px; text-align: center; font-size: 12px; }
.tagline b { color: var(--gold); }
.meta { display: flex; gap: 6.4px; color: var(--muted); font-size: 11.2px; margin: 6.4px 0 0; flex-wrap: wrap; justify-content: center; }
.meta b { color: var(--text); }
.dot { opacity: .5; }

/* ladder */
.ladder {
  display: flex; flex-direction: column; align-items: center; gap: 4.8px;
  /* fills all the room between the header and the keyboard, like Feetle; rows stack from the top */
  flex: 1; min-height: 0; justify-content: flex-start;
  width: 100%; overflow-y: auto; padding: 3.2px 0 6.4px;
  scrollbar-width: none;          /* still scrolls, just no visible bar */
}
.ladder::-webkit-scrollbar { display: none; }
.row { display: flex; gap: clamp(5px, 2.4vw, 10px); align-items: center; position: relative; }
.row .num {
  position: absolute; left: -24px; width: 19.2px; text-align: right;
  font-size: 9.6px; color: var(--muted); opacity: .7;
}
.tile {
  width: var(--tile-w); height: var(--tile-h); border-radius: 2px;
  display: grid; place-items: center;
  font-size: calc(var(--tile-w) * .56); font-weight: 800; text-transform: uppercase;
  background: transparent; border: 2px solid var(--border);
  transition: background .2s, transform .15s;
}
.tile.match { background: var(--gold); color: var(--gold-text); border-color: var(--gold); }
.tile.target { background: transparent; border: 2px dashed #555; color: #e6d3b399; }
.tile.input { background: transparent; border-color: var(--border); }
.tile.input.filled { border-color: #8a8a8a; }
.tile.input.filled { animation: pop .12s ease-out; }
.tile.input.cursor { border-color: #bdbdbd; }
.row.start .tile:not(.match) { background: #3a3a3c; border-color: #3a3a3c; }
.row.win .tile { background: var(--gold); color: var(--gold-text); border-color: var(--gold); box-shadow: 0 0 14.4px #e6d3b366; position: relative; }
/* the pulsing glow fades a ready-made shadow in and out (cheap), instead of redrawing the shadow every frame */
.row.win .tile::after {
  content: ""; position: absolute; inset: -2px; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 27.2px #e6d3b3cc; opacity: 0; animation: glow 1.2s ease-in-out infinite alternate;
}
.row.solution .tile { opacity: .55; border-style: dashed; }
.row.shake { animation: shake .35s; }
.row.flip .tile { animation: flip .4s ease-in-out both; }
.row.flip .tile:nth-child(3) { animation-delay: .06s; }
.row.flip .tile:nth-child(4) { animation-delay: .12s; }
.row.flip .tile:nth-child(5) { animation-delay: .18s; }
.gap { color: var(--muted); font-size: 14.4px; letter-spacing: 3.2px; opacity: .6; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes shake { 20%, 60% { transform: translateX(-6.4px); } 40%, 80% { transform: translateX(6.4px); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes glow { to { opacity: 1; } }

.toast {
  min-height: 19.2px; margin: 4.8px 0; font-weight: 600; text-align: center; font-size: 12px;
  transition: opacity .2s;
}
.toast.bad { color: var(--bad); }
.toast.good { color: var(--gold); }

.actions { display: flex; gap: 4.8px; flex-wrap: wrap; justify-content: center; margin-bottom: 6.4px; }
.actions .pill { padding: 4.8px 9.6px; font-size: 10.4px; }
.pill {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 6.4px 11.2px; border-radius: 799.2px; cursor: pointer; font-size: 11.2px; font-weight: 600;
}
.pill:hover:not(:disabled) { background: var(--panel-strong); }
.pill:disabled { opacity: .4; cursor: default; }
.pill.primary { background: var(--gold); color: var(--gold-text); border-color: var(--gold); }
.hidden { display: none !important; }

/* keyboard */
.keyboard {
  width: 100%; max-width: 304px; margin: 0 auto; padding: 3.2px 6.4px calc(9.6px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4.8px; user-select: none;
}
.kb-row { display: flex; gap: 4px; justify-content: center; }
.key {
  flex: 1; max-width: 27.2px; height: 35.2px; border-radius: 4.8px; border: none;
  background: #5a5a5c; color: var(--text); font-weight: 700; font-size: 11.2px;
  text-transform: uppercase; cursor: pointer;
}
.key.wide { flex: 1.6; max-width: 44.8px; font-size: 9.6px; }
.key:active { background: #6a6a6c; }
.key.hot { background: #6b5d45; }
.kb-spacer { flex: .5; max-width: 12.8px; }

/* modals */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .78);
  display: flex; padding: 24px 12.8px; z-index: 10;
  /* the dimmed backdrop scrolls, so the scrollbar sits outside the card at the window edge */
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: #5a5a5c transparent;
}
.modal::-webkit-scrollbar { width: 6px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal::-webkit-scrollbar-thumb { background: #5a5a5c; border-radius: 3px; }
.card {
  background: #2a2a2a; border: 1px solid #3c3c3c; border-radius: 9.6px;
  width: 100%; max-width: 336px; margin: auto;
  padding: 16px 17.6px; position: relative; box-shadow: 0 16px 48px #0008;
}
.card h2 { margin: 0 0 8px; }
.card h3 { margin: 14.4px 0 6.4px; font-size: 12px; color: var(--muted); }
.card p, .card li { line-height: 1.5; color: #dcdcdc; font-size: 12px; }
.card ol { padding-left: 16px; }
.close {
  position: absolute; top: 8px; right: 9.6px; background: none; border: none;
  color: var(--muted); font-size: 22.4px; cursor: pointer; line-height: 1;
}
.example { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 8px 0; }
.mini {
  font-weight: 800; letter-spacing: 4.8px; padding: 3.2px 8px 3.2px 12.8px; border-radius: 4.8px;
  background: var(--panel-strong);
}
.mini.win { background: var(--gold); color: var(--gold-text); }
.arrow { color: var(--muted); font-size: 9.6px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4.8px; text-align: center; }
.stat-grid b { display: block; font-size: 22.4px; }
.stat-grid span { font-size: 9.6px; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 3.2px; }
.bar-row { display: flex; align-items: center; gap: 6.4px; font-size: 10.4px; }
.bar-row .lbl { width: 62.4px; color: var(--muted); }
.bar-row .bar {
  background: #6a6a6c; color: #fff; font-weight: 700; padding: 2px 4.8px;
  border-radius: 3.2px; min-width: 17.6px; text-align: right;
}
.bar-row .bar.gold { background: var(--gold); }
.result {
  margin-top: 11.2px; padding: 14px; border-radius: 10px; background: var(--panel);
  display: flex; flex-direction: column; gap: 12px;
}
.rc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rc-title { font-weight: 800; font-size: 16px; }
.rc-verdict { color: var(--gold); font-weight: 700; font-size: 13px; }
.rc-chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.rc-chip { background: rgba(255,255,255,.06); border-radius: 8px; padding: 6px 4px; text-align: center; }
.rc-chip b { display: block; font-size: 18px; }
.rc-chip span { font-size: 11px; color: var(--muted); }
.rc-board { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rc-row { display: flex; gap: 4px; }
.rc-tile {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 2px;
  border: 1.5px solid var(--border); font-weight: 800; font-size: 15px; text-transform: uppercase;
}
.rc-row.start .rc-tile:not(.match) { background: #3a3a3c; border-color: #3a3a3c; }
.rc-tile.match { background: var(--gold); border-color: var(--gold); color: var(--gold-text); }
.share-row { display: flex; gap: 6.4px; margin-top: 11.2px; flex-wrap: wrap; }
.countdown { color: var(--muted); font-size: 10.4px; margin-bottom: 0; }

@media (max-width: 400px) {
  .brand h1 { font-size: 20.8px; }
  .key { height: 35.2px; font-size: 11.2px; }
  .kb-row { gap: 3.2px; }
}
@media (max-height: 700px) {
  .key { height: 32px; }
}

/* splash animation: drops fly from the keyboard, splat on the tile, spray and drip */
.drop, .drip, .splat { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 20; }
.drop { border-radius: 50%; background: #fff; }
.drip { border-radius: 3px 3px 50% 50%; background: #fff; transform-origin: top; }
/* splats are one pre-drawn picture (set in game.js), so the browser never has to redraw the shape */
.splat, .gooner-splat { background: var(--splat-img) center / contain no-repeat; }
.finale-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.finale { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; will-change: transform, opacity; }
.finale .drop, .finale .drip, .finale .splat { z-index: auto; }

/* GOONER! word after the finale */
.gooner { position: fixed; left: 50%; top: 46%; z-index: 40; pointer-events: none; will-change: transform, opacity; }
.gooner-word {
  position: relative; white-space: nowrap; line-height: 1;
  font-family: "Arial Black", "Helvetica Neue", Impact, system-ui, sans-serif; font-weight: 900; letter-spacing: -.02em;
  isolation: isolate;
}
/* the rough splattered letters are drawn once into a picture, then only moved and scaled */
.gooner-word > img { display: block; width: 100%; height: 100%; }
.gooner::before { content: ""; position: absolute; inset: -60% -15%; background: radial-gradient(closest-side, #000000aa, transparent); z-index: -1; }
.gooner-splat { position: absolute; opacity: .9; z-index: -1; }
.gooner-drip { position: absolute; background: #fff; border-radius: 40% 40% 50% 50% / 30% 30% 70% 70%; transform-origin: top; }

.head-right { display: flex; gap: 6px; }
/* keep the title centered now that the right side has two buttons */
header { display: grid; grid-template-columns: 1fr auto 1fr; }
header > #btn-help { justify-self: start; }
header > .head-right { justify-self: end; }

/* Archive */
.arc-note { margin: 0 0 9.6px; }
.arc-list { display: flex; flex-direction: column; gap: 5px; max-height: 55vh; overflow-y: auto; }
.arc-item {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px;
  padding: 8px 11px; border-radius: 8px; cursor: pointer; text-align: left;
  background: var(--panel); border: 1px solid var(--border); color: var(--text); font: inherit; font-size: 12.8px;
}
.arc-item:hover { background: var(--panel-strong); }
.arc-item.current { border-color: var(--gold); }
.arc-num { font-weight: 800; color: var(--gold); }
.arc-date { color: var(--muted); }
.arc-status { font-weight: 700; font-size: 11.2px; padding: 2.4px 8px; border-radius: 99px; border: 1px solid var(--border); }
.arc-item.won .arc-status { background: var(--gold); color: var(--gold-text); border-color: var(--gold); }
.arc-item.lost .arc-status { color: var(--bad); border-color: var(--bad); }
.arc-item.going .arc-status { color: var(--gold); border-color: var(--gold-deep); }
