:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #141416;
  --muted: #8a8890;
  --line: #e2dfd7;
  --tile-line: #d3cfc5;
  --key: #e6e3db;
  --hit: #e8a13a;
  --hit-ink: #221604;
  --win: #2e9c6c;
  --lose: #c9534a;
  --lock: #efe9dc;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1b1b1f;
    --ink: #f2f0ea;
    --muted: #85838b;
    --line: #2a2a30;
    --tile-line: #3a3a41;
    --key: #2a2a30;
    --hit: #e8a13a;
    --lose: #d8645b;
    --lock: #2b271f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

/* ---- Shared ---------------------------------------------------------- */
.logo {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}
.logo span {
  display: inline-block;
  margin-left: 4px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
}
.logo.small { font-size: 15px; }
.logo.small span { padding: 0 5px; border-radius: 5px; margin-left: 2px; }

.meta {
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.btn {
  display: block;
  width: 100%;
  height: 52px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.big { height: 60px; font-size: 19px; }

.link {
  color: var(--muted);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px 0;
}

/* ---- Start ----------------------------------------------------------- */
.start { justify-content: space-between; gap: 24px; }
.start-top { padding-top: 8vh; display: grid; gap: 12px; }
.tagline { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 20px; }

.challenge-card { padding: 16px 18px; margin-top: 20px; }
.eyebrow { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.challenge-line { display: flex; align-items: baseline; gap: 12px; }
.challenge-line b { font-size: 28px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.challenge-line span { font-size: 18px; letter-spacing: 1px; }

.rules { list-style: none; display: grid; gap: 14px; }
.rules li { display: flex; gap: 12px; font-size: 16px; line-height: 1.4; }
.rules .num {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--key);
}
.rules li:nth-child(2) .num { background: var(--hit); color: var(--hit-ink); }

.start-bottom { display: grid; gap: 16px; }
.langs { display: flex; justify-content: center; gap: 4px; }
.langs button { font-size: 13px; color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.langs button.on { color: var(--ink); background: var(--key); font-weight: 600; }

/* ---- Play ------------------------------------------------------------ */
.play { padding-bottom: max(8px, env(safe-area-inset-bottom)); }

.bar { display: flex; justify-content: space-between; align-items: center; height: 36px; }
.dots { display: flex; gap: 6px; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.2s, transform 0.2s;
}
.dot.now { background: var(--ink); transform: scale(1.2); }
.dot.win { background: var(--win); }
.dot.help { background: var(--hit); }
.dot.lose { background: var(--lose); }
.clock {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  text-align: center;
  min-height: 0;
}
.stage.enter { animation: enter 0.25s ease-out; }
.clue {
  font-size: clamp(22px, 6.4vw, 28px);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.02em;
  max-width: 22ch;
  text-wrap: balance;
}

.slots {
  --gap: 6px;
  --size: min(54px, calc((100vw - 32px - (var(--n) - 1) * var(--gap)) / var(--n)));
  display: flex;
  gap: var(--gap);
}
.tile {
  width: var(--size);
  height: calc(var(--size) * 1.15);
  border: 2px solid var(--tile-line);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: calc(var(--size) * 0.52);
  font-weight: 750;
  background: var(--surface);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.tile.filled { border-color: var(--ink); }
.tile.lock { background: var(--lock); border-color: var(--hit); color: var(--ink); }
.tile.pop { animation: pop 0.1s ease-out; }
.tile.flip { animation: flip 0.35s ease-out; }
.slots.shake { animation: shake 0.3s; }
.slots.win .tile { background: var(--win); border-color: var(--win); color: #fff; animation: bounce 0.35s ease-out backwards; }
.slots.lose .tile:not(.lock) { color: var(--lose); border-color: var(--lose); }
.slots.win .tile:nth-child(2) { animation-delay: 0.04s; }
.slots.win .tile:nth-child(3) { animation-delay: 0.08s; }
.slots.win .tile:nth-child(4) { animation-delay: 0.12s; }
.slots.win .tile:nth-child(5) { animation-delay: 0.16s; }
.slots.win .tile:nth-child(6) { animation-delay: 0.2s; }
.slots.win .tile:nth-child(7) { animation-delay: 0.24s; }
.slots.win .tile:nth-child(8) { animation-delay: 0.28s; }
.slots.win .tile:nth-child(9) { animation-delay: 0.32s; }

.last { display: flex; gap: 4px; min-height: 30px; }
.last.enter { animation: enter 0.2s ease-out; }
.mini {
  width: 26px;
  height: 30px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
}
.mini.hit { background: var(--hit); color: var(--hit-ink); }
.mini.miss { background: var(--key); color: var(--muted); }
.mini.lock { background: transparent; color: var(--muted); border: 1px dashed var(--tile-line); }

.hint { margin: 12px 0 10px; }
.hintbar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.hintbar .fill {
  height: 100%;
  background: var(--hit);
  transform-origin: left;
  transform: scaleX(0);
}
.hintbar .fill.final { background: var(--lose); }
.hint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}
.hint-row .link { font-size: 13px; }

.kb { display: grid; gap: 7px; user-select: none; -webkit-user-select: none; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  max-width: 44px;
  height: 54px;
  border-radius: 8px;
  background: var(--key);
  font-size: 17px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.key.wide { flex: 1.6; max-width: 70px; font-size: 20px; }
.key.hit { background: var(--hit); color: var(--hit-ink); }
.key.miss { opacity: 0.35; }
.key.down { animation: press 0.12s; }

/* ---- Result ---------------------------------------------------------- */
.result { gap: 20px; overflow-y: auto; }
.result .meta { display: flex; align-items: center; gap: 6px; justify-content: center; padding-top: 12px; }
.big-time {
  text-align: center;
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 13px; color: var(--muted); }

.vs { padding: 16px; }
.vs-verdict { text-align: center; font-weight: 700; font-size: 18px; margin-bottom: 12px; }
.vs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vs-col {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 12px 8px;
  border-radius: 12px;
  background: var(--bg);
}
.vs-col.lead { outline: 2px solid var(--win); }
.vs-name { font-size: 13px; color: var(--muted); font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-col b { font-size: 24px; font-variant-numeric: tabular-nums; }
.vs-sq { font-size: 14px; letter-spacing: 1px; }
.vs-sub { font-size: 12px; color: var(--muted); }

.words { list-style: none; border-top: 1px solid var(--line); }
.words li {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.words .ans { font-weight: 700; letter-spacing: 0.06em; }
.words .wmeta { font-size: 12px; color: var(--muted); }
.words .wtime { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 52px; text-align: right; }

.actions { display: grid; gap: 10px; }
.name {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  font: inherit;
  font-size: 16px;
}
.name:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.next { text-align: center; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.result > .link { align-self: center; }

/* ---- Toast ----------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Motion ---------------------------------------------------------- */
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes flip { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes bounce { 40% { transform: translateY(-8px); } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
@keyframes press { 50% { transform: scale(0.92); } }

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

@media (max-height: 640px) {
  .key { height: 46px; }
  .stage { gap: 18px; }
  .start-top { padding-top: 2vh; }
}

.error { padding: 40vh 24px 0; text-align: center; color: var(--muted); }
