* {
  box-sizing: border-box;
}

:root {
  --accent: hsl(14 100% 68%);
  --accent-soft: hsla(14, 100%, 60%, 0.28);
  --accent-glow: hsla(14, 100%, 60%, 0.45);
  --ink: #d1d8ff;
  --ink-dim: #c4cff6;
  --hint: #90a6ff;
  --glass: rgba(18, 6, 14, 0.62);
  --glass-strong: rgba(14, 4, 10, 0.9);
  --line: rgba(255, 140, 110, 0.22);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #090b26 0%, #030409 45%, #020206 100%);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  cursor: crosshair;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.hud {
  position: absolute;
  left: 24px;
  top: calc(24px + var(--safe-t));
  max-width: 320px;
  z-index: 10;
  text-shadow: 0 0 25px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  transition: opacity .5s ease, transform .5s ease;
}

.hud h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 3vw, 3rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hud p {
  margin: 0 0 8px;
  line-height: 1.35;
  color: var(--ink-dim);
  transition: opacity .6s ease, max-height .6s ease;
  max-height: 120px;
  overflow: hidden;
}

.hud .hint {
  margin-top: 10px;
  font-size: 0.92rem;
  color: var(--hint);
}

.hud.compact p { opacity: 0; max-height: 0; margin: 0; }
body.ui-hidden .hud, body.ui-hidden .dock, body.ui-hidden .topbar, body.ui-hidden .awaken { opacity: 0; pointer-events: none; }
body.ui-hidden .dock { transform: translate(-50%, 30px); }
body.in-game .hud p, body.in-game .dock, body.in-game .awaken { opacity: 0; pointer-events: none; }
body.in-game .dock { transform: translate(-50%, 30px); }

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  right: 18px;
  top: calc(20px + var(--safe-t));
  display: flex;
  gap: 8px;
  z-index: 12;
  transition: opacity .4s ease;
}

.tb, .dk {
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
}

.tb {
  height: 40px;
  padding: 0 14px 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .86rem;
  letter-spacing: .04em;
}

.tb.icon { width: 40px; padding: 0; justify-content: center; }

.tb svg, .dk svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tb:hover, .dk:hover { border-color: var(--accent); box-shadow: 0 0 18px var(--accent-soft); }
.tb:active, .dk:active { transform: scale(.94); }
.tb:focus-visible, .dk:focus-visible, .seg button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- dock ---------- */
.dock {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 22px;
  background: rgba(10, 3, 8, 0.45);
  border: 1px solid rgba(255, 140, 110, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 12;
  transition: opacity .4s ease, transform .4s ease;
  max-width: calc(100vw - 16px);
}

.dk {
  width: 80px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: .68rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.dk span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.dk.accent { color: #fff; border-color: var(--accent-glow); box-shadow: inset 0 0 16px var(--accent-soft); }
.dk[aria-pressed="true"] { color: #fff; border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), rgba(18, 6, 14, .7)); }
#btnSound .off { display: none; }
#btnSound[aria-pressed="false"] .on { display: none; }
#btnSound[aria-pressed="false"] .off { display: inline; }
.dk .sm { display: none; }
.dk .swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.awaken {
  position: absolute;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--accent-glow);
  background: rgba(20, 5, 10, .55);
  font-size: .8rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: #ffe6cc;
  pointer-events: none;
  z-index: 11;
  animation: awaken 2.4s ease-in-out infinite;
  transition: opacity .5s ease;
}
.awaken.gone { opacity: 0; animation: none; }
@keyframes awaken { 0%, 100% { box-shadow: 0 0 0 var(--accent-soft); opacity: .75; } 50% { box-shadow: 0 0 26px var(--accent-glow); opacity: 1; } }

/* ---------- game hud ---------- */
.game-hud {
  position: absolute;
  left: 50%;
  top: calc(18px + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 6px 6px 18px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 13;
}
.gh-score { display: flex; flex-direction: column; line-height: 1; }
.gh-score small { font-size: .62rem; letter-spacing: .2em; text-transform: uppercase; color: var(--hint); }
.gh-score b { font-size: 1.35rem; font-variant-numeric: tabular-nums; color: #ffe6cc; }
.gh-combo { font-weight: 700; color: var(--accent); min-width: 34px; text-align: center; transition: transform .15s; }
.gh-combo.pop { transform: scale(1.4); }
.gh-lives { display: flex; gap: 4px; }
.gh-lives i { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe6cc, var(--accent) 55%, #5a1010); box-shadow: 0 0 8px var(--accent-glow); }
.gh-lives i.lost { background: rgba(255, 255, 255, .1); box-shadow: none; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  top: calc(80px + var(--safe-t));
  transform: translate(-50%, -12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--accent-glow);
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 40;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 1, 4, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30;
  opacity: 0;
  transition: opacity .2s;
}
.overlay.show { opacity: 1; }
.panel {
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: linear-gradient(180deg, rgba(34, 10, 18, .96), rgba(12, 3, 9, .97));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 60px var(--accent-soft);
  transform: translateY(10px) scale(.98);
  transition: transform .25s;
}
.overlay.show .panel { transform: none; }
.panel h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.panel .sub { margin: 0 0 16px; color: var(--hint); font-size: .9rem; }
.panel .close {
  float: right;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid rgba(255, 140, 110, .1); }
.row label, .row .lbl { font-size: .92rem; }
.row small { display: block; color: var(--hint); font-size: .76rem; margin-top: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; flex-shrink: 0; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 999px; cursor: pointer; font-size: .8rem; color: var(--ink-dim); }
.seg button.on { background: var(--accent); color: #1a0508; font-weight: 600; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: rgba(255, 255, 255, .12); transition: background .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #ffe6cc; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=range] { accent-color: var(--accent); width: 150px; max-width: 45%; }
.btn {
  border: 1px solid var(--accent-glow);
  background: linear-gradient(180deg, var(--accent-soft), rgba(30, 8, 14, .8));
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: .9rem;
  letter-spacing: .04em;
}
.btn.ghost { background: transparent; border-color: var(--line); }
.btn:hover { box-shadow: 0 0 18px var(--accent-soft); }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: .9rem; align-items: center; }
kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .05);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  text-align: center;
  color: #ffe6cc;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .03);
  border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: .85rem;
}
.chip.on { border-color: var(--accent); box-shadow: 0 0 14px var(--accent-soft); color: #fff; }
.chip i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dl {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .03);
  border-radius: 14px; padding: 14px; cursor: pointer; text-decoration: none; color: inherit;
}
.dl:hover { border-color: var(--accent); }
.dl .ic { font-size: 1.4rem; }
.dl b { font-size: .95rem; }
.dl small { color: var(--hint); font-size: .76rem; line-height: 1.3; }
.muted { color: var(--hint); font-size: .85rem; margin: 14px 0 0; }
.snap-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; }
.big-score { text-align: center; margin: 8px 0 4px; }
.big-score b { display: block; font-size: 3.4rem; line-height: 1; color: #ffe6cc; text-shadow: 0 0 30px var(--accent-glow); font-variant-numeric: tabular-nums; }
.big-score small { letter-spacing: .2em; text-transform: uppercase; color: var(--hint); font-size: .72rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; text-align: center; }
.stats div { border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 1.15rem; color: #ffe6cc; }
.stats small { font-size: .68rem; color: var(--hint); letter-spacing: .1em; text-transform: uppercase; }
.newbest { text-align: center; color: var(--accent); font-weight: 700; letter-spacing: .2em; text-transform: uppercase; font-size: .8rem; animation: awaken 1.4s infinite; }
.rules { margin: 0; padding-left: 18px; line-height: 1.55; font-size: .9rem; color: var(--ink-dim); }
.rules b { color: #ffe6cc; }

@media (max-width: 640px) {
  .hud { left: 16px; top: calc(16px + var(--safe-t)); max-width: calc(100vw - 150px); }
  .hud h1 { font-size: 1.6rem; margin-bottom: 6px; }
  .hud p { font-size: .86rem; }
  .hud .hint { font-size: .8rem; }
  .topbar { right: 12px; top: calc(14px + var(--safe-t)); gap: 6px; }
  #btnApp span { display: none; }
  #btnApp { width: 40px; padding: 0; justify-content: center; }
  .dock { gap: 3px; padding: 4px; bottom: calc(10px + var(--safe-b)); }
  .dk { width: calc((100vw - 48px) / 7); min-width: 44px; height: 52px; font-size: .6rem; letter-spacing: 0; text-transform: none; padding: 0 2px; }
  .dk .lg { display: none; }
  .dk .sm { display: inline; }
  .awaken { bottom: calc(80px + var(--safe-b)); }
  .game-hud { gap: 10px; padding-left: 14px; top: calc(66px + var(--safe-t)); }
  .dl-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .awaken, .newbest { animation: none; }
}
