:root {
  color-scheme: dark;
  --bg: #070a08;
  --panel: #0a0e0b;
  --text: #c8d1c4;
  --muted: #778177;
  --faint: #465047;
  --line: #2c382f;
  --line-strong: #536257;
  --accent: #d8dfd2;
  --warning: #c9b98c;
  --danger: #d1a29d;
  --success: #a8c3a9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; background: var(--bg); }
body { overflow: hidden; }
button { font: inherit; }

.app-shell {
  width: min(100%, 760px);
  height: 100svh;
  min-height: 0;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.masthead { flex: 0 0 auto; margin-bottom: 8px; }
.brand {
  color: var(--faint);
  font-size: .7rem;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: hidden;
}

.terminal-screen {
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.012), transparent 34%);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow: hidden;
}

.screen-body {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 42svh;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding-right: 2px;
}

.section-title {
  flex: 0 0 auto;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  font-size: .76rem;
  letter-spacing: .04em;
}

.ascii-art {
  width: max-content;
  margin: 5px auto 12px;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(.76rem, 1.9vw, .98rem);
  line-height: 1.08;
  white-space: pre;
  text-align: left;
}

.terminal-visual {
  position: relative;
  width: 100%;
  margin: 4px 0 12px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(rgba(83,98,87,.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(83,98,87,.08) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, rgba(168,195,169,.075), transparent 66%);
  background-size: 18px 18px, 18px 18px, auto;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.012);
}

.terminal-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(216,223,210,.025), transparent);
  transform: translateX(-100%);
  animation: terminal-sweep 7s linear infinite;
}

@keyframes terminal-sweep {
  0%, 72% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.terminal-visual__header,
.terminal-visual__footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 7px;
  color: var(--faint);
  font-size: .58rem;
  letter-spacing: .07em;
  line-height: 1.2;
  text-transform: uppercase;
}

.terminal-visual__header { border-bottom: 1px solid var(--line); }
.terminal-visual__footer { border-top: 1px solid var(--line); }
.terminal-visual__header span:last-child,
.terminal-visual__footer span:last-child { color: var(--muted); }

.terminal-visual .ascii-art {
  position: relative;
  z-index: 1;
  margin: 12px auto;
  color: var(--text);
}

.ascii-art--map {
  font-size: clamp(.64rem, 2.55vw, .8rem);
  line-height: 1.16;
}

.ascii-art--location {
  font-size: clamp(.8rem, 3.05vw, 1rem);
  line-height: 1.1;
}

.prose { line-height: 1.54; font-size: .92rem; }
.prose p { margin: 0 0 .68em; }
.prose p:last-child { margin-bottom: 0; }
.dialogue { color: var(--accent); }
.muted { color: var(--muted); }
.warning { color: var(--warning); }
.danger { color: var(--danger); }
.success { color: var(--success); }

.context-line {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .7rem;
}

.context-line--single {
  padding: 6px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.context-stat {
  min-width: 0;
  padding: 5px 7px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  border-right: 1px solid rgba(44,56,47,.7);
}

.context-stat:nth-child(3n) { border-right: 0; }
.context-stat:nth-child(n+4) { border-top: 1px solid rgba(44,56,47,.7); }
.context-stat__label {
  color: var(--faint);
  font-size: .62rem;
  letter-spacing: .06em;
}
.context-stat strong {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.choices {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
  overscroll-behavior: contain;
  padding-top: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.choice {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-left: 2px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.choice:hover:not(:disabled), .choice:focus-visible {
  border-left-color: var(--accent);
  background: rgba(255,255,255,.026);
  outline: 0;
}
.choice:active:not(:disabled) { background: rgba(255,255,255,.05); }
.choice:disabled { color: var(--faint); cursor: not-allowed; }
.choice__title { display: block; line-height: 1.25; }
.choice__meta { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; line-height: 1.3; }

.list { display: grid; gap: 6px; margin-top: 8px; }
.row { border-top: 1px dotted var(--line); padding-top: 7px; }
.row:first-child { border-top: 0; padding-top: 0; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }

.specimen {
  margin: 2px auto 9px;
  width: min(100%, 32ch);
  border: 1px solid var(--line);
  padding: 11px 8px;
  text-align: center;
  color: var(--muted);
  white-space: pre;
}

.scan-strip {
  width: min(100%, 46ch);
  margin: 0 auto 10px;
  border: 1px solid var(--warning);
  padding: 9px 10px;
  display: grid;
  gap: 4px;
  color: var(--warning);
  font-size: .76rem;
  line-height: 1.35;
}
.scan-strip strong { color: var(--accent); letter-spacing: .06em; }
.scan-strip--routine { border-color: var(--line); color: var(--muted); }

.risk-list { display: grid; gap: 7px; margin-top: 10px; }
.risk-card {
  border: 1px solid var(--line);
  border-left-color: var(--warning);
  padding: 8px 9px;
  font-size: .78rem;
  color: var(--muted);
}
.risk-card p { margin: 5px 0 0; line-height: 1.35; }
.risk-card strong { color: var(--text); }

.receipt {
  width: min(100%, 30ch);
  margin: 0 auto 12px;
  border-top: 1px dashed var(--line-strong);
  border-bottom: 1px dashed var(--line-strong);
  padding: 9px 4px;
  color: var(--muted);
}
.receipt p { margin: 3px 0; display: flex; justify-content: space-between; }

.save-summary {
  width: min(100%, 38ch);
  margin: 8px auto 0;
  border: 1px solid var(--line);
  padding: 10px;
  color: var(--muted);
}
.save-summary p { margin: 3px 0; }

.status-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(3,5,4,.92);
}
.status-box {
  width: min(100%, 520px);
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 14px;
}
.status-box pre { margin: 11px 0; line-height: 1.58; color: var(--text); font-size: .82rem; }

.utility-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  color: var(--faint);
  font-size: .68rem;
}
.utility-button { border: 0; background: transparent; color: var(--muted); padding: 5px 0; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .terminal-visual::after { animation: none; }
}

@media (max-width: 430px) {
  .app-shell { padding-left: 9px; padding-right: 9px; }
  .terminal-screen { padding: 10px; gap: 7px; }
  .screen-body { max-height: 44svh; }
  .prose { font-size: .86rem; line-height: 1.46; }
  .choice { min-height: 42px; padding: 7px 8px; }
  .choice__meta { font-size: .69rem; }
  .ascii-art {
    width: max-content;
    font-size: clamp(.78rem, 3.4vw, .92rem);
    margin-top: 6px;
    margin-bottom: 12px;
  }
  .terminal-visual .ascii-art { margin-top: 11px; margin-bottom: 11px; }
  .ascii-art--map { font-size: clamp(.62rem, 2.55vw, .74rem); }
  .ascii-art--location { font-size: clamp(.76rem, 3.15vw, .92rem); }
  .terminal-visual__header,
  .terminal-visual__footer { font-size: .54rem; padding: 5px 6px; }
  .context-stat { padding: 5px 6px; }
  .context-stat__label { font-size: .58rem; }
}

@media (max-height: 680px) {
  .masthead { margin-bottom: 5px; }
  .terminal-screen { padding: 9px; gap: 6px; }
  .screen-body { max-height: 38svh; }
  .ascii-art { margin-bottom: 7px; font-size: .7rem; }
  .terminal-visual { margin-bottom: 8px; }
  .terminal-visual .ascii-art { margin-top: 8px; margin-bottom: 8px; }
  .ascii-art--map { font-size: .58rem; }
  .ascii-art--location { font-size: .68rem; }
  .prose { font-size: .82rem; line-height: 1.4; }
  .choice { min-height: 36px; padding-top: 5px; padding-bottom: 5px; }
  .scan-strip { padding: 7px 8px; margin-bottom: 7px; }
  .context-stat { padding-top: 4px; padding-bottom: 4px; }
}

@media (min-width: 761px) {
  .app-shell { padding-top: 20px; padding-bottom: 20px; }
  .terminal-screen { padding: 16px; }
  .screen-body { max-height: 48vh; }
  .ascii-art--map { font-size: .88rem; }
  .ascii-art--location { font-size: 1rem; }
}
