.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: rgba(3, 5, 4, .94);
  backdrop-filter: blur(4px);
}

.settings-panel {
  width: min(100%, 560px);
  max-height: min(100%, 720px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  padding: 20px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.012), 0 20px 70px rgba(0,0,0,.32);
}

.settings-kicker {
  color: var(--faint);
  font-size: .68rem;
  letter-spacing: .09em;
  margin-bottom: 18px;
}

.settings-title {
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: .05em;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.settings-copy {
  color: var(--text);
  font-size: .92rem;
  line-height: 1.65;
  margin: 16px 0 18px;
}

.settings-choices {
  display: grid;
  gap: 7px;
}

.settings-choice {
  min-height: 56px;
  padding: 10px 12px;
}

.settings-choice--back {
  margin-top: 8px;
}

.settings-note {
  color: var(--muted);
  border-top: 1px dotted var(--line);
  margin-top: 18px;
  padding-top: 12px;
  font-size: .75rem;
  line-height: 1.5;
}

.runtime-update {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.runtime-update__box {
  width: min(100%, 560px);
  border: 1px solid var(--warning);
  padding: 20px;
  color: var(--warning);
}

.runtime-update__box h1 {
  margin: 12px 0;
  color: var(--accent);
  font-size: 1rem;
}

/* Build 0006.3: denser character art without converting the game into pixel art. */
.ascii-art {
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  text-rendering: geometricPrecision;
  letter-spacing: 0;
}

.screen-body > .ascii-art:first-child {
  color: var(--text);
  animation: dr-art-idle 6.8s ease-in-out infinite;
}

.terminal-visual--location,
.terminal-visual--map {
  isolation: isolate;
  background:
    linear-gradient(rgba(83,98,87,.075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(83,98,87,.075) 1px, transparent 1px),
    radial-gradient(circle at 50% 52%, rgba(168,195,169,.095), transparent 60%);
  background-size: 18px 18px, 18px 18px, auto;
}

.terminal-visual--location::before,
.terminal-visual--map::before {
  content: "";
  position: absolute;
  inset: 25px 8px;
  z-index: 0;
  pointer-events: none;
  opacity: .25;
  background:
    radial-gradient(circle at 17% 24%, rgba(216,223,210,.4) 0 1px, transparent 1.5px),
    radial-gradient(circle at 82% 37%, rgba(216,223,210,.32) 0 1px, transparent 1.5px),
    radial-gradient(circle at 69% 78%, rgba(216,223,210,.24) 0 1px, transparent 1.5px);
  animation: dr-sensor-breathe 8s ease-in-out infinite;
}

.terminal-visual--location .ascii-art {
  min-height: 10.7em;
  display: flex;
  align-items: center;
  color: var(--text);
  font-size: clamp(.76rem, 2.8vw, .96rem);
  line-height: 1.08;
}

.terminal-visual--map .ascii-art {
  min-height: 9.7em;
  display: flex;
  align-items: center;
  color: var(--text);
  font-size: clamp(.62rem, 2.25vw, .78rem);
  line-height: 1.13;
}

@keyframes dr-art-idle {
  0%, 100% {
    transform: translateY(0);
    opacity: .96;
  }
  48% {
    transform: translateY(-1px);
    opacity: 1;
  }
  52% {
    transform: translateY(-1px);
    opacity: 1;
  }
}

@keyframes dr-sensor-breathe {
  0%, 100% { opacity: .16; }
  50% { opacity: .32; }
}

/* Tablet portrait: keep the single-screen terminal, but let ASCII carry more visual weight. */
@media (min-width: 600px) and (min-height: 700px) {
  .app-shell {
    width: min(100%, 900px);
    padding: max(16px, env(safe-area-inset-top)) 22px max(20px, env(safe-area-inset-bottom));
  }

  .masthead { margin-bottom: 12px; }
  .brand { font-size: .78rem; }

  .terminal-screen {
    padding: 20px;
    gap: 12px;
  }

  .section-title {
    font-size: .88rem;
    letter-spacing: .05em;
  }

  .screen-body {
    max-height: 58svh;
  }

  .ascii-art {
    font-size: 1.12rem;
    line-height: 1.08;
    margin-top: 14px;
    margin-bottom: 20px;
  }

  .terminal-visual .ascii-art {
    margin-top: 18px;
    margin-bottom: 18px;
  }

  .ascii-art--map {
    font-size: .9rem;
    line-height: 1.13;
  }

  .ascii-art--location {
    font-size: 1.04rem;
    line-height: 1.08;
  }

  .terminal-visual--map .ascii-art {
    font-size: .9rem;
    min-height: 10.2em;
  }

  .terminal-visual--location .ascii-art {
    font-size: 1.04rem;
    min-height: 11em;
  }

  .terminal-visual__header,
  .terminal-visual__footer {
    font-size: .66rem;
    padding: 7px 9px;
  }

  .prose {
    font-size: 1rem;
    line-height: 1.62;
  }

  .context-line { font-size: .76rem; }
  .context-stat { padding: 7px 9px; }
  .context-stat__label { font-size: .68rem; }

  .choices { gap: 6px; }
  .choice {
    min-height: 50px;
    padding: 9px 12px;
  }
  .choice__title { font-size: .98rem; }
  .choice__meta { font-size: .78rem; line-height: 1.4; }

  .utility-bar { font-size: .75rem; padding-top: 2px; }

  .settings-panel {
    width: min(92vw, 620px);
    padding: 26px;
  }
  .settings-kicker { font-size: .76rem; }
  .settings-title { font-size: 1.08rem; }
  .settings-copy { font-size: 1rem; }
  .settings-choice { min-height: 64px; }
  .settings-note { font-size: .82rem; }
}

/* Large iPad portrait should not inherit the old desktop rule that shrank map/location art. */
@media (min-width: 761px) and (min-height: 700px) {
  .screen-body { max-height: 58svh; }
  .ascii-art--map { font-size: .9rem; }
  .ascii-art--location { font-size: 1.04rem; }
}

@media (max-width: 430px) {
  .settings-overlay { padding-left: 10px; padding-right: 10px; }
  .settings-panel { padding: 15px; }
  .settings-choice { min-height: 50px; }

  .screen-body > .ascii-art:first-child {
    font-size: clamp(.72rem, 3.05vw, .86rem);
    line-height: 1.05;
  }

  .terminal-visual--map .ascii-art {
    font-size: clamp(.56rem, 2.18vw, .69rem);
  }

  .terminal-visual--location .ascii-art {
    font-size: clamp(.66rem, 2.62vw, .8rem);
  }
}

@media (max-height: 680px) {
  .terminal-visual--map .ascii-art {
    min-height: 8.4em;
    font-size: .55rem;
  }

  .terminal-visual--location .ascii-art {
    min-height: 9.2em;
    font-size: .62rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen-body > .ascii-art:first-child,
  .terminal-visual--location::before,
  .terminal-visual--map::before {
    animation: none;
  }
}


/* Build 0008.1: short-phone Local Map and terminal flow.
   On narrow screens the entire terminal becomes the scroll surface instead of
   clipping prose between a fixed scene pane and a second nested choices pane. */
@media (max-width: 430px) {
  .terminal-screen {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .terminal-screen .screen-body {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
  }

  .terminal-screen .choices {
    flex: 0 0 auto;
    overflow: visible;
  }

  .terminal-visual--map {
    margin-bottom: 8px;
  }

  .choice__meta {
    line-height: 1.28;
  }
}

@media (max-width: 430px) and (max-height: 700px) {
  .terminal-screen {
    gap: 6px;
    padding: 9px;
  }

  .scene-stage--map,
  .terminal-visual--map {
    max-height: 148px;
  }

  .prose {
    line-height: 1.42;
  }

  .choice {
    min-height: 38px;
    padding-top: 6px;
    padding-bottom: 6px;
  }
}
