/* Shared play controls and viewport-aware game layouts. */
button, summary, select { -webkit-tap-highlight-color: transparent; }
button, summary { touch-action: manipulation; }
button:focus-visible, a:focus-visible, summary:focus-visible, select:focus-visible {
  outline: 3px solid #b88428; outline-offset: 3px;
}
.play-controls { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.play-label { margin-right: auto; color: var(--muted); font: 600 .7rem var(--sans); letter-spacing: .08em; }
.play-controls button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #f7f2e8c9; cursor: pointer; }
.play-controls button span { font-size: 1.2rem; }
.play-controls button b { font-size: .72rem; }
.play-controls button:hover { background: #fffaf0; }
.play-controls button[aria-pressed="true"] { border-color: #53604d70; }
.play-controls #soundToggle[aria-pressed="false"] { color: var(--muted); }
.game-settings { margin: 0 0 12px; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: #f7f2e880; }
.game-settings summary { padding: 12px 14px; min-height: 44px; color: var(--muted); font-size: .75rem; font-weight: 700; cursor: pointer; }
.game-settings[open] { padding-bottom: 12px; }
.game-settings > p, .game-settings .level-switcher, .game-settings .assist-settings { margin-left: 12px; margin-right: 12px; }
.game-settings .setting-stepper button { height: 40px; }
.game-settings .assist-settings { grid-template-columns: 1fr 1fr; }
.game-settings .assist-setting { grid-template-columns: 1fr; }
.game-settings .setting-stepper { grid-template-columns: 36px 1fr 36px; }
.game-settings .assist-setting__copy small { display: none; }
.mine-settings { margin: 0 4% 14px; }
.mine-settings .control-deck { margin: 0; border: 0; background: transparent; padding-top: 0; }
.game-expanded { overflow: hidden; }
main.is-expanded { position: fixed; inset: 0; z-index: 100; }
main.is-immersive:not(.game-shell) {
  display: block; width: 100%; height: 100dvh; min-height: 0; margin: 0; overflow: auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--paper); overscroll-behavior: contain;
}
main.is-immersive > .game-intro, main.is-immersive > .hero { display: none; }
main.is-immersive .play-label::after { content: " · 专注模式"; }
main.is-immersive .game-station, main.is-immersive .puzzle-station { margin: 0 auto; }
.experience-notice { position: fixed; z-index: 110; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); margin: 0; padding: 12px 18px; border-radius: 12px; background: #26362f; color: #fff7e9; box-shadow: 0 6px 24px #0003; font: 500 .8rem/1.5 var(--sans); pointer-events: none; }
.experience-notice:empty { display: none; }
.landscape-help { width: min(460px, calc(100% - 32px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 24px; border: 1px solid #879680; border-radius: 18px; color: #f7f0d9; background: #213d33; font: 400 .85rem/1.7 var(--sans); }
.landscape-help::backdrop { background: #081b16b3; }
.landscape-help h2 { margin: 0; color: #f3d88f; font: 500 1.6rem/1.2 var(--serif); }
.landscape-help p { color: #e0e9ce; }
.landscape-help .landscape-help-note { font-size: .72rem; color: #bacbb6; }
.landscape-help form { position: sticky; bottom: -24px; margin: 16px 0 -24px; padding: 10px 0 24px; background: #213d33; }
.landscape-help button { width: 100%; min-height: 44px; border: 0; border-radius: 10px; color: #243629; background: #e7c778; font: 700 .85rem var(--sans); cursor: pointer; }
@media (orientation: portrait) and (max-width: 640px) {
  [data-game] #landscapeButton { width: auto; min-width: 58px; padding-inline: 6px; gap: 3px; }
  [data-game] #landscapeButton b { display: inline; font-size: .62rem; }
}

/* 2048: keep the board and controls in the same glance. */
[data-game="2048"] .game-layout, [data-game="sudoku"] .game-layout { grid-template-columns: minmax(220px, .75fr) minmax(0, 1fr); gap: clamp(28px, 6vw, 80px); padding: 32px 2%; min-height: calc(100dvh - 132px); }
[data-game="2048"] .game-station { width: min(100%, 560px, max(320px, calc(100dvh - 290px))); }
[data-game="2048"] .scorebar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 48px 48px 78px; }
[data-game="2048"] .score-card { min-height: 54px; padding: 6px; }
[data-game="2048"] .score-card strong { font-variant-numeric: tabular-nums; font-size: 1.3rem; }
[data-game="2048"] .history-button { min-width: 0; min-height: 44px; padding: 4px; }
[data-game="2048"] .new-game { min-width: 0; min-height: 44px; padding: 0 7px; grid-column: auto; }
[data-game="2048"] .mobile-controls { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
[data-game="2048"] .mobile-controls button { width: 100%; height: 44px; }
[data-game="2048"] .mobile-controls button:first-child { grid-column: auto; }
[data-game="2048"] .hint { margin-top: 14px; padding-top: 12px; }
[data-game="2048"] .board { container-type: inline-size; }
[data-game="2048"] .tile { font-size: 12cqi; }
[data-game="2048"] .tile:is([data-value="128"], [data-value="256"], [data-value="512"]) { font-size: 10cqi; }
[data-game="2048"] .tile:is([data-value="1024"], [data-value="2048"]) { font-size: 8cqi; }
[data-game="2048"] .tile[data-large="true"] { font-size: 6cqi; }
[data-game="2048"] .is-immersive .game-station { width: min(100%, 720px, max(240px, calc(100dvh - 230px))); }
.is-immersive .hint { display: none; }

/* Sudoku: settings fold away; time and errors stay beside the puzzle. */
[data-game="sudoku"] .puzzle-station { width: min(100%, 540px); }
[data-game="sudoku"] .stats { margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: #f7f2e880; }
[data-game="sudoku"] .stats div { display: flex; align-items: center; gap: 9px; }
[data-game="sudoku"] .board-wrap { transform: none; border-radius: 12px; }
[data-game="sudoku"] .sudoku-board { grid-template-rows: repeat(9, 1fr); }
[data-game="sudoku"] .cell { min-height: 0; }
[data-game="sudoku"] .number-pad { margin-top: 10px; }
[data-game="sudoku"] .number-pad button { min-height: 44px; aspect-ratio: auto; }
[data-game="sudoku"] .number-pad small { position: absolute; top: 2px; right: 3px; font-size: .5rem; }
[data-game="sudoku"] .is-immersive .puzzle-station { width: min(100%, 660px, max(220px, calc(100dvh - 355px))); }

/* Minesweeper: a scrollable board without shrinking tiny cells further. */
[data-game="minesweeper"] .hero { padding: 36px 4% 28px; }
[data-game="minesweeper"] .hero h1 { font-size: clamp(3.5rem, 6vw, 6rem); }
[data-game="minesweeper"] .board-viewport { height: min(65dvh, 760px); min-height: 240px; border-radius: 0 0 12px 12px; }
[data-game="minesweeper"] .game-toolbar { border-radius: 12px 12px 0 0; }
[data-game="minesweeper"] .is-immersive .mine-station { margin: 0; }
[data-game="minesweeper"] .is-immersive .mine-settings { margin: 0 0 10px; }
[data-game="minesweeper"] .is-immersive .board-viewport { height: calc(100dvh - 270px); min-height: 200px; }
[data-game="minesweeper"] .cell-size select { min-height: 32px; }

/* Keep the entire flight course visible on every aspect ratio. */
[data-game="flappy-bird"] canvas { object-fit: contain; }
[data-game="flappy-bird"] .game-shell { height: 100dvh; }
@media (max-width: 880px) {
  [data-game]:not([data-game="flappy-bird"]) .page-shell { width: min(100% - 24px, 640px); padding: 12px 0 24px; }
  [data-game] .topbar { padding-bottom: 10px; }
  [data-game="2048"] .game-layout, [data-game="sudoku"] .game-layout { grid-template-columns: minmax(0, 1fr); gap: 18px; padding: 22px 0; min-height: 0; }
  [data-game="2048"] .game-intro, [data-game="sudoku"] .game-intro { display: grid; grid-template-columns: auto 1fr; gap: 8px 20px; align-items: center; }
  [data-game="2048"] .game-intro h1, [data-game="sudoku"] .game-intro h1 { font-size: 3.4rem; line-height: 1; grid-column: 1; grid-row: 1 / 3; }
  [data-game="2048"] .eyebrow, [data-game="sudoku"] .eyebrow { grid-column: 2; margin: 0; font-size: .53rem; }
  [data-game="2048"] .lede, [data-game="sudoku"] .lede { grid-column: 2; margin: 0; font-size: .85rem; line-height: 1.5; }
  [data-game="2048"] .rule { display: none; }
  [data-game="2048"] .game-station { width: min(100%, 500px); }
  [data-game="2048"] main.is-immersive > .game-intro, [data-game="sudoku"] main.is-immersive > .game-intro { display: none; }
  [data-game="minesweeper"] .hero { grid-template-columns: auto 1fr; gap: 20px; padding: 22px 0; }
  [data-game="minesweeper"] .hero h1 { font-size: 3rem; line-height: 1; }
  [data-game="minesweeper"] .hero > p { font-size: .85rem; }
  [data-game="minesweeper"] .eyebrow { font-size: .5rem; margin-bottom: 8px; }
  [data-game="minesweeper"] .mine-settings { margin: 0 0 14px; }
  [data-game="minesweeper"] .is-immersive .board-viewport { height: calc(100dvh - 325px); }
}
@media (pointer: coarse) { [data-game="2048"] .mobile-controls { display: grid; } }
@media (max-width: 380px) {
  [data-game="2048"] .scorebar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px 42px 62px; gap: 4px; }
  .play-label { font-size: .6rem; letter-spacing: 0; }
  [data-game="sudoku"] .number-pad { gap: 3px; }
  [data-game="sudoku"] .stats { padding: 9px; }
  [data-game="sudoku"] .stats div { gap: 4px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  [data-game="2048"] .is-immersive .game-station, [data-game="sudoku"] .is-immersive .puzzle-station { display: grid; grid-template-columns: minmax(0, 1fr) 240px; grid-template-rows: auto auto auto 1fr; align-content: start; align-items: start; gap: 10px 20px; width: min(100%, calc(100dvh + 232px)); }
  [data-game="2048"] .is-immersive .board, [data-game="sudoku"] .is-immersive .board-wrap { grid-column: 1; grid-row: 1 / 7; width: 100%; }
  .is-immersive .play-controls { grid-column: 2; margin: 0; }
  .is-immersive .play-label { display: none; }
  .is-immersive .play-controls button { flex: 1; }
  [data-game="2048"] .is-immersive .scorebar { grid-column: 2; grid-template-columns: repeat(6, 1fr); margin: 0; }
  [data-game="2048"] .is-immersive .score-card { grid-column: span 3; }
  [data-game="2048"] .is-immersive .history-button, [data-game="2048"] .is-immersive .new-game { grid-column: span 2; }
  .is-immersive .mobile-controls, .is-immersive .game-status { grid-column: 2; margin: 0; }
  [data-game="sudoku"] .is-immersive .game-settings, [data-game="sudoku"] .is-immersive .stats, [data-game="sudoku"] .is-immersive .number-pad, [data-game="sudoku"] .is-immersive .tool-row { grid-column: 2; margin: 0; }
  [data-game="sudoku"] .is-immersive .number-pad { grid-template-columns: repeat(9, 1fr); gap: 2px; }
  [data-game="sudoku"] .is-immersive .stats { padding: 6px; }
  [data-game="sudoku"] .is-immersive .stats div { display: grid; gap: 2px; }
  [data-game="sudoku"] .is-immersive .tool-row { gap: 3px; }
  [data-game="sudoku"] .is-immersive .tool-row button { font-size: .6rem; }
}
@media (orientation: portrait) and (max-width: 760px) {
  [data-game="flappy-bird"] .game-frame { height: 100%; background: #26362f; }
  [data-game="flappy-bird"] .game-hud { top: max(16px, env(safe-area-inset-top)); }
  [data-game="flappy-bird"] .hud-actions button { height: 44px; }
  [data-game="flappy-bird"] .scorebar { top: max(76px, calc(env(safe-area-inset-top) + 60px)); left: 50%; transform: translateX(-50%); }
  [data-game="flappy-bird"] .scorebar strong { font-size: 1.4rem; }
  [data-game="flappy-bird"] .game-overlay { padding: 120px 20px; }
  [data-game="flappy-bird"] .flap-button { width: 74px; height: 74px; right: calc(50% - 37px); bottom: max(85px, calc(env(safe-area-inset-bottom) + 65px)); }
}

/* Center focused puzzles, while allowing short screens/settings to scroll. */
[data-game="2048"] main.is-immersive, [data-game="sudoku"] main.is-immersive { display: flex; flex-direction: column; }
[data-game="2048"] main.is-immersive .game-station, [data-game="sudoku"] main.is-immersive .puzzle-station { flex: 0 0 auto; margin: auto; }
[data-game="minesweeper"] main.is-immersive { display: flex; flex-direction: column; }
[data-game="minesweeper"] .is-immersive .mine-station { display: flex; flex-direction: column; flex: 1; min-height: 0; }
[data-game="minesweeper"] .is-immersive .board-viewport { flex: 1; height: auto; min-height: 150px; }
[data-game="minesweeper"] .is-immersive .board-note { flex: 0 0 auto; }
@media (max-width: 380px) {
  [data-game="minesweeper"] .counter { min-width: 60px; padding: 6px; }
  [data-game="minesweeper"] .cell-size { padding: 4px 0; }
  [data-game="minesweeper"] .face-button { width: 40px; }
}
/* Keep tools comfortably wide even when a short portrait screen needs a smaller board. */
[data-game="sudoku"] .is-immersive .puzzle-station { width: min(100%, 660px, max(280px, calc(100dvh - 355px))); }
[data-game="sudoku"] .is-immersive .board-wrap { width: min(100%, max(220px, calc(100dvh - 355px))); margin-inline: auto; }
@media (orientation: landscape) and (max-height: 600px) {
  [data-game="sudoku"] .is-immersive .puzzle-station { width: min(100%, calc(100dvh + 232px)); }
  [data-game="sudoku"] .is-immersive .board-wrap { width: 100%; }
  [data-game="minesweeper"] .is-immersive .mine-settings { width: calc(100% - 210px); }
  [data-game="minesweeper"] .is-immersive .play-controls { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); width: 190px; }
  [data-game="minesweeper"] .is-immersive .game-toolbar { flex-wrap: nowrap; }
  [data-game="minesweeper"] .is-immersive .mode-switch { order: initial; width: auto; margin-left: auto; }
  [data-game="minesweeper"] .is-immersive .board-note p + p { display: none; }
}
@media (min-width: 881px) {
  [data-game="sudoku"] .puzzle-station { width: min(100%, 540px, max(300px, calc(100dvh - 480px))); }
}
