:root {
  --bg: #0b1c25;
  --bg2: #10252f;
  --ice: #14303d;
  --ice2: #183845;
  --wall: #253844;
  --wall2: #1a2a33;
  --sticky: #0a1116;
  --teal: #56999f;
  --teal2: #8fd3d8;
  --yellow: #f2c230;
  --yellow2: #f8e39c;
  --text: #e8eef0;
  --muted: #8fa3ab;
  --danger: #e2574c;
  --cell: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, "Helvetica Neue", Arial, sans-serif; overscroll-behavior: none; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.screen { display: none; min-height: 100%; flex-direction: column; padding: max(env(safe-area-inset-top), 12px) 16px max(env(safe-area-inset-bottom), 16px); max-width: 480px; margin: 0 auto; }
.screen.active { display: flex; }

/* ---------- Главная ---------- */
.hero { text-align: center; padding: 28px 0 12px; }
.badge { display: inline-block; background: var(--yellow); color: #1a1a1a; font-weight: 800; letter-spacing: .25em; font-size: 11px; padding: 4px 10px 3px 12px; border-radius: 3px; }
h1 { margin: 10px 0 4px; font-size: 40px; letter-spacing: .02em; font-weight: 800; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.chapters { display: grid; gap: 10px; margin-top: 18px; }
.chapter-card { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; text-align: left; background: var(--bg2); border: 1px solid #1e3540; border-radius: 12px; padding: 12px 14px; }
.chapter-card:active { background: var(--ice); }
.chapter-card .num { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--ice); color: var(--teal2); }
.chapter-card.done .num { background: var(--yellow); color: #1a1a1a; }
.chapter-card .name { font-weight: 700; font-size: 17px; }
.chapter-card .beast { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chapter-card .prog { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.home-foot { margin-top: auto; padding-top: 24px; color: var(--muted); font-size: 12px; text-align: center; line-height: 1.5; }

/* ---------- Шапка ---------- */
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; min-height: 44px; }
.bar .icon { width: 44px; height: 44px; font-size: 26px; line-height: 1; border-radius: 10px; }
.bar .icon:active { background: var(--bg2); }
.bar-title { text-align: center; font-weight: 700; }
.bar-title small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }

/* ---------- Глава ---------- */
blockquote { margin: 18px 0 6px; padding: 0 0 0 14px; border-left: 3px solid var(--yellow); color: var(--yellow2); font-style: italic; line-height: 1.45; }
.howto { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 8px 0 18px; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.level-card { aspect-ratio: 1; border-radius: 12px; background: var(--bg2); border: 1px solid #1e3540; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 800; font-size: 22px; }
.level-card.done { border-color: var(--yellow); }
.level-card.locked { opacity: .35; }
.level-card small { font-size: 11px; color: var(--muted); font-weight: 400; }
.level-card.done small { color: var(--yellow2); }

/* ---------- Игра ---------- */
#play { padding-left: 0; padding-right: 0; }
#play .bar, .play-foot, .hint-text { padding-left: 12px; padding-right: 12px; }

.clock { display: flex; gap: 4px; justify-content: center; margin: 8px 0 10px; }
.clock i { width: 14px; height: 6px; border-radius: 3px; background: var(--wall); }
.clock i.day { background: var(--ice2); }
.clock i.lit { background: var(--yellow); }
.clock i.over { background: var(--danger); }

.board-wrap { position: relative; display: flex; justify-content: center; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--w), var(--cell));
  grid-template-rows: repeat(var(--h), var(--cell));
  gap: 2px;
  padding: 6px;
  background: var(--wall2);
  border-radius: 14px;
  touch-action: none;
}
.board.ring { box-shadow: 0 0 0 3px var(--teal), 0 0 24px rgba(86,153,159,.35); }
.cell { position: relative; border-radius: 5px; background: var(--ice); }
.cell.ice::after { content: ""; position: absolute; inset: 0; border-radius: 5px; background: linear-gradient(135deg, rgba(255,255,255,.05), transparent 60%); }
.cell.wall { background: var(--wall); border-radius: 3px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.05); }
.cell.sticky { background: var(--sticky); background-image: radial-gradient(rgba(255,255,255,.12) 1.2px, transparent 1.3px); background-size: 8px 8px; }
.cell.exit { background: var(--ice2); }
.cell.exit::before { content: ""; position: absolute; left: 25%; top: 12%; width: 50%; height: 76%; border: 2px solid var(--teal2); border-radius: 6px 6px 2px 2px; box-shadow: 0 0 14px rgba(143,211,216,.45) inset; }
.cell.exit.open::before { background: var(--teal); border-color: var(--yellow2); box-shadow: 0 0 16px rgba(248,227,156,.6); }
.cell .orb { position: absolute; left: 50%; top: 50%; width: 38%; height: 38%; margin: -19% 0 0 -19%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #d8fbff, var(--teal2) 40%, var(--teal) 80%); box-shadow: 0 0 12px rgba(143,211,216,.8); animation: pulse 1.6s ease-in-out infinite; transition: transform .25s, opacity .25s; }
.cell .orb.taken { transform: scale(0); opacity: 0; animation: none; }
@keyframes pulse { 50% { box-shadow: 0 0 18px rgba(143,211,216,1); } }

.hero-el { position: absolute; width: var(--cell); height: var(--cell); left: 6px; top: 6px; pointer-events: none; z-index: 2; will-change: transform; transition: transform .18s cubic-bezier(.2,.8,.3,1); }
.hero-el .body { position: absolute; inset: 15%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--yellow2), var(--yellow) 55%, #c9971c); box-shadow: 0 4px 10px rgba(0,0,0,.45); }
.hero-el .body::before { content: ""; position: absolute; left: 14%; right: 14%; top: 30%; height: 26%; border-radius: 40%; background: #1a1a1a; box-shadow: inset 0 0 0 2px #333; }
.hero-el .body::after { content: ""; position: absolute; left: 24%; right: 24%; top: 36%; height: 12%; border-radius: 40%; background: linear-gradient(90deg, rgba(86,153,159,.9), rgba(143,211,216,.9)); }
.hero-el.twin .body { background: radial-gradient(circle at 35% 30%, #dde8ea, #9fb3ba 55%, #5f7680); }
.hero-el.armed .body { box-shadow: 0 0 0 3px var(--yellow2), 0 0 22px rgba(248,227,156,.9), 0 4px 10px rgba(0,0,0,.45); animation: bob .6s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
.hero-el.jumping { transition-duration: .32s; }
.hero-el.jumping .body { animation: hop .32s ease-out; }
@keyframes hop { 50% { transform: scale(1.3) translateY(-10px); } }
.hero-el.bump .body { animation: bump .2s; }
@keyframes bump { 50% { transform: scale(.9); } }

.hint-arrow { position: absolute; pointer-events: none; font-size: 54px; color: var(--yellow2); text-shadow: 0 0 18px rgba(248,227,156,.9); opacity: 0; transition: opacity .2s; z-index: 3; }
.hint-arrow.show { opacity: 1; animation: nudge .6s ease-in-out infinite alternate; }
@keyframes nudge { to { transform: translate(var(--dx), var(--dy)); } }

.play-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 14px; gap: 10px; }
.stats { display: flex; gap: 16px; justify-content: center; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); font-size: 16px; }
.jump { justify-self: start; display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 12px; background: var(--bg2); border: 1px solid #1e3540; }
.jump .jump-ico { font-size: 20px; color: var(--yellow); }
.jump .jump-n { font-weight: 800; font-size: 18px; }
.jump .jump-lbl { color: var(--muted); font-size: 12px; }
.jump.armed { background: var(--yellow); color: #1a1a1a; border-color: var(--yellow); }
.jump.armed .jump-ico, .jump.armed .jump-lbl { color: #1a1a1a; }
.jump:disabled { opacity: .35; }
.hint { justify-self: end; padding: 8px 14px; border-radius: 12px; background: var(--bg2); border: 1px solid #1e3540; color: var(--teal2); font-weight: 700; letter-spacing: .05em; }
.hint-text { min-height: 20px; margin: 10px 0 0; color: var(--teal2); font-size: 13px; text-align: center; font-style: italic; }

/* ---------- Оверлей ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5,12,16,.78); display: grid; place-items: center; padding: 20px; z-index: 10; }
.overlay[hidden] { display: none; }
.card { width: 100%; max-width: 360px; background: var(--bg2); border: 1px solid #1e3540; border-radius: 18px; padding: 22px 20px; text-align: center; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.card-badge { display: inline-block; background: var(--yellow); color: #1a1a1a; font-weight: 800; letter-spacing: .2em; font-size: 10px; padding: 4px 8px 3px 10px; border-radius: 3px; }
.card h2 { margin: 12px 0 6px; font-size: 24px; }
.card p { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }
.row { display: flex; gap: 10px; }
.row button { flex: 1; padding: 12px; border-radius: 12px; font-weight: 700; }
.primary { background: var(--yellow); color: #1a1a1a; }
.ghost { background: var(--ice); color: var(--text); }

@media (max-width: 360px) { :root { --cell: 40px; } }
@media (min-height: 760px) and (min-width: 400px) { :root { --cell: 48px; } }
