body.page-terminal {
  height: 100dvh;
  overflow: hidden;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
}

.term {
  position: relative;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--bg-sink) 94%, transparent);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.term > * { position: relative; z-index: 1; }

.term::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    var(--scan, rgba(0, 0, 0, 0.04)) 2px 3px
  );
}

:root { --scan: rgba(70, 48, 20, 0.035); }
:root[data-theme="dark"] { --scan: rgba(182, 242, 92, 0.04); }

.term-bar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 3.3rem;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.page-terminal .theme-btn { margin-left: 0; }

.term-id {
  margin: 0;
  color: var(--faint);
  letter-spacing: 0.08em;
  font-size: 0.82rem;
}

.term-spacer { margin-left: auto; }

.bar-btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  font: inherit;
  letter-spacing: 0.08em;
  text-decoration: none;
  padding: 0.4rem 0.65rem;
}

.bar-btn:hover { border-color: var(--accent); color: var(--text); }

.screen {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.9rem 1rem 0.4rem;
}

.screen[hidden],
.stage[hidden],
.menu[hidden] { display: none !important; }

.line {
  margin: 0 0 0.12rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.line-gap { height: 0.55rem; }

.line-dim { color: var(--muted); }

.line-warn { color: var(--danger); }

.line-accent { color: var(--accent); }

.prompt-echo { color: var(--accent); }

.pre {
  margin: 0.25rem 0 0.7rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--glow);
  line-height: 1.25;
}

.typing::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.12rem;
  background: var(--phosphor);
  vertical-align: text-bottom;
  animation: blink 1.05s steps(1) infinite;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.45rem 0 0.8rem;
}

.choice {
  width: min(100%, 38rem);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.choice small { color: var(--muted); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #070806;
}

.stage-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raise);
}

.stage-bar span {
  margin-right: auto;
  letter-spacing: 0.08em;
}

.stage iframe {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #070806;
}

.menu {
  max-height: min(42vh, 22rem);
  overflow: auto;
  margin: 0 0.7rem 0.45rem;
  border: 1px solid var(--line-strong);
  background: var(--bg-raise);
}

.menu button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(7.5rem, 11rem) minmax(0, 1fr);
  gap: 0.75rem;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.42rem 0.7rem;
  cursor: pointer;
}

.menu button span:last-child {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu button[aria-selected="true"],
.menu button:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.composer {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem 0.45rem;
  border-top: 1px solid var(--line);
}

.composer:focus-within { box-shadow: inset 3px 0 0 var(--accent); }

.composer label {
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--glow);
  white-space: nowrap;
}

.composer input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 0.15rem 0;
  caret-color: var(--phosphor);
}

.composer input::placeholder { color: var(--faint); }

.term-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1rem;
  padding: 0.15rem 0.85rem 0.55rem;
  color: var(--faint);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
}

@media (max-width: 720px) {
  .term-id { display: none; }
  .menu button { grid-template-columns: 1fr; gap: 0.1rem; }
  .composer { flex-wrap: wrap; }
  .composer label { width: 100%; }
  .term-status span:nth-child(4) { flex-basis: 100%; }
}

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