:root {
  --bg: #070a1c; --bg2: #11173a; --panel: #151c45; --panel2: #222c66; --ink: #fff; --muted: #a9b3e6;
  --lime: #b6ff3b; --cyan: #2cf6ff; --pink: #ff3bd4; --yellow: #ffd801; --bad: #ff4d6a;
  --b: clamp(50px, 8.6dvh, 72px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% 0%, #1b2366 0%, var(--bg) 62%);
  color: var(--ink); font-family: "Rubik", system-ui, sans-serif; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
.app {
  max-width: 480px; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

/* ---------- setup ---------- */
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 0; }
.setup { gap: 10px; overflow-y: auto; padding: 8px 4px; justify-content: safe center; }
.logo { overflow-wrap: anywhere; max-width: 100%; margin: 0 0 6px; font: 400 clamp(40px, 13vw, 64px)/0.95 "Bungee", sans-serif; display: flex; flex-direction: column; letter-spacing: 1px; }
.logo span:first-child { color: var(--cyan); text-shadow: 0 0 18px rgba(44,246,255,.6); }
.logo span:last-child { color: var(--lime); text-shadow: 0 0 18px rgba(182,255,59,.6); }
.label { margin: 8px 0 0; font-size: 13px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.langs { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; width: 100%; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.opt {
  min-height: 52px; border: 2px solid rgba(255,255,255,.08); border-radius: 16px; background: var(--panel);
  padding: 6px 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .12s ease, border-color .15s, background .15s;
}
.opt b { font-size: 17px; font-weight: 900; line-height: 1.1; overflow-wrap: anywhere; }
.opt small { font-size: 11.5px; color: var(--muted); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.opt:active { transform: scale(.96); }
.opt.on { border-color: var(--lime); background: linear-gradient(180deg, #24411a, #1a2c18); box-shadow: 0 0 18px rgba(182,255,59,.35); }
.opt.on small { color: #e3ffc2; }
.tip { margin: 6px 0 0; color: var(--muted); font-size: 14px; line-height: 1.35; max-width: 360px; }
.go {
  margin-top: 6px; min-width: 200px; height: 58px; border: 0; border-radius: 99px; padding: 0 28px;
  background: linear-gradient(180deg, #d4ff6a, var(--lime)); color: #0d2400; font: 400 24px "Bungee", sans-serif;
  box-shadow: 0 6px 0 #5f9a12, 0 0 28px rgba(182,255,59,.45); transition: transform .1s;
}
.go:active { transform: translateY(3px); box-shadow: 0 3px 0 #5f9a12; }
.go.small { min-width: 0; height: 48px; font-size: 18px; }
.ghost { height: 46px; padding: 0 20px; border-radius: 99px; border: 2px solid rgba(255,255,255,.25); background: transparent; font-weight: 700; font-size: 16px; }

.idle-snake { width: 120px; height: 24px; border-radius: 12px; background: linear-gradient(90deg, var(--pink), var(--cyan), var(--lime)); opacity: .4; animation: wiggle 1.6s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: translateX(16px) scaleX(.85); } }

/* ---------- gameplay ---------- */
.play { flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 6px; }
.hud { display: flex; align-items: center; gap: 6px; height: 44px; flex: none; }
.stat { display: flex; flex-direction: column; align-items: flex-start; min-width: 56px; line-height: 1; }
.stat .k { font-size: 10px; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.stat b { font: 400 20px "Bungee", sans-serif; margin-top: 3px; }
#score { color: var(--yellow); min-width: 64px; }
.chip { margin-left: auto; font-size: 12px; font-weight: 900; padding: 5px 9px; border-radius: 99px; background: var(--panel); color: var(--cyan); white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--panel); font-size: 20px; flex: none; }
.icon-btn.off { opacity: .55; }

.wordbar { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tiles { display: flex; justify-content: center; gap: var(--gap, 5px); width: 100%; min-height: var(--tile, 38px); }
.tile {
  width: var(--tile, 38px); height: calc(var(--tile, 38px) * 1.12); border-radius: 9px; display: grid; place-items: center;
  background: rgba(255,255,255,.05); border: 2px dashed rgba(255,255,255,.18);
  font: 900 calc(var(--tile, 38px) * .62) "Rubik", sans-serif; transition: background .2s, border-color .2s, transform .2s;
}
.tile.next { border: 2px solid var(--yellow); box-shadow: 0 0 14px rgba(255,216,1,.5) inset, 0 0 12px rgba(255,216,1,.35); animation: pulse 0.9s ease-in-out infinite; }
.tile.got { background: linear-gradient(180deg, #2cf6ff, #1aa9d6); border: 2px solid transparent; color: #04202b; animation: popin .28s ease-out; }
.tile.voice { background: linear-gradient(180deg, #ff7ae6, var(--pink)); color: #2b0322; border-color: transparent; animation: popin .35s ease-out both; }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes popin { 0% { transform: scale(.4) rotate(-10deg); } 70% { transform: scale(1.18); } 100% { transform: scale(1); } }
.hint { margin: 0; font-size: 14px; color: var(--muted); text-align: center; min-height: 18px; line-height: 1.25; max-width: 100%; }
.hint-k { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; color: var(--yellow); }
.hint-v { color: #fff; font-weight: 700; }

.board-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board { display: block; border-radius: 16px; box-shadow: 0 0 0 2px rgba(44,246,255,.25), 0 0 40px rgba(44,246,255,.12); touch-action: none; }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  font: 400 clamp(30px, 10vw, 48px) "Bungee", sans-serif; color: var(--yellow); text-shadow: 0 0 22px rgba(255,216,1,.7), 0 4px 0 #6b4c00;
  text-align: center; white-space: nowrap; animation: zoom .45s ease-out;
}
.banner.small { font-size: clamp(16px, 5vw, 22px); white-space: normal; width: 80%; color: #fff; text-shadow: 0 2px 8px #000; }
@keyframes zoom { 0% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

.overlay {
  position: absolute; inset: 0; margin: auto; width: var(--bw, 100%); height: var(--bw, 100%); border-radius: 16px;
  background: rgba(5,8,26,.86); backdrop-filter: blur(3px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 14px; text-align: center; animation: fade .2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.mic-ring {
  width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; font-size: 40px;
  background: radial-gradient(circle, #ff63de, #b3189a); box-shadow: 0 0 0 0 rgba(255,59,212,.6); animation: ring 1.2s ease-out infinite;
}
.mic-ov.done .mic-ring { animation: none; }
.mic-ov.ok .mic-ring { background: radial-gradient(circle, #d4ff6a, #57a10c); }
.mic-ov.bad .mic-ring { background: radial-gradient(circle, #ff7d8f, #b3142f); animation: shake .4s; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(255,59,212,.6); } 100% { box-shadow: 0 0 0 28px rgba(255,59,212,0); } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.mic-title { margin: 0; font-weight: 900; font-size: 19px; line-height: 1.25; }
.mic-heard { margin: 0; min-height: 22px; color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.type-form { display: flex; flex-direction: column; gap: 10px; width: min(100%, 280px); }
.type-form input {
  height: 50px; border-radius: 14px; border: 2px solid var(--cyan); background: #0b1030; color: #fff; padding: 0 14px;
  font: 700 20px "Rubik", sans-serif; text-align: center; user-select: text; -webkit-user-select: text;
}
.type-form .row { display: flex; gap: 10px; justify-content: center; }

.reveal-ov { gap: 6px; cursor: pointer; }
.rv-top { margin: 0; font: 400 clamp(15px, 5vw, 20px) "Bungee", sans-serif; color: var(--lime); text-shadow: 0 0 14px rgba(182,255,59,.55); }
.rv-word { margin: 4px 0; font: 900 clamp(30px, 11vw, 52px)/1.05 "Rubik", sans-serif; color: #fff; text-shadow: 0 0 22px rgba(44,246,255,.7); overflow-wrap: anywhere; animation: popin .4s ease-out; }
.rv-gloss { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.3; }
.rv-gloss b { color: #fff; }
.hear { margin-top: 6px; height: 48px; padding: 0 20px; border-radius: 99px; border: 0; background: var(--cyan); color: #032029; font-weight: 900; font-size: 17px; }
.hear.talk { animation: pulse .6s ease-in-out infinite; }
.rv-bonus { margin: 0; min-height: 22px; font: 400 20px "Bungee", sans-serif; color: var(--pink); text-shadow: 0 0 14px rgba(255,59,212,.6); }
.rv-tap { margin: 0; font-size: 12px; color: var(--muted); opacity: .8; }

/* ---------- d-pad ---------- */
.pad {
  flex: none; display: grid; grid-template-columns: repeat(3, calc(var(--b) * 1.45)); grid-template-rows: repeat(3, var(--b));
  gap: 6px; justify-content: center; padding-top: 2px;
}
.pad .up { grid-area: 1 / 2; } .pad .left { grid-area: 2 / 1; } .pad .mic { grid-area: 2 / 2; }
.pad .right { grid-area: 2 / 3; } .pad .down { grid-area: 3 / 2; }
.dir {
  border: 0; border-radius: 18px; background: linear-gradient(180deg, var(--panel2), var(--panel));
  box-shadow: 0 4px 0 #0a0e2a, inset 0 1px 0 rgba(255,255,255,.12); display: grid; place-items: center; touch-action: none;
  transition: transform .06s, background .1s;
}
.dir i { width: 0; height: 0; border-left: 13px solid transparent; border-right: 13px solid transparent; border-bottom: 18px solid var(--cyan); filter: drop-shadow(0 0 6px rgba(44,246,255,.7)); }
.dir.down i { transform: rotate(180deg); } .dir.left i { transform: rotate(-90deg); } .dir.right i { transform: rotate(90deg); }
.dir.press, .dir:active { transform: translateY(3px); box-shadow: 0 1px 0 #0a0e2a; background: linear-gradient(180deg, #2e3a86, #1d2560); }
.mic {
  border: 0; border-radius: 50%; width: calc(var(--b) * 1.18); height: calc(var(--b) * 1.18); justify-self: center; align-self: center;
  background: radial-gradient(circle at 50% 35%, #ff7ae6, var(--pink) 55%, #a3118b); font-size: calc(var(--b) * .48);
  box-shadow: 0 0 0 4px rgba(255,59,212,.25), 0 0 26px rgba(255,59,212,.55); touch-action: none; transition: transform .08s;
  animation: micglow 2.2s ease-in-out infinite;
}
.mic:active { transform: scale(.93); }
.mic:disabled { opacity: .45; animation: none; }
@keyframes micglow { 50% { box-shadow: 0 0 0 7px rgba(255,59,212,.18), 0 0 34px rgba(255,59,212,.75); } }

@media (min-height: 760px) { .hint { font-size: 15px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.langs .opt b { font-size: clamp(13px, 4vw, 16px); overflow-wrap: normal; hyphens: auto; -webkit-hyphens: auto; }
.levels .opt small { hyphens: auto; -webkit-hyphens: auto; overflow-wrap: normal; }

/* ---------- next word card ---------- */
.intro-ov { gap: 6px; cursor: pointer; }
.in-top { margin: 0; font: 400 clamp(16px, 5.4vw, 22px) "Bungee", sans-serif; color: var(--cyan); text-shadow: 0 0 14px rgba(44,246,255,.55); }
.in-len { margin: 0; font-size: 13px; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.in-k { margin: 10px 0 0; font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .1em; color: var(--yellow); }
.in-gloss { margin: 0; font: 900 clamp(20px, 6.6vw, 30px)/1.2 "Rubik", sans-serif; color: #fff; max-width: 92%; overflow-wrap: anywhere; }
.in-count { margin: 8px 0 0; min-height: 64px; font: 400 56px/64px "Bungee", sans-serif; color: var(--yellow); text-shadow: 0 0 22px rgba(255,216,1,.7), 0 4px 0 #6b4c00; }
.in-count.tick { animation: cnt .6s ease-out; }
@keyframes cnt { 0% { transform: scale(1.9); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1); } }
