/* Rail Rush — styles for the canvas host, HUD and menu screens. */
:root {
  --ink: #1b1d3a;
  --panel: rgba(22, 24, 52, 0.86);
  --pill: rgba(20, 22, 46, 0.82);
  --gold: #ffd23f;
  --gold2: #ff9f1a;
  --accent: #26c6da;
  --danger: #ff4d5e;
  --text: #ffffff;
  --muted: #b9bfe0;
  --font: "Arial Black", "Segoe UI Black", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0f1024;
  color: var(--text);
  font-family: var(--font-body);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }

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

.hidden { display: none !important; }

/* ============================ HUD ============================ */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 5;
}
.hud-left { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hud-right { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.icon-btn {
  pointer-events: auto;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  border: 3px solid #ffffff;
  background: linear-gradient(#4fb6ff, #1f7fe0);
  box-shadow: 0 4px 0 #0f4f9a, 0 6px 14px rgba(0, 0, 0, 0.3);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.08s;
}
.icon-btn svg { width: 28px; height: 28px; fill: currentColor; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0f4f9a; }
.icon-btn.small { width: 40px; height: 40px; border-radius: 12px; border-width: 2px; background: rgba(20, 22, 46, 0.7); box-shadow: none; }
.icon-btn.small svg { width: 22px; height: 22px; }
.icon-btn .ico-off { display: none; }
.icon-btn.muted .ico-on { display: none; }
.icon-btn.muted .ico-off { display: block; }
.icon-btn:focus-visible, .btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.pill {
  background: var(--pill);
  border-radius: 14px;
  padding: 4px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.score-pill .score {
  font-size: clamp(24px, 6.2vmin, 40px);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.mult {
  font-size: clamp(16px, 4vmin, 24px);
  color: var(--gold);
  transition: transform 0.2s, color 0.2s;
}
.mult.boost { color: #d9a6ff; transform: scale(1.25); text-shadow: 0 0 12px rgba(190, 120, 255, 0.9); }
.coin-pill { font-size: clamp(20px, 5vmin, 30px); padding: 3px 12px; }
.coin-ico {
  width: 1.05em;
  height: 1.05em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a0, #ffcd1a 45%, #e89a00);
  border: 3px solid #d98a00;
  display: inline-block;
}
.coin-text { color: var(--gold); }

/* power-up indicators */
#hud-powerups { display: flex; flex-direction: column; gap: 6px; }
.pu {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--pill);
  border-radius: 12px;
  padding: 5px 10px 5px 5px;
  animation: puIn 0.3s ease-out;
}
.pu.on { display: flex; }
.pu-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; border: 2px solid #fff; }
.pu-icon svg { width: 22px; height: 22px; }
.pu-magnet .pu-icon { background: #ff4d5e; }
.pu-multiplier .pu-icon { background: #a45cff; }
.pu-jetpack .pu-icon { background: #ff9f1a; }
.pu-shield .pu-icon { background: #2fa8ff; }
.pu-bar { width: 72px; height: 9px; border-radius: 5px; background: rgba(255, 255, 255, 0.18); overflow: hidden; }
.pu-bar i { display: block; height: 100%; width: 100%; border-radius: 5px; background: linear-gradient(90deg, #7ef0ff, #fff); }
.pu-shield .pu-bar i { background: linear-gradient(90deg, #2fa8ff, #bfe9ff); }
.pu.ending { animation: blink 0.25s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
@keyframes puIn { from { transform: translateX(-30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* toast + countdown */
#toast {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -50%);
  font-family: var(--font);
  font-size: clamp(26px, 7vmin, 52px);
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  z-index: 6;
  -webkit-text-stroke: 2px rgba(20, 20, 45, 0.9);
  text-shadow: 0 4px 0 rgba(20, 20, 45, 0.6);
}
#toast.pop { animation: toast 1.3s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}
#countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font);
  font-size: clamp(90px, 28vmin, 220px);
  color: #fff;
  pointer-events: none;
  z-index: 7;
  -webkit-text-stroke: 4px var(--ink);
  text-shadow: 0 8px 0 rgba(20, 20, 45, 0.6);
}
#countdown.tick { animation: tick 0.5s ease-out; }
@keyframes tick { from { transform: scale(1.6); opacity: 0.2; } to { transform: scale(1); opacity: 1; } }

/* ============================ Screens ============================ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
  z-index: 10;
  overflow-y: auto;
  touch-action: pan-y;
}
.screen.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.25s ease, visibility 0s; }
#screen-loading { background: radial-gradient(ellipse at center, #2b2f6b 0%, #14152e 70%); }
#screen-menu { background: linear-gradient(rgba(16, 18, 44, 0.55), rgba(16, 18, 44, 0.15) 45%, rgba(16, 18, 44, 0.7)); cursor: pointer; }
.screen.dim { background: rgba(12, 12, 32, 0.62); }
#screen-gameover.celebrate { background: radial-gradient(ellipse at center, rgba(90, 40, 140, 0.55), rgba(12, 12, 32, 0.75)); }

.panel { width: min(560px, 100%); margin: auto; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.logo {
  margin: 0;
  font-family: var(--font);
  line-height: 0.88;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: clamp(48px, 13vmin, 96px);
  transform: rotate(-4deg);
  letter-spacing: 2px;
}
.logo span {
  background: linear-gradient(#fff27a, #ffd23f 40%, #ff8a1a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 3px #3a1f5c;
  filter: drop-shadow(0 6px 0 #3a1f5c) drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35));
}
.logo span:nth-child(2) { background: linear-gradient(#aef6ff, #26c6da 45%, #1f7fe0); -webkit-background-clip: text; background-clip: text; margin-left: 0.6em; }
.logo.big { font-size: clamp(56px, 16vmin, 124px); margin-bottom: 6px; }

.loadbar { width: min(320px, 80vw); height: 14px; border-radius: 8px; background: rgba(255, 255, 255, 0.12); overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.25); }
#load-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold2)); transition: width 0.15s; }
.muted { color: var(--muted); margin: 0; }
.tiny { font-size: 12px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.stats > div, .go-grid > div {
  background: var(--panel);
  border-radius: 14px;
  padding: 8px 16px;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
small { font-family: var(--font); font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.stats b, .go-grid b { font-family: var(--font); font-size: clamp(18px, 4.4vmin, 26px); font-variant-numeric: tabular-nums; }

.btn {
  pointer-events: auto;
  font-family: var(--font);
  font-size: clamp(18px, 4.6vmin, 26px);
  color: #fff;
  border: 3px solid #fff;
  border-radius: 16px;
  padding: 12px 28px;
  min-width: 220px;
  background: linear-gradient(#5a5f9e, #3b3f7a);
  box-shadow: 0 5px 0 #23264f, 0 8px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #23264f; }
.btn.primary { background: linear-gradient(#63e06b, #22a84a); box-shadow: 0 5px 0 #146b2e, 0 8px 18px rgba(0, 0, 0, 0.3); font-size: clamp(22px, 5.6vmin, 32px); }
.btn.primary:active { box-shadow: 0 1px 0 #146b2e; }
.btn.small { min-width: 0; font-size: 14px; padding: 7px 14px; border-width: 2px; border-radius: 12px; box-shadow: 0 3px 0 #23264f; }
.pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.toggles { display: flex; gap: 10px; }

.hint { margin: -4px 0 0; color: #fff; font-size: 14px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85em;
  box-shadow: 0 2px 0 #9aa0c8;
}

.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: 100%; }
.ctrl-col {
  flex: 1 1 150px;
  background: var(--panel);
  border-radius: 14px;
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
}
.ctrl-col h3 { margin: 0 0 4px; font-family: var(--font); font-size: 13px; color: var(--gold); letter-spacing: 1px; }
.ctrl-col p { margin: 4px 0; line-height: 1.5; }
.sw { display: inline-block; width: 18px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; border: 1px solid rgba(255, 255, 255, 0.5); }
.sw-low { background: repeating-linear-gradient(60deg, #e23b3b 0 4px, #fff 4px 8px); }
.sw-beam { background: repeating-linear-gradient(60deg, #ffcc1a 0 4px, #23232b 4px 8px); }
.sw-pit { background: #1a1220; border-color: #ffc928; }
.sw-train { background: linear-gradient(#c5cbd3 40%, #2f6fd6 40% 60%, #c5cbd3 60%); }

.title {
  margin: 0;
  font-family: var(--font);
  font-size: clamp(44px, 12vmin, 84px);
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 0 6px 0 var(--ink);
  transform: rotate(-3deg);
}
.newbest {
  font-family: var(--font);
  font-size: clamp(20px, 5.4vmin, 32px);
  color: var(--gold);
  -webkit-text-stroke: 1px #6b2a00;
  animation: glow 0.8s ease-in-out infinite alternate;
}
@keyframes glow {
  from { transform: scale(1); text-shadow: 0 0 6px rgba(255, 210, 63, 0.5); }
  to { transform: scale(1.08); text-shadow: 0 0 22px rgba(255, 210, 63, 1); }
}
.go-score { display: flex; flex-direction: column; }
.go-score b { font-family: var(--font); font-size: clamp(48px, 13vmin, 88px); line-height: 1; text-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); font-variant-numeric: tabular-nums; }
.go-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: min(420px, 100%); margin-bottom: 6px; }

/* hide keyboard hints on touch-only devices */
@media (hover: none) and (pointer: coarse) {
  .only-keys { display: none !important; }
}
/* short landscape phones: compact menu */
@media (max-height: 520px) {
  .logo.big { font-size: 44px; }
  .controls { display: none; }
  .center { gap: 8px; }
  .btn { padding: 8px 20px; }
  .title { font-size: 40px; }
  .go-score b { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse, .newbest, #countdown.tick { animation: none; }
}
