:root {
  --ink: #ffffff;
  --ink-dim: rgba(255, 255, 255, 0.72);
  --glass: rgba(14, 20, 40, 0.42);
  --glass-strong: rgba(12, 18, 36, 0.78);
  --line: rgba(255, 255, 255, 0.28);
  --accent: #ffd27a;
  --imperial: #003e74;
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1530; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.6em; padding: 0.1em 0.45em; border: 1px solid var(--line); border-radius: 6px;
  font: 600 0.78em/1.4 inherit; letter-spacing: 0.04em; text-align: center; background: rgba(255,255,255,0.08); }

/* ---------- title */
.boot { position: fixed; inset: 0; z-index: 9; pointer-events: none;
  background: linear-gradient(#0f1f6b 0%, #2e4fae 52%, #dcb3c8 100%); transition: opacity 1.4s ease; }
.boot.done { opacity: 0; }
.title { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  padding: calc(24px + var(--st)) calc(24px + var(--sr)) calc(24px + var(--sb)) calc(24px + var(--sl));
  transition: opacity 0.7s ease, visibility 0s 0.7s; }
.title.off { opacity: 0; visibility: hidden; pointer-events: none; }
.title::before { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(8, 14, 34, 0.25), rgba(8, 14, 34, 0.0) 70%); }
.title-inner { position: relative; display: grid; justify-items: center; gap: 28px; text-align: center; }
.title h1 { margin: 0; font-weight: 300; font-size: clamp(30px, 6.2vw, 74px); letter-spacing: 0.32em; text-transform: uppercase;
  text-shadow: 0 2px 24px rgba(10, 20, 60, 0.55); line-height: 1.15; padding-left: 0.32em; }
.title h1 span { display: inline-block; }
.bar { width: min(320px, 70vw); height: 3px; background: rgba(255,255,255,0.22); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: #fff; transform-origin: left; transform: scaleX(0); transition: transform 0.25s ease; }
.title.ready .bar { display: none; }
.menu { display: none; flex-direction: column; gap: 12px; width: min(300px, 80vw); }
.title.ready .menu { display: flex; }
.pill { appearance: none; border: 1px solid var(--line); background: var(--glass); color: var(--ink); border-radius: 999px;
  padding: 13px 22px; letter-spacing: 0.22em; text-transform: uppercase; font-size: 12.5px; font-weight: 500;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: background 0.2s, transform 0.1s; }
.pill:hover { background: rgba(255, 255, 255, 0.18); }
.pill:active { transform: scale(0.98); }
.pill.primary { background: rgba(255, 255, 255, 0.22); }
.title-note { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--ink-dim); max-width: 420px; }
.fact { position: absolute; left: calc(18px + var(--sl)); bottom: calc(16px + var(--sb)); font-size: 11px;
  letter-spacing: 0.22em; color: rgba(255,255,255,0.75); text-transform: uppercase; transition: opacity 0.8s; }
.corner-credit { position: absolute; right: calc(12px + var(--sr)); bottom: calc(8px + var(--sb)); font-size: 10.5px;
  color: rgba(255,255,255,0.65); letter-spacing: 0.04em; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }

/* ---------- HUD */
.hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45); }
.hud button, .hud .mm-wrap { pointer-events: auto; }
.mm-wrap { position: absolute; left: calc(14px + var(--sl)); top: calc(14px + var(--st)); width: 132px; text-align: center; }
#minimap { width: 132px; height: 132px; border-radius: 50%; box-shadow: 0 4px 18px rgba(0,0,0,0.35); border: 2px solid rgba(255,255,255,0.75); cursor: pointer; }
.mm-label { margin-top: 4px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.9); }
.clock { position: absolute; top: calc(10px + var(--st)); left: 50%; transform: translateX(-50%); text-align: center; display: grid; gap: 2px; }
.clock b { font-weight: 400; font-size: 17px; letter-spacing: 0.14em; }
.clock span { font-size: 10.5px; letter-spacing: 0.2em; color: rgba(255,255,255,0.85); text-transform: uppercase; }
.place { position: absolute; top: calc(66px + var(--st)); left: 50%; transform: translateX(-50%); text-align: center; display: grid; gap: 4px; width: 90vw; }
.place b { font-weight: 300; font-size: clamp(16px, 2.6vw, 25px); letter-spacing: 0.28em; text-transform: uppercase; transition: opacity 0.5s; }
.place span { font-size: 11px; letter-spacing: 0.12em; font-style: italic; color: rgba(255,255,255,0.85); }
.gear { position: absolute; right: calc(14px + var(--sr)); top: calc(14px + var(--st)); width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); display: grid; place-items: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.prompt { position: absolute; left: 50%; bottom: calc(120px + var(--sb)); transform: translateX(-50%); padding: 9px 16px; border-radius: 999px;
  background: var(--glass-strong); font-size: 13.5px; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.hints { position: absolute; left: calc(14px + var(--sl)); bottom: calc(14px + var(--sb)); display: flex; gap: 14px; font-size: 11.5px; color: rgba(255,255,255,0.85); }
.toast { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); padding: 14px 22px; border-radius: 16px; background: var(--glass-strong);
  font-size: 15px; letter-spacing: 0.04em; text-align: center; opacity: 0; transition: opacity 0.35s; max-width: 80vw; line-height: 1.45; }
.toast.on { opacity: 1; }
.toast small { display: block; font-size: 12px; color: var(--ink-dim); margin-top: 4px; }
.fps { position: absolute; right: calc(14px + var(--sr)); top: calc(64px + var(--st)); font: 11px/1 ui-monospace, Menlo, monospace; }
.dash { position: absolute; right: calc(14px + var(--sr)); top: calc(66px + var(--st)); width: 230px; padding: 12px 14px; border-radius: 14px;
  background: var(--glass-strong); display: grid; gap: 3px; text-align: left; }
.dash-title { font-size: 10.5px; letter-spacing: 0.24em; color: var(--accent); }
.dash-target { font-size: 14px; font-weight: 600; line-height: 1.3; }
.dash-time { font: 600 26px/1.1 ui-monospace, Menlo, monospace; }
.dash-par { font-size: 11.5px; color: var(--ink-dim); }
.dash-arrow { position: absolute; right: 14px; top: 34px; font-size: 22px; color: var(--accent); transition: transform 0.1s linear; }

/* ---------- overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(6, 10, 24, 0.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 16px; }
.overlay.see-through { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; place-items: center end; pointer-events: none; }
.overlay.see-through .panel { pointer-events: auto; }
.panel { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--glass-strong); border: 1px solid var(--line);
  border-radius: 20px; padding: 22px; display: grid; gap: 14px; user-select: text; }
.panel.side { width: min(380px, 100%); margin-right: max(2vw, 8px); }
.panel h2 { margin: 0; font-weight: 400; letter-spacing: 0.22em; text-transform: uppercase; font-size: 16px; }
.panel h3 { margin: 6px 0 2px; font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-dim); font-weight: 600; }
.panel p { margin: 0; font-size: 13.5px; line-height: 1.55; color: var(--ink-dim); }
.panel .sub { margin-top: -8px; }
.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 8px; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; }
.tabs button.on { background: rgba(255,255,255,0.18); }
.tab { display: grid; gap: 10px; }
.keys { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; font-size: 13.5px; align-items: center; }
.panel label { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; align-items: center; font-size: 13.5px; }
.panel label.check { grid-template-columns: auto 1fr; }
.panel select, .panel input:not([type="checkbox"]) { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.08); color: var(--ink); font: inherit; font-size: 13.5px; }
.panel select option { color: #111; }
.panel-buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.panel-buttons .pill { padding: 10px 16px; font-size: 11.5px; }
.opt-row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; align-items: center; font-size: 13px; }
.swatches, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); padding: 0; }
.swatches button.on { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.chips button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 11px; font-size: 12px; }
.chips button.on { background: rgba(255,255,255,0.2); }
#bigmap { place-items: center; }
#mapcanvas { max-width: 100%; max-height: calc(100vh - 80px); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); cursor: crosshair; }
.map-help { margin-top: 10px; font-size: 12.5px; color: var(--ink-dim); text-align: center; }

/* ---------- touch */
.touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
.stick { position: absolute; left: calc(28px + var(--sl)); bottom: calc(40px + var(--sb)); width: 128px; height: 128px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); background: rgba(10,16,36,0.25); pointer-events: auto; }
.stick i { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255,255,255,0.55); }
.tbtns { position: absolute; right: calc(20px + var(--sr)); bottom: calc(36px + var(--sb)); display: grid; grid-template-columns: repeat(2, 64px); gap: 10px; pointer-events: auto; }
.tbtns button { height: 56px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.35); background: rgba(10,16,36,0.4); font-size: 12px; letter-spacing: 0.08em; }
.tbtns button.on { background: rgba(255,255,255,0.3); }
@media (max-width: 700px) {
  .hints { display: none; }
  .place { top: calc(128px + var(--st)); }
  .place b { font-size: 15px; letter-spacing: 0.22em; }
  .mm-label { display: none; }
  .title .fact { left: 12px; right: 12px; text-align: center; bottom: calc(30px + var(--sb)); font-size: 10px; letter-spacing: 0.16em; }
  .title .corner-credit { left: 12px; right: 12px; text-align: center; }
  .dash { top: auto; bottom: calc(200px + var(--sb)); right: calc(12px + var(--sr)); width: 200px; }
  .mm-wrap, #minimap { width: 104px; }
  #minimap { height: 104px; }
}
