/* Final responsive layer: preserve the terminal character without desktop overflow. */
.after-dial-shell .line.selected {
  margin-inline: -8px;
  padding-inline: 8px;
  background: rgba(157, 233, 154, .08);
  color: #e6ffe2;
}
.after-dial-shell .line.connection-art {
  width: min(64ch, 100%);
  margin-top: clamp(40px, 12vh, 120px);
  color: #9de99a;
  font-size: clamp(9px, 1.25vw, 15px);
  line-height: 1.18;
  letter-spacing: 0;
  text-transform: none;
  white-space: pre;
}

@media (max-width: 650px) {
  body { overflow: auto; }
  .after-dial-shell { width: calc(100% - 24px); }
  .after-dial-shell .site-header {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 14px 0;
  }
  .after-dial-shell .site-header .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .after-dial-shell .site-header nav {
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: clamp(6px, 2.25vw, 11px);
  }
  .after-dial-shell .site-header nav a {
    flex: 0 0 auto;
    font-size: clamp(7px, 2.1vw, 9px);
    line-height: 1;
  }
  .after-dial-shell .site-header nav a.lab-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 28px;
    margin-left: 0;
    padding: 0 7px;
    line-height: 1;
  }
  .after-dial-shell .site-header .lab-bubbles { display: none; }
  .after-dial-shell .terminal {
    height: calc(100dvh - 62px);
    min-height: 520px;
    padding: 10px 0 12px;
  }
  .after-dial-shell .crt {
    height: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: 52px 14px 24px;
    border-width: 1px;
  }
  .after-dial-shell .crt::before,
  .after-dial-shell .crt::after { position: absolute; inset: 0; }
  .after-dial-shell #output,
  .after-dial-shell #command-form { max-width: 100%; }
  .after-dial-shell .line,
  .after-dial-shell #command-form {
    font-size: clamp(11px, 3.35vw, 15px);
    line-height: 1.28;
    overflow-wrap: anywhere;
  }
  .after-dial-shell .line.ascii-panel {
    font-size: clamp(7px, 2.15vw, 11px);
    white-space: pre;
    overflow: hidden;
  }
  .after-dial-shell .line.welcome-art {
    font-size: clamp(5px, 1.62vw, 8px);
    white-space: pre;
    overflow: hidden;
  }
  .after-dial-shell .line.connection-art {
    margin-top: 22px;
    font-size: clamp(5px, 1.75vw, 9px);
  }
  .after-dial-shell .lab-return {
    top: 12px;
    right: 12px;
    bottom: auto;
    min-width: 78px;
    padding: 8px;
    font-size: 9px;
  }
}

@media (max-width: 480px) {
  .after-dial-shell .site-header { grid-template-columns: 1fr; gap: 10px; }
  .after-dial-shell .site-header nav { width: 100%; justify-content: space-between; gap: 4px; }
  .after-dial-shell .terminal { height: calc(100dvh - 105px); }
}

@media (hover: none) {
  .after-dial-shell .site-header nav a.lab-nav { animation: none; }
}

.after-dial-shell .crt.threat-near {
  border-color: #7b382f;
  animation: threat-flicker .72s steps(2, end) infinite;
}
.after-dial-shell .crt.threat-near .line.title { color: #d87867; }
@keyframes threat-flicker {
  0%, 72%, 100% { background-color: #020702; transform: none; }
  73% { background-color: #090302; transform: translateX(1px); }
  76% { background-color: #020702; transform: translateX(-1px); }
}
@media (prefers-reduced-motion: reduce) {
  .after-dial-shell .crt.threat-near { animation: none; }
}

/* Scale the game from the usable CRT area, not the browser width. */
.after-dial-shell .crt {
  container-type: inline-size;
  --terminal-type: clamp(12px, 2.35cqi, 18px);
  --terminal-title: clamp(15px, 2.7cqi, 21px);
  --terminal-grid: clamp(8px, 2.15cqi, 17px);
}
.after-dial-shell .line,
.after-dial-shell #command-form {
  font-size: var(--terminal-type) !important;
  line-height: 1.22 !important;
}
.after-dial-shell .line.title {
  font-size: var(--terminal-title) !important;
}
.after-dial-shell .line.ascii-panel,
.after-dial-shell .line.bbs-menu-title,
.after-dial-shell .line.bbs-menu-row,
.after-dial-shell .line.bbs-menu-divider,
.after-dial-shell .line.bbs-menu-foot,
.after-dial-shell .line.bbs-list-row,
.after-dial-shell .line.welcome-art {
  font-size: var(--terminal-grid) !important;
}
html body .after-dial-shell .line.chat-state,
html body .after-dial-shell .case-mode .line.case-stamp,
html body .after-dial-shell .line.connection-art {
  font-size: var(--terminal-type) !important;
}

@media (min-width: 651px) and (max-width: 1100px) {
  .after-dial-shell { width: min(100% - 32px, 1500px); }
  .after-dial-shell .crt { padding: 58px clamp(22px, 4vw, 42px) 30px; }
  .after-dial-shell .terminal { padding-block: 12px 16px; }
}

@media (max-width: 650px) {
  .after-dial-shell .crt {
    --terminal-type: clamp(12px, 3.25cqi, 15px);
    --terminal-title: clamp(15px, 4cqi, 19px);
    --terminal-grid: clamp(7px, 2.15cqi, 11px);
  }
  .after-dial-shell .line { overflow-wrap: break-word; }
  .after-dial-shell .line.ascii-panel,
  .after-dial-shell .line.bbs-menu-title,
  .after-dial-shell .line.bbs-menu-row,
  .after-dial-shell .line.bbs-menu-divider,
  .after-dial-shell .line.bbs-menu-foot,
  .after-dial-shell .line.bbs-list-row,
  .after-dial-shell .line.welcome-art {
    overflow-wrap: normal;
  }
}

@media (max-height: 720px) and (min-width: 651px) {
  .after-dial-shell .crt {
    --terminal-type: clamp(12px, 2cqi, 15px);
    --terminal-title: clamp(14px, 2.3cqi, 18px);
    --terminal-grid: clamp(8px, 1.9cqi, 14px);
    padding-top: 52px;
  }
}
