:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #101525;
  --surface: #1b2338;
  --text: #f7faff;
  --muted: #a8b3cb;
  --accent: #b9f227;
  --cyan: #7ae1ff;
  --success: #63e6a6;
  --error: #ff6682;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

.app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: linear-gradient(180deg, #182440 0%, var(--bg) 100%);
  isolation: isolate;
}

#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.hud {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  align-items: stretch;
  pointer-events: none;
}

.score-card {
  min-width: 88px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  background: rgba(16,21,37,.82);
  backdrop-filter: blur(8px);
}
.score-card span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.score-card strong { display: block; margin-top: 1px; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.score-card--best strong { color: var(--accent); }

.icon-button {
  width: 48px;
  min-height: 48px;
  margin-left: auto;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  background: rgba(16,21,37,.88);
  color: var(--text);
  font-weight: 800;
  pointer-events: auto;
}

.panel {
  position: absolute;
  z-index: 8;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  top: 50%;
  width: min(440px, calc(100% - 32px));
  margin-inline: auto;
  padding: 26px 22px 22px;
  transform: translateY(-50%);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 24px;
  background: rgba(27,35,56,.94);
  box-shadow: 0 24px 70px rgba(0,0,0,.35);
  text-align: center;
}

.app[data-state="playing"] .panel { display: none; }
.eyebrow { margin: 0 0 7px; color: var(--cyan); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
h1 { margin: 0; font-size: clamp(28px, 8vw, 40px); line-height: 1.05; }
.panel-copy { margin: 12px auto 0; max-width: 34ch; color: var(--muted); line-height: 1.45; }

.loader { width: 38px; height: 38px; margin: 0 auto 18px; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.result { margin: 20px auto 0; }
.result span { display: block; color: var(--muted); font-size: 13px; }
.result strong { display: block; color: var(--accent); font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.status { min-height: 20px; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.status[data-tone="success"] { color: var(--success); }
.status[data-tone="error"] { color: var(--error); }
.status[data-tone="queued"] { color: var(--cyan); }
.actions { display: grid; gap: 10px; margin-top: 18px; }
.button { min-height: 52px; padding: 12px 18px; border-radius: 15px; border: 0; font-weight: 800; cursor: pointer; }
.button:disabled { opacity: .55; cursor: wait; }
.button--primary { background: var(--accent); color: #111708; box-shadow: 0 9px 28px rgba(185,242,39,.2); }
.button--secondary { border: 1px solid rgba(255,255,255,.16); background: transparent; color: var(--text); }
.controls-hint { margin: 15px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }

.touch-controls { position: absolute; z-index: 3; inset: 45% 0 0; display: grid; grid-template-columns: 1fr 1fr; }
.move-zone { min-width: 0; border: 0; background: transparent; color: var(--text); touch-action: none; user-select: none; opacity: .45; }
.move-zone span { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); width: 48px; height: 48px; padding-top: 11px; border: 1px solid rgba(255,255,255,.16); border-radius: 50%; background: rgba(16,21,37,.45); font-size: 22px; }
#move-left span { left: max(18px, env(safe-area-inset-left)); }
#move-right span { right: max(18px, env(safe-area-inset-right)); }
.move-zone.is-active { background: linear-gradient(0deg, rgba(122,225,255,.08), transparent); opacity: 1; }

.rotate-notice { position: absolute; z-index: 20; inset: 0; padding: 24px; place-items: center; background: rgba(16,21,37,.97); text-align: center; }
.rotate-notice:not([hidden]) { display: grid; }
.rotate-notice span { display: block; color: var(--accent); font-size: 50px; }
.rotate-notice h2 { margin: 12px 0 8px; }
.rotate-notice p { max-width: 34ch; margin: 0; color: var(--muted); line-height: 1.45; }

.sheet { position: absolute; z-index: 30; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.sheet__backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(4,7,14,.72); }
.sheet__body {
  position: relative;
  width: min(520px, 100%);
  max-height: min(82dvh, 760px);
  padding: 20px max(18px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,.1);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  box-shadow: 0 -24px 70px rgba(0,0,0,.42);
}
.sheet__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sheet__header h2 { margin: 0; font-size: 26px; }
.sheet__header .eyebrow { margin-bottom: 5px; }
.sheet__header .icon-button { flex: 0 0 auto; margin: 0; }
.sheet__state { min-height: 220px; display: grid; align-content: center; justify-items: center; text-align: center; color: var(--muted); }
.sheet__state .loader { margin-bottom: 8px; }
.sheet__state h3 { margin: 10px 0 5px; color: var(--text); }
.sheet__state p { max-width: 32ch; margin: 4px auto 16px; line-height: 1.45; }
.sheet__emoji { color: var(--accent); font-size: 52px; font-weight: 900; }
.leaderboard-list { display: grid; gap: 8px; margin: 18px 0 0; padding: 0; list-style: none; }
.leaderboard-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; min-height: 54px; padding: 9px 12px; border-radius: 15px; background: rgba(16,21,37,.62); }
.leaderboard-row--self { box-shadow: inset 0 0 0 1px var(--accent); }
.leaderboard-row__position { color: var(--cyan); font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.leaderboard-row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.leaderboard-row__score { color: var(--accent); font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.personal-result { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.1); }
.personal-result > p { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.leaderboard-list--personal { margin-top: 0; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-height: 600px) and (orientation: portrait) {
  .panel { padding: 20px 18px 16px; }
  .panel-copy { margin-top: 8px; }
  .controls-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
