:root {
  --ink: #eaf6ff;
  --dim: #8ea3b8;
  --cyan: #37e0ff;
  --red: #ff2d4a;
  --amber: #ffb02e;
  --glass: rgba(8, 14, 26, 0.55);
  --line: rgba(120, 200, 255, 0.18);
  --display: 'Orbitron', system-ui, sans-serif;
  --text: 'Rajdhani', system-ui, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070d;
  color: var(--ink);
  font-family: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }

.panel {
  position: absolute;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.label {
  font-family: var(--display);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--dim);
}
.label span { color: var(--ink); opacity: 0.6; }
.label .key {
  display: inline-block;
  border: 1px solid var(--dim);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 4px;
}

.big { font-family: var(--display); font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.small { font-size: 15px; color: var(--dim); font-weight: 600; }

.hud-top-left { top: 16px; left: 16px; min-width: 150px; }
.hud-top-right { top: 18px; right: 18px; padding: 12px 18px; }

.hull { display: flex; gap: 8px; justify-content: flex-end; }
.hull i {
  display: block; width: 32px; height: 29px;
  background: #ff2d55;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.6 10.3 20C4.2 14.5 0 10.7 0 6.1 0 2.6 2.7 0 6.2 0c2 0 3.9.9 5.8 2.6C13.9.9 15.8 0 17.8 0 21.3 0 24 2.6 24 6.1c0 4.6-4.2 8.4-10.3 13.9L12 21.6z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.6 10.3 20C4.2 14.5 0 10.7 0 6.1 0 2.6 2.7 0 6.2 0c2 0 3.9.9 5.8 2.6C13.9.9 15.8 0 17.8 0 21.3 0 24 2.6 24 6.1c0 4.6-4.2 8.4-10.3 13.9L12 21.6z'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 0 6px rgba(255, 45, 85, 0.85));
  transition: background 0.2s, transform 0.2s, opacity 0.2s;
}
.hull i.off { background: rgba(255, 255, 255, 0.85); opacity: 0.18; filter: none; transform: scale(0.8); }
.heat { margin-bottom: 0; }
.heat i {
  width: 12px; height: 12px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: rgba(255, 255, 255, 0.12);
}
.heat i.on { background: var(--red); filter: drop-shadow(0 0 4px var(--red)); }

.hud-bottom-left { left: 18px; bottom: 18px; width: 320px; padding: 14px 18px; }
.meter + .meter { margin-top: 12px; }
.meter .label { font-size: 13px; }
.bar {
  height: 14px; margin-top: 6px; border-radius: 7px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}
.bar i {
  display: block; height: 100%; width: 100%;
  transform-origin: left center;
  border-radius: 5px;
}
.bar.pressure i { background: linear-gradient(90deg, #8fb8ff, #ffffff); box-shadow: 0 0 10px #b8d4ff; }
.bar.fan i { background: linear-gradient(90deg, #0fb5d8, var(--cyan)); box-shadow: 0 0 10px var(--cyan); }
.bar.low i { background: var(--red); box-shadow: 0 0 10px var(--red); }

.hud-bottom-center {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  text-align: center;
  text-shadow: 0 0 18px rgba(55, 224, 255, 0.5);
}
#speed { font-family: var(--display); font-size: 54px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-family: var(--display); font-size: 11px; letter-spacing: 0.3em; color: var(--dim); }


#warning {
  text-align: center; padding: 10px 26px 12px;
  border: 2px solid var(--red); border-radius: 10px;
  background: rgba(40, 0, 8, 0.6);
  box-shadow: 0 0 30px rgba(255, 45, 74, 0.45);
  animation: warnIn 0.25s ease-out, warnPulse 0.5s ease-in-out infinite alternate;
  max-width: calc(100vw - 32px);
}
.warn-chev { color: var(--red); font-size: 22px; line-height: 1; }
#warn-title { font-family: var(--display); font-weight: 900; font-size: 26px; letter-spacing: 0.08em; color: #fff; }
#warn-hint { font-size: 19px; font-weight: 700; color: var(--amber); margin-top: 2px; }

#center-msg {
  position: absolute; top: 38%; left: 0; right: 0; text-align: center;
  font-family: var(--display); font-weight: 900; font-size: 84px;
  text-shadow: 0 0 30px rgba(55, 224, 255, 0.8);
  opacity: 0; transition: opacity 0.2s;
}
#center-msg.show { opacity: 1; animation: pop 0.35s ease-out; }
#center-msg.sub { font-size: 24px; top: 12%; }

#popups {
  display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none;
}
.popup {
  font-family: var(--display); font-weight: 700; font-size: 15px; white-space: nowrap;
  color: var(--cyan); text-shadow: 0 0 12px rgba(55, 224, 255, 0.8);
  animation: floatUp 1.4s ease-out forwards;
}
.popup.good { color: #7dff9a; text-shadow: 0 0 12px rgba(80, 255, 140, 0.7); }
.popup.bad { color: var(--red); text-shadow: 0 0 10px rgba(255, 45, 74, 0.8); }
.popup.gold { color: var(--amber); text-shadow: 0 0 10px rgba(255, 176, 46, 0.8); }

#top-stack {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: max-content; max-width: calc(100vw - 300px); pointer-events: none;
}
#flash { position: fixed; inset: 0; pointer-events: none; background: #fff; opacity: 0; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(5, 10, 22, 0.55), rgba(2, 4, 10, 0.92));
  overflow-y: auto;
  z-index: 5;
}
.card {
  width: min(640px, 100%);
  text-align: center;
  padding: 28px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(8, 14, 28, 0.78);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.small-card { width: min(360px, 100%); }
.kicker { font-family: var(--display); font-size: 11px; letter-spacing: 0.3em; color: var(--cyan); text-transform: uppercase; }
h1 { font-family: var(--display); font-weight: 900; font-size: clamp(38px, 9vw, 64px); line-height: 0.95; margin: 10px 0 12px; letter-spacing: 0.04em; }
h1 span { color: transparent; -webkit-text-stroke: 1.5px var(--ink); }
h2 { font-family: var(--display); font-weight: 900; font-size: 44px; margin: 6px 0 4px; letter-spacing: 0.06em; }
.lead { font-size: 18px; color: #c4d4e4; line-height: 1.35; max-width: 520px; margin: 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 14px 0 16px; }
.chips span {
  font-size: 14px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  border: 1px solid rgba(55, 224, 255, 0.35); color: var(--cyan);
}
.controls {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px;
  text-align: left; margin: 0 auto 18px; max-width: 540px; font-size: 16px;
}
.controls div { display: flex; align-items: center; gap: 4px; }
.controls span { color: #c4d4e4; margin-left: 6px; }
kbd {
  font-family: var(--display); font-size: 11px; min-width: 22px; text-align: center;
  padding: 3px 6px; border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25); border-bottom-width: 3px;
  background: rgba(255, 255, 255, 0.06);
}
.cta {
  font-family: var(--display); font-weight: 900; font-size: 18px; letter-spacing: 0.12em;
  color: #031018; background: var(--cyan);
  border: none; border-radius: 10px; padding: 14px 34px; cursor: pointer;
  box-shadow: 0 0 30px rgba(55, 224, 255, 0.5);
  transition: transform 0.1s, box-shadow 0.2s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 0 44px rgba(55, 224, 255, 0.8); }
.cta:active { transform: translateY(1px); }
.foot { margin-top: 12px; color: var(--dim); font-size: 14px; }
.final-score { font-family: var(--display); font-size: 52px; font-weight: 900; color: var(--cyan); text-shadow: 0 0 24px rgba(55, 224, 255, 0.6); }
.best { color: var(--amber); font-weight: 700; font-size: 18px; min-height: 22px; }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0 20px; }
.stats div {
  min-width: 92px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03);
}
.stats b { display: block; font-family: var(--display); font-size: 22px; }
.stats span { font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- Title / leaderboard ---------- */
.layout { display: flex; gap: 16px; align-items: stretch; justify-content: center; width: min(1000px, 100%); margin: auto; }
.layout > .card:first-child { flex: 1 1 600px; }
.intro { width: min(560px, 100%); }
.intro h1 { margin-top: 0; }
.board-card { flex: 0 1 320px; text-align: left; display: flex; flex-direction: column; }
.board { list-style: none; margin-top: 10px; counter-reset: none; font-size: 17px; }
.board li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: baseline; padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.board li .r { font-family: var(--display); font-size: 12px; color: var(--dim); }
.board li:nth-child(1) .r { color: var(--amber); }
.board li .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .s { font-family: var(--display); font-size: 14px; font-variant-numeric: tabular-nums; }
.board li.me { background: rgba(55, 224, 255, 0.14); border-radius: 6px; }
.board li.muted { display: block; color: var(--dim); border: none; }
.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0 20px; }
.how { padding: 14px 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,0.03); }
.how .keys { display: flex; gap: 4px; justify-content: center; }
.how kbd { font-size: 14px; padding: 6px 9px; }
.how kbd.wide { padding: 6px 18px; }
.how .or { font-size: 13px; color: var(--dim); margin: 6px 0 2px; }
.how b { font-family: var(--display); font-size: 13px; letter-spacing: 0.08em; }
.how.jump { border-color: rgba(184, 212, 255, 0.45); }
.how.suck { border-color: rgba(55, 224, 255, 0.45); }
.how.suck b { color: var(--cyan); }
.submit { margin: 0 0 18px; }
.submit-q { font-weight: 700; font-size: 17px; margin-bottom: 8px; }
.submit-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.submit input {
  font-family: var(--text); font-size: 18px; font-weight: 700; color: var(--ink);
  background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; width: 190px; outline: none;
}
.submit input:focus { border-color: var(--cyan); }
.cta.small { font-size: 13px; padding: 10px 16px; }
.ghost { font-family: var(--text); font-weight: 700; font-size: 16px; color: var(--dim); background: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.submit-msg { min-height: 20px; margin-top: 6px; color: var(--dim); font-size: 15px; }
.submit-msg.ok { color: #7dff9a; }
.submit-msg.err { color: var(--red); }

.legal-links { margin-top: 14px; font-size: 12px; color: var(--dim); display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.legal-links a { color: var(--dim); text-decoration: none; }
.legal-links a:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Touch ---------- */
html, body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#touch button {
  pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none;
  font-family: var(--display); font-weight: 900; color: var(--ink);
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(10, 20, 36, 0.5);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#touch button small { font-family: var(--text); font-weight: 600; font-size: 11px; color: var(--dim); }
#touch button.active { background: rgba(55, 224, 255, 0.38); transform: scale(0.95); }
#steer-zone {
  position: absolute; left: 0; bottom: 0; width: calc(100% - 132px); height: 58%;
  pointer-events: auto; touch-action: none;
}
.steer-hint {
  position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(26px, env(safe-area-inset-bottom));
  font-family: var(--display); font-size: 13px; letter-spacing: 0.12em; color: rgba(234, 246, 255, 0.55);
  padding: 12px 18px; border: 1px dashed rgba(234, 246, 255, 0.3); border-radius: 30px;
  transition: opacity 0.6s;
}
#steer-zone.used .steer-hint { opacity: 0; }
#stick-base {
  position: fixed; left: -60px; top: -60px; width: 120px; height: 120px; border-radius: 50%;
  border: 2px solid rgba(55, 224, 255, 0.45); background: rgba(55, 224, 255, 0.08);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
}
#steer-zone.active #stick-base { opacity: 1; }
#stick-knob {
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(55, 224, 255, 0.55); box-shadow: 0 0 18px rgba(55, 224, 255, 0.6);
}
.touch-right {
  position: absolute; width: 116px; height: 236px;
  right: max(12px, env(safe-area-inset-right)); bottom: max(22px, calc(env(safe-area-inset-bottom) + 8px));
}
/* stacked on the right edge: JUMP under the thumb, SUCTION just above */
.t-hop { position: absolute; right: 2px; bottom: 0; width: 108px; height: 108px; font-size: 17px; border-color: #b8d4ff !important; }
.t-suction { position: absolute; right: 12px; bottom: 132px; width: 88px; height: 88px; font-size: 12px; border-color: var(--cyan) !important; }
.touch-top { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); display: flex; gap: 8px; }
.touch-top button { width: 44px; height: 44px; font-size: 15px; }

/* storage rings around the touch buttons (replace the meters on touch) */
#touch .t-hop, #touch .t-suction { --fill: 1; }
#touch .t-hop { --ring: #d6e6ff; }
#touch .t-suction { --ring: #37e0ff; }
#touch .t-hop.low, #touch .t-suction.low { --ring: #ff2d4a; }
#touch .t-hop::before, #touch .t-suction::before {
  content: ''; position: absolute; inset: -9px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--ring) calc(var(--fill) * 1turn), rgba(255, 255, 255, 0.12) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  filter: drop-shadow(0 0 6px var(--ring));
}
html.touch .hud-bottom-left { display: none !important; }

/* HUD layout on touch devices: keep both thumbs' areas clear */
html.touch .hud-bottom-left {
  left: 50%; top: max(10px, env(safe-area-inset-top)); bottom: auto; transform: translateX(-50%);
  width: min(360px, 46vw); padding: 8px 12px; display: flex; gap: 12px;
}
html.touch .meter { flex: 1; }
html.touch .meter + .meter { margin-top: 0; }
html.touch .meter .label { font-size: 9px; }
html.touch .meter .label span { display: none; }
html.touch .bar { height: 10px; margin-top: 4px; }
html.touch .hud-top-right { top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); padding: 8px 12px; }
html.touch .hull i { width: 26px; height: 24px; }
html.touch .hud-bottom-center { top: max(8px, env(safe-area-inset-top)); bottom: auto; }
html.touch #speed { font-size: 30px; }
html.touch #warning { padding: 5px 14px 7px; }
html.touch #warn-title { font-size: 17px; }
html.touch #warn-hint { font-size: 14px; }
html.touch .warn-chev { font-size: 14px; }
html.touch #center-msg { font-size: 54px; }
html.touch #center-msg.sub { font-size: 18px; top: 13%; }
html.touch #top-stack { top: calc(max(8px, env(safe-area-inset-top)) + 54px); max-width: calc(100vw - 24px); }
html.touch .popup { font-size: 13px; }
html.touch .foot { display: none; }
html.touch .screen { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
html.touch .layout { flex-direction: column; align-items: stretch; }
html.touch .card { padding: 20px 16px 18px; }
html.touch .howto { gap: 8px; }
html.touch .how { padding: 12px 4px 10px; }
html.touch .how b { font-size: 11px; }
html.touch .stats div { min-width: 0; flex: 1 1 40%; }
html.touch .submit-row { flex-direction: column; align-items: stretch; }
html.touch .submit input { width: 100%; }
html.touch .cta { width: 100%; }
.tk {
  font-family: var(--display); font-size: 12px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.06);
}
.tk.round { border-radius: 99px; }
#rotate {
  display: none; position: fixed; inset: 0; z-index: 50;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: #05070d; text-align: center; padding: 24px;
}
html.touch.landscape #rotate { display: flex; }
.rotate-phone {
  width: 46px; height: 80px; border: 3px solid var(--cyan); border-radius: 10px;
  box-shadow: 0 0 20px rgba(55, 224, 255, 0.5); animation: turnUp 1.6s ease-in-out infinite;
}
.rotate-text { font-family: var(--display); font-weight: 900; font-size: 20px; letter-spacing: 0.06em; }
.rotate-sub { color: var(--dim); font-size: 15px; }
@keyframes turnUp { 0%, 20% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }

/* short landscape screens (phones): compact menus */
@media (max-height: 520px) {
  .screen { padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); align-items: flex-start; }
  .layout { flex-direction: row !important; align-items: flex-start; }
  .layout > .card:first-child { flex: 1 1 auto; min-width: 0; }
  .board-card { flex: 0 0 min(300px, 38%) !important; width: auto; }
  .card { padding: 14px 18px 14px; }
  h1 { font-size: 34px; margin: 2px 0 6px; }
  h2 { font-size: 26px; margin: 0; }
  .lead { font-size: 15px; }
  .howto { margin: 10px 0 12px; gap: 8px; }
  .how { padding: 8px 6px; }
  .final-score { font-size: 34px; }
  .best { font-size: 15px; min-height: 18px; }
  .stats { margin: 8px 0 10px; gap: 6px; }
  .stats div { min-width: 70px; padding: 4px 6px; }
  .stats b { font-size: 16px; }
  .submit { margin-bottom: 10px; }
  .submit-q { font-size: 15px; margin-bottom: 6px; }
  .submit input { font-size: 16px; padding: 6px 10px; width: 150px; }
  .cta { font-size: 15px; padding: 10px 26px; }
  .board { font-size: 15px; margin-top: 6px; }
  .board li { padding: 3px 4px; }
}

@media (max-width: 860px) {
  .layout { flex-direction: column; align-items: stretch; }
  .board-card { flex: none; }
}

@media (max-width: 720px) {
  .hud-bottom-left { width: 200px; bottom: 12px; left: 12px; padding: 10px 12px; }
  .hull i { width: 26px; height: 24px; }
  .hud-top-right { top: 12px; right: 12px; }
  #speed { font-size: 38px; }
  #warn-title { font-size: 18px; }
  #warn-hint { font-size: 15px; }
  #center-msg { font-size: 60px; }
  .layout { flex-direction: column; }
  .how kbd { font-size: 11px; padding: 4px 6px; }
  .how kbd.wide { padding: 4px 10px; }
  h2 { font-size: 34px; }
}

@keyframes pulse { from { opacity: 0.75; } to { opacity: 1; } }
@keyframes warnIn { from { transform: scale(1.25); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes warnPulse { from { box-shadow: 0 0 14px rgba(255, 45, 74, 0.3); } to { box-shadow: 0 0 40px rgba(255, 45, 74, 0.8); } }
@keyframes pop { from { transform: scale(1.5); } to { transform: scale(1); } }
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(-6px); }
  12% { opacity: 1; transform: translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}
