:root {
  --bg: #131b26; --panel: #1c2735; --panel2: #263447; --line: #33455d;
  --text: #eef3f8; --muted: #9fb0c3;
  --accent: #ffb545; --accent-ink: #2a1a00; --danger: #ff7b7b;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --table: #1b2636; --tray: #111923;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, p { margin: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 14px;
  background: var(--panel2); color: var(--text); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 38px; padding: 0 14px; border-radius: 12px; font-size: 15px; }
.btn.wide { width: 100%; }
.btn svg { width: 18px; height: 18px; stroke-width: 2.6; }
.btn:active { transform: scale(.97); }
.link { padding: 10px; color: var(--muted); font-size: 15px; }
.link.danger { color: var(--danger); }
.ib { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 12px; color: var(--text); }
.ib svg { width: 24px; height: 24px; }
.ib:active { background: rgba(255,255,255,.12); }
.ib[aria-pressed="true"].toggle { background: var(--accent); color: var(--accent-ink); }
.grow { flex: 1; }

/* ---------- gallery ---------- */
.gallery {
  max-width: 1100px; margin: 0 auto; min-height: 100%;
  padding: 0 calc(16px + var(--sar)) calc(28px + var(--sab)) calc(16px + var(--sal));
}
.g-head {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--sat)) 0 12px; background: var(--bg);
}
.g-head h1 { font-size: 21px; letter-spacing: -.01em; }
.logo { width: 32px; height: 32px; stroke: none; flex: none; }
#soundBtn .cross { display: none; }
#soundBtn[aria-pressed="false"] .waves { display: none; }
#soundBtn[aria-pressed="false"] .cross { display: inline; }
#soundBtn[aria-pressed="false"] { color: var(--muted); }
.sec-head { display: flex; align-items: center; justify-content: space-between; min-height: 38px; margin: 18px 0 10px; }
.sec-head h2 { font-size: 16px; color: var(--muted); font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; } }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden;
  background: var(--panel); display: block; width: 100%;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tile:active { transform: scale(.97); }
.tile .badge {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  background: rgba(10,15,22,.78); color: #fff; font-size: 12px; font-weight: 700;
}
.tile .badge.ok { background: #2e9e5b; }
.tile.add { display: grid; place-items: center; border: 2px dashed var(--line); background: none; color: var(--muted); }
.tile.add svg { width: 34px; height: 34px; }
.empty { background: var(--panel); border-radius: 16px; padding: 22px 18px; text-align: center; }
.empty p { color: var(--muted); margin-bottom: 14px; }
.foot { margin-top: 28px; text-align: center; color: var(--muted); font-size: 13px; opacity: .8; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(5,9,14,.66); }
.card {
  position: relative; width: 100%; max-width: 520px; max-height: 94%; overflow: auto;
  background: var(--panel); border-radius: 22px 22px 0 0; padding-bottom: var(--sab);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 620px) {
  .modal { align-items: center; }
  .card { border-radius: 22px; padding-bottom: 0; }
}
.card .close { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgba(10,15,22,.6); }
.sh-img { background: #0c121a; display: grid; place-items: center; }
.sh-img img { display: block; max-width: 100%; max-height: 34vh; object-fit: contain; }
.sh-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.sh-body h2 { font-size: 19px; }
.count { display: flex; align-items: baseline; gap: 8px; color: var(--muted); }
.count strong { font-size: 30px; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.count em { font-style: normal; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 52px; height: 40px; padding: 0 12px; border-radius: 12px;
  background: var(--panel2); font-weight: 600; font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
input[type="range"] { width: 100%; height: 34px; margin: 0; accent-color: var(--accent); background: none; }
.pv { padding: 14px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.pv canvas { max-width: 100%; max-height: 62vh; border-radius: 10px; display: block; }
.switch { display: flex; align-items: center; gap: 10px; align-self: stretch; padding: 6px 4px calc(6px + var(--sab)); color: var(--text); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 46px; height: 28px; border-radius: 999px; background: var(--panel2); position: relative; flex: none; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.tip { padding: 22px 20px calc(20px + var(--sab)); display: flex; flex-direction: column; gap: 14px; }
.tip p { color: var(--muted); }
.tip strong { color: var(--text); }

/* ---------- game ---------- */
.game { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--table); }
.bar {
  display: flex; align-items: center; gap: 1px; flex: none;
  padding: calc(5px + var(--sat)) calc(5px + var(--sar)) 5px calc(5px + var(--sal));
  background: #131b26; color: var(--text);
}
.status { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 4px; line-height: 1.15; }
.status strong { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.status span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .ib { position: relative; }
.bar .ib[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.bar .ib i {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: #fff; color: #1b2636; font: 700 11px/18px system-ui, sans-serif; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
@media (max-width: 420px) { .bar .ib { width: 39px; } .bar .ib svg { width: 23px; height: 23px; } }
@media (max-width: 345px) { .bar .ib { width: 35px; } .bar .ib svg { width: 21px; height: 21px; } .status strong { font-size: 13px; } }
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.safe-bottom { flex: none; height: var(--sab); background: var(--tray); }
.loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center;
  background: var(--table); color: var(--muted);
}
.spin { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255,255,255,.18); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.done {
  position: absolute; left: 12px; right: 12px; bottom: 12px; margin: 0 auto; max-width: 480px;
  background: rgba(19,27,38,.96); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px; text-align: center; animation: rise .3s ease-out; box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.done h2 { font-size: 20px; color: var(--accent); }
.done p { color: var(--muted); margin: 4px 0 14px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; padding: 0 8px; font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(118px + var(--sab)); transform: translateX(-50%); z-index: 50;
  max-width: 86%; padding: 10px 16px; border-radius: 12px; background: rgba(10,15,22,.94); color: #fff;
  font-size: 14px; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.35); pointer-events: none;
}
