:root {
  --paper: #fbf6ec;
  --card: #ffffff;
  --ink: #23324a;
  --muted: #6b7486;
  --line: #e8dfcf;
  --accent: #e8643c;
  --accent-dark: #c84d28;
  --blue: #2f6fd6;
  --blue-soft: #e7effc;
  --green: #2e9d5b;
  --green-soft: #e3f5e9;
  --red: #d64545;
  --red-soft: #fdeaea;
  --gold: #f2b531;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- Home ---------- */
.hero { text-align: center; padding: 18px 8px 8px; }
.hero .mark { width: 72px; height: 72px; }
.hero h1 { font-size: clamp(30px, 7vw, 44px); margin: 6px 0 2px; letter-spacing: -0.02em; }
.hero p { margin: 0 auto; max-width: 30em; color: var(--muted); font-size: 16px; }

.stats { display: flex; gap: 10px; justify-content: center; margin: 18px 0 6px; flex-wrap: wrap; }
.stat { background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.stat .ico { font-size: 18px; }

.big-btn {
  display: block; width: 100%; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 800; font-size: 22px;
  padding: 18px 20px; margin: 16px 0 6px; box-shadow: 0 5px 0 var(--accent-dark);
  transition: transform .06s ease, box-shadow .06s ease;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-dark); }
.big-btn small { display: block; font-weight: 600; font-size: 15px; opacity: .9; }

.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 4px 10px; font-weight: 800; }

.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.level {
  position: relative; text-align: left; background: var(--card); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 12px; min-height: 118px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 3px 0 var(--line);
}
.level:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.level .num { font-size: 26px; font-weight: 800; line-height: 1; }
.level .stage { font-size: 14px; color: var(--muted); font-weight: 700; }
.level .bar { margin-top: auto; height: 8px; border-radius: 99px; background: #f1ebdf; overflow: hidden; }
.level .bar span { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.level .meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 700; }
.level.locked { opacity: .55; cursor: not-allowed; }
.level.locked .num::after { content: " 🔒"; font-size: 18px; }
.level.done { border-color: #bfe5cc; background: #f6fcf8; }
.level.current { border-color: var(--accent); box-shadow: 0 3px 0 #f2b9a5; }
.level.detective { background: #fff8e6; border-color: #f1dca4; box-shadow: 0 3px 0 #f1dca4; }

.footer-links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 28px 0 8px; }
.link-btn { background: none; border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 16px; color: var(--ink); }

/* ---------- Play ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.back { border: 0; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 8px 14px; font-weight: 800; font-size: 16px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 18px; }
.topbar .title span { font-size: 14px; color: var(--muted); font-weight: 700; }
.progress { height: 10px; border-radius: 99px; background: #efe7d8; overflow: hidden; margin-bottom: 14px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: 99px; transition: width .4s ease; }

.card {
  background: var(--card); border: 2px solid var(--line); border-radius: 24px;
  padding: 20px 20px 22px; box-shadow: 0 4px 0 var(--line);
}
.card .label { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-weight: 800; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; }
.speak { border: 0; background: var(--blue-soft); color: var(--blue); border-radius: 99px; padding: 6px 12px; font-weight: 800; font-size: 14px; text-transform: none; letter-spacing: 0; }
.problem { font-size: clamp(21px, 4.6vw, 26px); line-height: 1.5; margin: 12px 0 4px; font-weight: 600; }
.problem .n { color: var(--blue); font-weight: 800; }

.answers { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.answer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 20px; font-weight: 700; }
.answer-row .word { color: var(--ink); }
.box {
  width: 6.2em; max-width: 46vw; padding: 10px 12px; border-radius: 14px;
  border: 3px solid #d7cdb9; background: #fffdf8; font-size: 24px; font-weight: 800; text-align: center;
  outline: none; transition: border-color .15s, background .15s;
}
.box.short { width: 4.2em; }
.box:focus { border-color: var(--blue); background: #fff; }
.box.right { border-color: var(--green); background: var(--green-soft); color: #1d6b3d; }
.box.wrong { border-color: var(--red); background: var(--red-soft); }
.think { background: #fff8e6; border: 2px dashed #ecd28e; border-radius: 14px; padding: 10px 14px; font-size: 17px; font-weight: 600; }
.think b { color: #8a6412; }

.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.btn {
  flex: 1 1 auto; border: 0; border-radius: 16px; padding: 14px 18px; font-weight: 800; font-size: 19px;
  min-height: 56px; transition: transform .06s ease, box-shadow .06s ease;
}
.btn:active { transform: translateY(3px); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); flex-basis: 100%; }
.btn.primary:active { box-shadow: 0 1px 0 var(--accent-dark); }
.btn.go { background: var(--green); color: #fff; box-shadow: 0 4px 0 #1f7442; flex-basis: 100%; }
.btn.soft { background: var(--blue-soft); color: var(--blue); box-shadow: 0 4px 0 #c8d8f5; }
.btn.plain { background: #f3ede1; color: var(--ink); box-shadow: 0 4px 0 #e2d8c4; }

.feedback { margin-top: 16px; border-radius: 16px; padding: 14px 16px; font-weight: 700; font-size: 18px; display: none; }
.feedback.show { display: block; animation: pop .25s ease; }
.feedback.good { background: var(--green-soft); color: #1d6b3d; }
.feedback.bad { background: var(--red-soft); color: #9c2b2b; }
.feedback.info { background: var(--blue-soft); color: #22508f; }
.feedback .stars { font-size: 28px; letter-spacing: 2px; display: block; margin-top: 4px; }

.hints { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.hint { background: #fff8e6; border-left: 6px solid var(--gold); border-radius: 12px; padding: 12px 14px; font-size: 17px; animation: pop .25s ease; }
.hint b { display: block; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: #8a6412; margin-bottom: 2px; }
.hint ul { margin: 4px 0 0; padding-left: 20px; }

.reveal { margin-top: 14px; background: #f4f0ff; border-left: 6px solid #8b6fe0; border-radius: 12px; padding: 12px 14px; font-size: 18px; }
.reveal b { color: #5a3fb0; }

.shake { animation: shake .4s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall 1.3s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .9; } }

.done-card { text-align: center; padding: 30px 20px; }
.done-card .big { font-size: 64px; }
.done-card h2 { margin: 6px 0; font-size: 30px; }
.done-card p { color: var(--muted); }

/* ---------- Sheets (units, grown-ups) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(35, 50, 74, .35); z-index: 30; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease; }
.sheet { background: var(--paper); width: 100%; max-width: 760px; max-height: 88vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 20px 20px max(24px, env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 24px; } }
.sheet h2 { margin: 0 0 10px; font-size: 24px; }
.sheet h3 { margin: 18px 0 6px; font-size: 17px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sheet table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 14px; overflow: hidden; }
.sheet td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 17px; }
.sheet td:first-child { font-weight: 800; white-space: nowrap; }
.sheet p { font-size: 16px; }
.sheet .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.toggle { display: flex; align-items: center; gap: 12px; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; font-weight: 700; }
.toggle input { width: 24px; height: 24px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 420px) {
  body { font-size: 17px; }
  .card { padding: 16px 16px 18px; border-radius: 20px; }
  .levels { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .btn { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
