/* ================================================================
 * TICKER RIDER — theme-driven styles.
 * Palette lives in CSS variables; [data-theme=...] swaps it wholesale.
 * Orbitron = display only (logo, tickers, big numbers).
 * Rajdhani = everything you actually have to read.
 * ================================================================ */

:root {
  /* default theme: arctic */
  --primary: #a8d4ff;
  --accent: #3d8bff;
  --up: #00e676;
  --down: #ff3b5c;
  --bg: #04070e;
  --text: #f0f6ff;
  --text-dim: #9fb4cc;
  --font-display: 'Orbitron', 'Segoe UI', sans-serif;
  --font-body: 'Rajdhani', 'Segoe UI', sans-serif;
}

[data-theme='cyan'] {
  --primary: #00e5ff;
  --accent: #ff7a18;
  --bg: #020308;
  --text: #eaf6fa;
  --text-dim: #9cb8c4;
}

[data-theme='amber'] {
  --primary: #ffb000;
  --accent: #ff5722;
  --bg: #0a0805;
  --text: #f7f0e0;
  --text-dim: #c0ae8c;
}

[data-theme='arctic'] {
  --primary: #a8d4ff;
  --accent: #3d8bff;
  --bg: #04070e;
  --text: #f0f6ff;
  --text-dim: #9fb4cc;
}

[data-theme='green'] {
  --primary: #2bff7e;
  --accent: #ffd60a;
  --bg: #020703;
  --text: #e8fbef;
  --text-dim: #94c2a5;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }

/* ============ ONBOARDING ============ */
#onboard {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(3px);
  padding: 4vh 4vw;
  overflow-y: auto;
}
.ob-box {
  max-width: 1000px; text-align: center;
  border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  box-shadow: 0 0 40px color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 5vh 4vw;
  clip-path: polygon(0 0, calc(100% - 24px) 0, 100% 24px, 100% 100%, 24px 100%, 0 calc(100% - 24px));
}
.ob-small {
  font-family: var(--font-display);
  font-size: 0.62rem; letter-spacing: 0.4em; color: var(--text-dim);
}
.ob-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3.4vw, 2.5rem); font-weight: 900; letter-spacing: 0.12em;
  margin: 2.2vh 0 0.5vh;
  color: var(--primary);
  text-shadow: 0 0 18px color-mix(in srgb, var(--primary) 45%, transparent);
}
.ob-title em { font-style: normal; color: var(--accent); }
.ob-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 3.5vh 0 2.5vh;
  text-align: left;
}
.ob-card {
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  background: color-mix(in srgb, var(--primary) 4%, var(--bg));
  padding: 22px 20px;
}
.ob-icon { font-size: 1.3rem; color: var(--accent); }
.ob-card h3 {
  font-family: var(--font-display);
  font-size: 0.8rem; letter-spacing: 0.14em; color: var(--primary);
  margin: 12px 0 10px;
}
.ob-card p {
  font-size: 1.02rem; font-weight: 500; line-height: 1.55;
  letter-spacing: 0.02em; color: var(--text);
}
.ob-foot {
  margin-top: 2vh;
  font-size: 0.85rem; font-weight: 600; letter-spacing: 0.12em; line-height: 1.7;
  color: var(--text-dim);
}

#btn-help {
  position: absolute; top: 20px; right: 24px; z-index: 5;
  width: 38px; height: 38px;
  font-family: var(--font-display); font-size: 1rem; font-weight: 700;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--primary) 50%, transparent);
  border-radius: 50%;
  cursor: pointer; transition: all 0.15s;
}
#btn-help:hover { border-color: var(--primary); box-shadow: 0 0 14px color-mix(in srgb, var(--primary) 50%, transparent); }

/* ============ MENU ============ */
#menu {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4vh 4vw;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 120%, color-mix(in srgb, var(--primary) 10%, transparent), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 59px, color-mix(in srgb, var(--primary) 4%, transparent) 59px 60px),
    repeating-linear-gradient(90deg, transparent 0 59px, color-mix(in srgb, var(--primary) 4%, transparent) 59px 60px),
    var(--bg);
}

#menu header { text-align: center; margin-bottom: 3vh; }

#menu h1 {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.3em;
  color: var(--primary);
  text-shadow: 0 0 24px color-mix(in srgb, var(--primary) 50%, transparent);
}
#menu h1 span { color: var(--accent); text-shadow: 0 0 24px color-mix(in srgb, var(--accent) 50%, transparent); }

.tagline {
  margin-top: 1.4vh;
  font-size: 1rem; font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--text-dim);
}

#ranges {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 2.4vh;
}
.range-btn {
  font-family: var(--font-display);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.18em;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
  padding: 9px 18px; cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  transition: all 0.15s;
}
.range-btn:hover { color: var(--primary); border-color: var(--primary); }
.range-btn.active {
  color: var(--bg); background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 16px color-mix(in srgb, var(--primary) 60%, transparent);
}

#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 1340px;
}

.card {
  position: relative;
  border: 1px solid color-mix(in srgb, var(--primary) 38%, transparent);
  background: color-mix(in srgb, var(--primary) 5%, var(--bg));
  padding: 15px 17px 13px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 40%, transparent);
}
.card:hover .card-enter { opacity: 1; }

.card-top { display: flex; justify-content: space-between; align-items: baseline; }
.card-ticker {
  font-family: var(--font-display);
  font-size: 1.2rem; font-weight: 700; letter-spacing: 0.1em;
  color: var(--primary);
}
.card-change { font-size: 0.95rem; font-weight: 700; }
.card-change.up { color: var(--up); }
.card-change.down { color: var(--down); }

.card-tag {
  font-family: var(--font-display);
  font-size: 0.5rem; font-weight: 700; letter-spacing: 0.15em;
  color: var(--accent); border: 1px solid var(--accent);
  padding: 1px 5px; margin-left: 8px; vertical-align: middle;
}

.card-name {
  font-size: 0.85rem; font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin: 3px 0 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card canvas { width: 100%; height: 70px; display: block; }

.card-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; }
.card-price { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.card-enter {
  font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.menu-footer {
  margin-top: 3.5vh;
  font-size: 0.82rem; font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

/* ============ GAME ============ */
#game { position: fixed; inset: 0; }
#canvas-holder, #canvas-holder canvas { position: absolute; inset: 0; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

#hud-stock {
  position: absolute; top: 26px; left: 30px;
  display: flex; flex-direction: column; gap: 8px;
}
#hud-ticker {
  font-family: var(--font-display);
  font-size: 1.6rem; font-weight: 900; letter-spacing: 0.18em;
  line-height: 1;
  color: var(--primary);
  text-shadow: 0 0 12px color-mix(in srgb, var(--primary) 60%, transparent);
}
#hud-price { font-size: 1.25rem; font-weight: 700; color: var(--text); line-height: 1; }
#hud-pl { font-size: 1rem; font-weight: 700; line-height: 1; }
#hud-pl.up { color: var(--up); }
#hud-pl.down { color: var(--down); }
#hud-date {
  font-size: 0.92rem; font-weight: 600; letter-spacing: 0.12em; color: var(--text-dim);
  line-height: 1; margin-top: 4px;
}
#hud-mode { font-size: 0.9rem; font-weight: 700; letter-spacing: 0.18em; line-height: 1; }
#hud-mode.live { color: var(--down); animation: blink 1.1s steps(2) infinite; }
#hud-mode.sim { color: var(--accent); }
@keyframes blink { 50% { opacity: 0.25; } }

#hud-score-box { position: absolute; top: 22px; right: 26px; text-align: right; }
#hud-score {
  font-family: var(--font-display);
  font-size: 1.7rem; font-weight: 900; letter-spacing: 0.1em;
  color: var(--accent);
  text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent);
}
#hud-coins { font-size: 1rem; font-weight: 700; color: var(--up); margin-top: 3px; }

#hud-shields { position: absolute; top: 168px; left: 31px; display: flex; gap: 9px; }
.shield {
  width: 16px; height: 16px;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
  clip-path: polygon(50% 0, 100% 30%, 100% 70%, 50% 100%, 0 70%, 0 30%);
  transition: opacity 0.3s;
}
.shield.lost { opacity: 0.12; box-shadow: none; }

#boost-wrap {
  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
  width: min(380px, 60vw); text-align: center;
}
.boost-label {
  font-family: var(--font-display);
  font-size: 0.6rem; letter-spacing: 0.4em; color: var(--text-dim); margin-bottom: 5px;
}
#boost-bar {
  height: 10px;
  border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}
#boost-fill {
  height: 100%; width: 30%;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary);
  transition: width 0.1s linear;
}
#boost-fill.burning { background: var(--accent); box-shadow: 0 0 12px var(--accent); }

#hud-controls {
  position: absolute; bottom: 10px; width: 100%; text-align: center;
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.15em;
  color: var(--text-dim); opacity: 0.8;
}

/* screen effects */
#vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  box-shadow: inset 0 0 180px rgba(0,0,0,0.85);
  transition: background 0.1s;
}
#vignette.hit { background: color-mix(in srgb, var(--down) 22%, transparent); }

#scanlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 7; opacity: 0.35;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,0.16) 3px 4px);
}

/* overlays */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(2px);
}
.overlay-inner { text-align: center; }
.overlay-big {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 5rem); font-weight: 900; letter-spacing: 0.3em;
  color: var(--primary);
  text-shadow: 0 0 18px color-mix(in srgb, var(--primary) 55%, transparent);
}
#end-title.derez { color: var(--down); text-shadow: 0 0 18px color-mix(in srgb, var(--down) 55%, transparent); }
#end-title.win { color: var(--up); text-shadow: 0 0 18px color-mix(in srgb, var(--up) 55%, transparent); }
.overlay-small {
  font-family: var(--font-display);
  font-size: 0.8rem; letter-spacing: 0.3em; color: var(--text-dim); margin-top: 14px;
}
#intro-overlay .overlay-small { margin: 0 0 14px; }

.end-stats {
  margin-top: 26px;
  font-size: 1.15rem; font-weight: 600; line-height: 2; letter-spacing: 0.08em;
  color: var(--text);
}
.end-stats .up { color: var(--up); }
.end-stats .down { color: var(--down); }
.end-stats .accent { color: var(--accent); }

.end-buttons { margin-top: 34px; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.neon-btn {
  display: inline-block;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.18em;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 7%, var(--bg));
  border: 1px solid var(--primary);
  padding: 13px 26px; cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
  transition: all 0.15s;
}
.neon-btn:hover {
  background: color-mix(in srgb, var(--primary) 20%, var(--bg));
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 50%, transparent);
}
.neon-btn.orange { color: var(--accent); border-color: var(--accent); }
.neon-btn.orange:hover {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg));
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 50%, transparent);
}

#webgl-fail {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 1.1rem; font-weight: 600; line-height: 2; letter-spacing: 0.1em;
  color: var(--down); background: var(--bg);
}

/* ================================================================
 * MOBILE / TOUCH
 * On-screen controls drive the same key state as the keyboard, so the
 * game loop is untouched. Everything here is gated on body.touch, which
 * game.js adds for coarse-pointer devices (or ?touch in the URL).
 * ================================================================ */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body { touch-action: manipulation; }                 /* kill double-tap zoom, keep taps */
/* menus scroll; the play surface must not */
#menu, #onboard { touch-action: pan-y; overscroll-behavior: contain; }
#game, #canvas-holder, #canvas-holder canvas { touch-action: none; }
/* keep menu content clear of notches */
#menu, #onboard {
  padding-left: max(4vw, env(safe-area-inset-left));
  padding-right: max(4vw, env(safe-area-inset-right));
}

/* touch hints / control visibility */
.touch-only { display: none; }
#touch-controls { display: none; }
body.touch .kbd-only { display: none; }
body.touch .touch-only { display: inline; }
body.touch #hud-controls { display: none; }   /* keyboard hint line */
body.touch .card-enter { opacity: 0.7; }       /* no hover on touch */

body.touch #touch-controls {
  display: block; position: absolute; inset: 0; z-index: 8;
  pointer-events: none;                         /* only the buttons take input */
}
.touch-btn {
  pointer-events: auto;
  touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; letter-spacing: 0.08em;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, color-mix(in srgb, var(--bg) 65%, transparent));
  border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  backdrop-filter: blur(2px);
  cursor: pointer;
  transition: background 0.08s, box-shadow 0.08s, transform 0.08s;
}
.touch-btn.pressed {
  background: color-mix(in srgb, var(--primary) 34%, var(--bg));
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 55%, transparent);
  transform: scale(0.93);
}

/* left thumb: steer */
.t-steer {
  position: absolute; display: flex; gap: 14px;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(20px + env(safe-area-inset-bottom));
}
.t-steer .touch-btn { width: 74px; height: 74px; font-size: 1.6rem; border-radius: 14px; }

/* right thumb: jump (primary) + boost (hold) */
.t-actions {
  position: absolute; display: flex; gap: 14px; align-items: flex-end;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
}
.t-actions .t-boost { width: 72px; height: 72px; font-size: 0.7rem; border-radius: 14px; }
.t-actions .t-jump {
  width: 92px; height: 92px; font-size: 0.92rem; border-radius: 50%;
  color: var(--accent); border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, color-mix(in srgb, var(--bg) 65%, transparent));
}
.t-actions .t-jump.pressed {
  background: color-mix(in srgb, var(--accent) 34%, var(--bg));
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 55%, transparent);
}

.t-pause {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  width: 48px; height: 40px; font-size: 0.8rem; border-radius: 8px;
}
.t-pause.pressed { transform: translateX(-50%) scale(0.93); }

/* pause overlay: tappable buttons instead of keyboard hints */
#pause-touch { display: none; margin-top: 24px; }
body.touch #pause-touch { display: flex; }
body.touch #pause-overlay .overlay-small { display: none; }

/* compact HUD + relocate the boost meter off the bottom (controls live there) */
@media (max-width: 680px), (pointer: coarse) {
  #hud-stock { top: 14px; left: 14px; gap: 5px; }
  #hud-ticker { font-size: 1.2rem; }
  #hud-price { font-size: 1rem; }
  #hud-pl, #hud-date, #hud-mode { font-size: 0.8rem; }
  #hud-score-box { top: 12px; right: 14px; }
  #hud-score { font-size: 1.3rem; }
  #hud-coins { font-size: 0.85rem; }
  #hud-shields { top: 74px; left: 16px; gap: 6px; }
  .shield { width: 13px; height: 13px; }
  #boost-wrap { bottom: auto; top: 108px; left: 50%; width: min(260px, 64vw); }
  .ob-foot { font-size: 0.78rem; }
  .tagline { font-size: 0.82rem; letter-spacing: 0.16em; }
  .end-buttons { gap: 12px; }
  .neon-btn { padding: 13px 20px; }
}
@media (max-width: 420px) {
  .t-steer .touch-btn { width: 64px; height: 64px; }
  .t-actions .t-jump { width: 80px; height: 80px; }
  .t-actions .t-boost { width: 64px; height: 64px; }
}
/* landscape phones are short: tuck the boost meter under the top HUD row */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 480px) {
  #boost-wrap { top: 64px; }
  #hud-shields { top: 64px; left: auto; right: 14px; }
}
