:root {
  --primary-gradient: linear-gradient(135deg, #ff4d6d 0%, #e63946 100%);
  --panel-bg: rgba(255, 255, 255, 0.92);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background-color: #4fa3f7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #0f172a;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #4fa3f7;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* UI Screens overlay */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: calc(16px + var(--safe-top)) 20px calc(16px + var(--safe-bottom)) 20px;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#screen-menu {
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.top-bar {
  width: 100%;
  max-width: 380px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
}

.brand-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: floatTitle 4.5s ease-in-out infinite;
}

.brand-title-1 {
  font-size: 2.7rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-transform: uppercase;
  text-shadow: 0 6px 18px rgba(3, 26, 60, 0.55);
}

.brand-title-2 {
  font-size: 2.7rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fef08a 0%, #fb7185 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 18px rgba(3, 26, 60, 0.35));
}

.brand-subtitle {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
}

.screen-title {
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  margin-bottom: 2px;
}

.screen-title.danger {
  color: #fda4af;
  text-shadow: 0 4px 18px rgba(225, 29, 72, 0.6);
}

/* Glass Panel */
.panel {
  width: 100%;
  max-width: 380px;
  background: var(--panel-bg);
  border-radius: 26px;
  padding: 20px;
  box-shadow: 0 28px 55px -15px rgba(8, 32, 70, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: popIn 0.3s cubic-bezier(0.22, 1.2, 0.36, 1) both;
  max-height: 82vh;
  overflow-y: auto;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.88);
  color: #1e293b;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 6px 18px -8px rgba(15, 42, 80, 0.5);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px) scale(0.985);
}

.btn-primary {
  background: linear-gradient(180deg, #f43f5e 0%, #e11d48 100%);
  color: #ffffff;
  border: none;
  box-shadow: 0 10px 24px -6px rgba(225, 29, 72, 0.75);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #fb7185 0%, #f43f5e 100%);
}

.btn-danger {
  background: #fff1f2;
  color: #e11d48;
  border: 1px solid #fecdd3;
}

.btn-danger:hover {
  background: #ffe4e6;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-fullscreen {
  margin-top: 2px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 24px -8px rgba(15, 23, 42, 0.8);
  padding: 12px 16px;
  justify-content: space-between;
}

.btn-fullscreen:hover {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.btn-fullscreen-left {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-fullscreen-title {
  display: block;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
}

.btn-fullscreen-sub {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
}

.badge-pill {
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  transition: all 0.2s ease;
}

.badge-pill.active {
  background: #34d399;
  color: #064e3b;
}

/* Round Icon Button */
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: transform 0.12s ease, background 0.15s ease;
  pointer-events: auto;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.4);
}

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

/* Best banner */
.stats-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(90deg, #f0f9ff 0%, #e0e7ff 100%);
  border-radius: 16px;
  border: 1px solid #e0f2fe;
  margin-bottom: 4px;
}

.stats-banner-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #334155;
}

.stats-banner-right {
  text-align: right;
}

.stats-banner-score {
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  color: #0f172a;
}

.stats-banner-runs {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #64748b;
  text-transform: uppercase;
}

/* Stats grid for game over / pause */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.stats-grid.two-col {
  grid-template-columns: 1fr 1fr;
}

.stat-cell {
  background: #f8fafc;
  border-radius: 16px;
  padding: 12px 8px;
  text-align: center;
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.stat-cell.accent {
  background: #fffbeb;
  border-color: #fde68a;
}

.stat-val {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  color: #0f172a;
}

.stat-lbl {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #64748b;
  text-transform: uppercase;
}

.record-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(90deg, #fcd34d 0%, #f59e0b 100%);
  color: #78350f;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
  animation: popIn 0.3s ease both;
}

/* Settings Row & Switch */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  cursor: pointer;
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-info {
  display: flex;
  flex-direction: column;
}

.setting-label {
  font-size: 13.5px;
  font-weight: 800;
  color: #1e293b;
}

.setting-hint {
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.2s;
  border-radius: 26px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
  background-color: #10b981;
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* How to step */
.how-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 6px 0;
}

.how-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  font-size: 18px;
  flex-shrink: 0;
}

.how-title {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
}

.how-body {
  font-size: 11.5px;
  line-height: 1.35;
  color: #64748b;
}

/* In-Game HUD */
#hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px calc(14px + var(--safe-bottom)) 16px;
  transition: opacity 0.2s ease;
}

#hud.hidden {
  opacity: 0;
  pointer-events: none;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
}

.hud-level-chip {
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 8px 12px;
  border-radius: 14px;
}

.hud-level-lbl {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
}

.hud-level-val {
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  color: #ffffff;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#hud-score {
  font-size: 3.4rem;
  font-weight: 900;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 4px 16px rgba(4, 20, 45, 0.75);
}

#hud-best {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.85);
  text-transform: uppercase;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

#hud-combo {
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.9);
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#hud-combo.power {
  background: #fbbf24;
  color: #78350f;
  animation: popIn 0.25s ease both;
}

.hud-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.hud-bottom {
  display: flex;
  justify-content: center;
  width: 100%;
}

.hud-hint {
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
}

.footer-credit {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
}

/* Animations */
@keyframes popIn {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  60% {
    transform: translateY(0) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes floatTitle {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.pop-trigger {
  animation: popIn 0.25s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
