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

:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-soft: #273549;
  --border-subtle: #334155;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --accent-amber: #f59e0b;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-blue: #38bdf8;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: radial-gradient(circle at top, #1e293b 0%, #0b1120 75%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 10px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* HUD Header */
.hud-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

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

.badge-rambu {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0f172a;
  font-weight: 900;
  font-size: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.35);
}

.game-title {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

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

.hud-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-box {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 10px;
  padding: 5px 10px;
  min-width: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

.stat-num {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

.lives-row {
  font-size: 0.95rem;
  letter-spacing: 2px;
  color: var(--accent-red);
  line-height: 1.2;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-soft);
  color: var(--text-main);
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

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

.icon-btn:active {
  transform: scale(0.95);
}

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

.canvas-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.canvas-frame {
  position: relative;
  width: min(100%, calc((100svh - 178px) * 420 / 720));
  max-width: 420px;
  aspect-ratio: 420 / 720;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #334155;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.5);
  background: #1e293b;
  touch-action: manipulation;
  user-select: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.combo-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--accent-amber);
  color: #fde68a;
  font-weight: 700;
  font-size: 0.84rem;
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.overlay-card {
  position: absolute;
  inset: 14px;
  background: rgba(15, 23, 42, 0.93);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 14px;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  overflow-y: auto;
  z-index: 10;
}

.hidden {
  display: none !important;
}

.rambu-stop {
  font-size: 2.3rem;
  line-height: 1;
}

.overlay-card h2 {
  margin: 0;
  font-size: 1.28rem;
  color: #f8fafc;
}

.overlay-lead {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.48;
  color: var(--text-muted);
}

.guide-list {
  margin: 2px 0;
  padding: 10px 12px;
  list-style: none;
  text-align: left;
  background: rgba(30, 41, 59, 0.85);
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8rem;
  line-height: 1.4;
  width: 100%;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

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

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

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

.primary-btn,
.secondary-btn {
  width: 100%;
  max-width: 240px;
  padding: 12px 18px;
  border-radius: 11px;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #052e16;
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.32);
}

.secondary-btn {
  background: #334155;
  color: #f8fafc;
  border: 1px solid #475569;
}

.primary-btn:hover,
.secondary-btn:hover {
  filter: brightness(1.07);
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.97);
}

.overlay-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.summary-item {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-item span {
  font-size: 0.72rem;
  color: #94a3b8;
}

.summary-item strong {
  font-size: 1.08rem;
  color: #f8fafc;
}

/* Whistle Action Bar */
.control-bar {
  width: 100%;
  max-width: 420px;
}

.whistle-btn {
  position: relative;
  width: 100%;
  padding: 11px 14px 15px;
  border-radius: 12px;
  border: 1px solid #0284c7;
  background: linear-gradient(135deg, #0369a1, #0f172a);
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.whistle-btn:disabled {
  opacity: 0.65;
  border-color: #334155;
  cursor: not-allowed;
}

.whistle-btn:not(:disabled):hover {
  filter: brightness(1.12);
}

.whistle-meter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: rgba(15, 23, 42, 0.75);
}

.whistle-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  transition: width 0.1s linear;
}

/* Sidebar Info */
.info-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-card {
  background: rgba(30, 41, 59, 0.88);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 14px 16px;
}

.info-card h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
  color: #fde68a;
}

.info-card p {
  margin: 0 0 8px;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.lane-diagram {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}

.lane-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.8rem;
  gap: 4px;
}

.lane-col .arrow {
  font-size: 1.1rem;
  font-weight: 800;
  color: #4ade80;
}

.lane-divider {
  width: 4px;
  background: repeating-linear-gradient(
    to bottom,
    #facc15 0,
    #facc15 8px,
    #1e293b 8px,
    #1e293b 14px
  );
  margin: 0 8px;
  border-radius: 2px;
}

.hint-note {
  margin: 0 !important;
  font-size: 0.78rem !important;
  color: #94a3b8 !important;
}

.profile-list,
.key-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.profile-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.38;
}

.badge-helmet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 22px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.helmet-blue {
  background: #2563eb;
}

.helmet-green {
  background: #16a34a;
}

.helmet-orange {
  background: #ea580c;
}

.helmet-pink {
  background: #db2777;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 700;
  color: #f8fafc;
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 5px;
}

/* Responsive adjustments down to 320px */
@media (max-width: 820px) {
  .stage-layout {
    grid-template-columns: 1fr;
  }

  .info-sidebar {
    max-width: 440px;
    width: 100%;
    margin: 0 auto;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 6px 8px 18px;
    gap: 8px;
  }

  .canvas-frame {
    width: min(100%, calc((100svh - 196px) * 420 / 720));
  }

  .hud-bar {
    padding: 8px 10px;
    gap: 8px;
  }

  .game-subtitle {
    display: none;
  }

  .hud-stats {
    width: 100%;
    justify-content: space-between;
    order: 3;
  }

  .stat-box {
    flex: 1;
    min-width: 0;
    padding: 4px 4px;
  }

  .stat-num {
    font-size: 0.9rem;
  }

  .lives-row {
    font-size: 0.8rem;
    letter-spacing: 0;
  }

  .overlay-card {
    inset: 8px;
    padding: 14px 12px;
    gap: 8px;
  }

  .overlay-card h2 {
    font-size: 1.08rem;
  }

  .overlay-lead {
    font-size: 0.8rem;
  }

  .guide-list {
    font-size: 0.75rem;
    padding: 8px 10px;
    gap: 6px;
  }
}
