/* Voxel Kart — chunky saturated diorama UI */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: "Arial Black", "Avenir Next Heavy", "Segoe UI Black", system-ui, sans-serif;
  background: #87c7f2;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- shared ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; text-align: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(20, 40, 70, 0.12), rgba(10, 20, 40, 0.45));
  z-index: 30; padding: 20px;
}
.screen.dim { background: rgba(10, 18, 34, 0.62); backdrop-filter: blur(3px); }
button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 12px 26px; font-size: 17px; letter-spacing: 1px; color: #fff;
  background: linear-gradient(#5a7bb5, #3d5a8f);
  box-shadow: 0 5px 0 #2a3f63, 0 8px 16px rgba(0,0,0,0.35);
  transition: transform 0.05s;
  text-shadow: 0 2px 0 rgba(0,0,0,0.3);
}
button:active { transform: translateY(4px); box-shadow: 0 1px 0 #2a3f63; }
button.primary { background: linear-gradient(#ff9d3b, #ef6c1a); box-shadow: 0 5px 0 #a84a10, 0 8px 16px rgba(0,0,0,0.35); }
button.big { font-size: 22px; padding: 16px 40px; }
.menu { display: flex; flex-direction: column; gap: 12px; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }

.logo {
  font-size: clamp(52px, 11vw, 120px); line-height: 0.92; color: #ffd23e; letter-spacing: 2px;
  text-shadow:
    0 2px 0 #e8a116, 0 -2px 0 #e8a116, 2px 0 0 #e8a116, -2px 0 0 #e8a116,
    0 6px 0 #b26a00, 0 10px 0 rgba(0,0,0,0.28), 0 18px 28px rgba(0,0,0,0.35);
  transform: rotate(-2deg);
}
.logo span { color: #f2f0e8; text-shadow:
  0 2px 0 #b23c2c, 0 -2px 0 #b23c2c, 2px 0 0 #b23c2c, -2px 0 0 #b23c2c,
  0 6px 0 #7c1f14, 0 10px 0 rgba(0,0,0,0.28), 0 18px 28px rgba(0,0,0,0.35); }
.logo.small { font-size: 54px; }
.subtitle {
  font-size: clamp(11px, 2.2vw, 16px); color: #23405e; background: rgba(255,255,255,0.55);
  padding: 6px 16px; border-radius: 999px; letter-spacing: 2px;
}
.title-hint { font-family: system-ui, sans-serif; font-size: 12px; color: rgba(255,255,255,0.9); text-shadow: 0 1px 2px rgba(0,0,0,0.4); line-height: 1.7; }

/* ---------- loading ---------- */
#loading { z-index: 60; background: linear-gradient(#8ed0f7, #d9b26a); }
.loader-label { font-size: 15px; color: #23405e; letter-spacing: 2px; }
#load-bar { width: min(340px, 70vw); height: 18px; border: 3px solid #23405e; border-radius: 10px; overflow: hidden; background: rgba(255,255,255,0.4); }
#load-fill { height: 100%; width: 0%; background: repeating-linear-gradient(45deg, #ffd23e 0 12px, #ff9d3b 12px 24px); transition: width 0.15s; }

/* ---------- select ---------- */
.screen-title { color: #fff; font-size: clamp(24px, 4.6vw, 40px); letter-spacing: 2px;
  text-shadow: 0 3px 0 #b23c2c, 0 6px 12px rgba(0,0,0,0.4); }
#select-grid { display: grid; grid-template-columns: repeat(4, minmax(70px, 108px)); gap: 10px; }
.sel-tile {
  aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; border: 4px solid rgba(255,255,255,0.55); background: rgba(255,255,255,0.18); cursor: pointer;
  transition: transform 0.08s;
}
.sel-tile:hover { transform: scale(1.06); }
.sel-tile.selected { border-color: #ffd23e; background: rgba(255, 210, 62, 0.25); transform: scale(1.08); }
.sel-tile .face { font-size: clamp(26px, 5vw, 42px); line-height: 1; filter: drop-shadow(0 3px 2px rgba(0,0,0,0.3)); }
.sel-tile .face img { width: clamp(40px, 6vw, 64px); height: auto; border-radius: 6px; filter: drop-shadow(0 4px 3px rgba(0,0,0,0.35)); }
.sel-tile .nm { font-size: clamp(9px, 1.6vw, 12px); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.4); letter-spacing: 1px; }
#select-panel { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 128px; }
#sel-name { font-size: clamp(26px, 5vw, 40px); color: #ffd23e; text-shadow: 0 3px 0 #b26a00, 0 6px 10px rgba(0,0,0,0.4); }
#sel-epithet { font-family: system-ui, sans-serif; font-style: italic; color: #eaf4ff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); font-size: 13px; }
#sel-stats { display: grid; grid-template-columns: auto auto; gap: 6px 14px; align-items: center; margin-top: 6px; }
.stat-label { font-size: 11px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.4); letter-spacing: 1px; text-align: right; }
.stat-track { width: min(200px, 40vw); height: 12px; background: rgba(0,0,0,0.35); border-radius: 7px; overflow: hidden; }
.stat-fill { height: 100%; background: linear-gradient(90deg, #6ee06e, #ffd23e, #ff9d3b); width: 0; transition: width 0.2s; border-radius: 7px; }

/* ---------- countdown ---------- */
#countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 25; pointer-events: none; }
#cd-num {
  font-size: clamp(120px, 26vw, 300px); color: #ffd23e; font-weight: 900;
  text-shadow: 0 6px 0 #b26a00, 0 12px 0 rgba(0,0,0,0.25), 0 24px 40px rgba(0,0,0,0.4);
  animation: cdPop 0.9s ease-out;
}
#cd-num.go { color: #5ce65c; text-shadow: 0 6px 0 #1e7c1e, 0 12px 0 rgba(0,0,0,0.25), 0 24px 40px rgba(0,0,0,0.4); }
@keyframes cdPop { 0% { transform: scale(2.2); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(1); opacity: 0.95; } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
#position {
  position: absolute; top: 14px; left: 16px; color: #ffd23e; line-height: 0.9;
  text-shadow: 0 4px 0 #b26a00, 0 8px 0 rgba(0,0,0,0.25), 0 12px 20px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
#position.pop { transform: scale(1.25); }
#pos-num { font-size: clamp(52px, 9vw, 92px); }
#pos-suffix { font-size: clamp(20px, 3.4vw, 34px); }
#lap-badge {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: clamp(15px, 2.6vw, 22px); color: #fff; background: rgba(20, 32, 52, 0.65);
  padding: 6px 18px; border-radius: 999px; letter-spacing: 2px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}
#lap-badge.final { background: #e3452f; animation: pulse 0.6s infinite alternate; }
@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.08); } }
#item-slot {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  width: clamp(64px, 11vw, 92px); height: clamp(64px, 11vw, 92px);
  background: rgba(255,255,255,0.16); border: 4px solid rgba(255,255,255,0.75);
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25), inset 0 0 18px rgba(255,255,255,0.15);
}
#item-icon { width: 70%; height: 70%; display: flex; align-items: center; justify-content: center; }
#item-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35)); }
#item-slot.spin { animation: slotSpin 0.14s infinite alternate; }
@keyframes slotSpin { from { transform: translateX(-50%) rotate(-3deg); } to { transform: translateX(-50%) rotate(3deg); } }
#coins-badge {
  position: absolute; top: 16px; right: 210px; display: flex; align-items: center; gap: 7px;
  font-size: clamp(17px, 3vw, 26px); color: #ffd23e; text-shadow: 0 3px 0 #b26a00, 0 6px 10px rgba(0,0,0,0.4);
}
.coin-ico { width: 0.9em; height: 0.9em; background: radial-gradient(circle at 35% 30%, #ffe27a, #e8a92e);
  border-radius: 4px; box-shadow: 0 2px 0 #a87a12; display: inline-block; }
#speedo {
  position: absolute; right: 18px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 5px;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.45);
}
#speed-num { font-size: clamp(34px, 6vw, 54px); line-height: 1; }
#speedo .unit { font-size: 12px; letter-spacing: 2px; opacity: 0.9; }
#speed-bar { width: clamp(130px, 22vw, 190px); height: 12px; background: rgba(0,0,0,0.4); border-radius: 7px; overflow: hidden; }
#speed-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #6ee06e, #ffd23e 60%, #ff5252); }
#speed-fill.boosted { background: linear-gradient(90deg, #ffd23e, #ff9d3b, #ff5252); }
#minimap {
  position: absolute; left: 16px; bottom: 16px; width: clamp(120px, 19vw, 190px); height: auto;
  background: rgba(16, 28, 46, 0.5); border-radius: 14px; box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
#standings {
  position: absolute; right: 16px; top: 16px; display: flex; flex-direction: column; gap: 3px;
  font-family: system-ui, sans-serif; font-size: clamp(9px, 1.5vw, 12px); color: #dfe9f5;
  background: rgba(16, 28, 46, 0.45); padding: 8px 10px; border-radius: 10px; min-width: 110px;
}
.stand-row { display: flex; gap: 6px; align-items: center; opacity: 0.85; }
.stand-row.me { opacity: 1; font-weight: 700; color: #ffd23e; }
.stand-row .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.stand-row .pl { width: 18px; opacity: 0.8; }
#center-banner {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%); font-size: clamp(34px, 7vw, 72px);
  color: #fff; text-shadow: 0 4px 0 #b23c2c, 0 8px 16px rgba(0,0,0,0.45); opacity: 0; white-space: nowrap;
  transition: opacity 0.25s; letter-spacing: 3px;
}
#center-banner.show { opacity: 1; animation: bannerIn 0.5s ease-out; }
@keyframes bannerIn { 0% { transform: translateX(-50%) scale(0.4); } 60% { transform: translateX(-50%) scale(1.15); } 100% { transform: translateX(-50%) scale(1); } }
#wrong-way {
  position: absolute; top: 38%; left: 50%; transform: translateX(-50%);
  font-size: clamp(22px, 4.4vw, 40px); color: #ff5252; text-shadow: 0 3px 0 rgba(0,0,0,0.5);
  animation: pulse2 0.5s infinite alternate; white-space: nowrap;
}
@keyframes pulse2 { from { opacity: 0.7; } to { opacity: 1; } }
#flash-msg {
  position: absolute; bottom: 26%; left: 50%; transform: translateX(-50%);
  font-size: clamp(18px, 3.4vw, 30px); color: #ffd23e; text-shadow: 0 3px 0 #b26a00, 0 6px 12px rgba(0,0,0,0.4);
  opacity: 0; transition: opacity 0.3s; white-space: nowrap;
}
#flash-msg.show { opacity: 1; }

/* ---------- touch controls ---------- */
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 22; }
.tc-cluster { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; }
.tc-left { left: 18px; }
.tc-right { right: 18px; flex-wrap: wrap; justify-content: flex-end; max-width: 46vw; }
.tc-btn {
  pointer-events: auto; touch-action: none; border-radius: 50%; border: 4px solid rgba(255,255,255,0.75);
  background: rgba(30, 48, 78, 0.55); color: #fff; font-family: inherit; font-size: 20px;
  width: 84px; height: 84px; box-shadow: 0 4px 0 rgba(0,0,0,0.35); padding: 0; display: flex; align-items: center; justify-content: center;
}
.tc-btn.pressed { background: rgba(255, 210, 62, 0.75); transform: scale(0.94); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.tc-btn.tc-big { width: 104px; height: 104px; background: rgba(105, 200, 90, 0.6); font-size: 24px; }
.tc-btn.tc-small { width: 72px; height: 72px; font-size: 13px; }
.tc-steer { width: 92px; height: 92px; font-size: 30px; background: rgba(30, 48, 78, 0.55); }

/* ---------- corner buttons ---------- */
#pause-btn {
  position: absolute; top: 14px; right: 14px; z-index: 24; width: 46px; height: 46px; border-radius: 12px;
  background: rgba(20, 32, 52, 0.6); color: #fff; font-size: 18px; box-shadow: 0 3px 0 rgba(0,0,0,0.3); padding: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- results ---------- */
#results { z-index: 35; }
#results-table {
  display: flex; flex-direction: column; gap: 6px; background: rgba(16, 28, 46, 0.72);
  padding: 18px 24px; border-radius: 16px; min-width: min(430px, 92vw); max-height: 52vh; overflow-y: auto;
}
.res-row { display: grid; grid-template-columns: 44px 24px 1fr auto; gap: 10px; align-items: center;
  font-family: system-ui, sans-serif; font-size: clamp(12px, 2vw, 16px); color: #dfe9f5; padding: 5px 8px; border-radius: 8px; }
.res-row.me { background: rgba(255, 210, 62, 0.18); color: #ffd23e; font-weight: 700; }
.res-row .place { font-family: inherit; font-weight: 800; font-size: 1.15em; color: #fff; }
.res-row:nth-child(1) .place { color: #ffd23e; }
.res-row:nth-child(2) .place { color: #d7dde6; }
.res-row:nth-child(3) .place { color: #e2a26a; }
.res-row .swatch { width: 14px; height: 14px; border-radius: 4px; }
.res-row .time { font-variant-numeric: tabular-nums; opacity: 0.9; }

@media (max-width: 720px) {
  #standings { display: none; }
  #coins-badge { right: 70px; top: 60px; }
  #minimap { width: 100px; }
  #position { top: 8px; left: 10px; }
  .tc-btn.tc-small { width: 62px; height: 62px; }
}
@media (max-height: 480px) {
  #select-grid { grid-template-columns: repeat(8, minmax(48px, 72px)); }
}
