:root {
  --bg-1: #14313a;
  --bg-2: #0b1d24;
  --ink: #0f1a1e;
  --paper: #f6f1e6;
  --paper-2: #e9e0cc;
  --tile: #f8ecd0;
  --tile-2: #ecd7a8;
  --tile-edge: #b88d4a;
  --accent: #f2a93b;
  --accent-2: #e0812a;
  --good: #4cc38a;
  --bad: #ef5b5b;
  --slot: rgba(0, 0, 0, 0.28);
  --muted: #9fb7bd;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-2);
  color: var(--paper);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.06) 1px, transparent 1.5px) 0 0 / 22px 22px,
    radial-gradient(ellipse at 50% 0%, var(--bg-1), var(--bg-2) 75%);
  background-attachment: fixed;
}

#app {
  position: relative;
  max-width: 480px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: fade-in .25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */
.btn {
  font: 800 18px/1 var(--font);
  letter-spacing: .04em;
  border: 0;
  border-radius: 14px;
  padding: 16px 28px;
  cursor: pointer;
  transition: transform .08s ease, opacity .2s, background .2s, box-shadow .2s;
}
.btn:active:not(:disabled) { transform: translateY(2px) scale(.98); }
.btn.primary {
  color: var(--ink);
  background: linear-gradient(var(--accent), var(--accent-2));
  box-shadow: 0 5px 0 #9c5414, 0 10px 20px rgba(0,0,0,.35);
}
.btn.primary:active { box-shadow: 0 3px 0 #9c5414, 0 6px 12px rgba(0,0,0,.35); }
.btn.ghost {
  color: var(--paper);
  background: rgba(255,255,255,.08);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
}
.btn.big { min-width: 200px; font-size: 20px; }

.round-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--paper-2), 0 8px 16px rgba(0,0,0,.35);
  cursor: pointer;
  transition: transform .2s;
}
.round-btn:active { transform: rotate(180deg) scale(.94); }

kbd {
  font: 700 12px var(--font);
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--paper-2);
  color: var(--ink);
}

/* ---------- Menu ---------- */
#menu { justify-content: center; gap: 32px; }
.logo { text-align: center; }
.logo h1 {
  margin: 10px 0 0;
  font-size: 48px;
  font-weight: 900;
  letter-spacing: -.02em;
}
.logo-tiles { display: flex; gap: 6px; justify-content: center; }
.mini-tile {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-weight: 900; font-size: 24px;
  color: var(--ink);
  border-radius: 8px;
  background: linear-gradient(var(--tile), var(--tile-2));
  box-shadow: 0 4px 0 var(--tile-edge), 0 6px 10px rgba(0,0,0,.4);
}
.mini-tile:nth-child(2) { transform: translateY(-6px) rotate(4deg); }
.mini-tile:nth-child(1) { transform: rotate(-5deg); }

.menu-card {
  width: 100%;
  background: rgba(0,0,0,.25);
  border-radius: 20px;
  padding: 20px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07);
}
.menu-card h2 {
  margin: 0 0 14px;
  font-size: 14px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 18px 8px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.12);
  background: transparent;
  color: var(--muted);
  font: 700 20px var(--font);
  cursor: pointer;
  transition: all .15s;
}
.mode.selected {
  color: var(--paper);
  border-color: var(--accent);
  background: rgba(242,169,59,.1);
}
.mode-bars { display: flex; gap: 3px; }
.mode-bars i { width: 12px; height: 12px; border-radius: 3px; background: currentColor; opacity: .8; }
.best { margin: 16px 0 0; text-align: center; color: var(--muted); }
.best b { color: var(--accent); }

/* ---------- How to ---------- */
#howto { justify-content: center; }
.card {
  width: 100%;
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.card h2 { margin: 0 0 10px; font-size: 34px; font-weight: 900; }
.card p { margin: 0 0 18px; font-size: 17px; font-weight: 600; color: #34444a; }
.card .hint { font-size: 14px; color: #5d6c71; margin-top: 4px; }
.demo-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.demo-row .mini-tile { transform: none; width: 42px; height: 42px; }
.points {
  list-style: none; padding: 0; margin: 0 auto 14px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
  max-width: 340px;
}
.points li {
  background: #fff; border-radius: 10px; padding: 8px 2px;
  font-size: 11px; color: #5d6c71; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 1px 0 var(--paper-2);
}
.points b { font-size: 18px; color: var(--ink); }
.points span { font-weight: 800; color: var(--accent-2); font-size: 13px; }

/* ---------- Game ---------- */
#game { gap: 0; }
.topbar {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
}
.timer {
  font: 800 22px var(--font);
  font-variant-numeric: tabular-nums;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(0,0,0,.35);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
  transition: background .3s, color .3s;
}
.timer.low { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.scorecard {
  margin-top: 8vh;
  width: 100%;
  display: flex; align-items: center; gap: 16px;
  padding: 18px 22px;
  color: var(--ink);
  background: var(--paper);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--paper-2), 0 16px 30px rgba(0,0,0,.35);
}
.badge {
  flex: none;
  width: 66px; height: 66px;
  border-radius: 50%;
  display: grid; place-items: center;
  font: 900 17px var(--font);
  color: var(--ink);
  background: conic-gradient(var(--accent) var(--p, 0%), #e2dccd 0);
  position: relative;
}
.badge::before {
  content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--paper);
}
.badge span, .badge { z-index: 0; }
.badge > * { position: relative; }
.score-text { line-height: 1; }
.words-line { font: 800 18px var(--font); letter-spacing: .02em; }
.score-line { font: 900 38px var(--font); letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.scorecard.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.04); } }

.toast {
  height: 40px;
  margin-top: 18px;
  font: 800 20px var(--font);
  display: flex; align-items: center;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.good { color: var(--good); }
.toast.bad { color: var(--bad); }
.toast.meh { color: var(--muted); }

.btn.enter {
  margin-top: auto;
  width: 66%;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 5px 0 var(--paper-2), 0 10px 20px rgba(0,0,0,.3);
}
.btn.enter:disabled {
  cursor: default;
  opacity: .35;
  box-shadow: none;
}

.board {
  position: relative;
  width: 100%;
  margin-top: 28px;
  margin-bottom: 6vh;
  touch-action: manipulation;
}
.board.shake { animation: shake .4s ease; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.slot {
  position: absolute;
  border-radius: 12%;
}
.slot.top { background: var(--slot); box-shadow: inset 0 3px 6px rgba(0,0,0,.35); }
.slot.bottom { box-shadow: inset 0 0 0 2px rgba(255,255,255,.12); }

.tile {
  position: absolute;
  left: 0; top: 0;
  display: grid; place-items: center;
  border-radius: 12%;
  border: 0;
  padding: 0;
  font-family: var(--font);
  font-weight: 900;
  color: var(--ink);
  background:
    repeating-linear-gradient(100deg, rgba(150,100,40,.06) 0 3px, transparent 3px 9px),
    linear-gradient(var(--tile), var(--tile-2));
  box-shadow: 0 5px 0 var(--tile-edge), 0 9px 14px rgba(0,0,0,.45);
  cursor: pointer;
  transition: transform .18s cubic-bezier(.3,1.4,.5,1);
  will-change: transform;
}
.board.good .tile.placed { background: linear-gradient(#d7f7e6, #9fe3bf); box-shadow: 0 5px 0 #3a9a6a, 0 9px 14px rgba(0,0,0,.45); }

/* ---------- Results ---------- */
#results { gap: 14px; }
.results-title { margin: 8px 0 0; font-size: 30px; font-weight: 900; }
.results-head {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
}
.results-head .score-line { font-size: 32px; }
.best-line { font-weight: 800; color: var(--accent-2); text-align: right; font-size: 15px; }
.columns {
  flex: 1; min-height: 0;
  width: 100%;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.col {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(0,0,0,.3);
  border-radius: 14px;
  padding: 12px;
}
.col h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.word-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; flex: 1;
}
.word-list li {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
  font-weight: 800;
}
.word-list .w {
  padding: 3px 7px;
  border-radius: 5px;
  color: var(--ink);
  background: linear-gradient(var(--tile), var(--tile-2));
  box-shadow: 0 2px 0 var(--tile-edge);
  font-size: 15px;
  letter-spacing: .03em;
}
.word-list .pts { font-variant-numeric: tabular-nums; font-size: 15px; }
.word-list.missed .w { background: rgba(255,255,255,.1); color: var(--paper); box-shadow: none; }
.word-list.missed .pts { color: var(--muted); }
.word-list .empty { color: var(--muted); font-weight: 600; justify-content: center; }
.results-actions { display: flex; gap: 12px; width: 100%; }
.results-actions .btn { flex: 1; }

@media (max-height: 640px) {
  .scorecard { margin-top: 3vh; }
  .score-line { font-size: 30px; }
}
