:root {
  --bg: #cfe8f6; /* light blue/gray */
  --panel: rgba(255, 255, 255, 0.75);
  --border: rgba(0, 0, 0, 0.12);
  --text: rgba(0, 0, 0, 0.85);
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.16);
  --shadow-soft: 0 10px 26px rgba(17, 24, 39, 0.12);

  /* Shared max width for game pages (HUD + canvas + controls). */
  --gameMaxW: 680px;
}

* {
  box-sizing: border-box;
}

/* Ensure the HTML `hidden` attribute always hides elements, even when a class sets `display`. */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  height: 100%;
  margin: 0;
  background:
    radial-gradient(
      900px 520px at 20% 10%,
      rgba(255, 255, 255, 0.75),
      rgba(255, 255, 255, 0) 55%
    ),
    radial-gradient(
      900px 520px at 80% 15%,
      rgba(255, 255, 255, 0.55),
      rgba(255, 255, 255, 0) 60%
    ),
    linear-gradient(180deg, #cfe8f6 0%, #eaf6fb 55%, #d7eefc 100%);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
}

.wrap {
  min-height: 100%;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 12px;
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-right: calc(18px + env(safe-area-inset-right));
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  padding-left: calc(18px + env(safe-area-inset-left));
}

.topNav {
  width: min(100%, var(--gameMaxW));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

body.threecushion .threeHeader {
  width: min(100%, var(--gameMaxW));
  position: relative;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
  overflow: visible;
}

body.threecushion .threeIntro {
  margin: 0;
  font-size: 13px;
  line-height: 1.25;
  opacity: 0.85;
}

body.threecushion .threeHeaderRow {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body.threecushion .hud--settings .hudRight {
  width: 100%;
  justify-content: flex-start;
}

body.threecushion .hud--settings .settingsToggleRow {
  display: none;
}

body.threecushion .hud--settings .settingsToggleBtn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
}

body.threecushion .hud--settings .settingsToggleIcon {
  font-size: 16px;
  line-height: 1;
}

body.threecushion .hud--settings .settingsPanel {
  width: 100%;
}

body.threecushion .hud--timer .hudLeft {
  width: 100%;
}

body.threecushion .scoreboardPanel {
  position: relative;
  z-index: 1;
}

body.threecushion .scoreboardGrid {
  grid-template-columns: 1fr minmax(120px, 0.6fr) 1fr;
}

body.threecushion .playerCard {
  background: rgba(0, 0, 0, 0.92);
  border-color: rgba(255, 255, 255, 0.16);
}

body.threecushion .inningCard {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(0, 0, 0, 0.12);
}

body.threecushion .inningCardLabel {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  font-weight: 850;
  opacity: 0.92;
  color: rgba(0, 0, 0, 0.88);
  letter-spacing: -0.01em;
}

body.threecushion .inningCardValue {
  font-variant-numeric: tabular-nums;
  font-weight: 950;
  letter-spacing: -0.02em;
  line-height: 1;
  font-size: clamp(44px, 9vw, 84px);
  color: rgba(0, 0, 0, 0.92);
}

/* Three Cushion: stream overlay (minimal) */
html.threecushionStream,
body.threecushionStream {
  height: 100%;
  margin: 0;
  background: #ffffff !important;
}

body.threecushion.threecushionStream {
  color: rgba(248, 250, 252, 0.98);
}

.tcStreamRoot {
  min-height: 100%;
  display: grid;
  place-items: start;
  padding: 0;
}

.tcStream {
  --tcGap: clamp(10px, 1.1vw, 14px);
  --tcH: clamp(180px, 12vw, 240px);
  --tcRow: calc((var(--tcH) - var(--tcGap)) / 2);
  --tcRadius: 22px;
  --tcBorder: 1px solid rgba(255, 255, 255, 0.18);
  --tcBg: rgba(0, 0, 0, 0.92);
  --tcShadow: 0 18px 50px rgba(0, 0, 0, 0.22);
  --tcFlag: clamp(56px, 5vw, 72px);

  display: grid;
  grid-template-columns:
    var(--tcH)
    clamp(520px, 44vw, 820px)
    clamp(180px, 14vw, 260px);
  grid-template-rows: var(--tcRow) var(--tcRow) auto;
  gap: var(--tcGap);
  padding: clamp(8px, 1.2vw, 14px);
}

.tcStreamInningBox {
  grid-column: 1;
  grid-row: 1 / span 2;

  border-radius: var(--tcRadius);
  border: var(--tcBorder);
  background: var(--tcBg);
  box-shadow: var(--tcShadow);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;

  user-select: none;
}

.tcStreamInningLabel {
  font-weight: 1000;
  letter-spacing: 0.08em;
  opacity: 0.94;
  font-size: clamp(26px, 2.4vw, 40px);
}

.tcStreamInningNum {
  font-variant-numeric: tabular-nums;
  font-weight: 1000;
  letter-spacing: -0.04em;
  line-height: 1;
  font-size: clamp(54px, 5.4vw, 92px);
}

.tcStreamPlayerBox {
  border-radius: var(--tcRadius);
  border: var(--tcBorder);
  background: var(--tcBg);
  box-shadow: var(--tcShadow);

  display: grid;
  grid-template-columns: var(--tcFlag) 1fr var(--tcFlag);
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  min-width: 0;

  user-select: none;
}

.tcStreamPlayerBox.isActive {
  /* No explicit active outline in the screenshot; run indicator covers this. */
}

.tcStreamFlag {
  width: var(--tcFlag);
  height: calc(var(--tcFlag) * 0.66);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.22);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
  object-fit: cover;
  justify-self: start;
}

.tcStreamPlayerPad {
  width: var(--tcFlag);
  height: 1px;
}

.tcStreamTurnWrap {
  width: var(--tcFlag);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: clamp(2px, 0.35vw, 6px);
}

.tcStreamTurnBall {
  width: clamp(24px, 2.6vw, 38px);
  height: clamp(24px, 2.6vw, 38px);
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: scale(0.75);
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

.tcStreamPlayerBox.isActive .tcStreamTurnBall {
  opacity: 1;
  transform: scale(1);
}

.tcStreamTurnBall--white {
  background: rgba(248, 250, 252, 0.98);
}

.tcStreamTurnBall--yellow {
  background: #ffd100;
}

.tcStreamName {
  min-width: 0;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: clamp(38px, 4.2vw, 72px);
  line-height: 1.05;
}

.tcStreamPlayerBox--white .tcStreamName {
  color: rgba(248, 250, 252, 0.98);
}

.tcStreamPlayerBox--yellow .tcStreamName {
  color: #ffd100;
}

.tcStreamScoreBox {
  border-radius: var(--tcRadius);
  border: var(--tcBorder);
  background: var(--tcBg);
  box-shadow: var(--tcShadow);

  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  column-gap: clamp(8px, 1.1vw, 14px);
  padding: 12px clamp(16px, 1.8vw, 26px);
  user-select: none;
}

.tcStreamScoreValue {
  font-variant-numeric: tabular-nums;
  font-weight: 1000;
  letter-spacing: -0.04em;
  line-height: 1;
  font-size: clamp(48px, 5.4vw, 92px);
  justify-self: end;
}

.tcStreamRunValue {
  font-variant-numeric: tabular-nums;
  font-weight: 1000;
  letter-spacing: -0.03em;
  opacity: 0.96;
  line-height: 1;
  font-size: clamp(30px, 3.2vw, 60px);
  min-width: 0;
  white-space: nowrap;
  text-align: right;
  justify-self: end;
}

.tcStreamRunValue.isHidden {
  visibility: hidden;
}

.tcStreamScoreBox--white .tcStreamScoreValue,
.tcStreamScoreBox--white .tcStreamRunValue {
  color: rgba(248, 250, 252, 0.98);
}

.tcStreamScoreBox--yellow .tcStreamScoreValue,
.tcStreamScoreBox--yellow .tcStreamRunValue {
  color: #ffd100;
}

.tcStreamTimerRow {
  grid-column: 2 / span 2;
  grid-row: 3;

  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 10px;
}

.tcStreamTimerShell {
  flex: 1 1 auto;
  min-width: 0;
  height: clamp(28px, 2.6vw, 38px);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.12);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.tcStreamTimerFill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  background: hsl(120 90% 34%);
  transition:
    transform 0.2s linear,
    background-color 0.2s linear;
}

.tcStreamTimerSeconds {
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 1000;
  letter-spacing: -0.02em;
  font-size: clamp(22px, 2.2vw, 34px);
  color: var(--text);
}

@media (max-width: 860px) {
  .tcStream {
    grid-template-columns:
      var(--tcH)
      minmax(320px, 1fr)
      clamp(160px, 20vw, 240px);
  }
  .tcStreamName {
    font-size: clamp(26px, 4.6vw, 56px);
  }
}

body.threecushion .threeHeader .topNav {
  width: 100%;
}

body.threecushion .threeHeader .topNavLink {
  background: rgba(255, 255, 255, 0.5);
}

.topNavLink {
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
}

.topNavBtn,
.shareBtn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  color: inherit;
  font-weight: 800;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  cursor: pointer;
}

.shareIcon {
  width: 16px;
  height: 16px;
  fill: currentColor;
  opacity: 0.9;
}

.topNavLink:hover {
  text-decoration: underline;
}

.topNavBtn:hover,
.shareBtn:hover {
  text-decoration: underline;
}

.topNavBtn:focus-visible,
.shareBtn:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.homeHeader {
  width: min(100%, 600px);
  text-align: center;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}

/* Home page: more color without affecting game pages */
body.home {
  --homeA: rgba(34, 211, 238, 0.55);
  --homeB: rgba(168, 85, 247, 0.45);
  --homeC: rgba(249, 115, 22, 0.35);
  --homeD: rgba(34, 197, 94, 0.25);
  background:
    radial-gradient(
      1200px 700px at 10% 10%,
      var(--homeA),
      rgba(255, 255, 255, 0) 55%
    ),
    radial-gradient(
      1100px 650px at 90% 20%,
      var(--homeB),
      rgba(255, 255, 255, 0) 60%
    ),
    radial-gradient(
      900px 600px at 30% 90%,
      var(--homeC),
      rgba(255, 255, 255, 0) 55%
    ),
    linear-gradient(180deg, #ecfeff 0%, #f5f3ff 45%, #fff7ed 100%);
  overflow-x: hidden;
  position: relative;
  isolation: isolate;
}

body.home::before,
body.home::after {
  content: '';
  position: fixed;
  inset: -30vmax;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      closest-side,
      rgba(59, 130, 246, 0.18),
      rgba(255, 255, 255, 0) 70%
    ),
    radial-gradient(
      closest-side,
      rgba(236, 72, 153, 0.14),
      rgba(255, 255, 255, 0) 75%
    ),
    radial-gradient(
      closest-side,
      rgba(34, 197, 94, 0.13),
      rgba(255, 255, 255, 0) 75%
    );
  transform: translate3d(0, 0, 0);
  filter: blur(12px);
  opacity: 0.8;
}

body.home::before {
  animation: homeFloat 18s ease-in-out infinite;
}

body.home::after {
  animation: homeFloat 26s ease-in-out infinite reverse;
  opacity: 0.55;
}

body.home .wrap {
  position: relative;
  z-index: 1;
}

@keyframes homeFloat {
  0% {
    transform: translate3d(-2%, -1%, 0) rotate(-6deg);
  }
  50% {
    transform: translate3d(2%, 1%, 0) rotate(6deg);
  }
  100% {
    transform: translate3d(-2%, -1%, 0) rotate(-6deg);
  }
}

.homeTitle {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

body.home .homeHeader {
  width: min(100%, 880px);
  padding: 14px 16px;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
}

body.home .homeTitle {
  font-size: clamp(24px, 3.4vw, 34px);
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, #2563eb, #7c3aed, #f97316);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  body.home .homeTitle {
    color: rgba(17, 24, 39, 0.9);
  }
}

.homeSubtitle {
  margin: 6px 0 0 0;
  opacity: 0.85;
  font-weight: 600;
}

.homeHeaderActions {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.shareToast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 9999;
  max-width: min(92vw, 520px);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(17, 24, 39, 0.92);
  color: rgba(255, 255, 255, 0.95);
  font-weight: 700;
  box-shadow: 0 14px 40px rgba(17, 24, 39, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.shareToast.show {
  opacity: 1;
}

.cards {
  width: min(100%, 600px);
  display: grid;
  gap: 12px;
}

body.home .cards {
  width: min(100%, 880px);
  gap: 14px;
}

@media (min-width: 740px) {
  body.home .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.card {
  display: grid;
  gap: 8px 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  align-items: start;
}

body.home .card {
  --accent: #3b82f6;
  border-radius: 18px;
  border-color: rgba(17, 24, 39, 0.14);
  box-shadow: 0 12px 28px rgba(17, 24, 39, 0.12);
  background:
    radial-gradient(
      1100px 240px at 10% 0%,
      rgba(255, 255, 255, 0.95),
      rgba(255, 255, 255, 0) 55%
    ),
    rgba(255, 255, 255, 0.84);
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    border-color 140ms ease;
  position: relative;
  overflow: hidden;
}

body.home .card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  pointer-events: none;
  background: linear-gradient(90deg, var(--accent), transparent);
  height: 6px;
}

body.home .card::after {
  content: '';
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 999px;
  top: -58px;
  right: -58px;
  pointer-events: none;
  background:
    radial-gradient(
      circle at 30% 30%,
      rgba(255, 255, 255, 0.9),
      rgba(255, 255, 255, 0) 62%
    ),
    radial-gradient(
      circle at 30% 30%,
      var(--accent),
      rgba(255, 255, 255, 0) 70%
    );
  opacity: 0.22;
}

@media (hover: hover) {
  body.home .card:hover {
    transform: translateY(-2px);
    border-color: rgba(17, 24, 39, 0.18);
    box-shadow:
      0 18px 38px rgba(17, 24, 39, 0.14),
      0 12px 26px rgba(59, 130, 246, 0.08);
  }
}

.card:active {
  transform: translateY(1px);
}

.cardText {
  grid-column: 1;
}

.cardIcon {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: end;
  align-self: start;
  width: clamp(48px, 14vw, 72px);
  height: clamp(48px, 14vw, 72px);
  max-width: 72px;
  max-height: 72px;
  flex: 0 0 auto;
  display: block;
}

.cardTitle {
  font-weight: 900;
  font-size: 18px;
}

body.home .cardTitle {
  letter-spacing: -0.02em;
}

.cardDesc {
  grid-column: 1;
  opacity: 0.85;
  font-weight: 600;
  line-height: 1.3;
}

.cardCta {
  grid-column: 1 / -1;
  justify-self: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: #111827;
  color: white;
  font-weight: 900;
  width: 100%;
  text-align: center;
}

body.home .cardCta {
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #111827 78%);
  box-shadow: 0 10px 20px rgba(17, 24, 39, 0.18);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}

body.home .footer {
  width: min(100%, 880px);
}

/* Home card accents */
body.home .card--stack {
  --accent: #3b82f6;
}
body.home .card--dodge {
  --accent: #ef4444;
}
body.home .card--zigzag {
  --accent: #a855f7;
}
body.home .card--jump {
  --accent: #22c55e;
}
body.home .card--panic {
  --accent: #f97316;
}
body.home .card--flick {
  --accent: #06b6d4;
}
body.home .card--bounce {
  --accent: #eab308;
}
body.home .card--slice {
  --accent: #14b8a6;
}
body.home .card--orbit {
  --accent: #8b5cf6;
}
body.home .card--switch {
  --accent: #fb7185;
}
body.home .card--color {
  --accent: #10b981;
}

body.home .card--xox {
  --accent: #f43f5e;
}

body.home .card--break {
  --accent: #6366f1;
}

body.home .card--coconut {
  --accent: #22c55e;
}

body.home .card--oyku {
  --accent: #a855f7;
}

body.home .card--nine {
  --accent: #0ea5e9;
}

body.home .card--threecushion {
  --accent: #2563eb;
}

.hud {
  width: min(100%, var(--gameMaxW));
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

body.threecushion .hud {
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px 12px;
  position: relative;
  z-index: auto;
}

/* Keep dropdown menus above the timer controls (same header stack). */
body.threecushion .hud--settings {
  position: relative;
  z-index: 200;
}

body.threecushion .hud--timer {
  position: relative;
  z-index: 100;
}

body.threecushion .timerTrackRow {
  width: min(100%, var(--gameMaxW));
  margin: 12px auto 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.timerTrack {
  width: min(100%, var(--gameMaxW));
  height: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.12);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

body.threecushion .scoreboardPanel .timerTrack {
  margin: 0;
}

body.threecushion .timerTrackRow .timerTrack {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
}

body.threecushion .timerTrackSeconds {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  font-size: clamp(16px, 3.2vw, 22px);
  letter-spacing: 0.02em;
  min-width: 2.4ch;
  text-align: right;
}

body.threecushion .timerTrack {
  height: 24px;
}

body.threecushion .threeHeader .timerTrack {
  width: 100%;
  margin-top: 2px;
}

.timerTrackFill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  background: hsl(120 90% 34%);
  transition:
    transform 0.2s linear,
    background-color 0.2s linear;
}

/* Ensure Three Cushion starts green even if other rules override defaults */
body.threecushion .timerTrackFill {
  background: hsl(120 90% 34%);
}

body.threecushion .hudLeft {
  padding-top: 2px;
}

body.threecushion .turnLine {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.belowLeft {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 6px;
}

.kbdHelpWrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
}

.kbdHelpWrap--message {
  margin-left: 4px;
}

.kbdHelp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow-soft);
  font-weight: 900;
  opacity: 0.9;
  cursor: help;
  user-select: none;
}

.kbdHelp:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.kbdTooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 9999;

  width: max-content;
  min-width: 260px;
  max-width: min(360px, 92vw);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.94);
  color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 55px rgba(17, 24, 39, 0.35);

  font-size: 12px;
  line-height: 1.35;
  font-weight: 750;
  white-space: pre-line;

  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

@media (max-width: 560px) {
  .kbdTooltip {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: calc(100vh - 180px);
    overflow: auto;
    transform: translateY(-2px);
  }
}

.kbdHelpWrap:hover .kbdTooltip,
.kbdHelpWrap:focus-within .kbdTooltip {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 560px) {
  .kbdHelpWrap:hover .kbdTooltip,
  .kbdHelpWrap:focus-within .kbdTooltip {
    transform: translateY(0);
    pointer-events: auto;
  }
}

body.threecushion .kbdHelpWrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
}

body.threecushion #message {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 6px;
}

body.threecushion .kbdHelpWrap--message {
  margin-left: 4px;
}

body.threecushion .kbdHelp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow-soft);
  font-weight: 900;
  opacity: 0.9;
  cursor: help;
  user-select: none;
}

body.threecushion .kbdHelp:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

body.threecushion .kbdTooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 9999;

  width: max-content;
  min-width: 260px;
  max-width: min(360px, 92vw);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 23, 42, 0.94);
  color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 55px rgba(17, 24, 39, 0.35);

  font-size: 12px;
  line-height: 1.35;
  font-weight: 750;
  white-space: pre-line;

  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

@media (max-width: 560px) {
  body.threecushion .kbdTooltip {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: calc(100vh - 180px);
    overflow: auto;
    transform: translateY(-2px);
  }
}

body.threecushion .kbdHelpWrap:hover .kbdTooltip,
body.threecushion .kbdHelpWrap:focus-within .kbdTooltip {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 560px) {
  body.threecushion .kbdHelpWrap:hover .kbdTooltip,
  body.threecushion .kbdHelpWrap:focus-within .kbdTooltip {
    transform: translateY(0);
    pointer-events: auto;
  }
}

.hudRight {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.hudField {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hudField .scoreInput {
  margin-left: 0;
}

.hudOption {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  user-select: none;
  cursor: pointer;
  opacity: 0.9;
  white-space: nowrap;
}

.hudOption input[type='checkbox'] {
  width: 16px;
  height: 16px;
}

/* Three Cushion scoreboard */
.scoreSep {
  margin: 0 8px;
  opacity: 0.65;
}

.turnTimer {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  margin-left: 4px;
  font-weight: 850;
  opacity: 0.9;
}

.turnTimer #turnTimer {
  font-size: 1.8em;
  font-weight: 950;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.timerBtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.65),
    rgba(255, 255, 255, 0.35)
  );
  color: inherit;
  font: inherit;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    0 10px 18px rgba(17, 24, 39, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition:
    transform 0.08s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease;
}

.timerBtn:hover {
  filter: brightness(1.03) saturate(1.05);
  box-shadow:
    0 14px 26px rgba(17, 24, 39, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transform: translateY(-1px);
}

.timerBtn:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.timerBtnIcon {
  width: 16px;
  height: 16px;
  opacity: 0.95;
}

body.threecushion .timerBtn--reset {
  padding: 6px 9px;
  margin-left: 8px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.58),
    rgba(255, 255, 255, 0.3)
  );
}

body.threecushion .timerBtn--reset .timerBtnIcon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.timerBtn:active {
  transform: translateY(1px) scale(0.99);
  box-shadow:
    0 8px 14px rgba(17, 24, 39, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.turnTimer.isWarn {
  color: rgba(239, 68, 68, 0.95);
}

.turnTimer.isAlarm {
  animation: timerAlarmBlink 0.22s linear 0s 6;
}

@keyframes timerAlarmBlink {
  0% {
    filter: none;
    opacity: 1;
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.75));
    opacity: 0.55;
  }
  100% {
    filter: none;
    opacity: 1;
  }
}

@media (max-width: 420px) {
  .timerBtn {
    margin-left: 8px;
    padding: 5px 9px;
  }

  .turnTimer #turnTimer {
    font-size: 2.05em;
  }
}

@media (max-width: 380px) {
  body.threecushion .timerBtn,
  body.threecushion .timerBtn--reset {
    padding: 8px 10px;
    min-height: 40px;
  }

  body.threecushion .timerBtnIcon {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 560px) {
  body.threecushion .topNav {
    justify-content: flex-start;
  }

  body.threecushion .threeHeader {
    padding: 10px 10px;
    gap: 10px;
  }

  body.threecushion .threeHeader .topNavLink {
    padding: 6px 8px;
  }

  body.threecushion .hud {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  body.threecushion .hudLeft {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-auto-rows: auto;
    gap: 8px 10px;
    padding-top: 0;
  }

  body.threecushion .turnLine {
    grid-column: 1;
  }

  body.threecushion .kbdHelpWrap {
    grid-column: 2;
    justify-self: end;
    margin-left: 0;
  }

  body.threecushion .turnTimer {
    grid-column: 1 / -1;
    margin-left: 0;
    gap: 8px;
  }

  body.threecushion .turnTimer #turnTimer {
    font-size: 1.6em;
  }

  body.threecushion .timerBtn {
    margin-left: 0;
  }

  body.threecushion .timerBtn--reset {
    margin-left: 0;
  }

  body.threecushion .hudRight {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  body.threecushion .hudRight .hudField {
    flex: 1 1 140px;
  }

  /* Collapsible settings on mobile */
  body.threecushion .hud--settings .settingsToggleRow {
    display: block;
  }

  body.threecushion .hud--settings .settingsPanel {
    display: none;
    padding-top: 6px;
  }

  body.threecushion .hud--settings.isOpen .settingsPanel {
    display: block;
  }

  body.threecushion .timerBtn {
    gap: 8px;
    padding: 10px 14px;
    min-height: 44px;
    min-width: 48px;
  }

  body.threecushion .timerBtn--reset {
    padding: 10px 14px;
    min-height: 44px;
    min-width: 48px;
  }

  body.threecushion .timerBtnIcon {
    width: 18px;
    height: 18px;
  }

  /* Very small phones: keep labels, just compact the buttons */
  body.threecushion .timerBtn {
    font-size: 0.95em;
  }
  /* Compact overall layout to avoid scrolling */
  body.threecushion .wrap {
    gap: 10px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-right: calc(12px + env(safe-area-inset-right));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
  }

  body.threecushion .scoreboardPanel {
    padding: 10px;
    border-radius: 16px;
  }

  /* Keep all 3 cards side-by-side (Player / Inning / Player) */
  body.threecushion .scoreboardGrid {
    grid-template-columns: 1fr minmax(92px, 0.55fr) 1fr;
    gap: 8px;
  }

  body.threecushion .playerCard {
    padding: 10px;
    border-radius: 14px;
  }

  body.threecushion .scoreName {
    padding: 6px 8px;
    border-radius: 10px;
    font-size: clamp(15px, 3.2vw, 18px);
  }

  body.threecushion .flagBtn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  body.threecushion .turnBall {
    width: 32px;
    height: 32px;
  }

  body.threecushion .turnIndicator {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  body.threecushion .scoreBigRow {
    margin-top: 6px;
    padding-left: 6px;
    gap: 10px;
  }

  body.threecushion .scoreBig {
    font-size: clamp(46px, 11.5vw, 78px);
  }

  body.threecushion .runBig {
    font-size: clamp(38px, 9.5vw, 62px);
    margin-left: 8px;
  }

  body.threecushion .scoreStats {
    margin-top: 8px;
    gap: 8px;
    font-size: 0.92em;
  }

  body.threecushion .below {
    gap: 10px;
  }

  body.threecushion .scoreBtnRow {
    gap: 8px;
  }

  body.threecushion .scoreBtnGroup {
    gap: 8px;
  }

  body.threecushion .scoreBtnGroup .btn {
    min-width: 0;
  }

  body.threecushion .btn {
    padding: 9px 10px;
    border-radius: 12px;
  }

  /* Hide long explanatory text and footer on small screens to keep everything above the fold */
  body.threecushion .message {
    display: none;
  }

  body.threecushion .footer {
    display: none;
  }
}

.scoreLabel {
  font-weight: 800;
  opacity: 0.9;
}

.scoreInput {
  width: 88px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.92);
  font: inherit;
  font-weight: 900;
  text-align: center;
  margin-left: 8px;
}

.scoreboardPanel {
  width: min(100%, var(--gameMaxW));
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 14px;
}

body.threecushion .scoreboardFullscreenBtn {
  margin-left: 6px;
  cursor: pointer;
}

@media (max-width: 560px) {
  body.threecushion .scoreboardFullscreenBtn {
    display: none;
  }
}

body.threecushion .scoreboardFullscreenBtn .scoreboardFullscreenIcon {
  font-size: 14px;
  line-height: 1;
}

/* Fullscreen: request fullscreen on the document element and style the scoreboard to fill. */
body.threecushion.scoreboardFullscreen .threeHeader,
body.threecushion.scoreboardFullscreen .below,
body.threecushion.scoreboardFullscreen .footer {
  display: none;
}

body.threecushion.scoreboardFullscreen .scoreboardPanel {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: none;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  padding: clamp(14px, 2.5vw, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vw, 18px);
  z-index: 1000;
}

/* In fullscreen, keep the winner banner in normal flow (just above the cards). */
body.threecushion.scoreboardFullscreen .winnerBanner,
body.threecushion.scoreboardPseudoFullscreen .winnerBanner {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  width: min(100%, 980px);
  margin: 0 0 clamp(12px, 1.8vw, 18px) 0;
  z-index: 2;
  pointer-events: none;
}

body.threecushion.scoreboardFullscreen .scoreboardPanel .timerTrackRow {
  margin-top: 0;
}

body.threecushion.scoreboardFullscreen .scoreboardGrid,
body.threecushion.scoreboardFullscreen .timerTrackRow {
  width: min(100%, 980px);
}

/* CSS-only fallback if Fullscreen API is unavailable (e.g. some mobile browsers). */
body.threecushion.scoreboardPseudoFullscreen .threeHeader,
body.threecushion.scoreboardPseudoFullscreen .below {
  display: none;
}

body.threecushion.scoreboardPseudoFullscreen .scoreboardPanel {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: none;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  padding: clamp(14px, 2.5vw, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vw, 18px);
  z-index: 1000;
}

body.threecushion.scoreboardPseudoFullscreen .scoreboardPanel .timerTrackRow {
  margin-top: 0;
}

body.threecushion.scoreboardPseudoFullscreen .scoreboardGrid,
body.threecushion.scoreboardPseudoFullscreen .timerTrackRow {
  width: min(100%, 980px);
}

.winnerBanner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(29, 78, 216, 0.18);
  background: rgba(239, 246, 255, 0.78);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: rgba(0, 0, 0, 0.86);
  font-weight: 950;
  letter-spacing: -0.02em;
  font-size: clamp(22px, 3.6vw, 34px);
  line-height: 1.15;
  text-align: center;
  margin-bottom: 12px;
}

.winnerBanner .winnerKey {
  color: #1d4ed8;
}

.winnerIcon {
  display: inline-block;
  margin-left: 0;
  font-size: 1.15em;
}

.scoreboardGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.playerCard {
  position: relative;
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: rgba(255, 255, 255, 0.76);
  padding: 12px;
  box-shadow: var(--shadow-soft);
  user-select: none;
}

.turnIndicator {
  position: relative;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.turnBall {
  position: absolute;
  width: 38px;
  height: 38px;
  pointer-events: none;
  filter: drop-shadow(0 8px 16px rgba(17, 24, 39, 0.12));
  opacity: 0.98;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  will-change: opacity, transform, filter;
}

.playerCard.isActive .turnBall {
  animation: threeBallPulse 1.35s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .playerCard.isActive .turnBall {
    animation: none;
  }
}

@keyframes threeBallPulse {
  0%,
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    filter: brightness(0) saturate(100%) invert(16%) sepia(88%) saturate(6800%)
      hue-rotate(355deg) brightness(110%) contrast(115%)
      drop-shadow(0 8px 16px rgba(220, 38, 38, 0.22));
  }
  50% {
    opacity: 0.65;
    transform: translate(-50%, -50%) scale(1.08);
    filter: brightness(0) saturate(100%) invert(16%) sepia(88%) saturate(6800%)
      hue-rotate(355deg) brightness(115%) contrast(120%)
      drop-shadow(0 12px 26px rgba(220, 38, 38, 0.35));
  }
}

/* Three-cushion convention: white vs yellow */
body.threecushion .playerCard.ballWhite {
  color: rgba(248, 250, 252, 0.98);
}

body.threecushion .playerCard.ballYellow {
  color: #ffd100;
}

body.threecushion .playerCard.ballYellow .scoreName {
  background: transparent;
}

body.threecushion .playerCard.ballWhite .scoreBig,
body.threecushion .playerCard.ballWhite .runBig {
  color: rgba(248, 250, 252, 0.98);
  text-shadow: 0 10px 22px rgba(2, 6, 23, 0.45);
}

body.threecushion .playerCard.ballYellow .scoreBig,
body.threecushion .playerCard.ballYellow .runBig {
  color: #ffd100;
  text-shadow: 0 10px 22px rgba(2, 6, 23, 0.45);
}

body.threecushion .playerCard.ballWhite .scoreName,
body.threecushion .playerCard.ballYellow .scoreName {
  color: inherit;
  caret-color: currentColor;
}

body.threecushion .playerCard.ballWhite .scoreStats,
body.threecushion .playerCard.ballYellow .scoreStats {
  color: inherit;
  text-shadow: 0 8px 18px rgba(2, 6, 23, 0.35);
}

body.threecushion .playerCard.ballWhite .scoreStat,
body.threecushion .playerCard.ballYellow .scoreStat,
body.threecushion .playerCard.ballWhite .avgBox,
body.threecushion .playerCard.ballYellow .avgBox {
  color: inherit;
}

body.threecushion .avgBox span:first-child {
  opacity: 0.82;
}

.avgBox {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  font-weight: 900;
  opacity: 0.92;
}

.avgBox span:first-child {
  opacity: 0.72;
  font-weight: 950;
}

.playerCard:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.playerCard.isActive {
  outline: 5px solid rgba(59, 130, 246, 0.65);
  outline-offset: 3px;
  box-shadow:
    0 18px 50px rgba(17, 24, 39, 0.16),
    0 0 0 6px rgba(59, 130, 246, 0.18);
}

.playerTop {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Three-cushion: make name + flag feel integrated (no frame),
   and let the card's ball color act as the background. */
body.threecushion .scoreName {
  background: transparent;
  border: 0;
  box-shadow: none;
}

body.threecushion .scoreName:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

body.threecushion .flagBtn {
  border: 1px solid rgba(0, 0, 0, 0.22);
  background: #fff;
  box-shadow: 0 10px 22px rgba(17, 24, 39, 0.12);
}

body.threecushion .flagBtn:hover {
  background: rgba(255, 255, 255, 0.92);
}

body.threecushion .playerTop .flagPicker {
  margin-left: auto;
}

.flagPicker {
  position: relative;
  z-index: 10000;
  flex: 0 0 auto;
}

.flagBtn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

.flagBtn:hover {
  background: rgba(255, 255, 255, 0.98);
}

.flagBtn:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.flagIcon {
  width: 24px;
  height: 24px;
  display: block;
}

.flagMenu {
  position: absolute;
  z-index: 10001;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.18);
  backdrop-filter: blur(10px);
}

.flagOption {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}

.flagOption:hover {
  background: rgba(59, 130, 246, 0.12);
}

.flagOption[aria-selected='true'] {
  background: rgba(59, 130, 246, 0.18);
}

/* Language dropdown reuses the flag dropdown styling */
.langPicker {
  position: relative;
  z-index: 10002;
}

.langPicker .langBtn {
  width: auto;
  min-width: 62px;
  padding: 0 10px;
  gap: 8px;
}

.langPicker .langIcon {
  font-size: 16px;
  line-height: 1;
}

.langPicker .langCode {
  font-weight: 950;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.scoreName {
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.92);
  font: inherit;
  font-size: clamp(24px, 3.3vw, 33px);
  text-transform: uppercase;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.activePill {
  white-space: nowrap;
  font-weight: 950;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(29, 78, 216, 0.9);
  background: #2563eb;
  color: rgba(255, 255, 255, 0.98);
  box-shadow:
    0 10px 18px rgba(17, 24, 39, 0.12),
    0 0 0 3px rgba(59, 130, 246, 0.18);
}

.scoreBig {
  font-size: clamp(63px, 10.8vw, 102px);
  font-weight: 1000;
  letter-spacing: -0.06em;
  margin-top: 8px;
}

.scoreBigRow {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 8px;
  padding-left: 10px;
}

.scoreBigRow .scoreBig {
  margin-top: 0;
}

.runBig {
  font-size: clamp(52px, 9vw, 90px);
  font-weight: 1000;
  letter-spacing: -0.06em;
  color: #2563eb;
  text-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
  margin-left: 14px;
}

.scoreStats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-weight: 850;
  opacity: 0.92;
}

.scoreStat {
  display: inline-flex;
  gap: 8px;
}

body.threecushion .timeoutIcons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

body.threecushion .timeoutIcon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  line-height: 1;
  color: rgba(22, 163, 74, 0.95);
  filter: drop-shadow(0 6px 12px rgba(17, 24, 39, 0.18));
}

body.threecushion .timeoutIconSvg {
  width: 18px;
  height: 18px;
  display: block;
}

body.threecushion .timeoutIcon.isUsed {
  opacity: 0.95;
  color: rgba(239, 68, 68, 0.98);
  filter: drop-shadow(0 6px 12px rgba(239, 68, 68, 0.18));
}

.scoreBtnRow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.scoreBtnGroup {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.scoreBtnGroup--secondary {
  flex-wrap: nowrap;
}

/* Three Cushion: justify action buttons horizontally */
body.threecushion .scoreBtnRow {
  width: 100%;
  justify-content: space-between;
}

body.threecushion .scoreBtnGroup {
  flex: 1 1 340px;
  justify-content: space-between;
}

body.threecushion .scoreBtnGroup .btn {
  flex: 1 1 0;
  min-width: 120px;
  text-align: center;
}

/* Emphasize primary actions */
body.threecushion #pointBtn.btn,
body.threecushion #missBtn.btn {
  flex: 2 1 0;
}

body.threecushion #undoBtn.btn {
  flex: 1 1 0;
  min-width: 110px;
}

body.threecushion .scoreBtnGroup--secondary {
  flex: 1 1 260px;
}

@media (max-width: 520px) {
  body.threecushion .scoreBtnGroup--secondary {
    flex-wrap: wrap;
  }
}

@media (max-width: 380px) {
  .scoreboardGrid {
    grid-template-columns: 1fr;
  }
}

#game {
  width: min(100%, var(--gameMaxW));
  height: auto;
  display: block;
  background: #e9f5fb;
  border: 1px solid rgba(17, 24, 39, 0.18);
  border-radius: 18px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.below {
  width: min(100%, var(--gameMaxW));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.message {
  font-weight: 750;
  letter-spacing: -0.01em;
}

.btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(17, 24, 39, 0.1);
}

/* Modern button styling (scoped to Three Cushion) */
body.threecushion .btn {
  --btn-bg: rgba(255, 255, 255, 0.92);
  --btn-bg2: rgba(255, 255, 255, 0.78);
  --btn-border: rgba(15, 23, 42, 0.18);

  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  border: 1px solid var(--btn-border);
  background: linear-gradient(180deg, var(--btn-bg), var(--btn-bg2));
  box-shadow:
    0 12px 22px rgba(17, 24, 39, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);

  transition:
    transform 0.08s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease;
}

@media (hover: hover) {
  body.threecushion .btn:hover {
    filter: brightness(1.03) saturate(1.05);
    box-shadow:
      0 16px 30px rgba(17, 24, 39, 0.14),
      inset 0 1px 0 rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
  }
}

body.threecushion .btn:active {
  transform: translateY(1px) scale(0.99);
  box-shadow:
    0 10px 18px rgba(17, 24, 39, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

body.threecushion .btn:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.55);
  outline-offset: 2px;
}

.btn:disabled,
.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.45) saturate(0.7);
  box-shadow: none;
  transform: none;
}

.timerBtn:disabled,
.timerBtn[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.45) saturate(0.7);
  box-shadow: none;
  transform: none;
}

/* Three-cushion button semantics */
body.threecushion #pointBtn.btn {
  --btn-bg: #2f6df0;
  --btn-bg2: #1d4ed8;
  --btn-border: rgba(29, 78, 216, 0.95);
  color: rgba(255, 255, 255, 0.98);
}

body.threecushion #missBtn.btn {
  --btn-bg: #22c55e;
  --btn-bg2: #16a34a;
  --btn-border: rgba(21, 128, 61, 0.95);
  color: rgba(255, 255, 255, 0.98);
}

body.threecushion #undoBtn.btn {
  --btn-bg: #7b8ba3;
  --btn-bg2: #475569;
  --btn-border: rgba(51, 65, 85, 0.8);
  color: rgba(255, 255, 255, 0.98);
}

body.threecushion #swapColorsBtn.btn {
  --btn-bg: #38bdf8;
  --btn-bg2: #0284c7;
  --btn-border: rgba(3, 105, 161, 0.85);
  color: rgba(255, 255, 255, 0.98);
}

body.threecushion #newBtn.btn {
  --btn-bg: #f87171;
  --btn-bg2: #dc2626;
  --btn-border: rgba(153, 27, 27, 0.8);
  color: rgba(255, 255, 255, 0.98);
}

.btn--soft {
  background: rgba(255, 255, 255, 0.68);
}

body.threecushion .btn--soft {
  --btn-bg: rgba(255, 255, 255, 0.7);
  --btn-bg2: rgba(255, 255, 255, 0.5);
  --btn-border: rgba(15, 23, 42, 0.16);
}

.btn:active {
  transform: translateY(1px);
}

/* Modal */
body.modalOpen {
  overflow: hidden;
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.45);
}

.modalPanel {
  width: min(520px, calc(100vw - 36px));
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 14px;
}

.modalTitle {
  font-weight: 950;
  letter-spacing: -0.02em;
  font-size: 18px;
  margin-bottom: 6px;
}

.modalBody {
  opacity: 0.9;
  font-weight: 700;
  margin-bottom: 12px;
}

.modalActions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

#newMatchConfirm.btn {
  background: #ffd100;
  border-color: rgba(0, 0, 0, 0.22);
  color: rgba(0, 0, 0, 0.88);
}

#timeoutAccept.btn {
  background: #ffd100;
  border-color: rgba(0, 0, 0, 0.22);
  color: rgba(0, 0, 0, 0.88);
}

#newMatchConfirm.btn:hover {
  filter: brightness(0.98);
}

#timeoutAccept.btn:hover {
  filter: brightness(0.98);
}

.footer {
  width: min(100%, var(--gameMaxW));
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

/* On game pages, push the footer further down so it's less distracting while playing. */
.below + .footer {
  margin-top: clamp(56px, 18vh, 260px);
}

.footer a {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.linkBtn {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

/* 9 Stones */
.hudRow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: rgba(255, 255, 255, 0.92);
  font: inherit;
  font-weight: 800;
}

.nineWrap {
  width: min(100%, var(--gameMaxW));
  display: flex;
  justify-content: center;
}

.nineBoard {
  width: min(92vw, 520px);
  height: auto;
  touch-action: manipulation;
  user-select: none;
}

.nineLines {
  stroke: rgba(17, 24, 39, 0.32);
  stroke-width: 10;
}

.ninePt {
  fill: rgba(255, 255, 255, 0.92);
  stroke: rgba(17, 24, 39, 0.28);
  stroke-width: 6;
  cursor: pointer;
}

.ninePt.isHuman {
  fill: #2563eb;
  stroke: rgba(17, 24, 39, 0.25);
}

.ninePt.isBot {
  fill: #f43f5e;
  stroke: rgba(17, 24, 39, 0.25);
}

.ninePt.isSelectable {
  stroke: rgba(234, 179, 8, 0.95);
  stroke-width: 9;
}

.ninePt.isSelected {
  stroke: rgba(6, 182, 212, 0.95);
  stroke-width: 10;
}

.ninePt.isBotFrom {
  stroke: rgba(59, 130, 246, 0.95);
  stroke-width: 11;
}

.ninePt.isBotTo {
  stroke: rgba(34, 197, 94, 0.95);
  stroke-width: 11;
}

.ninePt.isBotCapture {
  stroke: rgba(239, 68, 68, 0.98);
  stroke-width: 12;
}

.page {
  width: min(100%, 820px);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

@media (max-width: 520px) {
  /* A little extra breathing room on the right for thumbs/safe areas. */
  .wrap {
    padding-right: calc(28px + env(safe-area-inset-right));
  }

  /* Ensure the play area itself never hugs the right edge. */
  #game,
  .hud,
  .below {
    width: min(calc(100% - 14px), var(--gameMaxW));
  }
}

.page h1 {
  margin: 0 0 10px 0;
}

.page h2 {
  margin: 16px 0 6px 0;
}

.page hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.muted {
  opacity: 0.82;
}

.pageFooter {
  margin-top: 14px;
}

.pageFooter a {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.pageFooter a:hover {
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .btn:active {
    transform: none;
  }

  .card:active {
    transform: none;
  }

  body.home::before,
  body.home::after {
    animation: none;
  }

  body.home .card {
    transition: none;
  }
}
