:root {
  --bg: #141c28;
  --bg2: #1b2735;
  --ink: #f3ead8;
  --muted: #9fb0c3;
  --accent: #b56643;
  --gold: #f4c542;
  --good: #7ddb8a;
  --bad: #e05b4b;
  --panel: #f7f1e3;
  --panel-ink: #2a2118;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}
.shell {
  width: min(100vw, 520px);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  gap: 8px;
}

/* --- шапка --- */
.masthead { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .06em; font-size: 18px; text-transform: uppercase; }
.brand-mark { color: var(--gold); font-size: 22px; }
.header-tools { display: flex; gap: 6px; }
.quiet {
  background: rgba(255,255,255,.08); color: var(--ink);
  border: 1px solid rgba(255,255,255,.16); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.quiet:active { transform: translateY(1px); }

/* --- HUD --- */
.hud {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  background: var(--bg2); border: 1px solid rgba(255,255,255,.09);
  border-radius: 12px; padding: 8px 10px;
}
.hud > div { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.hud small { font-size: 9px; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.hud strong { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#hud-combo[data-hot="true"] { color: var(--gold); }
#hud-time { color: var(--good); }

/* --- полоска прогресса темпа --- */
.levelbar { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
#levelbar-label { font-size: 10px; color: var(--muted); font-weight: 700; letter-spacing: .05em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.levelbar-track { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.10); overflow: hidden; }
#levelbar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8ef4e4, #f4c542); border-radius: 3px; transition: width .15s linear; }

/* --- комбо-полоска --- */
.combobar { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.combobar[hidden] { display: none; }
#combobar-label { font-size: 10px; color: var(--gold); font-weight: 800; letter-spacing: .06em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.combobar-track { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.10); overflow: hidden; }
#combobar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #f4c542, #e05b4b); border-radius: 3px; }
.combobar[data-hot="true"] #combobar-label { color: #ff9f43; }
.combobar[data-hot="true"] #combobar-fill { background: linear-gradient(90deg, #ff9f43, #e05b4b); box-shadow: 0 0 8px #ff9f43aa; }

/* --- тост (достижения) --- */
.toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 6; background: #f7f1e3; color: #2a2118; font-weight: 800; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
  animation: toast-in .25s ease-out; pointer-events: none; white-space: nowrap;
}
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* --- звёзды и reward-кнопка --- */
.stars { color: var(--gold); font-size: 26px; letter-spacing: 4px; text-shadow: 0 2px 8px rgba(244,197,66,.4); }
.secondary.reward { border-color: #d9b24a; color: #8a6d1f; }
.panel[data-kind="over"] .stars { display: inline-block; margin-bottom: 6px; }

/* --- сцена --- */
.stage {
  position: relative; flex: 1; min-height: 0;
  border-radius: 16px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.1);
  background: var(--bg2);
}
#field { position: absolute; inset: 0; display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
#field:focus { outline: none; }
#field:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--gold); }
.stage:focus { outline: none; }

/* --- оверлей --- */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 18, 27, .72);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.overlay[hidden] { display: none; }
.panel {
  background: var(--panel); color: var(--panel-ink);
  border-radius: 18px; padding: 22px 22px 16px;
  width: 100%; max-width: 340px; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.eyebrow { font-size: 10px; letter-spacing: .14em; font-weight: 800; color: var(--accent); margin: 0 0 6px; text-transform: uppercase; }
.panel h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.1; }
.ov-text { margin: 0 0 8px; font-size: 14px; line-height: 1.45; }
.ov-text b { font-size: 18px; }
.ov-text .record { color: #b8860b; }
.ov-tip { margin: 0 0 14px; font-size: 12px; color: #6b5d4a; line-height: 1.4; }
.primary {
  width: 100%; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent); color: #fff8ee;
  font-size: 16px; font-weight: 800; padding: 13px 16px;
  box-shadow: 0 4px 0 #7e3f27;
}
.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #7e3f27; }
.primary:disabled { opacity: .6; cursor: default; }
.secondary {
  width: 100%; margin-top: 8px; border: 1px solid #cbbfa8; background: transparent; color: var(--panel-ink);
  border-radius: 12px; padding: 10px; font-weight: 700; cursor: pointer;
}
.panel-foot { margin: 14px 0 0; font-size: 10.5px; color: #8a7c66; letter-spacing: .04em; }
.panel[data-kind="over"] h1 { color: var(--accent); }

/* --- подвал --- */
.dock { text-align: center; color: var(--muted); }
.dock p { margin: 2px 0; font-size: 11.5px; }
.dock .credit a { color: var(--muted); }

@media (min-width: 560px) {
  .shell { padding-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .primary:active { transform: none; }
}

@media (max-height: 650px) {
  .shell { padding: 6px 9px calc(6px + env(safe-area-inset-bottom)); gap: 5px; }
  .hud { padding: 5px 6px; }
  .overlay { padding: 7px; }
  .panel { padding: 13px 14px 10px; }
  .panel h1 { margin-bottom: 6px; font-size: 22px; }
  .ov-text { margin-bottom: 5px; font-size: 12px; }
  .ov-tip { margin-bottom: 7px; font-size: 11px; }
  .panel-foot { margin-top: 8px; }
  .dock p { margin: 1px 0; font-size: 10px; }
}
@media (max-width: 350px) {
  .brand { font-size: 14px; gap: 5px; }
  .header-tools { gap: 4px; }
  .quiet { padding: 6px; }
  .hud { gap: 2px; }
  .hud strong { font-size: 14px; }
}
