:root {
  --bg: #0b0f18;
  --panel: #141927;
  --panel-2: #1d2434;
  --text: #f6f8ff;
  --muted: #aeb7cb;
  --line: rgba(255, 255, 255, 0.12);
  --primary: #f4bd37;
  --accent: #15c5b5;
  --danger: #ff5d5d;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.34);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #202944 0%, var(--bg) 46%, #070a10 100%);
  color: var(--text);
  overflow-x: hidden;
  touch-action: manipulation;
}

button, input { font: inherit; }
button { border: 0; cursor: pointer; color: inherit; }

.app-shell {
  width: min(100%, 460px);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(8px + var(--safe-top)) 10px calc(10px + var(--safe-bottom));
}

.brand-card,
.promo-card,
.round-control,
.race-control,
.player-zone,
.winner-panel,
.controls button {
  border: 1px solid var(--line);
}

.brand-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(20, 25, 39, 0.86);
  backdrop-filter: blur(14px);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand-left { display: flex; align-items: center; gap: 9px; min-width: 0; }

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 950;
  color: #151515;
  background: radial-gradient(circle at 35% 25%, #fff6c8, var(--primary) 52%, #b57509 100%);
  border: 3px solid #f9df8c;
  box-shadow: inset -7px -8px 12px rgba(0, 0, 0, 0.18), 0 8px 22px rgba(244, 189, 55, 0.22);
}

.brand-name {
  font-size: clamp(18px, 5.1vw, 22px);
  font-weight: 950;
  line-height: 1.02;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 19px;
  flex: 0 0 auto;
}

.promo-card {
  margin-top: 7px;
  padding: 8px 10px;
  border-radius: 17px;
  background:
    linear-gradient(135deg, rgba(244, 189, 55, 0.23), rgba(21, 197, 181, 0.10)),
    rgba(20, 25, 39, 0.92);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.promo-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  text-align: center;
}

.promo-main strong {
  color: var(--primary);
  font-size: clamp(17px, 5vw, 22px);
  font-weight: 950;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.promo-main span {
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.promo-sub {
  margin-top: 2px;
  color: rgba(246, 248, 255, 0.78);
  font-size: 11px;
  font-weight: 750;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.promo-card.nine-promo {
  padding-top: 10px;
  padding-bottom: 9px;
}

.promo-card.nine-promo .promo-main strong {
  max-width: 100%;
  color: var(--primary);
  font-size: clamp(13px, 3.45vw, 16px);
  line-height: 1.28;
  letter-spacing: 0.015em;
  white-space: normal;
  text-wrap: balance;
}

.score-app {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.race-row {
  display: grid;
  grid-template-columns: 1fr 0.82fr 1fr;
  gap: 6px;
  align-items: stretch;
}

.round-control,
.race-control {
  min-width: 0;
  border-radius: 16px;
  background: rgba(20, 25, 39, 0.9);
  overflow: hidden;
  display: grid;
  align-items: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.round-control,
.race-control {
  min-height: 92px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(48px, 1fr) 44px;
}
.race-control { outline: 2px solid rgba(244, 189, 55, 0.20); }

.round-control label,
.race-control label {
  grid-column: 1 / -1;
  grid-row: 1;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 7px 3px 5px;
}

.round-control span,
.race-control span {
  font-size: 9px;
  font-weight: 950;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.race-control span { color: var(--primary); }

.round-control input,
.race-control input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  text-align: center;
  color: var(--text);
  background: transparent;
  font-weight: 950;
  line-height: 1;
  padding: 0;
}
.round-control input { font-size: 32px; }
.race-control input { font-size: 34px; color: var(--primary); }

.step-btn,
.race-step {
  grid-row: 2;
  width: 100%;
  height: 44px;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.06);
  border-top: 1px solid var(--line);
  font-weight: 950;
  font-size: 18px;
}
#gameADown, #gameBDown, #raceDown { grid-column: 1; border-right: 1px solid var(--line); }
#gameAUp, #gameBUp, #raceUp { grid-column: 2; }
.race-step { color: var(--primary); font-size: 22px; }

.player-zones {
  display: grid;
  gap: 8px;
}

.player-zone {
  border-radius: 20px;
  padding: 9px 9px 10px;
  background: rgba(20, 25, 39, 0.86);
  box-shadow: var(--shadow);
}
.player-zone-a { border-color: rgba(244, 189, 55, 0.32); }
.player-zone-b { border-color: rgba(21, 197, 181, 0.32); }

.player-zone-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 8px;
}

.player-zone-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.player-zone-label {
  font-size: 14px;
  color: var(--text);
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.need { font-size: 11px; line-height: 1.3; color: var(--muted); font-weight: 750; }
.need b { color: var(--text); }

.player-zone-score {
  flex: 0 0 auto;
  font-size: clamp(34px, 10vw, 44px);
  line-height: 0.92;
  font-weight: 950;
}
.player-zone-a .player-zone-score { color: var(--primary); }
.player-zone-b .player-zone-score { color: var(--accent); }

.winner-panel {
  border-radius: 18px;
  padding: 9px 10px;
  border-color: rgba(244, 189, 55, 0.45);
  background: linear-gradient(135deg, rgba(244, 189, 55, 0.22), rgba(21, 197, 181, 0.12));
}
.winner-panel[hidden] { display: none; }
.winner-title { font-size: 16px; font-weight: 950; }
.winner-sub { margin-top: 1px; color: var(--muted); font-size: 11px; }

.rack {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  justify-items: center;
  align-items: center;
}

.ball {
  position: relative;
  width: min(100%, 54px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 28%, rgba(255,255,255,0.96) 0 13%, var(--ball) 15% 55%, #111 100%);
  border: 4px solid rgba(255, 255, 255, 0.88);
  box-shadow: inset -10px -13px 16px rgba(0, 0, 0, 0.26), inset 6px 6px 12px rgba(255, 255, 255, 0.18), 0 9px 20px rgba(0, 0, 0, 0.28);
  color: var(--ballText, #fff);
  transition: transform 0.1s ease, opacity 0.16s ease, filter 0.16s ease;
}

.ball.striped {
  background:
    radial-gradient(circle at 36% 29%, rgba(255,255,255,0.98) 0 12%, transparent 13%),
    linear-gradient(180deg, #f8f8f8 0 27%, var(--ball) 27% 73%, #f8f8f8 73% 100%);
  color: #151515;
}

.ball-num {
  width: 31px;
  height: 31px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.93);
  color: #121212;
  font-weight: 950;
  font-size: 17px;
  box-shadow: 0 2px 7px rgba(0,0,0,0.2);
  z-index: 1;
}
.ball.eight .ball-num { color: #050505; }

.ball:disabled { cursor: not-allowed; }

.ball-mine { transform: scale(1.04); }
.player-zone-a .ball-mine {
  box-shadow: 0 0 0 3px var(--primary), inset -10px -13px 16px rgba(0, 0, 0, 0.26), inset 6px 6px 12px rgba(255, 255, 255, 0.18), 0 10px 22px rgba(244, 189, 55, 0.35);
}
.player-zone-b .ball-mine {
  box-shadow: 0 0 0 3px var(--accent), inset -10px -13px 16px rgba(0, 0, 0, 0.26), inset 6px 6px 12px rgba(255, 255, 255, 0.18), 0 10px 22px rgba(21, 197, 181, 0.35);
}
.ball-mine::after {
  content: '✓';
  position: absolute;
  right: -4px;
  top: -5px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 950;
  color: #111;
  border: 2px solid #fff;
  box-shadow: 0 6px 14px rgba(0,0,0,0.3);
}
.player-zone-a .ball-mine::after { background: var(--primary); }
.player-zone-b .ball-mine::after { background: var(--accent); }

.ball-taken { opacity: 0.3; filter: saturate(0.35) brightness(0.55); }
.ball-taken .ball-num { opacity: 0.7; }

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}
.controls button {
  min-height: 42px;
  border-radius: 15px;
  padding: 0 5px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(0,0,0,0.16);
}
.controls button.danger {
  color: #fff;
  background: rgba(255, 93, 93, 0.2);
  border-color: rgba(255, 93, 93, 0.38);
}

.mode-switch-btn {
  justify-self: start;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-weight: 850;
}

.nine-app {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.nine-heading,
.nine-setup,
.nine-player-row {
  border: 1px solid var(--line);
  background: rgba(20, 25, 39, 0.9);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.nine-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(244, 189, 55, 0.19), rgba(21, 197, 181, 0.09)), rgba(20, 25, 39, 0.94);
}

.nine-kicker {
  color: var(--primary);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.nine-heading h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1;
}

.nine-setup {
  padding: 13px;
  border-radius: 20px;
}

.nine-section-title {
  font-size: 17px;
  font-weight: 950;
}

.nine-count-label {
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.nine-count-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.nine-count-options button {
  min-height: 42px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 950;
}

.nine-count-options button.active {
  color: #141414;
  background: var(--primary);
  border-color: var(--primary);
}

.nine-name-fields {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.nine-name-field {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 7px;
}

.nine-name-field span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 950;
  text-align: center;
}

.nine-name-field input {
  width: 100%;
  min-height: 43px;
  padding: 0 11px;
  border-radius: 13px;
  border: 1px solid var(--line);
  outline: 0;
  color: var(--text);
  background: var(--panel-2);
  font-size: 15px;
  font-weight: 800;
}

.nine-name-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(244, 189, 55, 0.12);
}

.nine-start-btn {
  width: 100%;
  min-height: 49px;
  margin-top: 12px;
  border-radius: 15px;
  color: #151515;
  background: linear-gradient(180deg, #fff4bd, var(--primary));
  font-size: 16px;
  font-weight: 950;
}

.nine-game {
  display: grid;
  gap: 8px;
}

.nine-balance-status {
  justify-self: end;
  min-height: 25px;
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.nine-balance-status.balanced {
  color: #8ce7be;
  border-color: rgba(81, 211, 151, 0.24);
  background: rgba(81, 211, 151, 0.08);
}

.nine-balance-warning {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 8px 11px;
  border: 1px solid rgba(244, 189, 55, 0.48);
  border-radius: 15px;
  color: #ffe7a1;
  background: rgba(178, 111, 13, 0.2);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
}

.nine-balance-warning strong {
  font-size: 13px;
  font-weight: 950;
}

.nine-balance-warning span {
  color: rgba(246, 248, 255, 0.78);
  font-size: 11px;
  font-weight: 750;
  text-align: right;
}

.nine-scoreboard {
  display: grid;
  gap: 6px;
}

.nine-player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 54px;
  overflow: hidden;
  border-radius: 16px;
}

.nine-player-row.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(244, 189, 55, 0.22);
}

.nine-player-select {
  min-width: 0;
  min-height: 52px;
  display: grid;
  grid-template-columns: 29px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  background: transparent;
  text-align: left;
}

.nine-player-index {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #151515;
  background: var(--primary);
  font-size: 12px;
  font-weight: 950;
}

.nine-player-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nine-player-score {
  min-width: 45px;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  font-weight: 950;
  text-align: right;
}

.nine-manual {
  align-self: stretch;
  display: grid;
  grid-template-columns: repeat(2, 46px);
  border-left: 1px solid var(--line);
}

.nine-manual button {
  min-height: 52px;
  background: rgba(255,255,255,0.055);
  font-size: 19px;
  font-weight: 950;
}

.nine-manual button + button { border-left: 1px solid var(--line); }

.nine-brand-card {
  min-height: 68px;
  display: grid;
  place-items: center;
  padding: 7px 14px;
  overflow: hidden;
  border: 1px solid rgba(244, 189, 55, 0.3);
  border-radius: 18px;
  background:
    radial-gradient(circle at 20% 50%, rgba(244, 189, 55, 0.16), transparent 32%),
    linear-gradient(135deg, rgba(255,255,255,0.055), rgba(21,197,181,0.055)),
    rgba(13, 18, 29, 0.92);
  box-shadow: 0 8px 20px rgba(0,0,0,0.16);
}

.nine-brand-card img {
  display: block;
  width: min(100%, 240px);
  height: 52px;
  object-fit: contain;
}

.nine-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.nine-controls button {
  min-height: 42px;
  padding: 0 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 900;
}

.nine-controls button.danger {
  background: rgba(255, 93, 93, 0.2);
  border-color: rgba(255, 93, 93, 0.38);
}

.footer-brand {
  padding: 3px 4px 1px;
  text-align: center;
}

#webPromo,
.web-promo-link {
  display: inline;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.35;
  font-weight: 750;
  text-decoration: none;
}

#webPromo strong,
.web-promo-link strong {
  color: var(--primary);
  font-size: 13px;
  font-weight: 950;
}

.splash-overlay[hidden] { display: none; }

.splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.splash-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 16, 0.7);
  backdrop-filter: blur(8px);
}

.splash-card {
  position: relative;
  z-index: 1;
  width: min(92vw, 390px);
  margin: 0 auto;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(19,28,50,0.98), rgba(8,12,22,0.98));
  box-shadow: 0 24px 60px rgba(0,0,0,0.42);
}

.splash-overlay {
  display: grid;
  place-items: center;
  padding: 18px;
}

.splash-card {
  padding: 24px 20px 20px;
  text-align: center;
  background: radial-gradient(circle at top, rgba(244,189,55,0.22), transparent 35%), linear-gradient(180deg, rgba(19,28,50,0.99), rgba(8,12,22,0.99));
}

.splash-mark {
  width: 78px;
  height: 78px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 950;
  color: #151515;
  background: radial-gradient(circle at 35% 25%, #fff6c8, var(--primary) 52%, #b57509 100%);
  border: 4px solid #f9df8c;
  box-shadow: inset -10px -12px 16px rgba(0,0,0,0.18), 0 12px 28px rgba(244,189,55,0.28);
}

.splash-title { font-size: clamp(28px, 8vw, 38px); font-weight: 950; line-height: 1.02; }
.splash-sub { margin-top: 7px; color: var(--text); font-size: 15px; font-weight: 800; line-height: 1.4; }
.splash-venue { margin-top: 14px; color: var(--primary); font-size: 28px; font-weight: 950; }
.splash-copy { margin-top: 6px; font-size: 15px; font-weight: 850; line-height: 1.4; }
.splash-contact { margin-top: 10px; color: rgba(246,248,255,0.82); font-size: 13px; line-height: 1.45; }
.splash-web { margin-top: 12px; color: var(--primary); font-size: 14px; font-weight: 900; line-height: 1.45; }
.mode-choices {
  display: grid;
  gap: 9px;
  margin-top: 17px;
}

.mode-choice {
  min-height: 66px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 9px 12px;
  border-radius: 17px;
  border: 1px solid var(--line);
  text-align: left;
}

.mode-choice strong {
  font-size: 17px;
  font-weight: 950;
}

.mode-choice span {
  font-size: 12px;
  font-weight: 800;
}

.mode-choice-53 {
  color: #151515;
  background: linear-gradient(180deg, #fff4bd, var(--primary));
}

.mode-choice-9 {
  color: var(--text);
  background: linear-gradient(135deg, rgba(21,197,181,0.23), rgba(255,255,255,0.07));
  border-color: rgba(21,197,181,0.42);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translate(-50%, 18px);
  min-width: 220px;
  max-width: min(92vw, 420px);
  padding: 11px 14px;
  border-radius: 999px;
  color: #111;
  background: var(--primary);
  font-weight: 900;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.step-btn:active,
.race-step:active,
.controls button:active,
.ball:active,
.mini-btn:active {
  transform: scale(0.97);
}

.mode-switch-btn:active,
.mode-choice:active,
.nine-count-options button:active,
.nine-start-btn:active,
.nine-player-select:active,
.nine-manual button:active,
.nine-controls button:active {
  transform: scale(0.97);
}

@media (min-width: 420px) {
  .ball { width: 58px; }
}

@media (max-height: 720px) {
  .app-shell { padding-top: calc(6px + var(--safe-top)); padding-bottom: calc(8px + var(--safe-bottom)); }
  .brand-card { padding: 7px 9px; border-radius: 17px; }
  .brand-mark { width: 36px; height: 36px; flex-basis: 36px; font-size: 14px; }
  .brand-name { font-size: 17px; }
  .brand-sub { font-size: 10px; }
  .mini-btn { width: 36px; height: 36px; border-radius: 13px; }
  .promo-card { margin-top: 6px; padding: 7px 9px; border-radius: 16px; }
  .promo-main strong { font-size: 17px; }
  .promo-main span { font-size: 11px; }
  .promo-sub { font-size: 10px; }
  .score-app { gap: 7px; margin-top: 7px; }
  .round-control, .race-control { min-height: 82px; grid-template-rows: minmax(42px, 1fr) 40px; }
  .step-btn, .race-step { min-height: 40px; height: 40px; }
  .round-control input { font-size: 29px; }
  .race-control input { font-size: 30px; }
  .player-zones { gap: 6px; }
  .player-zone { padding: 7px 7px 8px; border-radius: 17px; }
  .player-zone-head { padding-bottom: 6px; }
  .player-zone-label { font-size: 12.5px; }
  .player-zone-score { font-size: clamp(26px, 8vw, 34px); }
  .need { font-size: 10.5px; }
  .rack { gap: 5px; }
  .ball { width: min(100%, 44px); border-width: 3px; }
  .ball-num { width: 23px; height: 23px; font-size: 12px; }
  .controls button { min-height: 39px; font-size: 11px; border-radius: 13px; }
  .nine-player-row, .nine-player-select, .nine-manual button { min-height: 49px; }
  .nine-brand-card { min-height: 62px; }
  .nine-brand-card img { height: 47px; }
}

@media (max-width: 360px) {
  .app-shell { padding-left: 8px; padding-right: 8px; }
  .race-row, .controls, .rack { gap: 6px; }
  .race-row { grid-template-columns: 1fr 0.84fr 1fr; }
  .player-zones { gap: 6px; }
  .promo-main { gap: 5px; }
  .promo-main strong { font-size: 16px; }
  .promo-main span { font-size: 10.5px; }
  .ball { width: min(100%, 44px); }
  .ball-num { width: 23px; height: 23px; font-size: 12px; }
  .nine-player-select { grid-template-columns: 27px minmax(0, 1fr) auto; padding-left: 7px; }
  .nine-manual { grid-template-columns: repeat(2, 43px); }
}

@media (min-width: 700px) and (orientation: portrait) {
  .app-shell {
    width: min(94vw, 960px);
    max-width: none;
    padding: calc(18px + var(--safe-top)) 0 calc(22px + var(--safe-bottom));
  }

  .brand-card {
    gap: 16px;
    padding: 13px 18px;
    border-radius: 24px;
  }

  .brand-left { gap: 14px; }
  .brand-mark { width: 58px; height: 58px; flex-basis: 58px; font-size: 23px; border-width: 4px; }
  .brand-name { font-size: clamp(27px, 3.7vw, 35px); }
  .brand-sub { margin-top: 4px; font-size: 15px; }
  .mini-btn { width: 56px; height: 56px; border-radius: 18px; font-size: 24px; }

  .promo-card {
    margin-top: 12px;
    padding: 13px 18px;
    border-radius: 22px;
  }

  .promo-main { gap: 12px; }
  .promo-main strong { font-size: clamp(25px, 3.2vw, 31px); }
  .promo-main span { font-size: 17px; }
  .promo-sub { margin-top: 4px; font-size: 15px; }
  .promo-card.nine-promo { padding-top: 14px; padding-bottom: 13px; }
  .promo-card.nine-promo .promo-main strong {
    font-size: clamp(21px, 2.75vw, 28px);
    line-height: 1.2;
    letter-spacing: 0.02em;
  }

  .score-app,
  .nine-app {
    gap: 14px;
    margin-top: 14px;
  }

  .mode-switch-btn {
    min-height: 46px;
    padding: 0 18px;
    font-size: 15px;
  }

  .nine-heading {
    padding: 18px 20px;
    border-radius: 24px;
  }

  .nine-kicker { font-size: 13px; }
  .nine-heading h1 { margin-top: 4px; font-size: 33px; }
  .nine-setup { padding: 21px; border-radius: 26px; }
  .nine-section-title { font-size: 23px; }
  .nine-count-label { margin: 15px 0 9px; font-size: 14px; }
  .nine-count-options { gap: 10px; }
  .nine-count-options button { min-height: 54px; border-radius: 17px; font-size: 18px; }
  .nine-name-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px 14px; margin-top: 16px; }
  .nine-name-field { grid-template-columns: 38px 1fr; gap: 9px; }
  .nine-name-field span { font-size: 16px; }
  .nine-name-field input { min-height: 54px; padding: 0 15px; border-radius: 16px; font-size: 17px; }
  .nine-start-btn { min-height: 60px; margin-top: 18px; border-radius: 19px; font-size: 20px; }

  .nine-game { gap: 13px; }
  .nine-balance-status { min-height: 32px; padding: 6px 12px; font-size: 14px; }
  .nine-balance-warning { min-height: 60px; padding: 11px 16px; border-radius: 19px; }
  .nine-balance-warning strong { font-size: 17px; }
  .nine-balance-warning span { font-size: 14px; }
  .nine-scoreboard { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .nine-scoreboard .nine-player-row:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    width: calc(50% - 6px);
    justify-self: center;
  }

  .nine-player-row { min-height: 98px; border-radius: 22px; }
  .nine-player-select {
    min-height: 96px;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 12px;
    padding: 10px 13px;
  }
  .nine-player-index { width: 40px; height: 40px; font-size: 17px; }
  .nine-player-name { font-size: 20px; }
  .nine-player-score { min-width: 54px; font-size: 48px; }
  .nine-manual { grid-template-columns: repeat(2, 56px); }
  .nine-manual button { min-height: 96px; font-size: 27px; }

  .nine-brand-card { min-height: 108px; padding: 10px 20px; border-radius: 24px; }
  .nine-brand-card img { width: min(100%, 360px); height: 84px; }
  .nine-controls { gap: 11px; }
  .nine-controls button { min-height: 62px; padding: 0 10px; border-radius: 18px; font-size: 16px; }

  .footer-brand { padding: 5px 8px 2px; }
  #webPromo,
  .web-promo-link { font-size: 15px; }
  #webPromo strong,
  .web-promo-link strong { font-size: 17px; }

  .race-row { gap: 13px; }
  .round-control,
  .race-control {
    min-height: 132px;
    grid-template-rows: minmax(74px, 1fr) 56px;
    border-radius: 22px;
  }
  .round-control label,
  .race-control label { gap: 4px; padding: 12px 6px 8px; }
  .round-control span,
  .race-control span { font-size: 13px; }
  .round-control input { font-size: 48px; }
  .race-control input { font-size: 52px; }
  .step-btn,
  .race-step { height: 56px; min-height: 56px; font-size: 24px; }
  .race-step { font-size: 30px; }

  .player-zones { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .player-zone { padding: 16px 16px 15px; border-radius: 24px; }
  .player-zone-head { padding-bottom: 12px; }
  .player-zone-label { font-size: 18px; }
  .player-zone-score { font-size: clamp(52px, 7vw, 68px); }
  .need { font-size: 14px; }

  .winner-panel { padding: 14px 18px; border-radius: 22px; }
  .winner-title { font-size: 22px; }
  .winner-sub { margin-top: 3px; font-size: 14px; }

  .rack { gap: 13px; }
  .ball { width: min(100%, 84px); border-width: 5px; }
  .ball-num { width: 38px; height: 38px; font-size: 20px; }
  .ball-mine::after { width: 28px; height: 28px; font-size: 14px; }

  .controls { gap: 11px; }
  .controls button { min-height: 62px; border-radius: 18px; font-size: 16px; }

  .splash-card { width: min(88vw, 640px); padding: 34px 32px 30px; border-radius: 34px; }
  .splash-mark { width: 98px; height: 98px; font-size: 42px; }
  .splash-title { font-size: 46px; }
  .splash-sub { font-size: 19px; }
  .splash-venue { font-size: 34px; }
  .splash-copy { font-size: 18px; }
  .splash-contact { font-size: 16px; }
  .splash-web { font-size: 17px; }
  .mode-choices { gap: 13px; margin-top: 23px; }
  .mode-choice { min-height: 84px; padding: 13px 18px; border-radius: 22px; }
  .mode-choice strong { font-size: 22px; }
  .mode-choice span { font-size: 15px; }
}

@media (min-width: 700px) and (max-height: 1100px) and (orientation: portrait) {
  #mode53View.score-app { gap: 8px; }
  body:has(#mode53View:not([hidden])) .app-shell {
    padding-bottom: calc(6px + var(--safe-bottom));
  }
  #mode53View .player-zone {
    padding: 10px 12px 10px;
  }
  #mode53View .player-zone-head { padding-bottom: 6px; }
  #mode53View .rack { gap: 10px 12px; }
  #mode53View .ball { width: min(100%, 72px); border-width: 4px; }
  #mode53View .ball-num { width: 34px; height: 34px; font-size: 18px; }
  #mode53View .footer-brand { padding-top: 2px; padding-bottom: 0; }
}

/* iPad/tablet landscape only (bounded width+height so real desktop windows are not caught) */
@media (min-width: 900px) and (max-width: 1400px) and (min-height: 650px) and (orientation: landscape) {
  body:has(#mode53View:not([hidden])) .app-shell {
    width: min(96vw, 1080px);
    max-width: none;
    padding: calc(8px + var(--safe-top)) 0 calc(10px + var(--safe-bottom));
  }

  body:has(#mode53View:not([hidden])) .brand-card {
    gap: 12px;
    padding: 9px 16px;
    border-radius: 20px;
  }
  body:has(#mode53View:not([hidden])) .brand-left { gap: 11px; }
  body:has(#mode53View:not([hidden])) .brand-mark { width: 42px; height: 42px; flex-basis: 42px; font-size: 17px; }
  body:has(#mode53View:not([hidden])) .brand-name { font-size: clamp(19px, 2.2vw, 24px); }
  body:has(#mode53View:not([hidden])) .brand-sub { font-size: 11.5px; }
  body:has(#mode53View:not([hidden])) .mini-btn { width: 42px; height: 42px; border-radius: 15px; font-size: 18px; }

  body:has(#mode53View:not([hidden])) .promo-card {
    margin-top: 7px;
    padding: 8px 16px;
    border-radius: 17px;
  }
  body:has(#mode53View:not([hidden])) .promo-main { gap: 10px; }
  body:has(#mode53View:not([hidden])) .promo-main strong { font-size: clamp(17px, 1.9vw, 21px); }
  body:has(#mode53View:not([hidden])) .promo-main span { font-size: 12.5px; }
  body:has(#mode53View:not([hidden])) .promo-sub { font-size: 11px; }

  #mode53View.score-app { gap: 9px; margin-top: 8px; }
  #mode53View .mode-switch-btn { min-height: 40px; padding: 0 16px; font-size: 13px; }

  #mode53View .race-row { gap: 10px; }
  #mode53View .round-control,
  #mode53View .race-control {
    min-height: 76px;
    grid-template-rows: minmax(38px, 1fr) 36px;
    border-radius: 16px;
  }
  #mode53View .round-control label,
  #mode53View .race-control label { padding: 6px 4px 3px; }
  #mode53View .round-control input { font-size: 27px; }
  #mode53View .race-control input { font-size: 29px; }
  #mode53View .step-btn,
  #mode53View .race-step { height: 36px; min-height: 36px; font-size: 16px; }
  #mode53View .race-step { font-size: 19px; }

  #mode53View .player-zones { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  #mode53View .player-zone { padding: 11px 15px 12px; border-radius: 20px; }
  #mode53View .player-zone-head { padding-bottom: 6px; }
  #mode53View .player-zone-label { font-size: 16px; }
  #mode53View .player-zone-score { font-size: clamp(36px, 4.4vw, 46px); }
  #mode53View .need { font-size: 12px; }

  #mode53View .winner-panel { padding: 9px 16px; border-radius: 16px; }
  #mode53View .winner-title { font-size: 17px; }
  #mode53View .winner-sub { font-size: 12px; }

  #mode53View .rack { gap: 8px; }
  #mode53View .ball { width: min(100%, 58px); border-width: 4px; }
  #mode53View .ball-num { width: 27px; height: 27px; font-size: 15px; }
  #mode53View .ball-mine::after { width: 21px; height: 21px; font-size: 12px; }

  #mode53View .controls { gap: 9px; }
  #mode53View .controls button { min-height: 46px; border-radius: 15px; font-size: 13px; }

  #mode53View .footer-brand { padding-top: 3px; padding-bottom: 0; }
}
