*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1722;
  --surface: #182232;
  --surface-2: #202d42;
  --border: #2e3e57;
  --text: #eef3f9;
  --muted: #a6b4c8;
  --accent: #f59e0b;
  --accent-dark: #d97706;
  --ok: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1b283b 0%, var(--bg) 68%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

.page {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #ea580c);
  color: #111827;
  font-weight: 800;
  font-size: 1rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.15;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: #465b7c;
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.stage-column {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.hud-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 8px;
  text-align: center;
}

.hud-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hud-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.hud-strikes {
  color: #fca5a5;
}

.canvas-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 420 / 700;
  background: #27303c;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 17, 27, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 4;
}

.overlay.hidden {
  display: none;
}

.card {
  width: 100%;
  max-width: 356px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  max-height: 100%;
  overflow-y: auto;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.eyebrow-danger {
  color: #f87171;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.18rem;
  line-height: 1.25;
}

.card-text {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: #d6e0ec;
}

.legend {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 7px;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.legend li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.dot-warn {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.28);
}

.dot-ok {
  background: var(--ok);
}

.dot-key {
  background: var(--accent);
}

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 8px 12px;
  margin-bottom: 14px;
  font-size: 0.88rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--surface-2);
  border-radius: 9px;
  padding: 8px 10px;
}

.stat-box span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.stat-box strong {
  display: block;
  font-size: 1.08rem;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.btn-stack {
  display: grid;
  gap: 8px;
}

.primary-btn,
.secondary-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #111827;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary-btn:hover {
  background: #293954;
}

.info-panel {
  display: grid;
  gap: 14px;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-card h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--accent);
}

.panel-card ol,
.panel-card ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
  font-size: 0.88rem;
  color: #d6e0ec;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage-column {
    max-width: 420px;
  }
}

@media (max-width: 400px) {
  .page {
    padding: 8px 8px 18px;
  }

  .brand h1 {
    font-size: 1.06rem;
  }

  .subtitle {
    font-size: 0.76rem;
  }

  .icon-btn {
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .hud-item {
    padding: 6px 4px;
    overflow: hidden;
  }

  .hud-label {
    font-size: 0.56rem;
    letter-spacing: 0.02em;
  }

  .hud-value {
    font-size: 0.94rem;
  }

  .card {
    padding: 14px 12px;
  }
}
