:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --danger: #ef4444;
  --safe: #22c55e;
  --info: #38bdf8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.badge-dishub {
  background: #1d4ed8;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid #60a5fa;
}

.brand h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand h1 span {
  color: var(--accent);
}

.hud {
  display: flex;
  gap: 0.5rem;
}

.hud-box {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  min-width: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

.hud-val {
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#livesVal {
  color: #f87171;
  letter-spacing: 1px;
}

#comboVal {
  color: var(--accent);
}

.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  gap: 0.5rem;
}

.canvas-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 2 / 3;
  max-height: calc(100vh - 130px);
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--panel-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  background: #1e293b;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  cursor: pointer;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1.35rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.card-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.55rem;
}

.card-tag-danger {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.4);
}

.card h2 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  color: #fff;
}

.card .lead {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #cbd5e1;
  margin-bottom: 0.9rem;
}

.rules {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.15rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #e2e8f0;
}

.rules li {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.3rem;
  flex-shrink: 0;
}

.dot-danger {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

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

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

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1.15rem;
}

.sum-item {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sum-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.sum-val {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
}

.controls-row {
  display: flex;
  gap: 0.6rem;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

button:active {
  transform: scale(0.97);
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #0f172a;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #334155;
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.75rem 0.9rem;
}

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

.bottom-bar {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.swatch-left {
  background: #38bdf8;
}

.swatch-right {
  background: #4ade80;
}

.swatch-wrong {
  background: #ef4444;
}

.action-btns {
  display: flex;
  gap: 0.4rem;
}

.btn-small {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-small:hover {
  background: #334155;
}

@media (max-width: 480px) {
  .topbar {
    padding: 0.5rem 0.65rem;
  }
  .brand h1 {
    font-size: 0.95rem;
  }
  .hud-box {
    min-width: 54px;
    padding: 0.2rem 0.4rem;
  }
  .hud-val {
    font-size: 0.85rem;
  }
  .canvas-shell {
    max-height: calc(100vh - 140px);
  }
}
