/* Device layout and input support. Loaded after the shared visual theme. */
html { min-width: 280px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; overflow-y: auto; }
button, a { touch-action: manipulation; }

/* Small viewport units keep controls still as phone browser bars show/hide.
   Short windows can scroll instead of losing controls outside the viewport. */
.shell {
  height: 100vh;
  height: 100svh;
  min-height: 540px;
  padding: env(safe-area-inset-top, 0px) max(28px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(28px, env(safe-area-inset-left, 0px));
}
.stage > *, .site-header > * { min-width: 0; }
.lang button { min-width: 44px; min-height: 44px; font-size: 12px; }
.mt-top { flex-shrink: 0; }
.mt-bar { min-width: 16px; }
.mt-status { flex-basis: 30px; min-height: 30px; max-width: 100%; white-space: nowrap; }
.mt-panel { flex: 1 0 auto; min-width: 0; }
.mt-stop, .board-close, .finish-head .btn, .join-status .btn { min-height: 44px; }
.board-close, .finish-head .btn { min-width: 44px; flex-shrink: 0; }
.site-footer { flex-wrap: wrap; gap: 4px 20px; }
.board-head { flex-shrink: 0; }
.board-body { overscroll-behavior-y: contain; }
.toast { max-width: calc(100% - 24px); bottom: max(24px, env(safe-area-inset-bottom, 0px)); }

/* The visual viewport contracts when the software keyboard is open. */
.finish-dialog {
  position: fixed;
  inset: 14px 0 auto;
  width: min(480px, calc(100% - 28px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-height: calc(100vh - 28px);
  max-height: calc(var(--visible-height, 100dvh) - 28px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  top: calc(var(--visible-top, 0px) + max(14px, env(safe-area-inset-top, 0px)));
  margin: 0 auto;
  overscroll-behavior-y: contain;
  scroll-padding-block: 16px;
}
.field input, .field textarea { scroll-margin-block: 16px; }
@media (min-height: 760px) {
  .finish-dialog { top: calc(var(--visible-top, 0px) + max(14px, env(safe-area-inset-top, 0px)) + max(0px, (var(--visible-height, 100vh) - 740px) / 2)); }
}

/* Tablets and smaller laptops retain a spacious game and a full-screen board. */
@media (max-width: 960px) {
  .site-header { grid-template-columns: minmax(0, 1fr) auto; }
  .brand-name { display: none; }
  .brand { justify-self: start; width: min(340px, 100%); }
  .board-panel { padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
  body.board-is-open { overflow: hidden; }
}

/* Phones: give the brand and toolbar their own rows, including at 320px. */
@media (max-width: 600px) {
  .shell { padding-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px)); }
  .site-header { grid-template-columns: minmax(0, 1fr); height: auto; gap: 10px; padding: 12px 0 10px; }
  .brand { justify-self: center; place-items: center; width: min(280px, 100%); padding-left: 0; }
  .brand::before { inset-inline: 0; }
  .brand::after { display: none; }
  .brand-mark { font-size: 30px; transform: none; }
  .brand-location { font-size: 8px; letter-spacing: .2em; }
  .head-tools { justify-self: stretch; justify-content: space-between; gap: 8px; }
  .board-open { min-height: 44px; padding: 8px 12px; }
  .board-open span { display: inline; }
  .lang button { min-width: 44px; }
  .game { padding: 16px 12px; gap: 8px; }
  .game::after { inset: 8px; }
  .mt-skor { gap: 5px; letter-spacing: .08em; }
  .mt-skor strong { font-size: 28px; }
  .mt-combo:not(:empty), .mt-neg { padding-inline: 7px; }
  .mt-neg { font-size: 10px; }
  .mt-pilih { min-height: 64px; font-size: clamp(28px, 7vw, 38px); }
  .mt-panel { gap: 12px; }
  .mt-end { gap: 16px; }
  .end-actions { width: 100%; }
  .finish-dialog { padding: 18px; }
}

/* Phone landscape, split-screen tablets and short laptop windows. */
@media (max-height: 500px) and (min-width: 480px) {
  .shell { min-height: 340px; }
  .site-header { grid-template-columns: minmax(0, 1fr) auto; height: 54px; padding-block: 0; gap: 12px; }
  .head-tools { justify-self: end; }
  .brand-mark { font-size: 28px; }
  .brand-location { font-size: 7px; }
  .stage { padding: 8px 0; gap: 12px; }
  .game { padding: 10px 18px; gap: 4px; }
  .game::after { inset: 6px; }
  .mt-top { min-height: 28px; }
  .mt-masa { font-size: 23px; }
  .mt-skor strong { font-size: 26px; }
  .mt-panel { gap: 6px; }
  .mt-soalan { height: 48px; margin-bottom: 2px; font-size: 40px; }
  .mt-pilih { height: 52px; min-height: 48px; font-size: 30px; }
  .mt-stop { margin-top: 0; }
  .mt-ready { font-size: 42px; }
  .btn-big { min-height: 48px; padding-block: 10px; }
  .mt-besar { font-size: 52px; }
  .end-actions { gap: 6px; }
  .site-footer { padding-block: 4px; }
}
@media (max-height: 500px) and (min-width: 480px) and (max-width: 600px) {
  .brand { justify-self: start; width: auto; }
  .brand-mark { font-size: 25px; }
  .brand-location { font-size: 7px; letter-spacing: .1em; }
}
@media (max-height: 500px) and (max-width: 960px) {
  .site-footer { display: none; }
}
@media (pointer: coarse) {
  .mt-pilih kbd { display: none; }
}
