@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=DM+Sans:wght@300;400;500&display=swap');

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

:root {
  --ink:    #111111;
  --muted:  #888888;
  --line:   #e0e0e0;
  --bg:     #ffffff;
  --red:    #e63946;
  --teal:   #2ec4b6;
  --amber:  #f4a261;
  --violet: #7b68ee;
  --gold:   #f9c74f;
  --blue:   #457b9d;
  --water:  #4a9edd;
  --panel-bg: rgba(255,255,255,0.97);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

body {
  background: var(--bg);
  font-family: 'DM Mono', monospace;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  color: var(--ink);
}

#game-canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

/* ── OVERLAYS ── */
#welcome-screen, #death-screen, #shop-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px) saturate(0.6);
  background: rgba(255,255,255,0.25);
  transition: opacity 0.35s var(--ease);
}
#welcome-screen.fade-out { opacity: 0; pointer-events: none; }
#death-screen.hidden, #shop-screen.hidden { display: none; }

.overlay-panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 36px 40px;
  max-width: 480px;
  width: 94%;
  text-align: center;
  box-shadow: 0 28px 70px rgba(0,0,0,0.09), 0 2px 8px rgba(0,0,0,0.04);
  animation: panelIn 0.45s var(--ease) both;
  max-height: 92vh;
  overflow-y: auto;
  scrollbar-width: none;
}
.overlay-panel::-webkit-scrollbar { display: none; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.logo {
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  font-size: 46px;
  letter-spacing: -1.5px;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 6px;
}
.logo em { font-style: normal; color: var(--red); }

.sub {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 22px;
  font-weight: 300;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 22px;
}
.ctrl-item {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
kbd {
  background: var(--ink);
  color: #fff;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
}

.section-label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ── MODE PICKER ── */
#mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.mode-btn {
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s, transform 0.15s var(--ease), box-shadow 0.18s;
  font-family: 'DM Mono', monospace;
}
.mode-btn:hover { border-color: var(--ink); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,0.07); }
.mode-btn.active { border-color: var(--ink); background: #f8f8f8; }
.mode-btn[data-mode="water"].active { border-color: var(--water); background: rgba(74,158,221,0.06); }
.mode-btn[data-mode="hard"].active  { border-color: var(--red);   background: rgba(230,57,70,0.04); }
.mode-btn[data-mode="easy"].active  { border-color: var(--teal);  background: rgba(46,196,182,0.04); }
.mode-name { display: block; font-size: 12px; font-weight: 500; color: var(--ink); margin-bottom: 3px; }
.mode-desc { display: block; font-size: 9px; color: var(--muted); line-height: 1.4; }

#lifetime-block {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 10px 18px;
  background: #f5f5f5;
  border-radius: 8px;
}
.lt-label { font-size: 10px; color: var(--muted); }
.lt-value  { font-size: 20px; font-weight: 500; letter-spacing: -0.5px; }

/* ── BUTTONS ── */
.pill-btn {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 11px 32px;
  cursor: pointer;
  border-radius: 100px;
  transition: transform 0.14s var(--ease), opacity 0.14s;
  letter-spacing: 0.3px;
}
.pill-btn:hover  { transform: translateY(-1px); opacity: 0.87; }
.pill-btn:active { transform: translateY(1px); }
.pill-btn.ghost  { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.pill-btn.ghost:hover { color: var(--ink); border-color: var(--ink); }
.pill-btn.danger { color: var(--red); border-color: rgba(230,57,70,0.3); }
.pill-btn.danger:hover { border-color: var(--red); }

.welcome-btns, .death-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ── HUD ── */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  pointer-events: none;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
}

#speedometer { position: relative; width: 110px; height: 110px; flex-shrink: 0; }
#speed-digits {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  font-family: 'DM Sans', sans-serif; font-size: 26px; font-weight: 400;
  color: var(--ink); line-height: 1; letter-spacing: -1px;
}
#speed-unit {
  position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%);
  font-size: 8px; color: var(--muted); letter-spacing: 1px; font-weight: 300;
}

#hud-center { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding-top: 16px; }
#mode-badge {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 5px 14px;
  font-size: 10px;
  color: var(--muted);
  backdrop-filter: blur(4px);
}

#hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.hud-chip {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  backdrop-filter: blur(4px);
  transition: opacity 0.3s;
}
.hud-chip.hidden { opacity: 0; pointer-events: none; }
.chip-label { font-size: 8px; color: var(--muted); letter-spacing: 0.5px; }
.chip-val   { font-size: 13px; font-weight: 500; letter-spacing: -0.3px; }
#limit-chip .chip-val { color: var(--red); }
#limit-chip { border-color: rgba(230,57,70,0.25); animation: blink 1.1s ease-in-out infinite; }

@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

/* ── BOOST MENU ── */
#boost-menu {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px) saturate(0.7);
  background: rgba(255,255,255,0.22);
  transition: opacity 0.25s var(--ease);
}
#boost-menu.hidden { display: none; }

.boost-menu-inner {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 440px;
  width: 92%;
  animation: panelIn 0.3s var(--ease) both;
}
.boost-menu-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#boost-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ── BOOST HINT ── */
#boost-hint {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 50;
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 5px 12px;
  font-size: 10px;
  color: var(--muted);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  transition: opacity 0.3s;
}

/* ── DEATH SCREEN ── */
.death-panel { max-width: 520px; }
.death-emoji { font-size: 44px; line-height: 1; margin-bottom: 8px; }
.death-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 30px;
  font-weight: 300;
  letter-spacing: -0.5px;
  margin-bottom: 3px;
}
.death-reason { font-size: 10px; color: var(--muted); margin-bottom: 20px; letter-spacing: 0.3px; }

.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
  background: #f7f7f7;
  border-radius: 10px;
  overflow: hidden;
}
.score-col { flex: 1; padding: 12px 14px; }
.score-divider { width: 1px; height: 36px; background: var(--line); }
.sc-label { font-size: 8px; color: var(--muted); letter-spacing: 0.5px; margin-bottom: 3px; }
.sc-val   { font-size: 24px; font-weight: 500; letter-spacing: -1px; }

/* ── SHOP CARDS ── */
#shop-grid, #shop-grid-welcome, #boost-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 18px;
}
#boost-menu-grid { margin-bottom: 0; }

.shop-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s, transform 0.14s var(--ease), box-shadow 0.18s;
  background: #fff;
  position: relative;
}
.shop-card:hover:not(.disabled):not(.owned) {
  border-color: var(--ink);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
}
.shop-card.disabled  { opacity: 0.38; cursor: not-allowed; }
.shop-card.owned     { border-color: var(--teal); background: rgba(46,196,182,0.04); cursor: default; }
.shop-card.boost-card { border-color: var(--amber); background: rgba(244,162,97,0.04); }
.shop-card.boost-card:hover:not(.disabled) { border-color: var(--amber); }

.shop-card-icon  { font-size: 18px; margin-bottom: 5px; }
.shop-card-name  { font-size: 11px; font-weight: 500; color: var(--ink); margin-bottom: 2px; }
.shop-card-desc  { font-size: 9px; color: var(--muted); line-height: 1.4; margin-bottom: 6px; }
.shop-card-cost  {
  font-size: 9px; color: var(--ink);
  background: #f0f0f0; border-radius: 4px;
  padding: 2px 6px; display: inline-block;
}
.shop-card.owned .shop-card-cost { background: rgba(46,196,182,0.15); color: var(--teal); }
.shop-card.boost-card .shop-card-cost { background: rgba(244,162,97,0.15); color: #c07020; }
.cost-rising { font-size: 8px; color: var(--muted); margin-left: 4px; }

/* ── ACTIVE POWERUP BADGES ── */
#active-powerups {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
  max-width: 80vw;
}
.ap-badge {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 4px 11px;
  font-size: 10px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 4px;
  backdrop-filter: blur(4px);
  animation: badgeIn 0.3s var(--ease) both;
}
@keyframes badgeIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  padding: 7px 16px;
  border-radius: 100px;
  pointer-events: none;
  z-index: 300;
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.28s, transform 0.28s var(--ease);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
