:root {
  --bg: #0b1322;
  --panel: #132036;
  --panel-soft: #1b2c48;
  --border: rgba(148, 163, 184, 0.22);
  --ink: #f8fafc;
  --muted: #b7c5d8;
  --amber: #f59e0b;
  --amber-bright: #fbbf24;
  --cyan: #38bdf8;
  --mint: #34d399;
  --danger: #ef4444;
  --coral: #fb7185;
  --shadow: 0 14px 36px rgba(2, 6, 23, 0.52);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #1b2845 0%, var(--bg) 68%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

.app-shell {
  max-width: 560px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

.hud {
  background: rgba(19, 32, 54, 0.94);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.back-link,
.mute-btn,
.primary-btn,
.ctrl-btn {
  touch-action: manipulation;
  cursor: pointer;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  transition: background 0.15s ease;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.15);
}

.rush-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--amber-bright);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.rush-badge.squall {
  color: #e0f2fe;
  background: rgba(14, 165, 233, 0.28);
  border-color: rgba(56, 189, 248, 0.7);
}

.mute-btn {
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
}

.mute-btn.muted {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

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

.stat-pill {
  background: rgba(11, 19, 34, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 11px;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.stat-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1.1;
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin-top: 2px;
}

.stat-extra .stat-value {
  font-size: 0.76rem;
  color: var(--cyan);
}

.flood-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flood-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: #dbeafe;
}

.flood-pct {
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

.flood-track {
  width: 100%;
  height: 10px;
  background: rgba(15, 23, 42, 0.95);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  overflow: hidden;
}

.flood-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  transition: width 0.1s linear, background 0.2s ease;
}

.flood-wrap.warn .flood-fill {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.flood-wrap.warn .flood-pct {
  color: var(--amber-bright);
}

.flood-wrap.danger .flood-fill {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.flood-wrap.danger .flood-pct {
  color: #fca5a5;
}

.flood-wrap.danger {
  animation: pulse-danger 0.65s infinite alternate;
}

@keyframes pulse-danger {
  from {
    filter: drop-shadow(0 0 0 rgba(239, 68, 68, 0));
  }
  to {
    filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.65));
  }
}

.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d1628;
  box-shadow: var(--shadow);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.squall-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(14, 116, 144, 0.92);
  color: #f0f9ff;
  border: 1px solid rgba(125, 211, 252, 0.75);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.4);
  pointer-events: none;
  z-index: 4;
  animation: squall-bob 0.8s ease-in-out infinite alternate;
}

@keyframes squall-bob {
  from {
    transform: translateX(-50%) translateY(0);
  }
  to {
    transform: translateX(-50%) translateY(3px);
  }
}

.combo-pill {
  position: absolute;
  top: 46px;
  right: 12px;
  background: rgba(249, 115, 22, 0.92);
  color: #fff;
  border: 1px solid rgba(254, 215, 170, 0.85);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 800;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 6px 14px rgba(249, 115, 22, 0.35);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 13, 25, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 10;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(165deg, rgba(25, 39, 65, 0.98), rgba(15, 24, 43, 0.98));
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 20px;
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.6);
}

.modal-eyebrow,
.crash-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.modal-eyebrow {
  background: rgba(56, 189, 248, 0.16);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.crash-badge {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.modal-card h1,
.modal-card h2 {
  font-size: 1.32rem;
  line-height: 1.25;
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 0.87rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 12px;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  text-align: left;
  margin-bottom: 12px;
}

.legend-col {
  background: rgba(11, 19, 34, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px;
  padding: 9px;
}

.legend-col h2 {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--amber-bright);
  margin-bottom: 6px;
}

.legend-col ul {
  list-style: none;
  display: grid;
  gap: 5px;
  font-size: 0.76rem;
  color: #e2e8f0;
  line-height: 1.3;
}

.best-strip {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.best-strip strong {
  color: var(--amber-bright);
}

.new-record {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f59e0b, #f97316);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}

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

.result-box {
  background: rgba(11, 19, 34, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.result-box strong {
  font-size: 1.08rem;
  color: var(--ink);
}

.primary-btn {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.42);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.primary-btn:active {
  transform: scale(0.98);
}

.controls-note {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.controls-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  flex-shrink: 0;
}

.ctrl-btn {
  min-height: 52px;
  border-radius: 15px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: linear-gradient(180deg, #1d3152, #15243e);
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 16px rgba(2, 6, 23, 0.45);
  transition: transform 0.08s ease, background 0.12s ease;
}

.ctrl-btn:active {
  transform: scale(0.96);
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
}

.ctrl-arrow {
  font-size: 1.1rem;
  color: var(--amber-bright);
}

@media (max-width: 390px) {
  .legend-grid {
    grid-template-columns: 1fr;
  }
  .hud-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ctrl-btn {
    min-height: 46px;
  }
}
