:root {
  --night: #1b2433;
  --panel: #243043;
  --ink: #eef3fa;
  --gold: #ffd25a;
  --orange: #ff8a2b;
  --ice: #9fdcff;
  --red: #ff5d5d;
  --display: "Lilita One", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(#2f3f58, #22304a);
  box-shadow: 0 2px 0 #121a28, 0 4px 14px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 2;
}

.brand {
  font-family: var(--display);
  font-size: 22px;
  color: var(--orange);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 #7a3a0c, 0 0 12px rgba(255, 160, 60, 0.4);
  white-space: nowrap;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
  font-family: var(--display);
  font-size: 18px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stat small, .meter small, .graph small {
  font-family: system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
}
.stat.road.low span { color: var(--red); }

.graph {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.graph canvas {
  display: block;
  width: 120px;
  height: 28px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 120px;
  max-width: 260px;
}
.meter .track {
  flex: 1;
  height: 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.meter .track i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd25a, #ff8a2b 60%, #ff3b3b);
  transition: width 0.15s linear;
}
.meter.hot .track i { animation: pulse 0.4s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.55; } }

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

.stat { flex: none; }
.meter { min-width: 48px; }

@media (max-width: 640px) {
  #bar { gap: 6px; padding: 6px 8px; }
  .brand { display: none; }
  .stat { padding: 3px 9px; font-size: 16px; }
  .stat.best, .stat.road small, .meter small, .graph small { display: none; }
  .graph canvas { width: 72px; height: 24px; }
}
@media (max-width: 480px) {
  .stat.fallen { display: none; }
}
@media (max-width: 400px) {
  .stat small { display: none; }
  .stat { padding: 3px 8px; }
}

#stage {
  flex: 1;
  position: relative;
  min-height: 0;
  background: var(--night);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(20, 30, 50, 0.85);
  border: 2px solid var(--ice);
  color: #fff;
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.banner.storm { border-color: var(--red); animation: pulse 0.5s ease-in-out infinite alternate; }
.banner.respite { border-color: #7be0a0; }
.banner[hidden] { display: none; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: var(--mc-top) 0 0 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 20px;
  background: rgba(8, 14, 26, 0.66);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }

.card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 24px 20px;
  border-radius: 22px;
  background: linear-gradient(#2d3d57, #1d2a40);
  border: 2px solid rgba(159, 220, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.3), 0 18px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h1, .card h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: normal;
  color: var(--orange);
  text-shadow: 0 3px 0 #7a3a0c, 0 0 18px rgba(255, 160, 60, 0.35);
}
.card h1 { font-size: 46px; }
.card h2 { font-size: 32px; }
.lede { margin: 0; font-size: 16px; color: #dbe7f7; }

.legend {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14.5px;
  line-height: 1.35;
  color: #cfdcef;
}
.legend li { display: flex; gap: 10px; align-items: center; }
.legend b { color: #fff; }
.legend i { flex: none; }

.key { width: 18px; height: 18px; border-radius: 5px; }
.key.plow { background: linear-gradient(90deg, #ff8a2b 60%, #ffd25a 60%); }
.key.snow { background: linear-gradient(#fff, #c9d6e6); border-radius: 50%; }
.key.ave { background: repeating-linear-gradient(90deg, #ffd25a 0 3px, #3a3f4a 3px 6px); }
.key.tow { background: #ffd25a; border: 3px solid #1b2433; outline: 2px solid #ffd25a; }
.key.gridlock { background: linear-gradient(90deg, #ffd25a, #ff3b3b); border-radius: 999px; height: 10px; }

.keys { margin: 2px 0 0; font-size: 12.5px; line-height: 1.6; color: #9fb0c9; }

.primary, .soft {
  padding: 13px 20px;
  border-radius: 14px;
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.02em;
}
.primary {
  background: linear-gradient(#ffd25a, #ff9a2b);
  color: #4a1b00;
  box-shadow: 0 4px 0 #7a3a0c, 0 0 20px rgba(255, 170, 60, 0.4);
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #7a3a0c; }
.soft {
  background: rgba(255, 255, 255, 0.1);
  color: #dbe7f7;
  font-size: 18px;
  padding: 10px 16px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.results {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 16px;
  margin: 4px 8px;
  text-align: left;
  font-size: 16px;
}
.results dt { color: #a9bbd4; }
.results dd { margin: 0; font-family: var(--display); font-size: 19px; text-align: right; font-variant-numeric: tabular-nums; }
.results dd:first-of-type { color: var(--gold); font-size: 24px; }

.badge {
  margin: -4px auto 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

/* ---------- salt spreader ---------- */

.salt-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 104px;
  padding: 8px 12px 9px;
  border-radius: 16px;
  background: rgba(20, 30, 50, 0.85);
  border: 2px solid rgba(159, 220, 255, 0.45);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}
.salt-btn:active { transform: translateY(2px); }
.salt-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.03em;
}
.salt-top b { font-weight: normal; }
.salt-top span { font-size: 13px; opacity: 0.6; }
.salt-track {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.salt-track i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #bfe3ff, #fff);
  transition: width 0.15s linear;
}
.salt-btn kbd {
  font: 700 10px system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.45;
}
.salt-btn.on {
  border-color: #dff3ff;
  background: rgba(60, 100, 150, 0.9);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 18px rgba(159, 220, 255, 0.55);
}
.salt-btn.on .salt-top span { opacity: 1; color: #fff; }
.salt-btn.low .salt-track i { background: linear-gradient(90deg, #ff8a5d, #ffd25a); }
.salt-btn.empty { opacity: 0.6; }
.salt-btn.empty .salt-top span { color: var(--red); opacity: 1; }
@media (pointer: coarse) {
  .salt-btn kbd { display: none; }
}
@media (max-width: 640px) {
  .salt-btn { right: 8px; bottom: 8px; width: 92px; padding: 7px 10px 8px; }
  .salt-btn kbd { display: none; }
}

.key.salt { background: radial-gradient(circle at 35% 35%, #fff 0 2px, transparent 2.5px), radial-gradient(circle at 70% 60%, #fff 0 2px, transparent 2.5px), radial-gradient(circle at 30% 75%, #bfe3ff 0 2px, transparent 2.5px), #5f7896; }
