/* Input size is a deliberate preference; viewport rules remain a safety net. */
:root { --control-size:44px; --game-control-size:46px; }
/* Let the viewport, not a long table title, determine the single grid track. */
.game-shell { grid-template-columns:minmax(0,1fr); }
.game-shell > *, .game-layout { min-width:0; }
:root[data-device="phone"] { --control-size:52px; --game-control-size:58px; }
:root[data-device="tablet"] { --control-size:52px; --game-control-size:56px; }
button, a, input, select { -webkit-tap-highlight-color:transparent; }
button, a { touch-action:manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline:2px solid var(--glow,#ead8a1); outline-offset:4px; }
.button,.close-game,.sound-toggle,#deviceSettings,.difficulty button,#boardCategory { min-height:var(--control-size); }
#playerName,#gamePlayerName { min-height:var(--control-size); font-size:16px; }
.device-prompt-open { overflow:hidden; }
#deviceSettings { display:inline-flex;align-items:center;justify-content:center;gap:7px;padding:9px 12px;border:1px solid #ffffff2b;border-radius:4px;background:transparent;color:#ddd9ce;font-family:inherit;font-size:12px;font-weight:600;line-height:1.2;cursor:pointer;white-space:nowrap; }
#deviceSettings svg { width:17px;height:17px;flex:none; }
#deviceDialog { width:min(760px,calc(100% - 32px));max-height:calc(100dvh - 32px);overflow:auto;padding:clamp(24px,5vw,44px);border:1px solid #66675f;border-radius:10px;color:#f1eee3;background:#191d1d;box-shadow:0 28px 100px #0008; }
#deviceDialog::backdrop { background:#070b0de8;backdrop-filter:blur(8px); }
#deviceDialog .device-kicker { display:flex;align-items:center;gap:10px;margin:0 0 18px;font:700 11px ui-monospace,monospace;letter-spacing:.12em;text-transform:uppercase;color:#d7c68f; }
#deviceDialog .device-kicker .brand-mark { display:block;flex:none;width:27px;height:27px; }
#deviceDialog h2 { margin:0;max-width:18ch;font-size:clamp(27px,4vw,42px);font-weight:700;line-height:1.08;letter-spacing:-.045em; }
#deviceDialog .device-intro { max-width:48ch;margin:14px 0 26px;color:#b0b8b5;font-size:15px;line-height:1.6; }
.device-options { display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px; }
[data-device-choice] { position:relative;display:flex;flex-direction:column;align-items:flex-start;gap:8px;min-width:0;min-height:178px;padding:20px 17px;text-align:left;color:#ecebe1;border:1px solid #4c5551;border-radius:6px;background:#222827;cursor:pointer;transition:background .15s,border-color .15s; }
[data-device-choice]:hover { border-color:#b7c1b7;background:#2b3430; }
[data-device-choice][aria-pressed="true"] { border-color:#d3c083;background:#33382b;box-shadow:inset 0 0 0 1px #d3c083; }
[data-device-choice][aria-pressed="true"]::after { content:'✓';position:absolute;right:14px;top:14px;color:#e9d79c;font-size:16px; }
[data-device-choice] .device-icon { width:48px;height:40px;margin-bottom:12px;stroke:#c9d0c6;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round; }
[data-device-choice] i { position:absolute;right:17px;bottom:18px;color:#b9c1b7;font-size:19px;font-style:normal; }
[data-device-choice] strong { font-size:18px;font-weight:650;letter-spacing:-.02em; }
[data-device-choice] span:not(.device-icon) { font-size:12px;line-height:1.5;color:#adb7af; }
#deviceChoiceHint { margin:20px 0 0;padding-top:16px;border-top:1px solid #ffffff15;color:#aeb7b1;font-size:12px;line-height:1.6; }
#gameDetailsToggle { display:none; }
.game-header>div:first-child { min-width:0; }
.game-header h2 { overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.game-header-actions { display:flex;align-items:center;gap:8px;flex:none; }
.game-playfield { min-width:0; }
.mobile-flippers button { min-height:var(--game-control-size);user-select:none;-webkit-user-select:none;touch-action:none; }
.mobile-flippers button:active { background:#e9d49b;color:#171b19; }

/* A phone layout stays comfortable even when selected on a large monitor. */
:root[data-device="phone"] .wrap { width:min(680px,calc(100% - 32px)); }
:root[data-device="phone"] .hero { grid-template-columns:1fr;gap:26px;min-height:0;padding-top:32px; }
:root[data-device="phone"] .machine-stage { min-height:400px;max-height:430px;order:0; }
:root[data-device="phone"] .machine-cabinet { width:min(85%,270px); }
:root[data-device="phone"] .hero-copy h1 { max-width:12ch;font-size:clamp(44px,10vw,70px); }
:root[data-device="phone"] .machine-grid { grid-template-columns:repeat(2,minmax(0,1fr));gap:18px 12px; }
:root[data-device="phone"] .hero-actions>.button { flex:1 1 200px; }
:root[data-device="phone"] .nav-links { display:none; }
:root[data-device="phone"] .arcade-wallet { grid-template-columns:1fr;gap:16px; }
:root[data-device="phone"] .section-heading { display:block; }
:root[data-device="phone"] .section-heading>div+div { margin-top:18px; }
:root[data-device="phone"] .leaderboard-layout,:root[data-device="phone"] .how-grid { grid-template-columns:1fr; }
:root[data-device="phone"] #playerForm { border-left:0;border-top:1px solid #ffffff15;padding:22px 0 0; }
:root[data-device="phone"] .global-leaderboard>header { flex-direction:column;align-items:flex-start; }
:root[data-device="phone"] .machine-toolbar { flex-direction:column;align-items:stretch;gap:6px; }
:root[data-device="phone"] .machine-toolbar .button { width:100%; }
:root[data-device="tablet"] .machine-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
:root[data-device="tablet"] .difficulty button { padding-inline:17px; }
:root[data-device="phone"] .difficulty button { flex:1 1 65px; }
:root[data-device="phone"] .card-meta { padding:14px 12px; }
:root[data-device="phone"] .machine-card h3 { font-size:17px; }

/* Touch play is a fitted instrument panel: no scrolling to reach flippers. */
:root:is([data-device="phone"],[data-device="tablet"]) .game-overlay { overflow:hidden;background:#101413;backdrop-filter:none; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-shell { display:grid;grid-template-rows:auto minmax(0,1fr);width:100%;height:100dvh;min-height:0;margin:0;padding:max(8px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left));gap:8px; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-header { min-height:42px;margin:0;gap:8px; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-header h2 { margin:0;font-size:clamp(16px,3vw,22px); }
:root:is([data-device="phone"],[data-device="tablet"]) .game-header small { font-size:9px;line-height:1.6;letter-spacing:.04em; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-header button { padding:8px 10px;font-size:11px;letter-spacing:0;border-radius:5px;white-space:nowrap; }
:root:is([data-device="phone"],[data-device="tablet"]) #gameDetailsToggle { display:inline-flex;align-items:center;justify-content:center;min-height:44px;border:1px solid #ffffff2b;background:#202722;color:#f0eddf;cursor:pointer; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-layout { display:grid;grid-template-columns:1fr;grid-template-rows:auto minmax(0,1fr);align-items:stretch;align-self:stretch;height:100%;min-height:0;gap:8px; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard { display:grid;grid-column:auto;grid-template-columns:1.6fr repeat(4,1fr);gap:6px;padding:8px 10px;border-radius:5px;background:#1a211e; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard h3 { display:none; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat { display:flex;flex-direction:column;align-items:flex-start;justify-content:center;min-width:0;gap:3px;margin:0;padding:0 0 0 8px;border:0;border-left:1px solid #ffffff15;grid-column:auto; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat:first-of-type { padding-left:0;border-left:0; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat span { font-size:9px;line-height:1.25; }
:root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat strong { font-size:14px;line-height:1.15;white-space:nowrap; }
:root:is([data-device="phone"],[data-device="tablet"]) #scoreValue { font-size:clamp(21px,4.3vw,28px); }
:root:is([data-device="phone"],[data-device="tablet"]) .game-playfield { display:grid;grid-template-rows:minmax(0,1fr) auto;justify-items:center;align-items:stretch;align-self:stretch;height:100%;gap:8px;min-height:0; }
:root:is([data-device="phone"],[data-device="tablet"]) .pinball-wrap { align-self:stretch;height:100%;min-height:0;max-height:100%;width:auto;max-width:100%;aspect-ratio:400/720;border:3px solid #4a514b;border-radius:7px;box-shadow:0 0 0 1px #ffffff12; }
:root:is([data-device="phone"],[data-device="tablet"]) #engine { width:100%;height:100%;min-height:0; }
:root:is([data-device="phone"],[data-device="tablet"]) .mobile-flippers { display:grid;grid-template-columns:1fr 1.2fr 1fr;width:min(100%,660px);gap:8px;margin:0; }
:root:is([data-device="phone"],[data-device="tablet"]) .mobile-flippers button { padding:10px 4px;border:1px solid #6b7366;border-radius:6px;background:#28332c;color:#f4f0e0;font-size:12px;letter-spacing:.02em; }
:root:is([data-device="phone"],[data-device="tablet"]) #launchButton { background:#d9c48a;color:#1c211b;border-color:#e8d79f; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-side { display:none; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-overlay.details-open .game-side { display:block;position:absolute;z-index:5;inset:74px 10px calc(var(--game-control-size) + 28px) auto;width:min(370px,calc(100% - 20px));overflow:auto;overscroll-behavior:contain;padding:20px;border:1px solid #667163;border-radius:7px;background:#1a211efc;box-shadow:0 15px 40px #000b; }
:root:is([data-device="phone"],[data-device="tablet"]) .game-side .button { min-height:var(--control-size);font-size:13px; }

@media(min-width:900px) and (min-height:600px) {
  :root[data-device="tablet"] .game-layout { width:min(100%,1040px);justify-self:center;grid-template-columns:160px minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:24px; }
  :root[data-device="tablet"] .scoreboard { display:flex;flex-direction:column;align-self:start;gap:12px;padding:20px; }
  :root[data-device="tablet"] .scoreboard .stat { border:0;border-bottom:1px solid #ffffff15;padding:0 0 12px;gap:7px; }
  :root[data-device="tablet"] .scoreboard .stat span { font-size:12px; }
  :root[data-device="tablet"] .scoreboard .stat strong { font-size:22px; }
}

/* Actual screen limits take priority over any preference. */
@media(max-width:700px) {
  .wrap { width:calc(100% - 32px); }
  .nav { min-height:64px;gap:8px;flex-wrap:wrap;padding:10px 0; }
  .brand { font-size:12px;gap:8px; }
  .brand-mark { width:25px;height:25px;flex:none; }
  .brand-mark::after { left:7px; }
  .nav-links { display:none; }
  .sound-toggle { font-size:10px;padding:7px 9px; }
  #deviceSettings { font-size:11px;padding:7px 9px; }
  .header-tools { display:flex;gap:6px; }
  .hero { min-height:0; }
  .hero-stats { flex-wrap:wrap;gap:18px; }
  .section { padding-block:48px; }
  .global-leaderboard { min-width:0;padding:18px; }
  .leaderboard-layout>* { min-width:0; }
  .leaderboard-columns,.leaderboard-row { grid-template-columns:32px minmax(0,1fr) auto;gap:8px; }
  .leaderboard-row strong { overflow:hidden;text-overflow:ellipsis; }
  .board-actions { width:100%; }
  #boardCategory { flex:1;min-width:0;font-size:14px; }
  .board-actions .button { flex:1;font-size:12px; }
  .control-list { grid-template-columns:1fr; }
  .footer-line { flex-wrap:wrap; }
  #deviceDialog { padding:24px; }
  .device-options { grid-template-columns:1fr;gap:10px; }
  [data-device-choice] { display:grid;grid-template-columns:44px 1fr;gap:3px 16px;min-height:84px;padding:15px 18px; }
  [data-device-choice] .device-icon { grid-column:1;grid-row:1/3;width:44px;height:38px;align-self:center;margin:0; }
  [data-device-choice] i { display:none; }
  [data-device-choice] strong,[data-device-choice] span:not(.device-icon) { grid-column:2; }
  [data-device-choice][aria-pressed="true"]::after { right:12px;top:12px; }
  #deviceDialog h2 { font-size:30px; }
  #deviceDialog .device-intro { font-size:14px;margin-bottom:20px; }
  #deviceChoiceHint { margin-top:18px;font-size:11px; }
  :root[data-device="tablet"] .machine-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  :root[data-device="computer"] .game-overlay { overflow:hidden;background:#101413; }
  :root[data-device="computer"] .game-shell { display:grid;grid-template-rows:auto minmax(0,1fr);width:100%;height:100dvh;min-height:0;padding:8px 10px max(8px,env(safe-area-inset-bottom));gap:8px; }
  :root[data-device="computer"] .game-header { margin:0;min-height:42px;gap:8px; }
  :root[data-device="computer"] .game-header h2 { font-size:16px; }
  :root[data-device="computer"] .game-header small { font-size:9px; }
  :root[data-device="computer"] .game-header button { padding:8px;font-size:11px;border-radius:5px;white-space:nowrap; }
  :root[data-device="computer"] #gameDetailsToggle { display:inline-flex;align-items:center;justify-content:center;min-height:44px;border:1px solid #ffffff2b;background:#202722;color:#f0eddf; }
  :root[data-device="computer"] .game-layout { grid-template-columns:1fr;grid-template-rows:auto minmax(0,1fr);align-items:stretch;align-self:stretch;height:100%;gap:8px;min-height:0; }
  :root[data-device="computer"] .scoreboard { display:grid;grid-template-columns:1.6fr repeat(4,1fr);grid-column:auto;gap:5px;padding:8px;border-radius:5px; }
  :root[data-device="computer"] .scoreboard h3 { display:none; }
  :root[data-device="computer"] .scoreboard .stat { display:flex;flex-direction:column;align-items:flex-start;grid-column:auto;gap:4px;padding:0 0 0 6px;border:0;border-left:1px solid #ffffff15; }
  :root[data-device="computer"] .scoreboard .stat:first-of-type { border:0;padding:0; }
  :root[data-device="computer"] .scoreboard .stat span { font-size:9px; }
  :root[data-device="computer"] .scoreboard .stat strong { font-size:13px;white-space:nowrap; }
  :root[data-device="computer"] #scoreValue { font-size:21px; }
  :root[data-device="computer"] .game-playfield { display:grid;grid-template-rows:minmax(0,1fr) auto;justify-items:center;align-items:stretch;align-self:stretch;height:100%;gap:8px;min-height:0; }
  :root[data-device="computer"] .pinball-wrap { align-self:stretch;height:100%;min-height:0;max-height:100%;width:auto;max-width:100%;aspect-ratio:400/720;border-width:3px;border-radius:6px; }
  :root[data-device="computer"] #engine { height:100%;width:100%;min-height:0; }
  :root[data-device="computer"] .mobile-flippers { width:100%;margin:0;gap:7px; }
  :root[data-device="computer"] .mobile-flippers button { padding:10px 4px;font-size:11px; }
  :root[data-device="computer"] .game-side { display:none; }
  :root[data-device="computer"] .game-overlay.details-open .game-side { display:block;position:absolute;z-index:5;inset:70px 10px 70px auto;width:calc(100% - 20px);overflow:auto;background:#1a211efc; }
}
@media(max-width:380px) {
  :root[data-device="phone"] .machine-grid,:root[data-device="tablet"] .machine-grid,.machine-grid { grid-template-columns:1fr; }
  .brand { font-size:11px; }
  .sound-toggle { max-width:44px;overflow:hidden;white-space:nowrap; }
  #deviceSettings { min-width:44px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard { gap:3px;padding:7px;grid-template-columns:1.5fr repeat(4,1fr); }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat { padding-left:5px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat span { font-size:8px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat strong { font-size:12px; }
  :root:is([data-device="phone"],[data-device="tablet"]) #scoreValue { font-size:20px; }
}
@media(max-height:500px) and (orientation:landscape) {
  :root:is([data-device="phone"],[data-device="tablet"]) .game-shell { padding-top:4px;padding-bottom:4px;gap:4px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-header { min-height:38px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-header small { display:none; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-header button { min-height:36px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-layout { grid-template-columns:126px minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:10px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard { display:flex;flex-direction:column;gap:5px;padding:10px;align-self:start; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat { border:0;padding:4px 0;gap:2px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .scoreboard .stat strong { font-size:14px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-playfield { gap:5px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .mobile-flippers { max-width:500px; }
  :root:is([data-device="phone"],[data-device="tablet"]) .game-overlay.details-open .game-side { top:48px; }
  #deviceDialog { padding:20px 26px; }
  .device-options { grid-template-columns:repeat(3,minmax(0,1fr)); }
  [data-device-choice] { min-height:80px;padding:14px; }
  [data-device-choice] .device-icon { display:none; }
  [data-device-choice] strong,[data-device-choice] span:not(.device-icon) { grid-column:1/-1; }
  #deviceDialog .device-intro { margin:8px 0 12px; }
  #deviceDialog h2 { font-size:27px;max-width:none; }
  #deviceChoiceHint { margin-top:12px;padding-top:10px; }
}
@media(prefers-reduced-motion:reduce) {
  html { scroll-behavior:auto; }
  *,*::before,*::after { animation:none!important;transition:none!important; }
}
