/* ========== GAME UI - Shake Sprint 100 ========== */
:root {
  --bg-deep: #060e1a;
  --bg-mid: #0a1628;
  --ink: #e8f4ff;
  --muted: #7eb8d6;
  --gold: #ffd700;
  --orange: #ff8c42;
  --orange-dark: #d4601a;
  --green: #4dff91;
  --green-dark: #1fa855;
  --blue: #44b8ff;
  --red: #ff5a4f;
  --panel-bg: rgba(8, 18, 32, 0.85);
}

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

html, body {
  height: 100%; overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

body {
  min-height: 100dvh;
  font-family: "Avenir Next", "PingFang SC", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, #060e1a, #0c1e36 40%, #0a1425 70%, #050c16);
}

/* ===== Static bg (no animation) ===== */
.bg-stars { display: none; }

/* ===== Layout ===== */
.page-shell {
  position: relative; z-index: 1;
  width: min(480px, 100vw); height: 100dvh;
  margin: 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.stage-anchor { display: none; }

/* ===== Notice banner ===== */
.notice-banner {
  display: none; position: absolute;
  left: 12px; right: 12px; top: 12px; z-index: 50;
  border-radius: 14px; padding: 10px 14px;
  font-size: 14px; font-weight: 700;
  backdrop-filter: blur(8px);
  text-align: center;
}
.notice-banner.show { display: block; }
.notice-banner.info    { color: #9fdfff; background: rgba(20,80,140,0.7); border: 1px solid rgba(76,182,239,0.5); }
.notice-banner.success { color: #95f2c7; background: rgba(20,120,70,0.6); border: 1px solid rgba(88,225,161,0.5); }
.notice-banner.error   { color: #ffb1a5; background: rgba(160,40,30,0.6); border: 1px solid rgba(255,139,117,0.5); }

/* ===== Scenes ===== */
.scene {
  display: none; min-height: 0; padding-top: 0;
}
#noticeBar.show ~ .scene { padding-top: 52px; }
.scene.active {
  display: flex; flex: 1; min-height: 0;
  animation: sceneSlam 350ms cubic-bezier(0.17,0.67,0.35,1.1);
}
@keyframes sceneSlam {
  0%   { opacity: 0; transform: scale(0.92) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== Game buttons ===== */
.game-btn {
  border: none; border-radius: 16px;
  padding: 14px 24px;
  font-size: 17px; font-weight: 800;
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: relative; overflow: hidden;
}
.game-btn:active { transform: scale(0.94); }
.game-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.game-btn .btn-icon { display: none; }

.game-btn-primary {
  color: #fff;
  background: linear-gradient(145deg, var(--orange), #ff6a1a);
  box-shadow: 0 4px 20px rgba(255,140,66,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.game-btn-primary:active { box-shadow: 0 2px 8px rgba(255,140,66,0.3); }

.game-btn-secondary {
  color: #e0f4ff;
  background: linear-gradient(145deg, #1a4a6e, #2a6a90);
  box-shadow: 0 4px 16px rgba(30,80,130,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}

.game-btn-start {
  font-size: 22px; padding: 18px 36px;
  color: #fff;
  background: linear-gradient(145deg, var(--green-dark), #2dd868);
  box-shadow: 0 4px 24px rgba(45,216,104,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
  border-radius: 20px; margin-top: auto;
}

.game-btn-big { font-size: 20px; padding: 16px 32px; }
.game-btn-small { font-size: 13px; padding: 8px 14px; border-radius: 10px; }

.game-btn.loading::after { content: "…"; margin-left: 6px; }

/* pulse breathing - lightweight */
.pulse-anim:not(:disabled) {
  animation: pulseGlow 2.5s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

/* ===== Game input ===== */
.game-input {
  border: 2px solid rgba(120,200,255,0.2);
  border-radius: 14px; padding: 12px 14px;
  background: rgba(10,25,45,0.8);
  color: #e0f4ff; font-size: 16px; font-weight: 600;
  text-align: center; width: 100%;
  transition: border-color 200ms;
}
.game-input:focus { border-color: var(--orange); outline: none; }
.game-input-code { font-size: 20px; letter-spacing: 0.2em; text-transform: uppercase; }

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(255,200,60,0.15);
  color: var(--gold); border: 1px solid rgba(255,200,60,0.3);
  font-size: 12px; font-weight: 700;
}

/* ============================================
   SCENE: AUTH / SPLASH
   ============================================ */
.splash-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 100%; height: 100%;
  padding: 40px 24px 32px;
  gap: 8px; text-align: center;
}

.splash-deco {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--gold));
  box-shadow: 0 0 40px rgba(255,180,60,0.3);
  margin-bottom: 8px;
}

.game-title {
  font-size: clamp(42px, 10vw, 64px);
  font-weight: 900; line-height: 0.95;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--gold), var(--orange), #ff5a4f);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 4px 16px rgba(255,180,60,0.35));
}
.game-title em {
  font-style: normal; font-size: 0.65em;
  letter-spacing: 0.16em;
}

.game-tagline {
  color: var(--muted); font-size: 15px; font-weight: 600;
  letter-spacing: 0.08em; margin-top: 4px;
}

.splash-actions {
  display: flex; flex-direction: column;
  gap: 12px; width: 100%; max-width: 300px;
  margin-top: 28px;
}

.guest-login-group {
  display: flex; flex-direction: column; gap: 8px;
}

/* ============================================
   SCENE: ROOM / WAITING
   ============================================ */
.waiting-room {
  display: flex; flex-direction: column;
  align-items: center; width: 100%; height: 100%;
  padding: 20px 16px 24px; gap: 12px;
}

.scene-title {
  font-size: 24px; font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, var(--blue), #8be0ff);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 8px rgba(68,184,255,0.3));
}

.room-actions-top {
  display: flex; gap: 8px; width: 100%;
  align-items: center;
}
.room-actions-top .game-btn { flex: 0 0 auto; }
.join-row {
  display: flex; gap: 6px; flex: 1;
}
.join-row .game-input { flex: 1; }

.room-code-display {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 24px; border-radius: 20px;
  background: rgba(255,215,0,0.08);
  border: 2px solid rgba(255,215,0,0.25);
  cursor: pointer; transition: border-color 200ms;
  width: 100%; max-width: 280px;
}
.room-code-display:active { border-color: var(--gold); }
.room-code-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.room-code-value {
  font-size: 42px; font-weight: 900; letter-spacing: 0.2em;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255,215,0,0.4);
}
.room-code-hint { font-size: 11px; color: var(--muted); opacity: 0.7; }

/* QR code area */
.qr-area {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.qr-area canvas {
  border-radius: 10px; background: #fff; padding: 8px;
}
.qr-hint {
  font-size: 11px; color: var(--muted); letter-spacing: 0.05em;
}

/* Motion permission hint */
.motion-perm-hint {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 20px; background: rgba(255, 60, 60, 0.12);
  border: 1px solid rgba(255, 80, 80, 0.3); border-radius: 14px;
  text-align: center;
}
.motion-perm-icon { font-size: 28px; }
.motion-perm-text {
  font-size: 14px; color: var(--fg); line-height: 1.5;
}

/* Motion gate on auth page */
.motion-gate {
  margin: 12px 0;
}
.motion-gate-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 24px 20px; background: rgba(255, 180, 50, 0.12);
  border: 1px solid rgba(255, 180, 50, 0.35); border-radius: 16px;
  text-align: center;
}
.motion-gate-icon { font-size: 36px; }
.motion-gate-text {
  font-size: 15px; color: var(--fg); line-height: 1.5; margin: 0;
}
.motion-gate-error {
  font-size: 13px; color: #ff6b6b; margin: 0;
}
.motion-gate-card .game-btn {
  min-width: 160px;
}

.room-info-row {
  display: flex; gap: 8px; align-items: center;
  font-size: 14px; color: var(--muted);
}

/* player grid */
.players-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; padding: 8px 0;
  flex: 1; min-height: 0; overflow: auto;
  align-content: flex-start;
}

.player-avatar-cell {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; width: 56px;
}
.player-avatar-cell .rank-avatar {
  width: 40px; height: 40px;
  border-radius: 50%; overflow: hidden;
  border: 2px solid rgba(120,200,255,0.3);
  background: linear-gradient(145deg, #1a3a5a, #2a5578);
}
.player-avatar-cell .rank-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.player-avatar-cell .rank-avatar-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-size: 16px; font-weight: 800; color: #c8edff;
}
.player-avatar-cell .player-nick {
  font-size: 11px; color: var(--muted);
  max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: center;
}

/* ============================================
   SCENE: RACE
   ============================================ */
.race-fullscreen {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  position: relative;
}

/* HUD top overlay */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: calc(env(safe-area-inset-top, 8px) + 4px) 12px 8px;
  background: linear-gradient(180deg, rgba(6,14,26,0.9) 60%, transparent);
  pointer-events: none;
}
.hud-item {
  display: flex; align-items: center; gap: 4px;
}
.hud-label { font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: 0.1em; text-transform: uppercase; }
.hud-value {
  font-size: 22px; font-weight: 900; color: #fff;
  text-shadow: 0 0 12px rgba(255,255,255,0.4);
}
.hud-rank .hud-value { color: var(--gold); }

#myRankValue.rank-badge-up { animation: myRankRise 420ms ease; color: var(--green); }
#myRankValue.rank-badge-down { animation: myRankFall 420ms ease; color: var(--red); }
@keyframes myRankRise {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-6px) scale(1.2); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes myRankFall {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(5px) scale(1.15); }
  100% { transform: translateY(0) scale(1); }
}

/* Canvas */
.track-wrap {
  flex: 1; min-height: 0;
  border-radius: 0; overflow: hidden;
  background: transparent;
  position: relative;
}
#trackCanvas { display: block; width: 100%; height: 100%; }

/* Energy bar */
.energy-bar-wrap {
  padding: 4px 16px 2px; height: 22px;
  display: flex; align-items: center;
}
.energy-bar {
  width: 100%; height: 10px; border-radius: 999px;
  background: rgba(255,255,255,0.1);
  overflow: hidden; position: relative;
  border: 1px solid rgba(255,255,255,0.08);
}
.energy-bar i {
  display: block; width: 0%; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--gold) 50%, var(--orange) 80%, var(--red));
  box-shadow: 0 0 12px rgba(255,200,60,0.5);
  transition: width 180ms ease;
}

/* Race toast */
.race-event-toast {
  min-height: 28px; text-align: center;
  padding: 4px 10px; font-size: 15px; font-weight: 800;
  letter-spacing: 0.04em;
  opacity: 0; transform: translateY(6px) scale(0.95);
  transition: opacity 180ms ease, transform 180ms ease;
}
.race-event-toast.show { opacity: 1; transform: translateY(0) scale(1); }
.race-event-toast.up   { color: var(--green); }
.race-event-toast.down { color: var(--red); }
.race-event-toast.system { color: var(--blue); }

.orientation-hint { display: none; }

/* Race bottom */
.race-bottom {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 6px 16px 10px;
  position: relative;
}
.race-bottom:empty { display: none; padding: 0; }

/* Mini rank panels */
.race-rank-drawer {
  display: flex; gap: 6px;
  padding: 4px 8px calc(env(safe-area-inset-bottom, 6px) + 6px);
  max-height: 22vh; min-height: 60px;
  overflow: hidden;
}
.rank-mini-panel {
  flex: 1; padding: 6px 8px;
  border-radius: 10px;
  background: var(--panel-bg);
  overflow: auto; max-height: 100%;
  -webkit-overflow-scrolling: touch;
}
.rank-mini-panel h4 {
  font-size: 11px; font-weight: 800;
  color: var(--muted); margin-bottom: 4px;
  letter-spacing: 0.06em; text-transform: uppercase;
  position: sticky; top: 0;
  background: var(--panel-bg); padding: 2px 0;
}

/* ===== Rank list (shared) ===== */
.rank-list {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 3px;
}
.rank-list li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; padding: 3px 6px; border-radius: 8px;
  font-size: 13px; color: #d0e8ff;
  transition: transform 200ms ease, background 200ms ease;
}
.rank-list li.rank-rise {
  animation: rankRise 400ms ease;
  background: rgba(77,255,145,0.12);
}
.rank-list li.rank-fall {
  animation: rankFall 400ms ease;
  background: rgba(255,90,79,0.12);
}
@keyframes rankRise {
  0%  { transform: translateX(0); }
  35% { transform: translateX(-6px) scale(1.02); }
  100%{ transform: translateX(0) scale(1); }
}
@keyframes rankFall {
  0%  { transform: translateX(0); }
  35% { transform: translateX(6px) scale(1.02); }
  100%{ transform: translateX(0) scale(1); }
}

.rank-left {
  min-width: 0; display: flex; align-items: center; gap: 6px; flex: 1;
}
.rank-avatar {
  width: 20px; height: 20px; border-radius: 50%;
  overflow: hidden; flex: 0 0 auto;
  border: 1px solid rgba(120,200,255,0.3);
  background: linear-gradient(145deg, #1a3a5a, #2a5578);
}
.rank-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rank-avatar-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-size: 9px; font-weight: 800; color: #c8edff;
}
.rank-name {
  flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.rank-distance { color: var(--blue); font-weight: 700; font-size: 12px; }

/* ============================================
   SCENE: RESULT
   ============================================ */
.result-screen {
  display: flex; flex-direction: column;
  align-items: center; width: 100%; height: 100%;
  padding: 20px 16px 24px; gap: 12px;
}

.winner-text {
  font-size: 16px; font-weight: 700; color: var(--gold);
  text-align: center;
  text-shadow: 0 0 12px rgba(255,215,0,0.3);
}

/* Podium */
.podium {
  display: flex; align-items: flex-end; justify-content: center;
  gap: 8px; width: 100%; max-width: 340px;
  padding: 12px 0;
}
.podium-slot {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; flex: 1;
}
.podium-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  overflow: hidden; border: 2px solid rgba(120,200,255,0.3);
  background: linear-gradient(145deg, #1a3a5a, #2a5578);
}
.podium-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.podium-avatar .rank-avatar-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-size: 18px; font-weight: 800; color: #c8edff;
}
.podium-name {
  font-size: 13px; font-weight: 700; color: var(--ink);
  max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.podium-dist {
  font-size: 11px; color: var(--muted);
}
.podium-block {
  width: 100%; border-radius: 8px 8px 0 0;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 4px 0;
}
.podium-block span {
  font-size: 22px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.podium-1st .podium-avatar { width: 56px; height: 56px; border-color: var(--gold); }
.podium-1st .podium-block {
  height: 80px; background: linear-gradient(180deg, var(--gold), #c5a000);
}
.podium-2nd .podium-block {
  height: 56px; background: linear-gradient(180deg, #b0c4d8, #7a8ea0);
}
.podium-3rd .podium-block {
  height: 40px; background: linear-gradient(180deg, #cd7f32, #9a5e20);
}

.result-rest {
  flex: 1; min-height: 0; width: 100%;
  overflow: auto; padding: 0 4px;
}

.result-actions {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 300px;
}

/* ===== Debug log ===== */
.log-panel {
  display: none; position: absolute; bottom: 0; left: 0; right: 0;
  z-index: 100; background: rgba(0,10,20,0.95);
  padding: 10px; border-radius: 14px 14px 0 0;
}
.log-panel[open] { display: block; }
.log-panel summary {
  cursor: pointer; font-weight: 700; color: var(--muted); font-size: 13px;
}
.log-panel pre {
  max-height: 180px; margin: 8px 0 0; overflow: auto;
  padding: 8px; border-radius: 8px;
  background: rgba(10,30,50,0.9);
  color: #c8f0ff; font-size: 11px; line-height: 1.5;
}
.panel-title-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 4px;
}
.panel-title-row h2 { font-size: 14px; color: var(--muted); }

/* ===== Hidden compat elements ===== */
.hero, .stage-bar, .hero-kicker, .hero-subtitle { display: none; }
.meta-grid, .pace-meter-wrap, .pace-meter-label, .pace-meter,
.inline-grid, .auth-actions, .inline-input-row,
.sub-panel, .players-panel,
.panel, .panel-hint { /* no longer used but keep class compat */ }

/* ===== Mobile portrait race ===== */
@media (max-width: 900px) and (orientation: portrait) {
  .page-shell { width: 100vw; }
  .race-rank-drawer { max-height: 20vh; }
  .hud-value { font-size: 20px; }
}

@media (max-width: 900px) and (orientation: landscape) {
  #raceOrientationHint { display: block;
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    z-index: 20; padding: 12px 20px; border-radius: 12px;
    background: rgba(20,40,60,0.9); color: var(--orange);
    font-size: 14px; font-weight: 700; text-align: center;
  }
}

/* Small phones */
@media (max-height: 700px) {
  .hud-value { font-size: 18px; }
  .race-rank-drawer { max-height: 16vh; }
  .rank-list li { padding: 2px 4px; font-size: 12px; }
}
