:root {
  --bg: #F2F1EE;
  --scene: #D3D6D9;
  --text: #22262B;
  --muted: #5E656D;
  --accent: #2F6F73;
  --hover: #4F7CA3;
  --ok: #3F8A5F;
  --bad: #B4544E;
  --line: #D4D6D9;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1 { font-size: 34px; margin: 0 0 4px; }

#stage { position: fixed; inset: 0; background: var(--scene); }
#stage canvas { display: block; touch-action: none; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; flex-direction: column; }
.page { background: var(--bg); overflow-y: auto; }
.overlay { pointer-events: none; }
.overlay > * { pointer-events: auto; }
.overlay > .question, .overlay > .hint { pointer-events: none; }

.home-inner, .page-inner {
  width: 100%; max-width: 480px; margin: 0 auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.home-inner { margin: auto; text-align: center; }
.sub { color: var(--muted); margin: 0 0 20px; }

.bar {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 8px 8px;
  background: rgba(242, 241, 238, 0.92);
  border-bottom: 1px solid var(--line);
}
.page .bar { position: sticky; top: 0; }
.bar-title { font-weight: 600; flex: 1; text-align: center; }
.bar-title.left { text-align: left; padding-left: 8px; flex: none; }
.bar-spacer { flex: 1; }
.link { background: none; border: 0; padding: 12px 8px; min-height: 48px; color: var(--accent); font-weight: 600; }
#explore .bar-spacer, #setup .bar-spacer { flex: 0 0 72px; }
#explore .link { flex: 0 0 auto; }

.btn {
  min-height: 48px; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; width: 100%;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn:disabled { background: #C9CED4; border-color: #C9CED4; cursor: default; }

.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 16px; border-radius: var(--radius); border: 2px solid var(--line); background: #fff; text-align: left;
}
.tile span { color: var(--muted); }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.label { margin: 8px 0 0; color: var(--muted); font-weight: 600; }

.round {
  position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; font-size: 24px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
#quiz .round { bottom: auto; top: calc(72px + env(safe-area-inset-top)); }
.hint {
  position: absolute; left: 0; right: 0; bottom: calc(28px + env(safe-area-inset-bottom));
  margin: 0; text-align: center; color: var(--muted); font-size: 14px;
}
.question {
  margin: 12px 16px 0; text-align: center; font-size: 22px; font-weight: 700;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
}

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: #fff; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto;
  max-height: 45dvh; overflow-y: auto;
}
.sheet.slide-in { animation: slide-up 260ms cubic-bezier(.2, .8, .2, 1); }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.float-back {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px;
  min-height: 44px; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92); color: var(--accent); font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.sheet .close {
  position: absolute; top: 6px; right: 6px; width: 48px; height: 48px;
  border: 0; background: none; font-size: 28px; color: var(--muted);
}
.la { font-style: italic; font-size: 26px; margin: 0 40px 2px 0; }
.cz { margin: 0 0 8px; font-size: 18px; }
.meta { margin: 0 0 8px; color: var(--muted); }
.meta i { color: var(--text); }
.badge { margin: 0 0 4px; color: var(--ok); font-weight: 700; font-size: 18px; }
.badge.wrong { color: var(--bad); }
.fact { margin: 0 0 14px; padding: 10px 12px; background: var(--bg); border-radius: 10px; }

.answer-panel {
  margin-top: auto; background: rgba(242, 241, 238, 0.96); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
}
.options { display: flex; flex-direction: column; gap: 8px; }
.options .btn { font-style: italic; text-align: left; }
.options .btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.options .btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.hard { display: flex; gap: 8px; }
.hard input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 12px; font: inherit; font-style: italic;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.hard .btn { width: auto; }
.feedback { font-size: 17px; }
.feedback .good { color: var(--ok); font-weight: 700; font-size: 20px; }
.feedback .wrong { color: var(--bad); font-weight: 700; }
.after { display: flex; gap: 8px; }

.score { font-size: 44px; font-weight: 800; margin: 8px 0 0; }
.review { list-style: none; margin: 0 0 12px; padding: 0; }
.review li button {
  width: 100%; text-align: left; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; margin-bottom: 6px; min-height: 48px;
}

.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 9; pointer-events: none; }
.proto-badge {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 2px; z-index: 20;
  font-size: 10px; color: #8a8f96; letter-spacing: .05em; pointer-events: none;
}
