/* Share the landing page's header, typography, palette, and buttons. */
.site-header { position: sticky; }
main { max-width: 1684px; margin: auto; padding: 28px; line-height: 1.5; }
main a { color: var(--teal-dark); text-decoration: underline; text-underline-offset: 3px; }
h1 { margin: 0 0 8px; font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.2; white-space: normal; }
h2 { margin-bottom: 8px; font-size: 1.15rem; line-height: 1.3; }
p { margin: 8px 0 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 12px; }
.controls .button { min-width: 0; font-family: inherit; cursor: pointer; }
.controls .button:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
.screens { display: grid; grid-template-columns: repeat(2, minmax(0, 802px)); gap: 24px; }
section { min-width: 0; }
section > p { min-height: 3em; color: #516167; }
#screen, .snapshot {
  box-sizing: content-box;
  width: 800px;
  max-width: calc(100% - 2px);
  aspect-ratio: 4 / 3;
  overflow: auto;
  background: #10171b;
  border: 1px solid #bcc9c7;
}
#screen canvas, #snapshot {
  /* Fit narrow viewports without changing the 800×600 canvas backing pixels. */
  width: 100% !important;
  height: auto !important;
  max-width: none;
  image-rendering: pixelated;
}
#snapshot:not([hidden]) { display: block; }
#screen { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.text-screen { white-space: pre; font: 12px/12px monospace; color: white; }
.credits { margin-top: 32px; color: #516167; font-size: .9rem; }
@media (max-width: 1683px) {
  .screens { grid-template-columns: minmax(0, 802px); }
  section > p { min-height: 0; }
}
@media (max-width: 850px) {
  main { padding: 18px; }
}

/* A phone/tablet is a fixed console: both displays share the available height. */
@media (max-width: 900px), (pointer: coarse) and (max-width: 1400px) {
  html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
  body {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    touch-action: none;
  }
  .site-header {
    position: relative;
    align-items: center;
    padding: max(8px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
             8px max(18px, env(safe-area-inset-left));
  }
  main {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 8px max(8px, env(safe-area-inset-right))
             max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    gap: 6px;
    overflow: hidden;
  }
  .intro { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: .8rem; }
  .intro h1 { margin: 0; font-size: .9rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .intro > p, section > p, .credits { display: none; }
  .controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
  .controls .button { min-height: 44px; padding: 5px; font-size: .8rem; line-height: 1.2; }
  .status-lines { min-width: 0; }
  .status-lines p { margin: 0; font-size: .75rem; line-height: 1.3; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .screens { min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .screens section { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 4px; }
  h2 { margin: 0; font-size: .85rem; line-height: 1.2; }
  .display-area { min-width: 0; min-height: 0; display: grid; place-items: center; container-type: size; overflow: hidden; }
  #screen, .snapshot {
    /* Fit both axes of the panel, keeping 4:3 and never enlarging the pixels. */
    width: min(800px, calc(100cqw - 2px), calc((100cqh - 2px) * 4 / 3));
    max-width: none;
    overflow: hidden;
  }
}

@media (max-width: 900px) and (orientation: landscape),
       (pointer: coarse) and (max-width: 1400px) and (orientation: landscape) {
  .screens { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); }
}
