/* ほしのわだち — 探査隊の観測台帳 */
:root {
  color-scheme: dark;
  --ink: #242c24;
  --ink-soft: #4e594d;
  --paper: #f0ead7;
  --paper-rule: #c5bea5;
  --paper-grid: #3b554212;
  --panel: #202821;
  --instrument: rgb(26 34 28 / 92%);
  --instrument-rule: #929783;
  --bright: #f6f0db;
  --muted: #cbcdbb;
  --signal: #ffb47d;
  --signal-pressed: #f19860;
  --ready: #d7ed9d;
  --stamp: #87452e;
  --edge: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --mono: ui-monospace, Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-variant-numeric: tabular-nums;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #080b08;
  color: var(--bright);
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

#view {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { cursor: default; }

button:focus-visible,
.report:focus-visible {
  outline: 3px solid var(--focus, var(--signal));
  outline-offset: -4px;
}

button svg {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
}

/* 着陸じゅんび */
#loading {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--panel);
}

#loading-text {
  margin: 0;
  padding-inline: 16px;
  color: var(--bright);
  font-size: 14px;
}

.loading-mark {
  width: 52px;
  height: 26px;
  border-block: 3px solid var(--paper-rule);
  background: repeating-linear-gradient(116deg, transparent 0 7px, var(--signal) 7px 10px, transparent 10px 15px);
  animation: tread 800ms linear infinite;
}

@keyframes tread { to { background-position-x: 17px; } }

/* タイトルと着陸チケット */
#title {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  justify-items: center;
  gap: 6px;
  overflow: auto;
  padding: calc(clamp(18px, 4.5vh, 48px) + var(--safe-t))
    calc(18px + var(--safe-r)) calc(14px + var(--safe-b)) calc(18px + var(--safe-l));
  background: linear-gradient(180deg, #080b08b3, transparent 23%, transparent 78%, #080b08d9);
  pointer-events: none;
}

.title-head {
  grid-row: 1;
  width: min(100%, 380px);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--bright);
}

.mission-patch {
  display: block;
  flex: none;
  width: clamp(44px, 14vw, 64px);
  height: auto;
}

.wordmark-type {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
}

.title-sub {
  margin: 0 0 0 calc(clamp(44px, 14vw, 64px) + 10px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .2em;
}

.orbit-guide {
  position: absolute;
  top: 47.5%;
  left: 50%;
  width: min(98vw, 72vh);
  height: auto;
  transform: translate(-50%, -50%);
  color: #cdcbab99;
  pointer-events: none;
}

#title-ship {
  position: relative;
  grid-row: 3;
  align-self: end;
  margin: 0 0 clamp(6px, 2vh, 18px);
  transform: translateX(clamp(52px, 27vw, 125px));
  padding: 3px 6px;
  border: 1px solid #92978380;
  background: var(--instrument);
  color: var(--bright);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}

#title-ship::before {
  position: absolute;
  top: calc(50% - 2px);
  right: 100%;
  width: clamp(28px, 12vw, 56px);
  height: 5px;
  transform: rotate(23deg);
  transform-origin: right center;
  background:
    radial-gradient(circle, var(--bright) 1px, transparent 2px) var(--leader-dot, left) center / 5px 5px no-repeat,
    linear-gradient(var(--paper-rule), var(--paper-rule)) center / 100% 1px no-repeat;
  content: "";
}

.mission-ticket {
  --ticket-stock: #e6dfc8;
  --focus: var(--stamp);
  position: relative;
  grid-row: 4;
  width: min(100%, 396px);
  overflow: hidden;
  padding: 0 14px;
  border: 1px solid var(--paper-rule);
  background: var(--ticket-stock);
  color: var(--ink);
  box-shadow: 0 12px 28px #0007;
  pointer-events: auto;
}

.ticket-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
  gap: 10px;
  border-bottom: 1px solid var(--paper-rule);
  font-size: 12px;
  font-weight: 750;
}

.ticket-code {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font: 700 11px var(--mono);
  letter-spacing: .15em;
}

.ticket-code::after {
  width: 20px;
  height: 9px;
  background: repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 3px, currentColor 3px 5px, transparent 5px 7px);
  content: "";
}

.planet-pick {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.ticket-arrow {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid #9d9e88;
  border-radius: 2px;
  background: transparent;
}

.ticket-arrow:active,
.btn-sub:active { background: #d8d1b9; }

.planet-info { text-align: center; }

#p-name {
  margin: 0;
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 850;
  line-height: 1.15;
  letter-spacing: .08em;
}

#p-grav {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

#p-blurb {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

#p-prog {
  margin: 5px 1px 0;
  color: #375131;
  font-size: 12px;
  font-weight: 750;
}

#p-prog:empty { display: none; }

.ticket-foot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-block: 6px;
  border-top: 1px dashed #98947d;
}

.ticket-notes { flex: 1; }

.ticket-foot::before,
.ticket-foot::after {
  position: absolute;
  top: -6px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #080b08;
  content: "";
}

.ticket-foot::before { left: -20px; }
.ticket-foot::after { right: -20px; }

.btn-main,
.btn-sub {
  display: flex;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
}

.btn-main {
  --focus: var(--ink);
  background: var(--signal);
  color: var(--ink);
}

.btn-main:active { background: var(--signal-pressed); }

.btn-sub {
  border-color: #8c907d;
  background: transparent;
}

#go {
  position: relative;
  flex: 0 0 106px;
  padding-inline: 6px 24px;
  font-size: 14px;
}

#go svg {
  position: absolute;
  right: 6px;
  width: 15px;
  height: 15px;
}

.title-hint {
  grid-row: 2;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

/* 走行HUD */
#hud {
  --brake-rule: #ff8e82;
  --brake-text: #ffe4dc;
  --brake-state-height: 0px;
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

#hud:has(#brake-state:not([hidden])) { --brake-state-height: 20px; }

#hud button { pointer-events: auto; }

.hud-top {
  position: absolute;
  z-index: 1;
  top: calc(var(--edge) + var(--safe-t));
  right: calc(var(--edge) + var(--safe-r));
  left: calc(var(--edge) + var(--safe-l));
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 88px;
  grid-template-rows: calc(44px + var(--brake-state-height)) 36px auto;
  grid-template-areas:
    "menu gauges map"
    "compass compass map"
    "nav nav .";
  align-items: start;
  gap: 8px;
}

.icon-btn {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--instrument-rule);
  border-radius: 2px;
  background: var(--instrument);
  color: var(--bright);
}

.icon-btn:active,
.icon-btn.on {
  border-color: var(--signal);
  background: var(--signal);
  color: var(--ink);
}

.icon-btn.on:focus-visible,
.icon-btn:active:focus-visible { outline-color: var(--ink); }

#menu-btn { grid-area: menu; }

.gauges {
  display: grid;
  grid-area: gauges;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr 1fr var(--brake-state-height);
  align-items: center;
  width: fit-content;
  max-width: 100%;
  height: calc(44px + var(--brake-state-height));
  padding: 2px 7px 2px 0;
  border: 1px solid var(--instrument-rule);
  background: var(--instrument);
}

.speed {
  grid-row: span 2;
  margin-right: 7px;
  padding: 0 7px;
  border-right: 1px solid #92978373;
  white-space: nowrap;
}

.speed b {
  font-family: var(--mono);
  font-size: 23px;
  line-height: 1;
}

.speed small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 10px;
}

#brake-state {
  grid-column: 1 / -1;
  justify-self: start;
  margin-left: 7px;
  padding: 1px 3px;
  border: 1px solid var(--brake-rule);
  border-radius: 2px;
  background: #612d28;
  color: var(--brake-text);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
}

.mini-stats,
.tilt {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
}

#prog { color: var(--bright); }
.tilt .warn { color: var(--signal); }

.map-frame {
  position: relative;
  grid-area: map;
  width: 100%;
  aspect-ratio: 1;
  background: var(--instrument);
  box-shadow: inset 0 0 0 1px var(--instrument-rule);
}

#minimap {
  display: block;
  width: 100%;
  height: 100%;
}

.map-frame svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--bright);
  stroke-width: 1;
}

.compass {
  position: relative;
  grid-area: compass;
  width: 100%;
  max-width: 72vw;
  height: 36px;
  overflow: hidden;
  border: 1px solid var(--instrument-rule);
  background: var(--instrument);
}

.compass::after {
  position: absolute;
  inset: auto 0 0;
  height: 5px;
  background:
    repeating-linear-gradient(90deg, #cbcdbb8c 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, #cbcdbb53 0 1px, transparent 1px 8px) bottom / 100% 3px no-repeat;
  content: "";
}

#compass-strip { position: absolute; inset: 0 6px; }

#compass-strip > span {
  position: absolute;
  transform: translateX(-50%);
}

#compass-strip .dir {
  top: 11px;
  color: var(--bright);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

#compass-strip .site.target {
  top: 3px;
  width: 8px;
  height: 8px;
  transform: translateX(-50%) rotate(45deg);
  border: 1px solid var(--panel);
  background: var(--signal);
}

#compass-strip .site.target.edge {
  border-color: var(--signal);
  background: var(--panel);
}

.compass-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: #ffb47d80;
}

.compass-tick::after {
  position: absolute;
  bottom: 0;
  left: -3px;
  border: solid transparent;
  border-width: 0 3.5px 5px;
  border-bottom-color: var(--signal);
  content: "";
}

.hud-nav {
  display: flex;
  grid-area: nav;
  align-items: start;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  max-width: 72vw;
}

.sky-clock {
  display: inline-flex;
  flex: none;
  flex-direction: row-reverse;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 2px 5px;
  border: 1px solid var(--instrument-rule);
  border-radius: 2px;
  background: var(--instrument);
  color: #ffdaa0;
  font: 700 11px / 1 var(--mono);
  white-space: nowrap;
}

.sky-clock:has(#sky-time:empty) { display: none; }
.sky-clock:has(.night) { color: #c2d8ff; }
.sky-clock:has(.eclipse) { color: #ffbb91; }

.sky-clock svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sky-moon,
.sky-eclipse { display: none; }

#sky-time:is(.night, .eclipse) + svg .sky-sun { display: none; }
#sky-time.night:not(.eclipse) + svg .sky-moon,
#sky-time.eclipse + svg .sky-eclipse { display: inline; }

#target {
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  min-height: 27px;
  padding: 3px 6px;
  border-left: 2px solid var(--signal);
  background: var(--instrument);
  font-size: 12px;
  line-height: 1.35;
}

#target > svg {
  width: 13px;
  height: 13px;
  flex: none;
  fill: none;
  stroke: var(--signal);
  stroke-width: 1.35;
  stroke-linecap: round;
}

#target-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

#target-dist {
  color: var(--signal);
  font-weight: 800;
  white-space: nowrap;
}

#target.ready { border-color: var(--ready); }
#target.ready > svg { stroke: var(--ready); }
#target.ready #target-dist { color: var(--ready); }

.toast {
  position: absolute;
  top: calc(151px + var(--safe-t) + var(--brake-state-height));
  left: 50%;
  width: max-content;
  max-width: min(400px, 80%);
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid var(--paper-rule);
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  animation: toast-in 180ms ease-out;
}

@keyframes toast-in {
  from { transform: translate(-50%, -6px); opacity: 0; }
}

/* 可動スティックの中心と外周は JS の 128px 基準に合わせる。 */
.stick {
  position: fixed;
  z-index: 4;
  bottom: 0;
  left: 0;
  width: 50%;
  height: 62%;
  touch-action: none;
}

#hud[hidden] + .stick { display: none; }

.stick-base {
  position: absolute;
  bottom: calc(17px + var(--safe-b));
  left: calc(14px + var(--safe-l));
  width: 128px;
  height: 128px;
  opacity: .8;
  pointer-events: none;
  transition: opacity 150ms;
}

.stick.active .stick-base {
  opacity: 1;
  transition: none;
}

.stick-base > svg { display: block; width: 100%; height: 100%; }
.stick-plate { fill: #20282194; stroke: var(--instrument-rule); }
.stick-scale { fill: none; stroke: var(--bright); stroke-width: 4; stroke-dasharray: 1 10.25; }
.stick-axis { fill: none; stroke: var(--paper-rule); stroke-width: 1.15; }

.stick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  margin: -25px;
  clip-path: polygon(25% 0, 75% 0, 100% 25%, 100% 75%, 75% 100%, 25% 100%, 0 75%, 0 25%);
  background:
    repeating-linear-gradient(135deg, transparent 0 4px, #4a4b3f42 4px 6px, transparent 6px 10px) center / 27px 18px no-repeat,
    var(--paper-rule);
}

.stick.active .stick-knob {
  background-color: var(--signal);
}

.actions {
  --scan-size: 92px;
  --brake-width: 76px;
  position: absolute;
  z-index: 1;
  right: calc(var(--edge) + var(--safe-r));
  bottom: calc(var(--edge) + var(--safe-b));
  display: grid;
  grid-template-columns: var(--brake-width) 92px;
  grid-template-areas:
    "recovery recovery"
    "brake scan"
    "hop dash"
    "gas tools";
  align-items: end;
  gap: 6px;
  justify-items: end;
}

.recovery-actions {
  grid-area: recovery;
  display: flex;
  gap: 4px;
}

.recovery-actions:not(:has(> button:not([hidden]))) { display: none; }

.recovery-actions > button {
  place-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 750;
  line-height: 1;
}

.recovery-actions svg { width: 17px; height: 17px; }

#flip-btn {
  border-color: var(--signal);
  color: var(--signal);
}

#flip-btn:active { color: var(--ink); }

#garage-btn {
  --focus: var(--ink);
  width: 70px;
  border-color: var(--signal);
  background: var(--signal);
  color: var(--ink);
  font-size: 11px;
  animation: garage-available 850ms ease-in-out 2;
}

#garage-btn:active { background: var(--signal-pressed); }

@keyframes garage-available {
  50% { box-shadow: 0 0 0 3px #ffb47d55, 0 0 12px #ffb47d66; }
}

#anchor-btn {
  grid-area: brake;
  width: 100%;
  height: 66px;
  place-content: center;
  gap: 3px;
  border-color: #b58b7b;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.1;
  touch-action: none;
}

#anchor-btn:is(:active, .on) {
  border-color: var(--brake-rule);
  background: #8b322b;
  color: var(--brake-text);
  box-shadow: inset 0 0 12px #ff8e8240, 0 0 10px #ff665b70;
  outline-color: var(--brake-text);
}

.drive-action {
  width: 100%;
  height: 54px;
  place-content: center;
  gap: 2px;
  border-color: var(--action-rule);
  background: rgb(26 34 28 / 83%);
  color: var(--action-color);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.1;
}

#dash-btn {
  --action-rule: #b88b61;
  --action-color: #ffc48b;
  grid-area: dash;
  touch-action: none;
}

#hop-btn {
  --action-rule: #799bab;
  --action-color: #bde9ff;
  grid-area: hop;
}

.drive-action:not(:disabled):is(:active, .on) {
  border-color: var(--action-color);
  background: var(--action-color);
  color: var(--ink);
}

.drive-action:disabled {
  border-color: #727b71;
  background: rgb(24 30 26 / 74%);
  color: #a4aca1;
}

#gas-gauge {
  --gas-color: #bde9ff;
  display: grid;
  grid-area: gas;
  align-self: center;
  gap: 3px;
  inline-size: 100%;
  padding-inline: 4px;
  color: var(--bright);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 3px #151a16, 0 0 4px #151a16;
}

.gas-level {
  display: block;
  height: 6px;
  padding: 1px;
  border: 1px solid var(--instrument-rule);
  border-radius: 2px;
  background: var(--panel);
}

.gas-level::before {
  display: block;
  height: 100%;
  transform: scaleX(clamp(0, var(--gas, 1), 1));
  transform-origin: left;
  background: var(--gas-color);
  content: "";
}

#gas-gauge.low { --gas-color: #ff9a4f; color: var(--gas-color); }
#gas-gauge.low .gas-level {
  border-color: var(--gas-color);
  animation: gas-low 850ms ease-in-out infinite alternate;
}

@keyframes gas-low { to { opacity: .4; } }

.tool-actions {
  display: flex;
  grid-area: tools;
  gap: 5px;
}

.scan-btn {
  position: relative;
  grid-area: scan;
  display: grid;
  width: var(--scan-size);
  height: var(--scan-size);
  place-content: center;
  justify-items: center;
  gap: 1px;
  padding: 0;
  border: 1px solid var(--instrument-rule);
  border-radius: 2px;
  background:
    linear-gradient(var(--instrument-rule), var(--instrument-rule)) left 4px top 4px / 10px 1px no-repeat,
    linear-gradient(var(--instrument-rule), var(--instrument-rule)) left 4px top 4px / 1px 10px no-repeat,
    linear-gradient(var(--instrument-rule), var(--instrument-rule)) right 4px bottom 4px / 10px 1px no-repeat,
    linear-gradient(var(--instrument-rule), var(--instrument-rule)) right 4px bottom 4px / 1px 10px no-repeat,
    var(--instrument);
  color: var(--muted);
  font-size: 15px;
  font-weight: 850;
  line-height: 1.1;
}

.scan-btn .scan-icon { width: 19px; height: 19px; }

.scan-btn .scan-progress {
  position: absolute;
  inset: 1px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  transform: rotate(-90deg);
}

.scan-progress circle { stroke-width: 2.5; }
.scan-progress .ring-bg { stroke: #92978366; stroke-dasharray: 2 4; }
.scan-progress .ring { stroke: var(--ready); stroke-dasharray: 283; stroke-dashoffset: 283; }

.scan-btn:not(:disabled) {
  --focus: var(--ready);
  border-color: var(--ready);
  background-color: #303f26;
  color: var(--ready);
}

.scan-btn:not(:disabled):active { background-color: #415535; }

/* 調査カードとメニュー */
.card-wrap {
  z-index: 20;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r))
    calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: #0b110c99;
}

.paper {
  --focus: var(--stamp);
  color-scheme: light;
  border: 1px solid var(--paper-rule);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px #0006;
}

.report,
.menu-card {
  position: relative;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  animation: sheet-in 200ms ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(8px); opacity: 0; }
}

.report {
  width: min(100%, 470px);
  padding: clamp(14px, 4vw, 23px);
  border-top: 5px solid #64694e;
  background-image:
    linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px),
    linear-gradient(var(--paper-grid) 1px, transparent 1px);
  background-size: 16px 16px;
}

.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--paper-rule);
}

.card-tag {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 7px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

#card-no {
  padding: 2px 6px;
  background: var(--ink);
  color: var(--paper);
  font: 700 12px var(--mono);
}

.survey-stamp {
  flex: none;
  transform: rotate(-7deg);
  padding: 3px 6px;
  border: 3px double var(--stamp);
  color: var(--stamp);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.2;
  letter-spacing: .12em;
}

#card-title,
#menu-title,
#garage-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
  font-weight: 850;
}

#card-title { margin-block: 10px 8px; }

#card-fact {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.75;
}

#card-data {
  display: grid;
  grid-template-columns: minmax(0, 39%) minmax(0, 1fr);
  margin: 12px 0 0;
  border: 1px solid var(--paper-rule);
  border-bottom: 0;
  background: #f5f0e2;
  font-size: 12px;
  line-height: 1.5;
}

#card-data dt,
#card-data dd {
  margin: 0;
  overflow-wrap: anywhere;
  padding: 6px 8px;
  border-bottom: 1px solid var(--paper-rule);
}

#card-data dt {
  border-right: 1px solid var(--paper-rule);
  background: #e6dfc9;
  color: var(--ink-soft);
  font-weight: 700;
}

#card-data dd { font-weight: 700; }

#card-reward {
  margin: 10px 0 0;
  padding: 7px 9px;
  border-left: 3px solid var(--stamp);
  background: #e7d8ba;
  color: #603c2c;
  font-size: 13px;
  font-weight: 750;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.report-actions > button { flex: 1 1 125px; }
.report-actions .btn-sub { background: var(--paper); }
.report-actions .btn-sub:active { background: #d8d1b9; }

.menu-card {
  display: grid;
  gap: 8px;
  width: min(100%, 320px);
  border-top: 5px solid #64694e;
}

#menu-title {
  margin-bottom: 3px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--paper-rule);
}

/* ガレージは画面の下半分。分類は横、パーツ一覧は縦にスクロールする。 */
#garage {
  --focus: var(--signal);
  position: fixed;
  inset: auto 0 0;
  z-index: 25;
  height: 50%;
  padding-inline: var(--safe-l) var(--safe-r);
  border-top: 2px solid var(--instrument-rule);
  background: var(--panel);
  color: var(--bright);
  box-shadow: 0 -5px 18px #080b0833;
  animation: sheet-in 200ms ease-out;
}

body:has(> :is(#card, #menu):not([hidden])) #hud button { visibility: hidden; }

.garage-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(44px, 1fr) auto;
  gap: 5px;
  width: min(100%, 760px);
  height: 100%;
  margin-inline: auto;
  padding: 5px 12px calc(6px + var(--safe-b));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.garage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#garage-close {
  color: var(--bright);
  font-size: 13px;
}

#garage-close svg {
  width: 16px;
  height: 16px;
}

#garage-close:active { color: var(--ink); }

#garage-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overflow-anchor: none;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  border-bottom: 1px solid var(--instrument-rule);
  scrollbar-width: thin;
}

.g-tab {
  flex: 1 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-bottom: 3px solid transparent;
  border-radius: 2px 2px 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.g-tab.on {
  border-color: #92978373;
  border-bottom-color: var(--signal);
  background: #343d32;
  color: var(--bright);
}

.g-tab.perf {
  background: #242f26;
  color: #b9d8a9;
}

.g-tab.perf.on {
  border-color: #718d65;
  border-bottom-color: #b9ed98;
  background: #344a35;
  color: #e6f6d9;
}

.g-tab.perf + .g-tab:not(.perf) {
  margin-inline-start: 5px;
  border-inline-start-color: var(--instrument-rule);
}

#garage-list {
  display: grid;
  align-content: start;
  gap: 4px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.part {
  position: relative;
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  grid-template-areas: "swatch name" "swatch note";
  align-content: center;
  align-items: center;
  min-height: 48px;
  gap: 1px 8px;
  padding: 4px 8px;
  border: 1px solid #92978373;
  border-radius: 2px;
  background: #2a332a;
  color: var(--bright);
  text-align: left;
}

.part-swatch {
  display: grid;
  grid-area: swatch;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid var(--instrument-rule);
  background: #1a221c;
  font-size: 13px;
}

.part-name {
  grid-area: name;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.25;
}

.part-note {
  grid-area: note;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.part.on {
  padding-right: 22px;
  border-color: var(--ready);
  background: #333e2c;
}

.part.on::after {
  position: absolute;
  top: 50%;
  right: 9px;
  width: 5px;
  height: 9px;
  transform: translateY(-65%) rotate(45deg);
  border: solid var(--ready);
  border-width: 0 2px 2px 0;
  content: "";
}

.part:disabled,
.part.locked {
  border-style: dashed;
  background: #1c241e;
  color: var(--muted);
}

.part.locked .part-swatch {
  position: relative;
  opacity: .72;
}

.part.locked .part-swatch::after {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, #111a138c 0 2px, transparent 2px 5px);
  content: "";
}

.garage-footer {
  position: relative;
  display: grid;
  gap: 3px;
  min-width: 0;
  padding-top: 4px;
  border-top: 1px solid var(--instrument-rule);
  line-height: 1.2;
}

.garage-footer > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

#garage-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 12px;
  min-width: 0;
  margin: 0;
}

#garage-stats .stat {
  --meter-color: #c0c6ac;
  display: grid;
  grid-template-columns: 5em minmax(0, 1fr) 4ch;
  align-items: center;
  gap: 4px;
  color: var(--bright);
  font-size: 11px;
  white-space: nowrap;
}

#garage-stats .stat.up { --meter-color: #a9ec86; }
#garage-stats .stat.down { --meter-color: #ffad70; }

#garage-stats .bar {
  position: relative;
  display: block;
  height: 7px;
  background: #131b16;
  box-shadow: inset 0 0 0 1px #677261;
}

#garage-stats .bar > i {
  display: block;
  height: 100%;
  background: var(--meter-color);
}

#garage-stats .bar::after {
  position: absolute;
  inset: -1px auto -1px 50%;
  width: 1px;
  background: #f6f0db;
  box-shadow: 0 0 0 1px #171e18aa;
  content: "";
}

#garage-stats .stat em {
  color: var(--meter-color);
  font: 700 11px var(--mono);
  text-align: right;
}

#garage-stats .stat-parts {
  grid-column: 1 / -1;
  min-height: 13px;
  padding-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.garage-footer:has(> .garage-page:not([hidden])) .stat-parts {
  display: flex;
  align-items: center;
  min-height: 30px;
  padding: 0 65px 0 0;
}

.garage-page {
  position: absolute;
  inset: auto 0 0 auto;
  min-height: 30px;
  padding-inline: 8px;
  border: 1px solid var(--instrument-rule);
  border-radius: 2px;
  background: #2a332a;
  color: var(--bright);
  font-size: 12px;
  white-space: nowrap;
}

@media (max-width: 350px) {
  #hud { --edge: 8px; }

  .hud-top {
    grid-template-columns: 44px minmax(0, 1fr) 84px;
    column-gap: 6px;
  }

  .speed {
    margin-right: 5px;
    padding-inline: 5px;
  }

  .speed b { font-size: 20px; }
  .speed small { margin-left: 2px; }
  #brake-state { margin-left: 5px; }

  .actions { --brake-width: 68px; }
}

@media (min-width: 620px) {
  .compass,
  .hud-nav { justify-self: center; }

  .hud-nav {
    display: grid;
    grid-template-columns: 60px minmax(0, 1fr) 60px;
  }

  #target { grid-column: 2; justify-self: center; }
  .sky-clock { grid-column: 3; justify-self: end; }

  #garage-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  .compass,
  .hud-nav {
    grid-column: 1 / -1;
    width: min(72vw, calc(100% - 192px), 720px);
  }

  .compass { grid-row: 2; }
  .hud-nav { grid-row: 3; }
}

@media (min-aspect-ratio: 6/5) {
  #title {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    justify-items: stretch;
    gap: 8px 14px;
    padding: calc(14px + var(--safe-t)) calc(clamp(14px, 3vw, 56px) + var(--safe-r))
      calc(10px + var(--safe-b)) calc(clamp(14px, 3vw, 56px) + var(--safe-l));
    background: linear-gradient(90deg, #080b088c, transparent 47%, transparent 60%, #080b088c);
  }

  .title-head {
    grid-area: 1 / 1;
    align-self: start;
    width: min(79%, 380px);
  }

  #title-ship {
    --leader-dot: right;
    position: absolute;
    grid-area: auto;
    top: 72%;
    right: calc(50% + clamp(45px, 8vw, 92px));
    margin: 0;
    transform: none;
  }

  #title-ship::before {
    right: auto;
    left: 100%;
    transform: rotate(-23deg);
    transform-origin: left center;
  }

  .mission-ticket {
    grid-area: 1 / 2;
    align-self: end;
    justify-self: end;
    width: min(100%, 318px, 36vw);
  }

  .title-hint {
    grid-area: 2 / 2;
    justify-self: end;
    width: min(100%, 318px, 36vw);
  }

  .orbit-guide { top: 48%; }
  #p-name { font-size: clamp(25px, 6vh, 36px); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .mission-patch { width: 44px; }
  .title-sub { margin-left: 52px; }

  .toast {
    top: calc(102px + var(--safe-t));
    left: auto;
    right: calc(var(--edge) + var(--safe-r));
    max-width: 40%;
    transform: none;
    animation: none;
  }

  .stick { height: 60%; }
  .actions { --scan-size: 76px; }
  .report { width: min(100%, 580px); }

  .garage-sheet {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(44px, 1fr) auto;
    column-gap: 10px;
  }

  .garage-head { display: contents; }
  #garage-title { grid-area: 1 / 1; align-self: center; font-size: 18px; }
  #garage-tabs { grid-area: 1 / 2; }
  #garage-close { grid-area: 1 / 3; }

  #garage-list {
    grid-area: 2 / 1 / 3 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .garage-footer { grid-area: 3 / 1 / 4 / -1; }
}

@media (orientation: landscape) and (max-height: 500px) and (min-width: 620px) {
  #garage-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-mark,
  .toast,
  .report,
  .menu-card,
  #garage-btn,
  #garage,
  #gas-gauge.low .gas-level { animation: none; }
  .stick-base { transition: none; }
}
