/* Real viewport dimensions keep touch positions and game physics aligned. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body { height: 100vh; height: 100dvh; touch-action: auto; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 3px solid white; outline-offset: 2px; }
.play-toolbar { display: flex; gap: 6px; align-items: center; width: 98%; flex: 0 0 48px; }
.play-toolbar button, .play-toolbar a, .dialog-bar button { min-height: 44px; padding: 8px 12px; border: 1px solid #8caa77; border-radius: 8px; background: #294e24; color: white; font: bold 14px 'Segoe UI', sans-serif; text-decoration: none; }
#fullscreen { margin-left: auto; }
#chart-toggle, #settings-toggle { display: none; }
.main-layout { flex: 1; height: auto; min-height: 0; margin: 0 0 6px; }
.center-wrapper, .center-panel, .panel { min-width: 0; min-height: 0; }
.center-panel, .dpad-btn { touch-action: none; }
.number-line-container { height: auto; min-height: 44px; flex-wrap: wrap; }
.nl-box { flex: 1; min-width: 20px; }
.right-panel { overflow-y: auto; }
.dpad-btn { min-height: 44px; }
#game-dialog { width: min(420px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 14px; color: white; background: #1a3317; border: 2px solid #ffd54f; border-radius: 14px; overflow-y: auto; touch-action: pan-y; }
#game-dialog::backdrop { background: #000a; }
.dialog-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dialog-bar h2 { margin: 0; font-size: 20px; }
#dialog-content .right-panel { display: flex; width: 100%; overflow: visible; }
#dialog-content button.ui-btn { min-height: 44px; flex-shrink: 0; }
#dialog-content .grid-cell { font-size: 13px; }
#win-overlay { min-width: 0; width: min(90%, 430px); max-height: 95%; overflow-y: auto; padding: 16px; }
#win-overlay h1 { font-size: clamp(1.25rem, 4vw, 2.5rem); }
#win-overlay h2 { font-size: 1.3rem; }
#win-overlay h3 { font-size: 1rem; }
body.play-fullscreen { position: fixed; inset: 0; width: 100%; }
/* Fullscreen and small screens prioritise the arena; panels open as dialogs. */
@media (max-width: 950px), (max-height: 600px) {
    #chart-toggle, #settings-toggle { display: inline-block; }
    .main-layout { display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 108px; gap: 6px; }
    .left-panel { grid-row: 2; padding: 0; border: 0; background: none; display: flex; flex-direction: row; justify-content: center; gap: 16px; }
    .left-panel > div:first-child, .main-layout > .right-panel { display: none; }
    .start-num-display { width: 76px; padding: 6px; margin: 0; }
    .center-wrapper { grid-row: 1; gap: 5px; }
    .center-panel { border-width: 4px; }
    .dpad-container { width: 154px; margin: 0; gap: 4px; }
    .dpad-btn { height: 48px; font-size: 20px; }
    .number-line-container { padding: 4px; gap: 3px; }
    .nl-box { height: 28px; font-size: 13px; border-width: 1px; }
    .feedback-msg { font-size: 2rem; }
}
@media (max-width: 950px) and (orientation: portrait) {
    .number-line-container { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .nl-box { width: auto; }
    .play-toolbar { gap: 4px; }
    .play-toolbar button, .play-toolbar a { padding: 7px; font-size: 13px; }
}
@media (max-height: 600px) and (orientation: landscape) {
    .main-layout { grid-template-columns: 158px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
    .left-panel { grid-column: 1; grid-row: 1; flex-direction: column; gap: 8px; }
    .center-wrapper { grid-column: 2; grid-row: 1; }
    .play-toolbar { flex-basis: 46px; }
}
body.play-fullscreen #chart-toggle, body.play-fullscreen #settings-toggle { display: inline-block; }
body.play-fullscreen .main-layout > .right-panel, body.play-fullscreen .left-panel > div:first-child { display: none; }
body.play-fullscreen .left-panel { flex-basis: 170px; justify-content: flex-end; }
@media (prefers-reduced-motion: reduce) { .safe-zone, .nl-box.current { animation: none; } }
/* Phone-sized portrait and landscape layouts only. */
@media (max-width: 600px) and (orientation: portrait), (max-width: 1000px) and (max-height: 500px) and (orientation: landscape) {
    :root { --phone-sprites: 1; --ball-size: 44px; }
    .animal { font-size: 30px; }
    .bubble { font-size: 0.96rem; border-width: 3.2px; }
}
