:root { --game-shell-touch: 48px; }
.sd-app { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
#squareDetectiveHost { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.sd-toolbar { justify-content: flex-start; padding: 8px 16px; }
.sd-progress { margin-left: auto; font-size: 20px; font-weight: 700; }
.sd-layout { min-height: 0; display: grid; grid-template-columns: minmax(0,1fr) minmax(300px, 27%); gap: 16px; padding: 16px; }
.sd-board, .sd-play-panel { min-width: 0; min-height: 0; border: 1px solid #d8e2ea; border-radius: 8px; background: #fff; padding: 16px; }
.sd-board { display: grid; grid-template-rows: auto minmax(0,1fr) 40px auto; gap: 8px; }
.sd-given { display: flex; align-items: center; justify-content: center; gap: 24px; }
.sd-given span { font-size: 20px; color: #5c6b78; }
.sd-given strong { font-size: clamp(48px,5vw,72px); line-height: 1; color: #102131; }
.sd-model-host { min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.fixed-total-primary { min-width: 0; height: 100%; flex: 1 1 0; }
.fixed-total-spare { min-width: 0; height: min(100%, 320px); flex: 0 0 116px; margin-left: 12px; }
.sd-model-host figure { margin: 0; width: 100%; height: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; }
  .sd-model-host figure svg { display: block; width: 100%; height: 100%; max-height: none; }
.sd-model-host figcaption { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.fixed-total-empty { margin: 0; font-size: 32px; color: #5c6b78; }
.sd-arrangement { align-self: center; margin: 0; text-align: center; font-size: 22px; font-weight: 700; line-height: 1.25; }
.sd-row-control { display: flex; align-items: center; justify-content: center; gap: 10px; }
.sd-row-control label { font-size: 20px; font-weight: 700; }
.sd-layout button, .sd-row-control input { font: 700 20px/1.2 Arial, Helvetica, sans-serif; min-height: 48px; border: 2px solid #d8e2ea; border-radius: 8px; background: #f8fbfd; color: #102131; }
.sd-layout button { cursor: pointer; padding: 8px 12px; }
.sd-row-control button { width: 48px; padding: 0; font-size: 28px; }
.sd-row-control input { width: 76px; padding: 4px; text-align: center; }
.sd-layout button:hover:not(:disabled) { background: #eaf7fd; border-color: #149bd7; }
.sd-layout button[aria-pressed="true"] { background: #dff3fc; border-color: #149bd7; color: #0b3650; }
.sd-layout button:focus-visible, .sd-row-control input:focus-visible { outline: 3px solid #149bd7; outline-offset: 3px; }
.sd-layout button:disabled { cursor: default; opacity: .6; }
.sd-play-panel { display: grid; grid-template-rows: auto auto 132px auto minmax(0,1fr); gap: 12px; }
.sd-decisions, .sd-check-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sd-decisions button { min-height: 66px; }
#sdCheck, .sd-next:not(:disabled) { background: #149bd7; border-color: #149bd7; color: #071018; }
.sd-feedback { margin: 0; padding: 10px; border-radius: 8px; background: #f3f7fa; font-size: 20px; line-height: 1.4; overflow-wrap: anywhere; }
.sd-feedback[data-tone="correct"] { background: #eaf7f0; color: #125b3b; }
.sd-feedback[data-tone="retry"] { background: #fff4df; color: #654305; }
.sd-piles { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 12px; }
.sd-piles section { min-width: 0; }
.sd-piles h2 { font-size: 19px; line-height: 1.15; margin: 0 0 10px; min-height: 44px; }
.sd-piles h2 span { font-size: 16px; color: #5c6b78; }
.sd-piles ul { list-style: none; display: flex; flex-wrap: wrap; align-content: start; gap: 6px 10px; padding: 0; margin: 0; }
.sd-piles li { font-size: 20px; font-weight: 700; line-height: 1.25; min-width: 22px; }
.sd-settings-panel { position: absolute; top: calc(100% + 8px); left: 0; z-index: 5; width: min(470px,calc(100vw - 32px)); padding: 16px; background: white; border: 2px solid #d8e2ea; border-radius: 8px; box-shadow: 0 10px 28px #10213122; }
.sd-settings-panel label { display: block; margin-bottom: 8px; font-size: 18px; font-weight: 700; }
.sd-settings-panel input { width: 100%; min-height: 48px; font: 18px/1.4 Arial, sans-serif; border: 2px solid #d8e2ea; border-radius: 8px; padding: 8px; }
.sd-settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#sdDeckError { margin: 10px 0 0; font-size: 18px; }
@media (max-width: 1050px) and (min-width: 866px) {
  .sd-layout { gap: 10px; padding: 10px; grid-template-columns: minmax(0,1fr) 300px; }
  .sd-board, .sd-play-panel { padding: 12px; }
  .sd-row-control { gap: 6px; }
  .sd-row-control label { font-size: 18px; }
}
/* A readable scrolling fallback below the classroom fit threshold. */
@media (max-width: 865px), (max-height: 649px) {
  .sd-app { height: auto; min-height: 100dvh; }
  #squareDetectiveHost { display: block; }
  .sd-layout { display: grid; grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .sd-board { min-height: 430px; grid-template-rows: auto 260px 40px auto; padding: 12px; }
  .sd-play-panel { grid-template-rows: auto auto 140px auto auto; padding: 12px; }
  .sd-piles { min-height: 100px; }
  .sd-progress { font-size: 17px; }
  .sd-toolbar { padding: 8px; gap: 6px; }
  .sd-toolbar button, .sd-toolbar summary { font-size: 16px; padding: 0 8px; }
  .sd-row-control { gap: 6px; }
  .sd-row-control label { font-size: 17px; }
  .sd-settings-panel { position: fixed; left: 10px; right: 10px; top: 170px; width: auto; max-height: calc(100dvh - 190px); overflow: auto; }
}
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  @page spire-tool { size: A4 landscape; margin: 10mm; }
  html[data-spire-print-page="a4-landscape"], html[data-spire-print-page="a4-landscape"] body { width: 277mm !important; height: auto !important; max-height: none !important; overflow: visible !important; }
  html, body { width: auto !important; height: auto !important; min-height: 0 !important; background: white !important; }
  .sd-app { display: block !important; height: auto !important; min-height: 0 !important; }
  .topbar, .sd-toolbar, .sd-row-control, .sd-decisions, .sd-check-actions, .sd-next { display: none !important; }
  #squareDetectiveHost { display: block !important; }
  .sd-layout { display: grid !important; grid-template-columns: minmax(0,1fr) 80mm !important; height: 160mm; padding: 5mm 0 0 !important; gap: 5mm !important; }
  .sd-board { min-height: 0 !important; grid-template-rows: auto minmax(0,1fr) 12mm !important; }
  .sd-play-panel { display: grid !important; grid-template-rows: 55mm minmax(0,1fr) !important; gap: 4mm !important; }
  .sd-feedback { font-size: 15pt !important; }
  .sd-given strong { font-size: 40pt; }
  .sd-arrangement, .sd-piles li { font-size: 15pt; }
  .sd-piles h2 { font-size: 14pt; }
  .sd-piles { min-height: 0; }
  .sd-board, .sd-play-panel { break-inside: avoid; }
}
