:root {
  --ink: #0d1210;
  --bone: #ece9df;
  --bone-soft: rgba(236, 233, 223, 0.8);
  --bone-dim: rgba(236, 233, 223, 0.5);
  --line: rgba(236, 233, 223, 0.3);
  --line-soft: rgba(236, 233, 223, 0.14);
  --accent: #e8642f;
  --font-display: "Chakra Petch", "Arial Narrow", sans-serif;
  --font-mono: "Space Mono", "Courier New", monospace;
  --font-body: "Barlow", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #0d1110;
  color: var(--bone);
  font-family: var(--font-mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
[hidden] { display: none !important; }

canvas#scene {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; background: #c9cdc2; z-index: 0;
}

/* ===================== HUD ===================== */
#game { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#hud { position: absolute; inset: 0; pointer-events: none; }

.panel {
  background: linear-gradient(180deg, rgba(13, 18, 15, 0.58), rgba(13, 18, 15, 0.34));
  border: 1px solid var(--line);
  color: var(--bone);
}
#brandPanel {
  position: absolute; top: 15px; left: 17px;
  min-width: 258px; max-width: min(48vw, 400px);
  padding: 9px 12px 11px 13px;
  border-left: 2px solid var(--accent);
  pointer-events: auto;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
#brandMark {
  font-family: var(--font-display); font-weight: 600;
  font-size: 13px; letter-spacing: 0.23em; white-space: nowrap;
}
.microbtn {
  font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.16em;
  color: var(--bone-dim); border: 1px solid var(--line-soft);
  padding: 3px 5px; min-height: 20px; pointer-events: auto;
}
.microbtn:hover { color: var(--bone); border-color: var(--line); }
.brand-place {
  margin-top: 7px; font-family: var(--font-display); font-weight: 500;
  font-size: 11px; letter-spacing: 0.18em; color: var(--bone-soft);
}
.brand-place .sep { margin: 0 7px; color: var(--accent); }
.brand-hint { margin-top: 5px; font-size: 7px; letter-spacing: 0.12em; color: var(--bone-dim); line-height: 1.5; }
.brand-tools { display: flex; gap: 5px; margin-top: 7px; }

#tapeWrap {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: min(46vw, 560px); height: 56px;
}
#tape { width: 100%; height: 100%; display: block; }

#targetCard {
  position: absolute; top: 15px; right: 17px;
  min-width: 190px; padding: 8px 11px 8px;
  border-right: 2px solid var(--accent);
  text-align: right;
}
.target-top { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.pinico {
  width: 8px; height: 8px; background: var(--accent);
  display: inline-block; transform: rotate(45deg); flex: none;
}
#wpLabel {
  font-family: var(--font-display); font-weight: 600; font-size: 10px;
  letter-spacing: 0.17em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.target-nums { margin-top: 3px; font-size: 12px; color: var(--bone); letter-spacing: 0.04em; }
.wpsep { margin: 0 7px; color: var(--bone-dim); }
.widebtn {
  margin-top: 7px; width: 100%; padding: 5px 7px;
  border: 1px solid var(--line);
  font-family: var(--font-display); font-weight: 500; font-size: 9px;
  letter-spacing: 0.22em; color: var(--bone-soft);
  background: rgba(232, 100, 47, 0.06);
  pointer-events: auto;
}
.widebtn span { color: var(--accent); margin-left: 6px; }
.widebtn:hover { color: var(--bone); border-color: var(--bone-soft); }

#waypointPin {
  position: absolute; width: 0; height: 0; left: 0; top: 0;
  pointer-events: none; transform: translate(-50%, -100%);
  opacity: 0; transition: opacity .25s;
}
#waypointPin.on { opacity: 1; }
.wp-diamond {
  position: absolute; left: -6px; top: -6px; width: 12px; height: 12px;
  background: var(--accent); transform: rotate(45deg);
  box-shadow: 0 0 0 1px rgba(13,18,15,.5);
}
.wp-tail {
  position: absolute; left: -0.5px; top: 8px; width: 1px; height: 18px;
  background: linear-gradient(var(--accent), rgba(232,100,47,0));
}
.wp-name {
  position: absolute; left: 10px; top: -3px; white-space: nowrap;
  font-size: 7px; letter-spacing: 0.16em; color: var(--bone);
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
}

#scaleBox {
  position: absolute; left: 17px; bottom: 16px;
  width: 208px; padding: 7px 9px 6px;
}
#scaleCanvas { display: block; width: 100%; height: 40px; }
.microlabel { margin-top: 2px; font-size: 6px; letter-spacing: 0.24em; }

#coords {
  position: absolute; right: 17px; bottom: 16px;
  width: 238px; padding: 8px 11px 7px;
}
.coord-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.coord-row b { font-weight: 400; font-size: 13px; letter-spacing: 0.02em; }
.coord-row .cl { font-size: 7px; letter-spacing: 0.2em; color: var(--bone-dim); }
.coord-row.tiny {
  margin-top: 5px; padding-top: 4px; border-top: 1px solid var(--line-soft);
  font-size: 7px; letter-spacing: 0.14em; color: var(--bone-dim);
  justify-content: flex-start; gap: 7px;
}
.coord-row.tiny span:nth-child(even) { color: var(--bone-soft); margin-right: 8px; }
.coord-credit { margin-top: 5px; font-size: 5.5px; letter-spacing: 0.08em; color: rgba(236,233,223,.32); }

#speedWrap {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  width: 186px; height: 96px;
  background: radial-gradient(ellipse at 50% 100%, rgba(13,18,15,.7), rgba(13,18,15,.18) 68%, transparent 72%);
}
#speedCanvas { width: 100%; height: 100%; display: block; }

#edgeNote {
  position: absolute; left: 50%; bottom: 104px; transform: translateX(-50%);
  font-family: var(--font-display); font-weight: 600; font-size: 10px;
  letter-spacing: 0.34em; color: var(--bone);
  padding: 4px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: rgba(13, 18, 15, 0.34); opacity: 0; transition: opacity .2s;
  white-space: nowrap;
}
#edgeNote.on { opacity: 1; }
#toast {
  position: absolute; left: 50%; bottom: 18%; transform: translateX(-50%);
  max-width: 86vw; padding: 7px 13px;
  border: 1px solid var(--line); background: rgba(13, 18, 15, 0.8);
  font-family: var(--font-display); font-weight: 500; font-size: 10px;
  letter-spacing: 0.2em; text-align: center; color: var(--bone);
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
#toast.on { opacity: 1; }

.bracket {
  position: absolute; width: 22px; height: 22px; opacity: 0.55;
  border-color: var(--bone); border-style: solid; border-width: 0;
}
.bracket.tl { top: 8px; left: 8px; border-top-width: 1px; border-left-width: 1px; }
.bracket.tr { top: 8px; right: 8px; border-top-width: 1px; border-right-width: 1px; }
.bracket.bl { bottom: 8px; left: 8px; border-bottom-width: 1px; border-left-width: 1px; }
.bracket.br { bottom: 8px; right: 8px; border-bottom-width: 1px; border-right-width: 1px; }

/* touch controls */
#touch { position: absolute; inset: 0; pointer-events: none; display: none; }
.touch-group { position: absolute; bottom: 26px; display: flex; gap: 8px; align-items: flex-end; pointer-events: none; }
.touch-group.left { left: 18px; }
.touch-group.right { right: 18px; }
.tbtn {
  pointer-events: auto; width: 58px; height: 58px; border: 1px solid var(--line);
  background: rgba(13, 18, 15, 0.46); color: var(--bone);
  font-family: var(--font-display); font-weight: 500; font-size: 13px;
  letter-spacing: 0.04em; touch-action: none;
}
.tbtn.gas { width: 64px; height: 68px; border-color: rgba(236,233,223,.48); }
.tbtn.brake { font-size: 10px; }
.tbtn.hb { width: 46px; height: 44px; font-size: 8px; letter-spacing: 0.12em; color: var(--bone-soft); }
.tbtn.on, .tbtn:active { background: rgba(232, 233, 223, 0.18); }
.touch-tools { display: none; }
.tbtn.mini { width: 42px; height: 24px; font-size: 8px; letter-spacing: 0.14em; }
@media (pointer: coarse), (max-width: 900px) {
  #touch { display: block; }
  #coords { bottom: 104px; }
  #scaleBox { bottom: 104px; }
}
@media (max-width: 1000px) {
  #tapeWrap { top: 78px; width: 72vw; height: 50px; }
}
@media (max-width: 760px) {
  #brandPanel { min-width: 0; max-width: 58vw; top: 10px; left: 10px; padding: 7px 8px; }
  #brandMark { font-size: 10px; letter-spacing: 0.16em; }
  .brand-hint { display: none; }
  #targetCard { top: 10px; right: 10px; min-width: 0; padding: 6px 8px; max-width: 40vw; }
  #wpLabel { font-size: 8px; }
  .target-nums { font-size: 10px; }
  .widebtn { font-size: 7px; padding: 4px; letter-spacing: 0.14em; }
  #tapeWrap { top: 78px; width: 92vw; height: 48px; }
  #scaleBox { display: none; }
  #coords { right: 10px; bottom: 88px; width: 190px; padding: 5px 8px; }
  .coord-row b { font-size: 10px; }
  #speedWrap { width: 128px; height: 74px; bottom: 8px; }
  #edgeNote { bottom: 168px; font-size: 8px; letter-spacing: 0.22em; }
  #toast { font-size: 8px; bottom: 24%; }
  .touch-group { bottom: 24px; }
  .tbtn { width: 52px; height: 52px; font-size: 12px; }
  .tbtn.gas { width: 56px; height: 62px; }
  .tbtn.hb { width: 40px; height: 38px; }
  .touch-tools { bottom: 92px; }
  #hud .bracket { width: 14px; height: 14px; }
}

/* ===================== intro title ===================== */
#introTitle {
  position: fixed; left: 50%; top: 44%; transform: translate(-50%, -50%);
  z-index: 7; text-align: center; pointer-events: none;
  width: min(90vw, 900px);
  text-shadow: 0 2px 18px rgba(0,0,0,.45);
}
.it-brand {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(16px, 4.6vw, 66px); letter-spacing: 0.26em;
  color: var(--bone); white-space: nowrap;
}
.it-rule { width: 42%; height: 1px; background: var(--line); margin: 13px auto; }
.it-place {
  font-family: var(--font-display); font-weight: 500;
  font-size: clamp(12px, 1.8vw, 20px); letter-spacing: 0.42em; color: var(--bone-soft);
}
.it-sub {
  margin-top: 7px; font-family: var(--font-mono); font-size: 8px;
  letter-spacing: 0.3em; color: var(--bone-dim);
}
.it-skip {
  margin-top: 22px; font-family: var(--font-mono); font-size: 7px;
  letter-spacing: 0.26em; color: rgba(236,233,223,.4);
}

/* ===================== help ===================== */
#helpPanel {
  position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 7, 0.58); pointer-events: auto;
}
.help-inner {
  width: min(560px, 90vw); padding: 18px 20px 20px;
  background: rgba(13,18,15,.95); border: 1px solid var(--line);
}
.help-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.help-head span { font-family: var(--font-display); font-weight: 600; font-size: 12px; letter-spacing: 0.28em; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-top: 15px; }
.help-grid div { display: flex; flex-direction: column; gap: 2px; }
.help-grid b { font-family: var(--font-display); font-weight: 500; font-size: 8px; letter-spacing: 0.2em; color: var(--accent); }
.help-grid span { font-family: var(--font-body); font-size: 13px; color: var(--bone-soft); }
.help-inner p { font-family: var(--font-body); font-size: 12px; line-height: 1.5; color: var(--bone-dim); margin: 16px 0 0; }

/* ===================== atlas ===================== */
#atlas {
  position: fixed; inset: 0; z-index: 20;
  display: block;
  background: transparent;
  transition: opacity .3s;
}
#mapWrap { position: absolute; top: 208px; bottom: 34px; left: 0; right: auto; width: 42%; z-index: 0; overflow: hidden; }
#mapWrap::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 1px; background: rgba(236,233,223,.35); pointer-events: none; }
#atlasCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.atlas-head {
  position: absolute; top: 0; left: 0; right: auto; width: 42%; z-index: 3;
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 12px; padding: 20px 26px 48px;
  background: linear-gradient(180deg, rgba(6,9,7,.82) 0%, rgba(6,9,7,.5) 55%, rgba(6,9,7,0) 100%);
  pointer-events: none;
}
.atlas-head > * { pointer-events: auto; }
.atlas-eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.26em;
  color: var(--bone-dim); text-transform: uppercase;
}
.atlas-eyebrow .sq { width: 5px; height: 5px; background: var(--accent); }
#atlas h1 {
  margin: 7px 0 0; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(17px, 2.7vw, 32px); letter-spacing: 0.13em; line-height: 1;
  white-space: nowrap; color: var(--bone);
}
.atlas-lede {
  margin: 8px 0 0; max-width: 440px;
  font-family: var(--font-body); font-size: 13px; line-height: 1.45;
  color: var(--bone-dim);
}
.atlas-search { width: min(400px, 100%); position: relative; flex: none; z-index: 3; }
#searchForm label {
  display: block; margin-bottom: 5px;
  font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.26em; color: var(--bone-dim);
}
.search-line { display: flex; border: 1px solid var(--line); background: rgba(13,18,15,.6); }
#searchInput {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: 0;
  padding: 10px 11px; font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.1em; color: var(--bone);
}
#searchInput::placeholder { color: rgba(236,233,223,.36); }
.search-line button {
  flex: none; padding: 0 15px; border-left: 1px solid var(--line);
  font-family: var(--font-display); font-weight: 600; font-size: 9px;
  letter-spacing: 0.2em; color: var(--accent);
}
.search-line button:hover { background: rgba(232,100,47,.1); }
#suggestions {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 4; margin-top: 3px;
  background: rgba(11,16,14,.97); border: 1px solid var(--line); max-height: 280px; overflow: auto;
}
#suggestions:empty { display: none; }
.sug {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  width: 100%; padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line-soft);
}
.sug:last-child { border-bottom: 0; }
.sug:hover, .sug.sel { background: rgba(232,100,47,.12); }
.sug .sname { font-family: var(--font-display); font-weight: 500; font-size: 11px; letter-spacing: 0.14em; }
.sug .ssub { font-family: var(--font-body); font-size: 11px; color: var(--bone-dim); }
#searchNote { margin-top: 6px; min-height: 12px; font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.08em; color: var(--bone-dim); line-height: 1.5; }
#searchNote.err { color: var(--accent); }
#resumeBtn, #returnBtn {
  margin-top: 8px; padding: 7px 10px; border: 1px solid var(--line);
  font-family: var(--font-display); font-weight: 500; font-size: 9px; letter-spacing: 0.18em;
  color: var(--bone-soft); width: 100%;
}
#resumeBtn:hover, #returnBtn:hover { border-color: var(--accent); color: var(--bone); }
#resumeName, #returnBtn span { color: var(--accent); }
#returnBtn { border-color: rgba(232,100,47,.5); color: var(--bone); }

#mapWrap { cursor: grab; }
#mapWrap.drag { cursor: grabbing; }
#atlasCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#livePreview {
  display: none; position: absolute; right: 26px; top: 22%; width: 38%; height: 56%; z-index: 2;
  border: 1px solid var(--line); pointer-events: auto; overflow: hidden;
  background: transparent;
}
.lp-head {
  position: absolute; left: 0; top: 0; right: 0; display: flex; align-items: center; gap: 7px;
  padding: 7px 9px; background: linear-gradient(180deg, rgba(8,12,10,.88), rgba(8,12,10,0));
  font-family: var(--font-mono); font-size: 7px; letter-spacing: .18em; color: var(--bone-dim);
  pointer-events: none;
}
.lp-head b { margin-left: auto; font-family: var(--font-display); font-weight: 500; font-size: 9px; letter-spacing: .16em; color: var(--bone); }
.lp-dot { width: 5px; height: 5px; background: var(--accent); transform: rotate(45deg); display: inline-block; }
#lpDrive {
  position: absolute; left: 9px; bottom: 9px; padding: 5px 9px; border: 1px solid var(--line);
  background: rgba(13,18,15,.72); font-family: var(--font-display); font-weight: 500;
  font-size: 8px; letter-spacing: .2em; color: var(--bone);
}
#lpDrive:hover { border-color: var(--accent); }
.map-tools { position: absolute; right: 20px; bottom: 52px; z-index: 4; display: flex; flex-direction: column; border: 1px solid var(--line); }
.map-tools button { width: 34px; height: 32px; color: var(--bone-soft); font-size: 16px; font-family: var(--font-mono); background: rgba(11,16,14,.68); }
.map-tools button + button { border-top: 1px solid var(--line); }
.map-tools button:hover { color: var(--bone); background: rgba(232,100,47,.14); }
.map-hint {
  position: absolute; left: 22px; bottom: 52px; z-index: 4;
  font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.16em; color: var(--bone-dim);
  background: rgba(11,16,14,.5); padding: 4px 7px; border: 1px solid var(--line-soft);
}
#mapCard {
  position: absolute; left: 22px; bottom: 100px; width: 236px; z-index: 4;
  padding: 11px 13px 10px; border: 1px solid var(--line);
  background: rgba(11,16,14,.88); pointer-events: none;
}
.mc-tag { font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.24em; color: var(--accent); }
.mc-name { margin-top: 3px; font-family: var(--font-display); font-weight: 600; font-size: 19px; letter-spacing: 0.14em; }
.mc-sub { font-family: var(--font-body); font-size: 12px; color: var(--bone-soft); margin-top: 2px; }
.mc-coord { margin-top: 7px; font-size: 9px; color: var(--bone-dim); letter-spacing: 0.02em; }
.mc-go { margin-top: 9px; padding-top: 7px; border-top: 1px solid var(--line-soft); font-family: var(--font-display); font-weight: 500; font-size: 8px; letter-spacing: 0.22em; color: var(--bone-soft); }
.atlas-foot {
  position: absolute; left: 0; right: auto; width: 42%; bottom: 0; z-index: 3;
  display: flex; justify-content: space-between; gap: 18px;
  padding: 24px 26px 10px; border-top: 0;
  background: linear-gradient(0deg, rgba(6,9,7,.82) 0%, rgba(6,9,7,.42) 55%, rgba(6,9,7,0) 100%);
  font-family: var(--font-mono); font-size: 6.5px; letter-spacing: 0.12em; color: rgba(236,233,223,.5);
}
.orange-dot { display: inline-block; width: 5px; height: 5px; background: var(--accent); margin-right: 6px; transform: rotate(45deg); }
.credit-link { font-family: var(--font-mono); font-size: 6.5px; letter-spacing: .14em; color: var(--bone-dim); border-bottom: 1px solid var(--line-soft); pointer-events: auto; }
.credit-link:hover { color: var(--bone); }
#sourcesPanel { position: fixed; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; background: rgba(6,9,7,.5); }
.sources-inner { width: min(460px, 88vw); padding: 16px 18px 18px; border: 1px solid var(--line); background: rgba(11,16,14,.97); }
.sources-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.sources-head span { font-family: var(--font-display); font-weight: 600; font-size: 11px; letter-spacing: .24em; }
.sources-inner p { margin: 12px 0 0; font-family: var(--font-body); font-size: 12px; line-height: 1.5; color: var(--bone-soft); }
#atlasCount { color: var(--bone-soft); }

#diveOverlay {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 30; width: min(430px, 86vw);
  display: block; background: rgba(9,14,11,.92);
  border: 1px solid var(--line); color: var(--bone);
  padding: 12px 16px 13px; text-align: left;
}
.dive-kicker { font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.24em; color: var(--accent); }
.dive-name { margin-top: 3px; font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: 0.22em; }
.dive-sub { margin-top: 3px; font-size: 8px; letter-spacing: 0.12em; color: var(--bone-dim); }
.dive-load { margin-top: 10px; width: 100%; }
.dive-load span { font-family: var(--font-mono); font-size: 7px; letter-spacing: 0.24em; color: var(--bone-dim); }
.loadline { margin-top: 6px; height: 1px; background: var(--line-soft); }
.loadline i { display: block; height: 1px; width: 0%; background: var(--accent); transition: width .3s; }
#fade { position: fixed; inset: 0; z-index: 40; background: #0b100e; opacity: 0; pointer-events: none; transition: opacity .35s; }
#fade.on { opacity: 1; }

@media (max-width: 900px) {
  .atlas-head { width: 42%; flex-direction: column; gap: 8px; padding: 12px 12px 32px; }
  #mapWrap { width: 42%; }
  .atlas-foot { width: 42%; flex-direction: column; gap: 3px; padding: 20px 12px 8px; }
  #atlas h1 { font-size: 15px; letter-spacing: 0.08em; }
  .atlas-lede { font-size: 11px; max-width: none; }
  .atlas-search { width: 100%; }
  .map-hint { display: none; }
  #mapCard { left: 12px; right: auto; bottom: 90px; width: 200px; }
  .map-tools { right: 12px; bottom: 46px; }
}
@media (max-width: 760px) and (orientation: portrait) {
  .atlas-head { width: 100%; padding: 14px 14px 38px; }
  #mapWrap { width: 100%; }
  .atlas-foot { width: 100%; padding: 20px 14px 8px; }
  #atlas h1 { font-size: clamp(15px, 5.6vw, 26px); letter-spacing: 0.1em; }
  .atlas-lede { font-size: 12px; }
}
