/* The game ticket shares the visible window with the masthead and any practice controls. */
html { height: 100%; overflow: hidden; }
body {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: clip;
}
.mast { flex: none; }
main {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: max(clamp(12px, 2.7vh, 32px), env(safe-area-inset-bottom));
}
.intro { flex: none; height: clamp(82px, 14vh, 128px); }
.test-mode-bar, .test-status { flex: none; }
.game-layout {
  flex: 1;
  min-height: 0;
  max-height: min(740px, max(500px, 52vw));
}

@media (max-width: 760px) {
  main { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .intro { height: auto; padding-block: 8px; }
  .game-layout {
    max-height: none;
    grid-template-rows: var(--ticket-rows, minmax(0, 9fr) minmax(0, 11fr));
  }
  .game-layout[data-phase="reveal"] { --ticket-rows: minmax(0, 1fr) minmax(0, 2fr); }
  .game-layout:has(#bonus-panel:not([hidden])) { --ticket-rows: minmax(0, 1fr) auto; }
  .game-layout:has(#recap-screen:not([hidden]), #profile-screen:not([hidden])) {
    --ticket-rows: minmax(0, 11fr) minmax(0, 9fr);
  }
  .game-layout:has(#rules:not([hidden]), #board-dialog:not([hidden])):has(#tool-panel:not([hidden])) {
    --ticket-rows: minmax(0, 1fr) auto;
  }
  .game-layout:has(#rules:not([hidden]), #board-dialog:not([hidden])) #tool-title {
    display: none;
  }
  .test-mode-bar { gap: 4px; margin-bottom: 0; padding: 4px 6px; }
  .test-mode-bar strong { font-size: .76rem; }
  .test-mode-bar button { min-height: 29px; padding: 3px 6px; font-size: .67rem; }
}

/* Short windows get compact chrome, leaving room for the clues and controls. */
@media (max-height: 640px) {
  .mast-inner { min-height: 45px; }
  .mast .brand-mark { width: 29px; }
  .mast .wordmark { width: clamp(112px, 18vw, 160px); }
  .intro { height: auto; padding-block: 6px; }
  .ticket-ledger > div { min-height: 42px; padding-block: 3px; }
  .rail-body { padding-block: 9px; }
  .panel-cap { min-height: 30px; padding-block: 5px; }
  .category-strip { min-height: 24px; padding-block: 2px; }
  .ready-actions { padding-top: 5px; }
  #ready-panel .rail-title { font-size: clamp(1.6rem, 3.6vw, 2.1rem); margin-bottom: 5px; }
  .ready-copy { font-size: .9rem; line-height: 1.3; }
  #hop-question { font-size: clamp(1.7rem, 3.6vw, 2.8rem); }
}

@media (min-width: 560px) and (max-width: 760px) and (orientation: landscape) and (max-height: 520px) {
  .game-layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
  .play-panel { border-top: 0; border-inline-start: 2px dashed #778a76; }
  .play-panel::before, .play-panel::after { display: none; }
}

@media (max-width: 760px) and (max-height: 740px), (max-height: 520px) {
  .clue-readout { display: flex; align-items: center; gap: 12px; }
  .clue-readout h2 { margin: 0; font-size: clamp(1.45rem, 3.3vw, 2rem); }
  .clue-readout .reveal-bars { margin: 0; flex: 1; }
  #answer-form { margin-top: 7px; }
  #answer-form label { margin-bottom: 3px; font-size: .82rem; }
  #answer { min-height: 37px; padding-block: 5px; }
  .guess-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 7px; }
  #answer-form .guess-actions button { margin: 0; min-height: 37px; padding: 5px 6px; font-size: .87rem; }
  #hop-question { font-size: clamp(1.45rem, 4vw, 1.95rem); }
  #hop-status, .hop-answer { font-size: .82rem; line-height: 1.23; }
  .hop-actions .decal-button { min-height: 37px; padding: 5px 7px; font-size: 1.03rem; }
  .hop-screen { padding: 6px; }
  .hop-card { padding: 9px 12px; gap: 8px; }
  .hop-ballot { gap: 5px; }
  .hop-heading > .icon { width: 23px; height: 23px; padding: 3px; }
  .hop-options { gap: 4px; }
  .hop-option { min-height: 31px; padding: 4px 6px; }
  .mrg-intro-layer { padding: 4px; }
  .mrg-intro {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    width: min(100%, 21rem); padding: 7px 10px; gap: 3px 8px;
  }
  .mrg-intro h3 { grid-area: 1 / 1; font-size: 1.25rem; }
  .mrg-intro p, .mrg-intro #pin-intro-how { grid-column: 1 / -1; margin: 0; font-size: .77rem; line-height: 1.24; }
  .mrg-intro .mrg-start { grid-area: 1 / 2; width: auto; min-height: 31px; margin: 0; padding: 3px 12px; font-size: 1.06rem; }
  #bonus-panel {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 5px;
  }
  #bonus-lock, #globe-verdict { grid-column: 1 / -1; }
  #globe-verdict { padding-bottom: 4px; margin: 0; }
  #globe-verdict > div { display: flex; align-items: center; gap: 8px; }
  #globe-verdict-title { flex: none; padding: 1px 4px; font-size: 1.1rem; border-width: 2px; }
  #globe-verdict-detail { font-size: .75rem; margin: 0; }
  #bonus-panel h2 { margin: 0; font-size: 1.32rem; }
  .pin-bonus-value { margin: 0; font-size: .74rem; }
}

@media (min-width: 560px) and (max-height: 520px) {
  .hop-screen .bonus-ready-art { height: 65px; padding: 4px; }
  .hop-screen .bonus-countface { width: 52px; }
  .hop-screen .bonus-countface-numeral { font-size: 2rem; }
  .hop-screen .bonus-countface-unit { font-size: .45rem; }
}

@media (max-width: 500px) and (max-height: 740px) {
  .test-mode-bar:has(#practice-switch:not([hidden])) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .test-mode-bar strong { grid-column: 1 / -1; grid-row: 1; }
  .test-mode-bar button { grid-row: 2; }
  .game-layout:has(#guess-controls:not([hidden])) { --ticket-rows: minmax(0, 2fr) minmax(0, 3fr); }
}

@media (min-width: 560px) and (max-height: 520px) {
  main { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .intro { padding-block: 3px; }
  .ticket-ledger .stop-sticker { height: 30px; }
  .stop-node { padding-block: 4px; }
  .test-mode-bar { gap: 5px; padding: 2px 8px; margin: 0; }
  .test-mode-bar strong { font-size: .77rem; }
  .test-mode-bar button { min-height: 26px; padding: 2px 7px; font-size: .69rem; }
  .play-panel:has(.category-strip:not([hidden])) {
    display: grid;
    grid-template: auto minmax(0, 1fr) / auto minmax(0, 1fr);
  }
  .play-panel .panel-cap, .play-panel .category-strip { padding-inline: 8px; }
  .play-panel .category-strip { line-height: 1.1; }
  .play-panel .rail-body { grid-column: 1 / -1; }
}
