:root {
  --bg: #0a1128;
  --blue: #0052ff;
  --teal: #40e0bb;
  --orange: #ff6501;
  --gold: #ffd23f;
  --text: #e8ecff;
  --muted: #93a0c9;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  background: #000;
  overflow: hidden;
  font-family: "Inter Tight", system-ui, sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

input { user-select: text; -webkit-user-select: text; touch-action: manipulation; }

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
#game {
  image-rendering: auto;
  background: #000;
}

/* ============ screens ============ */
.screen {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  z-index: 20;
}
.screen.visible { display: flex; }
.screen.dim { background: rgba(8, 10, 22, 0.78); }
.screen.solid { background: var(--bg); }

.panel {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 26px 34px;
  background: rgba(10, 16, 30, 0.72);
  border: 1px solid rgba(0, 82, 255, 0.35);
  border-radius: 16px;
  box-shadow: 0 0 24px rgba(0, 82, 255, 0.18);
  text-align: center;
  max-width: min(92vw, 560px);
}
.panel-wide { min-width: min(92vw, 480px); }
.panel-title { font-size: 30px; font-weight: 900; letter-spacing: 0.04em; text-shadow: 0 3px 0 #16244f, 0 0 18px rgba(0, 82, 255, 0.35); }
.go-red { color: #ff4d5e; }
.hl-blue { color: var(--blue); }
.hl-red { color: #ff4d5e; }
.go-flavor { color: var(--muted); font-size: 14px; max-width: 380px; }
.go-stats { font: 18px "VT323", monospace; color: var(--gold); letter-spacing: 0.02em; }

.btn {
  font: 800 15px "Inter Tight", sans-serif;
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--blue);
  border: none; border-radius: 12px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 30, 0.45);
  text-decoration: none;
  display: inline-block;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 30, 0.45); }
.btn-big { background: var(--orange); font-size: 18px; padding: 14px 34px; }
.btn-ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.2); }
.hidden { display: none !important; }

/* ============ title ============ */
.title-art {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}
.title-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 40%, transparent 30%, rgba(5, 8, 18, 0.82) 100%);
}
.title-content {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding-top: 4vh;
}
.logo { text-align: center; filter: drop-shadow(0 4px 0 rgba(0,0,20,0.6)); }
.logo-main {
  display: block;
  font-size: clamp(52px, 12vw, 96px);
  font-weight: 900; letter-spacing: 0.06em;
  color: #fff;
  -webkit-text-stroke: 3px #16244f;
  text-shadow: 0 6px 0 #16244f;
}
.logo-sub {
  display: block;
  font-size: clamp(16px, 3.4vw, 26px);
  font-weight: 900; letter-spacing: 0.22em;
  color: var(--orange);
  text-shadow: 0 2px 0 #16244f, 0 0 14px rgba(0, 0, 20, 0.8);
  margin-top: 2px;
}
.menu-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.more-games { margin-top: 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.more-label { font-size: 11px; font-weight: 800; letter-spacing: 0.2em; color: #c6cdea; text-shadow: 0 1px 0 #000; }
.more-row { display: flex; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; min-height: 36px;
  background: rgba(10, 16, 30, 0.65);
  border: 1px solid rgba(0, 82, 255, 0.45);
  border-radius: 10px;
  font: 800 12px "Inter Tight", sans-serif;
  letter-spacing: 0.05em;
  color: #fff; text-decoration: none;
  box-shadow: 0 3px 0 rgba(0, 0, 30, 0.4);
}
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 30, 0.4); }
.chip img { width: 20px; height: 20px; border-radius: 6px; }
.controls-hint { color: #c6cdea; font-size: 12px; text-shadow: 0 1px 0 #000; }
.desktop-only { display: inline; }
.touch-only { display: none; }
@media (pointer: coarse) {
  .desktop-only { display: none; }
  .touch-only { display: inline; }
}
.rotate-hint {
  display: none;
  font-size: 11px; font-weight: 800; letter-spacing: 0.08em;
  color: var(--gold); text-shadow: 0 1px 0 #000;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(10, 16, 30, 0.65); border: 1px solid rgba(255, 210, 63, 0.35);
}
@media (pointer: coarse) and (orientation: portrait) {
  .rotate-hint { display: block; }
}

/* ============ story ============ */
.story-panel {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  max-width: min(92vw, 520px);
  text-align: center;
  padding: 20px;
}
.story-text { font: 22px "VT323", monospace; color: var(--text); line-height: 1.35; }

/* ============ win / lb ============ */
.win-time { font: 54px "VT323", monospace; color: var(--gold); }
.win-stats { color: var(--muted); font-size: 14px; }
.win-checking { color: var(--muted); font-size: 13px; }
.go-top20 { color: #ffd23f; font-weight: 800; font-size: 14px; }
.submit-row { display: flex; gap: 8px; }
.submit-row input {
  font: 800 15px "Inter Tight", sans-serif;
  padding: 10px 14px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08); color: #fff;
  width: 180px; text-transform: uppercase;
}
.go-submit-msg { font-size: 13px; color: var(--muted); min-height: 16px; }
.go-submit-msg.ok { color: var(--teal); }
.go-submit-msg.err { color: #ff4d5e; }
.lb-list { touch-action: pan-y; width: 100%; max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px; padding: 7px 12px;
  font-size: 14px;
}
.lb-rank { color: var(--muted); font-weight: 800; width: 34px; }
.lb-name { flex: 1; text-align: left; font-weight: 700; }
.lb-score { font: 18px "VT323", monospace; color: var(--gold); }
.lb-loading { color: var(--muted); }
.pause-hint { color: var(--muted); font-size: 12px; }

/* ============ touch controls ============ */
#touch-ui { display: none; }
@media (pointer: coarse) {
  body.in-game #touch-ui { display: block; }
}
.tbtn {
  position: fixed; z-index: 30;
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 2px solid rgba(0, 82, 255, 0.55);
  background: rgba(10, 16, 30, 0.55);
  color: #fff;
  font-size: 22px; font-weight: 900;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tbtn:active, .tbtn.on { background: rgba(45, 98, 255, 0.5); }
/* one slide pad: a thumb can glide from left to right without lifting */
.tbtn-dpad {
  position: fixed; z-index: 30;
  left: calc(env(safe-area-inset-left, 0px) + 18px); bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  width: 140px; height: 62px;
  touch-action: none;
}
.tbtn-dpad .tbtn { position: absolute; bottom: 0; }
.tbtn-left  { left: 0; }
.tbtn-right { left: 78px; }
.tbtn-run   { right: calc(env(safe-area-inset-right, 0px) + 96px); bottom: calc(env(safe-area-inset-bottom, 0px) + 30px); border-color: rgba(255, 101, 1, 0.6); }
.tbtn-jump  { right: calc(env(safe-area-inset-right, 0px) + 18px); bottom: calc(env(safe-area-inset-bottom, 0px) + 46px); width: 74px; height: 74px; border-color: rgba(45, 98, 255, 0.7); }
.tbtn-pause { right: calc(env(safe-area-inset-right, 0px) + 14px); top: calc(env(safe-area-inset-top, 0px) + 24px); width: 44px; height: 44px; font-size: 16px; }

/* portrait phone: game strip at the top, thumbs right under it, bigger targets */
@media (pointer: coarse) and (orientation: portrait) {
  #stage { align-items: flex-start; padding-top: calc(env(safe-area-inset-top, 0px) + 84px); }
  .tbtn-pause { top: calc(env(safe-area-inset-top, 0px) + 20px); }   /* above the canvas, off the HUD */
  .tbtn-dpad, .tbtn-run, .tbtn-jump {
    bottom: auto;
    top: calc(env(safe-area-inset-top, 0px) + 84px + 100vw * 180 / 320 + 24px);
  }
  .tbtn-dpad { left: calc(env(safe-area-inset-left, 0px) + 12px); width: 164px; height: 76px; }
  .tbtn-dpad .tbtn { width: 76px; height: 76px; font-size: 26px; }
  .tbtn-right { left: 88px; }
  /* A up-right, B down-left: staggered like a pad, so both fit beside the d-pad on a 390px phone */
  .tbtn-run  { right: calc(env(safe-area-inset-right, 0px) + 108px); width: 76px; height: 76px; font-size: 26px; margin-top: 50px; }
  .tbtn-jump { right: calc(env(safe-area-inset-right, 0px) + 14px); width: 88px; height: 88px; font-size: 30px; margin-top: -6px; }
}

/* ============ install page ============ */
.install-panel {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-width: 640px; padding: 18px 22px; text-align: center;
  max-height: 100dvh; overflow-y: auto;
}
.install-icon { width: 56px; height: 56px; border-radius: 14px; }
.install-title { font-size: 24px; font-weight: 900; letter-spacing: 0.04em; color: #fff; }
.install-lead { color: var(--muted); font-size: 14px; max-width: 460px; }
.install-cols { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.install-col {
  background: rgba(10, 16, 30, 0.6); border: 1px solid rgba(0, 82, 255, 0.3);
  border-radius: 12px; padding: 12px 18px; min-width: 220px; text-align: left;
}
.install-col h3 { font-size: 14px; font-weight: 800; color: #6ea0ff; margin-bottom: 6px; }
.install-col ol { margin: 0; padding-left: 18px; color: #d6ddf5; font-size: 13px; line-height: 1.75; }
.install-glyph { color: #8ecbff; }

/* ============ loading ============ */
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); }
.loading-cat { width: 90px; height: auto; animation: bounce 0.8s ease-in-out infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-14px); } }


/* ============ Toshi brand backdrop ============ */
.screen.solid { background: radial-gradient(120% 90% at 50% 0%, #101b3c 0%, var(--bg) 55%, #070c1c 100%); }
.screen.solid::before {
  content: '';
  position: absolute; inset: -20%;
  background: radial-gradient(38% 30% at 30% 35%, rgba(0, 82, 255, 0.28), transparent 70%),
              radial-gradient(30% 26% at 72% 62%, rgba(255, 101, 1, 0.12), transparent 70%);
  animation: brand-drift 22s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: -1;
}
.screen.solid::after {
  content: '';
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 4px);
  opacity: 0.35;
  pointer-events: none;
  z-index: -1;
}
#screen-title::before, #screen-title::after { display: none; }  /* splash art owns the title */
@keyframes brand-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.06); }
}
@media (prefers-reduced-motion: reduce) {
  .screen.solid::before { animation: none; }
  .loading-cat { animation: none; }
}
.best-val { font: 20px "VT323", monospace; color: var(--gold); }
.medal-val { color: var(--gold); font-weight: 800; }

/* ============ course select (title) ============ */
.course-row { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.course-row .more-row { flex-wrap: wrap; justify-content: center; }
.course-chip { padding: 7px 10px; min-height: 34px; font-size: 11px; cursor: pointer; }
.course-chip:disabled { opacity: 0.45; cursor: default; border-color: rgba(255, 255, 255, 0.12); }
.course-chip:disabled:active { transform: none; box-shadow: 0 3px 0 rgba(0, 0, 30, 0.4); }
.star-label { color: #c9a7ff; font-size: 10px; margin-top: 4px; }
.star-chip { border-color: rgba(201, 167, 255, 0.55); }
.star-chip:not(:disabled):hover { border-color: #c9a7ff; }
.medal-dot {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: #1a2038;
}
.medal-dot.gold   { background: var(--gold);  border-color: #b8860b; }
.medal-dot.silver { background: #dfe6f5;      border-color: #7f8ca6; }
.medal-dot.bronze { background: #d08a4a;      border-color: #7a4a20; }
.medal-dot.star   { background: #c9a7ff;      border-color: #6a3fc4; }
