:root {
  --ink: #e8eefc;
  --dim: #8fa0c4;
  --panel: rgba(8, 13, 26, 0.62);
  --line: rgba(140, 170, 255, 0.22);
  --cyan: #58e6ff;
  --amber: #ffb347;
  --red: #ff5a4d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #05070d; color: var(--ink);
  font: 14px/1.45 system-ui, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none; overscroll-behavior: none;
}
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
[hidden] { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; font-variant-numeric: tabular-nums; }
#stats {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: 210px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(6px);
}
.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar label { width: 30px; font-size: 11px; letter-spacing: .08em; color: var(--dim); }
.track { flex: 1; height: 7px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
.track i { display: block; height: 100%; width: 100%; background: var(--cyan); border-radius: 4px; transition: background .3s; }
#fuel { background: var(--amber); }
.track i.low { background: var(--red); }
.row { display: flex; align-items: baseline; gap: 6px; }
#speed { font-size: 26px; font-weight: 600; min-width: 2.2ch; text-align: right; }
.row small { color: var(--dim); }
#mode { margin-left: auto; font-size: 11px; letter-spacing: .1em; color: var(--dim); }
.money { justify-content: space-between; margin-top: 4px; color: var(--dim); }
.money b { color: var(--ink); }

#compass {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(420px, 56vw); height: 26px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  mask-image: linear-gradient(90deg, transparent, #000 14%, #000 86%, transparent);
}
#strip { position: absolute; top: 4px; left: 50%; height: 18px; white-space: nowrap; color: var(--dim); font-size: 12px; letter-spacing: .05em; }
#strip span { position: absolute; top: 0; transform: translateX(-50%); }
#strip span.card { color: var(--ink); font-weight: 600; }
#needle { position: absolute; left: 50%; top: 0; width: 1px; height: 100%; background: rgba(255,255,255,.55); }
#goal { position: absolute; top: 3px; color: var(--cyan); transform: translateX(-50%); text-shadow: 0 0 8px var(--cyan); }
#objective {
  position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 32px); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--cyan); text-shadow: 0 1px 4px #000; white-space: nowrap;
}
#map {
  position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top));
  width: 168px; height: 168px; border-radius: 50%; border: 1px solid var(--line); background: #0a0f1c;
}
#clock {
  position: absolute; right: max(14px, env(safe-area-inset-right)); top: calc(max(12px, env(safe-area-inset-top)) + 174px);
  width: 168px; text-align: center; font-size: 11px; color: var(--dim); letter-spacing: .08em;
}
#prompt {
  position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%);
  padding: 8px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  max-width: calc(100vw - 24px); text-align: center; backdrop-filter: blur(6px);
}
#prompt kbd, #keys kbd {
  display: inline-block; min-width: 1.7em; padding: 1px 6px; margin-right: 4px; text-align: center;
  font: inherit; font-weight: 600; color: #05070d; background: var(--ink); border-radius: 4px;
}
#toasts { position: absolute; left: 50%; top: 20%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  padding: 6px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  animation: toast 3.2s forwards; white-space: nowrap;
}
.toast.warn { border-color: var(--red); color: #ffd2cd; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-8px); } }
#fps { position: absolute; left: 8px; top: 6px; font-size: 11px; color: rgba(255,255,255,.35); }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; }

#overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(20, 44, 120, .55), rgba(3, 5, 12, .9) 70%);
  -webkit-user-select: text; user-select: text; touch-action: auto;
}
.card { width: min(560px, 100%); padding: 26px 28px; background: rgba(8, 13, 26, .82); border: 1px solid var(--line); border-radius: 16px; text-align: center; }
h1 { margin: 0; font-size: clamp(34px, 8vw, 54px); letter-spacing: .32em; text-indent: .32em; font-weight: 300; }
.sub { margin: 2px 0 14px; color: var(--cyan); letter-spacing: .18em; font-size: 12px; }
.lead { margin: 0 0 16px; color: var(--dim); text-wrap: balance; }
#progress { height: 4px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
#progress i { display: block; height: 100%; width: 0; background: var(--cyan); transition: width .15s; }
#status { margin: 8px 0 14px; min-height: 1.45em; color: var(--dim); font-size: 12px; }
#status.error { color: #ffb3ab; font-size: 14px; }
#start {
  padding: 12px 34px; font: inherit; font-size: 16px; font-weight: 600; letter-spacing: .1em; color: #05070d;
  background: var(--cyan); border: 0; border-radius: 999px; cursor: pointer;
}
#start:disabled { opacity: .35; cursor: default; }
#start:not(:disabled):hover { filter: brightness(1.1); }
#start:focus-visible, .link:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
#keys { margin: 18px auto 6px; border-collapse: collapse; text-align: left; font-size: 12.5px; color: var(--dim); }
#keys td { padding: 3px 10px; vertical-align: top; }
#keys td:first-child { white-space: nowrap; text-align: right; }
.foot { margin: 12px 0 0; font-size: 11px; color: var(--dim); }
.link { font: inherit; color: var(--dim); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }

#touch { position: fixed; inset: 0; pointer-events: none; }
#stick {
  position: absolute; left: 26px; bottom: 150px; width: 120px; height: 120px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255,255,255,.05);
}
#stick i { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.25); }
#touch button {
  position: absolute; right: 24px; width: 62px; height: 62px; border-radius: 50%; pointer-events: auto;
  font: 600 20px system-ui; color: var(--ink); background: rgba(255,255,255,.1); border: 1px solid var(--line);
}
#tJump { bottom: 40px; }
#tUse { bottom: 114px; }
#tBoost { bottom: 40px; right: 100px !important; }
#touch button.small { width: 42px; height: 42px; font-size: 14px; right: 24px; }
#tUpgrade { bottom: 196px; }
#tRecall { bottom: 246px; }
#tLight { bottom: 296px; }
#tPause { top: max(190px, calc(env(safe-area-inset-top) + 190px)); }
body.touch #prompt { bottom: 46%; border-radius: 14px; }
body.touch #objective { display: none; }

@media (max-width: 640px) {
  #map, #clock { width: 112px; } #map { height: 112px; }
  #tPause { top: max(140px, calc(env(safe-area-inset-top) + 140px)); }
  .card { padding: 18px 14px; } h1 { letter-spacing: .2em; text-indent: .2em; }
  #clock { top: calc(max(12px, env(safe-area-inset-top)) + 116px); }
  #stats { width: 170px; bottom: auto; top: max(12px, env(safe-area-inset-top)); }
  #compass { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  #objective { top: auto; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 30px); }
  #fps { display: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { animation-duration: 3.2s; animation-timing-function: step-end; } }
