:root {
  color-scheme: dark;
  --bg: #0c1017;
  --panel: #151b26;
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eef2f7;
  --muted: #8b98ab;
  --accent: #eab308;
  --accent-glow: rgba(234, 179, 8, 0.35);
  --green: #22c55e;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: #090c12;
  background-image: radial-gradient(circle at 50% 35%, #162030 0%, #090c12 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  /* positioned (paints above the .stage-backdrop that comes before it) but
     with no z-index: a stacking context here would trap the rules /
     controls guide (z 80) under the home screen (z 40) */
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  padding:
    max(10px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  gap: 8px;
}

/* =======================================================================
   STAGE BACKDROP — subtle, dark, distant CSS scenes behind the table
   ([data-bg-theme] set by abacusTheme.js from BACKGROUND_STYLES)
   ======================================================================= */
.stage-backdrop {
  position: fixed;
  inset: -2px;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-color: #090c12;
  background-image: radial-gradient(circle at 50% 35%, #162030 0%, #090c12 100%);
  transition: background 0.35s ease;
}

.stage-backdrop::before,
.stage-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

/* Ciudad nocturna: distant skyline silhouettes + soft warm/cool city lights */
:root[data-bg-theme="city"] .stage-backdrop {
  background:
    radial-gradient(ellipse 85% 45% at 50% 92%, rgba(214, 146, 78, 0.14) 0%, rgba(28, 42, 66, 0.08) 48%, transparent 78%),
    linear-gradient(180deg, #060911 0%, #0b1220 46%, #131b2b 78%, #0a0d14 100%);
}
:root[data-bg-theme="city"] .stage-backdrop::before {
  opacity: 0.9;
  background-repeat: repeat-x;
  background-position: bottom center;
  background-size: 960px 44vh;
  filter: blur(0.6px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 260' preserveAspectRatio='none'%3E%3Cg fill='%23070b13'%3E%3Crect x='0' y='150' width='58' height='110'/%3E%3Crect x='54' y='118' width='44' height='142'/%3E%3Crect x='94' y='162' width='66' height='98'/%3E%3Crect x='156' y='92' width='52' height='168'/%3E%3Crect x='204' y='138' width='72' height='122'/%3E%3Crect x='272' y='74' width='48' height='186'/%3E%3Crect x='316' y='124' width='64' height='136'/%3E%3Crect x='376' y='156' width='54' height='104'/%3E%3Crect x='426' y='102' width='58' height='158'/%3E%3Crect x='480' y='140' width='74' height='120'/%3E%3Crect x='550' y='84' width='50' height='176'/%3E%3Crect x='596' y='128' width='68' height='132'/%3E%3Crect x='660' y='152' width='58' height='108'/%3E%3Crect x='714' y='96' width='46' height='164'/%3E%3Crect x='756' y='132' width='64' height='128'/%3E%3Crect x='816' y='110' width='56' height='150'/%3E%3Crect x='868' y='148' width='92' height='112'/%3E%3C/g%3E%3Cg fill='%23ffcf88' opacity='0.52'%3E%3Crect x='64' y='132' width='4' height='3'/%3E%3Crect x='78' y='144' width='4' height='3'/%3E%3Crect x='166' y='108' width='4' height='3'/%3E%3Crect x='184' y='122' width='4' height='3'/%3E%3Crect x='172' y='148' width='4' height='3'/%3E%3Crect x='284' y='92' width='4' height='3'/%3E%3Crect x='298' y='110' width='4' height='3'/%3E%3Crect x='288' y='138' width='4' height='3'/%3E%3Crect x='438' y='118' width='4' height='3'/%3E%3Crect x='456' y='134' width='4' height='3'/%3E%3Crect x='562' y='102' width='4' height='3'/%3E%3Crect x='578' y='120' width='4' height='3'/%3E%3Crect x='566' y='146' width='4' height='3'/%3E%3Crect x='726' y='114' width='4' height='3'/%3E%3Crect x='738' y='136' width='4' height='3'/%3E%3Crect x='828' y='126' width='4' height='3'/%3E%3Crect x='844' y='144' width='4' height='3'/%3E%3C/g%3E%3Cg fill='%239ec8ff' opacity='0.36'%3E%3Crect x='112' y='176' width='4' height='3'/%3E%3Crect x='224' y='156' width='4' height='3'/%3E%3Crect x='334' y='142' width='4' height='3'/%3E%3Crect x='502' y='158' width='4' height='3'/%3E%3Crect x='618' y='146' width='4' height='3'/%3E%3Crect x='776' y='150' width='4' height='3'/%3E%3C/g%3E%3C/svg%3E");
}
:root[data-bg-theme="city"] .stage-backdrop::after {
  opacity: 0.7;
  background:
    radial-gradient(circle 46px at 14% 84%, rgba(255, 198, 122, 0.14), transparent 72%),
    radial-gradient(circle 60px at 36% 88%, rgba(125, 182, 255, 0.11), transparent 72%),
    radial-gradient(circle 54px at 66% 86%, rgba(255, 190, 110, 0.13), transparent 72%),
    radial-gradient(circle 48px at 88% 82%, rgba(145, 196, 255, 0.1), transparent 72%);
  animation: backdropTwinkle 11s ease-in-out infinite;
}

/* Horizonte neón: dark distant skyscrapers with faint cyan & violet horizon */
:root[data-bg-theme="skyline-neon"] .stage-backdrop {
  background:
    radial-gradient(ellipse 75% 42% at 24% 88%, rgba(56, 200, 232, 0.12), transparent 70%),
    radial-gradient(ellipse 70% 42% at 78% 86%, rgba(154, 108, 245, 0.13), transparent 70%),
    linear-gradient(180deg, #05070e 0%, #0b0f1e 52%, #131326 84%, #080912 100%);
}
:root[data-bg-theme="skyline-neon"] .stage-backdrop::before {
  opacity: 0.92;
  background-repeat: repeat-x;
  background-position: bottom center;
  background-size: 960px 48vh;
  filter: blur(0.6px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 280' preserveAspectRatio='none'%3E%3Cg fill='%23060812'%3E%3Crect x='0' y='152' width='52' height='128'/%3E%3Crect x='48' y='96' width='42' height='184'/%3E%3Crect x='86' y='142' width='68' height='138'/%3E%3Crect x='150' y='64' width='46' height='216'/%3E%3Crect x='192' y='128' width='62' height='152'/%3E%3Crect x='250' y='88' width='54' height='192'/%3E%3Crect x='300' y='146' width='76' height='134'/%3E%3Crect x='372' y='72' width='44' height='208'/%3E%3Crect x='412' y='118' width='66' height='162'/%3E%3Crect x='474' y='150' width='60' height='130'/%3E%3Crect x='530' y='58' width='48' height='222'/%3E%3Crect x='574' y='116' width='70' height='164'/%3E%3Crect x='640' y='148' width='56' height='132'/%3E%3Crect x='692' y='82' width='52' height='198'/%3E%3Crect x='740' y='132' width='68' height='148'/%3E%3Crect x='804' y='94' width='50' height='186'/%3E%3Crect x='850' y='140' width='110' height='140'/%3E%3C/g%3E%3Cg fill='%234de4ff' opacity='0.48'%3E%3Crect x='168' y='74' width='10' height='2'/%3E%3Crect x='162' y='108' width='4' height='3'/%3E%3Crect x='178' y='132' width='4' height='3'/%3E%3Crect x='386' y='82' width='14' height='2'/%3E%3Crect x='384' y='114' width='4' height='3'/%3E%3Crect x='708' y='94' width='12' height='2'/%3E%3Crect x='714' y='126' width='4' height='3'/%3E%3C/g%3E%3Cg fill='%23c084fc' opacity='0.44'%3E%3Crect x='60' y='108' width='12' height='2'/%3E%3Crect x='268' y='102' width='4' height='3'/%3E%3Crect x='282' y='128' width='4' height='3'/%3E%3Crect x='546' y='68' width='14' height='2'/%3E%3Crect x='544' y='104' width='4' height='3'/%3E%3Crect x='560' y='136' width='4' height='3'/%3E%3Crect x='820' y='106' width='12' height='2'/%3E%3C/g%3E%3C/svg%3E");
}
:root[data-bg-theme="skyline-neon"] .stage-backdrop::after {
  opacity: 0.75;
  background:
    radial-gradient(circle 70px at 18% 82%, rgba(56, 224, 255, 0.11), transparent 72%),
    radial-gradient(circle 80px at 56% 86%, rgba(168, 117, 255, 0.11), transparent 72%),
    radial-gradient(circle 66px at 86% 80%, rgba(77, 136, 255, 0.1), transparent 72%);
  animation: backdropTwinkle 13s ease-in-out infinite;
}

/* Luces de avenida: soft out-of-focus distant bokeh lights in the dark */
:root[data-bg-theme="avenue"] .stage-backdrop {
  background: linear-gradient(180deg, #060910 0%, #0d1320 58%, #0a0e16 100%);
}
:root[data-bg-theme="avenue"] .stage-backdrop::before {
  opacity: 0.85;
  background:
    radial-gradient(circle 18px at 8% 24%, rgba(255, 206, 134, 0.14), transparent 72%),
    radial-gradient(circle 28px at 16% 78%, rgba(255, 184, 102, 0.15), transparent 72%),
    radial-gradient(circle 22px at 26% 16%, rgba(134, 186, 255, 0.13), transparent 72%),
    radial-gradient(circle 34px at 34% 88%, rgba(255, 214, 154, 0.12), transparent 72%),
    radial-gradient(circle 24px at 72% 18%, rgba(255, 194, 120, 0.13), transparent 72%),
    radial-gradient(circle 32px at 84% 76%, rgba(130, 184, 255, 0.14), transparent 72%),
    radial-gradient(circle 20px at 92% 28%, rgba(255, 174, 102, 0.14), transparent 72%),
    radial-gradient(circle 26px at 62% 90%, rgba(244, 152, 186, 0.1), transparent 72%);
}
:root[data-bg-theme="avenue"] .stage-backdrop::after {
  opacity: 0.7;
  background:
    radial-gradient(circle 6px at 12% 32%, rgba(255, 224, 176, 0.24), transparent 70%),
    radial-gradient(circle 5px at 22% 84%, rgba(255, 204, 136, 0.22), transparent 70%),
    radial-gradient(circle 6px at 78% 84%, rgba(162, 206, 255, 0.22), transparent 70%),
    radial-gradient(circle 5px at 88% 22%, rgba(255, 214, 160, 0.24), transparent 70%),
    radial-gradient(circle 4px at 46% 92%, rgba(255, 198, 128, 0.2), transparent 70%);
  animation: backdropTwinkle 12s ease-in-out infinite;
}

/* Terraza nocturna: quiet starry sky over distant hills & scattered town lights */
:root[data-bg-theme="rooftop"] .stage-backdrop {
  background:
    radial-gradient(ellipse 90% 40% at 50% 94%, rgba(112, 148, 198, 0.12), transparent 72%),
    linear-gradient(180deg, #04070e 0%, #091121 56%, #0f1a2c 86%, #080d16 100%);
}
:root[data-bg-theme="rooftop"] .stage-backdrop::before {
  opacity: 0.78;
  background-image:
    radial-gradient(1.5px 1.5px at 11% 14%, rgba(226, 238, 255, 0.55), transparent),
    radial-gradient(1.2px 1.2px at 24% 9%, rgba(226, 238, 255, 0.4), transparent),
    radial-gradient(1.5px 1.5px at 39% 18%, rgba(226, 238, 255, 0.45), transparent),
    radial-gradient(1.2px 1.2px at 58% 11%, rgba(226, 238, 255, 0.5), transparent),
    radial-gradient(1.5px 1.5px at 76% 16%, rgba(226, 238, 255, 0.45), transparent),
    radial-gradient(1.2px 1.2px at 89% 10%, rgba(226, 238, 255, 0.5), transparent),
    radial-gradient(1.2px 1.2px at 18% 28%, rgba(226, 238, 255, 0.32), transparent),
    radial-gradient(1.2px 1.2px at 83% 26%, rgba(226, 238, 255, 0.34), transparent);
  animation: starBreath 14s ease-in-out infinite;
}
:root[data-bg-theme="rooftop"] .stage-backdrop::after {
  opacity: 0.88;
  background-repeat: repeat-x;
  background-position: bottom center;
  background-size: 960px 38vh;
  filter: blur(0.8px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 210' preserveAspectRatio='none'%3E%3Cpath d='M0 148 Q120 112 240 134 T480 122 T720 138 T960 124 L960 210 L0 210 Z' fill='%23070b14'/%3E%3Cg fill='%23ffd598' opacity='0.48'%3E%3Ccircle cx='88' cy='162' r='2'/%3E%3Ccircle cx='144' cy='154' r='1.6'/%3E%3Ccircle cx='212' cy='166' r='2'/%3E%3Ccircle cx='326' cy='156' r='1.8'/%3E%3Ccircle cx='402' cy='164' r='2'/%3E%3Ccircle cx='518' cy='152' r='1.8'/%3E%3Ccircle cx='612' cy='162' r='2'/%3E%3Ccircle cx='704' cy='158' r='1.6'/%3E%3Ccircle cx='796' cy='154' r='2'/%3E%3Ccircle cx='878' cy='164' r='1.8'/%3E%3C/g%3E%3C/svg%3E");
}

/* Salón de madera: dark vertical wood-panel lounge wall with subtle warm glow */
:root[data-bg-theme="club"] .stage-backdrop {
  background:
    radial-gradient(ellipse 70% 45% at 50% 24%, rgba(168, 114, 62, 0.14), transparent 72%),
    linear-gradient(180deg, #120d09 0%, #19120c 55%, #0c0907 100%);
}
:root[data-bg-theme="club"] .stage-backdrop::before {
  opacity: 0.45;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 224, 180, 0.03) 0px,
    rgba(255, 224, 180, 0.03) 2px,
    transparent 2px,
    transparent 56px,
    rgba(0, 0, 0, 0.24) 56px,
    rgba(0, 0, 0, 0.24) 60px
  );
}

@keyframes backdropTwinkle {
  0%, 100% { opacity: 0.54; }
  50% { opacity: 0.86; }
}

@keyframes starBreath {
  0%, 100% { opacity: 0.56; }
  50% { opacity: 0.84; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-backdrop::before,
  .stage-backdrop::after {
    animation: none !important;
  }
}

/* Buttons */
.btn-row {
  display: flex;
  gap: 6px;
}

.btn {
  background: #1e2736;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn:hover {
  background: #283447;
  border-color: rgba(255, 255, 255, 0.25);
}

.btn:active {
  transform: scale(0.96);
}

.btn-accent {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  color: #111827;
  border-color: #fde047;
}

.btn-accent:hover {
  background: linear-gradient(135deg, #facc15, #eab308);
}

.btn-xs {
  padding: 3px 7px;
  font-size: 11px;
}

.btn-lg {
  padding: 10px 24px;
  font-size: 15px;
  border-radius: 10px;
}

.btn-with-pad {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-with-pad .pad-key {
  padding: 1px 6px;
  font-size: 10px;
}

.btn-gamepad.connected {
  border-color: rgba(74, 222, 128, 0.75);
  background: rgba(34, 197, 94, 0.2);
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.4);
}

/* Xbox Controls Quick Modal */
.gamepad-modal-card {
  width: min(1040px, 96vw);
  max-width: 96vw;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 22px 26px 18px;
  gap: 14px;
  align-items: stretch;
  text-align: left;
  background: linear-gradient(160deg, #18212c 0%, #111923 72%, #0d151e 100%);
  border-color: rgba(159, 180, 168, 0.35);
}
#gamepad-modal .gamepad-modal-card {
  width: min(1040px, 96vw);
  max-width: 96vw;
}

.pad-guide-heading {
  text-align: center;
}
.pad-guide-heading .win-eyebrow {
  color: #d8e2dc;
  background: rgba(150, 178, 163, 0.1);
  border-color: rgba(159, 180, 168, 0.25);
}
.pad-guide-heading h2 {
  margin: 8px 0 4px;
  color: #edf0ea;
  font-size: 23px;
}
.pad-guide-heading p {
  color: #b4c0ca;
  font-size: 13px;
  line-height: 1.5;
}

.pad-guide-layout {
  display: grid;
  grid-template-columns: minmax(330px, 0.95fr) minmax(390px, 1.05fr);
  align-items: start;
  gap: 20px;
}
.pad-illustration {
  min-width: 0;
  padding: 12px 10px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 42%, rgba(74, 97, 112, 0.2), rgba(14, 21, 29, 0.7) 72%);
}
.xbox-controller {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.pad-svg-label {
  fill: #dce3e6;
  font: 800 10px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.8px;
  text-anchor: middle;
}
.pad-svg-button {
  fill: #f2f4f5;
  font: 900 11px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-anchor: middle;
}
.pad-svg-face-key {
  fill: #fff;
  font: 900 16px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-anchor: middle;
}
.pad-svg-caption {
  fill: #aab7c0;
  font: 700 9px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 1.1px;
  text-anchor: middle;
}
.pad-diagram-key {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  color: #b4c0ca;
  font-size: 11px;
}
.pad-diagram-key span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pad-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.pad-dot-move { background: #8db5a1; }
.pad-dot-action { background: #b9b69a; }

.pad-guide-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 9px;
}
.pad-guide-section {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}
.pad-guide-section h3 {
  margin: 0 0 7px;
  color: #d4dccf;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pad-guide-row {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  align-items: start;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.045);
  color: #d1d8dd;
  font-size: 11px;
  line-height: 1.38;
}
.pad-guide-row:first-of-type {
  border-top: 0;
}
.pad-guide-row .pad-key {
  justify-self: start;
  padding: 3px 7px;
  font-size: 10px;
  background: #34414e;
  border-color: rgba(202, 215, 221, 0.25);
  color: #eef2f3;
}
.pad-guide-row .pad-key.key-a { background: #477d5a; border-color: #83b691; color: #f3fbf3; }
.pad-guide-row .pad-key.key-b { background: #86494e; border-color: #c18588; color: #fff4f4; }
.pad-guide-row .pad-key.key-x { background: #416b91; border-color: #82a9cb; color: #f4f9ff; }
.pad-guide-row .pad-key.key-y { background: #817648; border-color: #b2a86e; color: #fffdf2; }
.pad-guide-row .pad-key.key-bumper { background: #394550; border-color: #82909b; color: #e5e9e7; }
.gamepad-modal-card > #btn-close-gamepad {
  align-self: center;
}

@media (max-width: 820px) {
  .pad-guide-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .pad-illustration {
    width: min(560px, 100%);
    justify-self: center;
  }
}
@media (max-width: 520px) {
  .gamepad-modal-card {
    width: 96vw;
    padding: 16px 12px 14px;
  }
  .pad-guide-heading h2 {
    font-size: 20px;
  }
  .pad-guide-heading p {
    font-size: 12px;
  }
  .pad-guide-legend {
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
  }
  .pad-guide-row {
    grid-template-columns: minmax(98px, auto) 1fr;
    gap: 6px;
  }
  .pad-guide-row .pad-key {
    white-space: normal;
  }
}

.pad-grid {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 4px 0 8px;
}

.pad-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px;
  color: #e2e8f0;
}

.pad-key {
  font-size: 11px;
  font-weight: 900;
  padding: 3px 9px;
  border-radius: 7px;
  background: #273245;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
  white-space: nowrap;
}

.pad-key.key-a { background: #16a34a; border-color: #86efac; color: #052e16; }
.pad-key.key-b { background: #dc2626; border-color: #fca5a5; color: #ffffff; }
.pad-key.key-x { background: #2563eb; border-color: #93c5fd; color: #ffffff; }
.pad-key.key-y { background: #eab308; border-color: #fef08a; color: #111827; }
.pad-key.key-bumper { background: #334155; border-color: #94a3b8; color: #fef08a; }

/* Pause & Settings Modal (Gamepad-Navigable) */
.pause-modal-card {
  width: 470px;
  max-width: 94vw;
  padding: 24px 28px 20px;
}

.pause-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 8px;
}

.pause-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}

.pause-item:hover,
.pause-item.focused {
  background: rgba(234, 179, 8, 0.14);
  border-color: rgba(250, 204, 21, 0.8);
  box-shadow: 0 0 16px rgba(234, 179, 8, 0.2);
  transform: translateX(2px);
}

.pause-item.pause-danger:hover,
.pause-item.pause-danger.focused {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(248, 113, 113, 0.85);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.22);
}

.pause-value {
  font-size: 12px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.pause-value.on {
  background: rgba(34, 197, 94, 0.22);
  color: #86efac;
}

.pause-felt-item {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.pause-felt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pause-felt-name {
  font-size: 12px;
  font-weight: 800;
  color: #fde047;
}

.felt-swatches {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 7px;
}

/* Mini table: felt centre, wood frame (border-box), metal line between */
.felt-swatch {
  height: 30px;
  min-width: 0;
  padding: 0;
  border-radius: 7px;
  border: 5px solid transparent;
  box-shadow: inset 0 0 0 1.5px var(--swatch-metal, #d4a84f), 0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, outline-color 0.15s;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.felt-swatch:hover {
  transform: scale(1.08);
}

.felt-swatch.selected {
  outline-color: #fde047;
  box-shadow: inset 0 0 0 1.5px var(--swatch-metal, #d4a84f), 0 0 12px rgba(250, 204, 21, 0.45), 0 4px 10px rgba(0, 0, 0, 0.5);
  transform: scale(1.1);
}

.pause-footer-hint {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 2px;
}

.pause-footer-hint .pad-key {
  padding: 1px 6px;
  font-size: 10px;
}

/* Table Stage */
.table-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pool-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.05);
  touch-action: none;
  cursor: crosshair;
}

/* Toast Banner */
.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(234, 179, 8, 0.55);
  color: #fef08a;
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.foul {
  border-color: rgba(239, 68, 68, 0.75);
  color: #fca5a5;
}

/* Modals */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 14, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  border-radius: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: #151c28;
  border: 1px solid rgba(234, 179, 8, 0.4);
  border-radius: 20px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 520px;
}

.modal-trophy {
  font-size: 46px;
  line-height: 1;
}

.modal-card h2 {
  font-size: 24px;
  color: #fef08a;
}

.modal-card p {
  color: var(--muted);
  font-size: 14px;
}

/* Championship Victory Modal */
.win-modal-card {
  width: 560px;
  max-width: 94vw;
  padding: 28px 34px 26px;
  background: radial-gradient(circle at 50% 0%, #242f44 0%, #121824 62%, #0c1018 100%);
  border: 1.5px solid rgba(234, 179, 8, 0.6);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.88), 0 0 50px rgba(234, 179, 8, 0.22);
  gap: 10px;
  animation: winCardReveal 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes winCardReveal {
  0% { opacity: 0; transform: scale(0.84) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.win-eyebrow {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 2.8px;
  text-transform: uppercase;
  color: #fde047;
  background: rgba(234, 179, 8, 0.14);
  border: 1px solid rgba(234, 179, 8, 0.35);
  padding: 3px 14px;
  border-radius: 999px;
}

.win-crest {
  position: relative;
  width: 78px;
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px 0;
}

.win-crest-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(250, 204, 21, 0.45) 0%, rgba(234, 179, 8, 0) 70%);
  animation: crestPulse 2.2s ease-in-out infinite;
}

@keyframes crestPulse {
  0%, 100% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.18); opacity: 1; }
}

.win-trophy-icon {
  position: relative;
  font-size: 52px;
  line-height: 1;
  filter: drop-shadow(0 6px 14px rgba(234, 179, 8, 0.55));
  animation: trophyFloat 2.4s ease-in-out infinite;
}

@keyframes trophyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.win-headline {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ffffff 0%, #fef08a 55%, #eab308 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.win-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.win-versus {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.win-player-box {
  position: relative;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.win-player-box.champion {
  background: linear-gradient(180deg, rgba(234, 179, 8, 0.16) 0%, rgba(234, 179, 8, 0.04) 100%);
  border-color: rgba(250, 204, 21, 0.65);
  box-shadow: 0 0 22px rgba(234, 179, 8, 0.18);
}

.win-champ-tag {
  position: absolute;
  top: -10px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  background: linear-gradient(135deg, #fde047, #ca8a04);
  color: #111827;
  padding: 2px 10px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.win-player-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.win-player-score {
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
  color: #fef08a;
  font-variant-numeric: tabular-nums;
}

.win-player-score small {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.win-player-breakdown {
  display: flex;
  gap: 10px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.win-balls-mini {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 2px;
}

.win-cta {
  padding: 11px 32px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 24px rgba(234, 179, 8, 0.3);
}

.rules-card {
  text-align: left;
  align-items: flex-start;
}

.rules-card h2 {
  align-self: center;
}

.rules-card button {
  align-self: center;
  margin-top: 6px;
}

.rules-list {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #cbd5e1;
}

.rules-list ul {
  margin-top: 4px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---- Big-screen scaling (see src/ui/uiScale.js) ----
   `zoom` keeps layout and hit-testing consistent (unlike transform: scale).
   Viewport-relative limits are divided by the scale so zoomed panels still fit. */
.home-card,
.modal-card,
.name-kb-card,
.power-hud-overlay,
.spin-hud-overlay {
  zoom: var(--ui-scale, 1);
}
.home-card {
  max-width: calc(96vw / var(--ui-scale, 1));
  max-height: calc(94vh / var(--ui-scale, 1));
}
.hud-top,
.hud-bottom {
  zoom: var(--ui-scale, 1);
}

/* TV / console: focus must be obvious from across the room */
.tv-mode .focused {
  outline: 3px solid rgba(250, 204, 21, 0.9);
  outline-offset: 3px;
}
.tv-mode .home-pad-hint,
.tv-mode .pause-footer-hint {
  font-size: 14px;
}

/* =======================================================================
   MENU ROWS (home + pause) — big rows, clear gold focus for TV / Xbox
   ======================================================================= */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
/* Tabs on top of a menu (Juego · Mesa), switched with LB / RB:
   a segmented control on a dark rail, the active tab in gold */
.menu-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 2px auto 6px;
  width: 100%;
}
.menu-tabs-rail {
  display: flex;
  flex: 1;
  max-width: 320px;
  padding: 4px;
  gap: 4px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid rgba(251, 191, 36, 0.22);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.04);
}
.menu-tab {
  flex: 1;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #94a3b8;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.menu-tab:hover {
  color: #e2e8f0;
}
.menu-tab.active {
  color: #1c1405;
  background: linear-gradient(180deg, #fde68a 0%, #fbbf24 55%, #d97706 100%);
  box-shadow: 0 2px 10px rgba(251, 191, 36, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.menu-tab-icon {
  margin-right: 6px;
}
.menu-tab-key {
  flex: none;
  opacity: 0.85;
}
body.touch-device .menu-tab-key {
  display: none;
}
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 8px 14px 8px 18px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
  -webkit-user-select: none;
  user-select: none;
}
.menu-row.hidden {
  display: none;
}
.menu-row:hover {
  background: rgba(255, 255, 255, 0.07);
}
.menu-row.focused {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.1);
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.18), 0 6px 18px rgba(0, 0, 0, 0.35);
}
.menu-label {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.menu-choice {
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 170px;
  font-size: 16px;
  font-weight: 700;
  color: #fde68a;
}
.menu-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 23, 42, 0.6);
  color: #cbd5e1;
  font-size: 13px;
  cursor: pointer;
}
.menu-row.focused .menu-arrow {
  color: #fde047;
  border-color: rgba(250, 204, 21, 0.6);
}
.menu-mini-table.felt-swatch {
  width: 34px;
  height: 22px;
  border-width: 4px;
  border-radius: 5px;
  outline: none;
  transform: none;
  cursor: inherit;
}
/* Main action (Jugar) */
.menu-row.menu-primary {
  justify-content: center;
  min-height: 58px;
  margin-top: 6px;
  background: linear-gradient(180deg, #facc15, #ca8a04);
  border-color: #fde68a;
  color: #1c1917;
}
.menu-row.menu-primary .menu-label {
  font-size: 20px;
  font-weight: 900;
}
.menu-row.menu-primary.focused {
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.35), 0 8px 22px rgba(250, 204, 21, 0.35);
  transform: scale(1.01);
}
/* Actions that ask for a second press */
.menu-row.confirming {
  border-color: #f87171;
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
}
.menu-row.menu-danger .menu-label {
  color: #fca5a5;
}
.menu-row.menu-danger.confirming .menu-label {
  color: #fecaca;
}

/* Narrow screens (phones): rows must fit without cutting the ▶ arrow */
@media (max-width: 560px) {
  .home-card {
    padding: 18px 14px 16px;
    gap: 12px;
  }
  .home-title {
    font-size: 30px;
    white-space: nowrap;
  }
  .menu-row {
    min-height: 46px;
    padding: 6px 8px 6px 12px;
    gap: 6px;
  }
  .menu-label {
    font-size: 14px;
    white-space: nowrap;
  }
  .menu-choice {
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
    gap: 4px;
  }
  .menu-value {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .menu-arrow {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
  }
  .menu-row.menu-primary .menu-label {
    font-size: 18px;
  }
}
@media (max-width: 400px) {
  .menu-mini-table {
    display: none !important;
  }
}

/* =======================================================================
   PHONES & TABLETS
   ======================================================================= */

/* Phone upright (narrow): controls wrap, compact names and bubbles */
@media (max-width: 560px) {
  .app {
    padding: 6px 8px;
    gap: 6px;
  }
  .player-name {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 30vw;
  }
  .hud-bottom {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 10px;
  }
  .hud-bottom .power-control {
    flex: 1 1 100%;
  }
  .banter-bubble {
    max-width: 72vw;
  }
  .banter-text {
    font-size: 14px !important;
    padding: 7px 11px !important;
  }
  .banter-avatar {
    width: 44px !important;
    height: 44px !important;
  }
}
/* Touch devices held upright (iPad / phone): ask to turn sideways */
.rotate-screen {
  display: none;
}
@media (orientation: portrait) {
  body.touch-device .rotate-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: radial-gradient(circle at 50% 40%, #1a2232, #0a0e15);
    color: #fde68a;
    text-align: center;
    padding: 24px;
  }
  body.touch-device .rotate-icon {
    font-size: 56px;
    animation: rotateHint 1.8s ease-in-out infinite;
  }
  body.touch-device .rotate-title {
    font-size: 22px;
    font-weight: 900;
  }
  body.touch-device .rotate-sub {
    font-size: 14px;
    color: #cbd5e1;
  }
}
@keyframes rotateHint {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

/* Phone sideways (short screen): one compact strip on top, compact
   controls below, so the table gets almost all the height */
@media (max-height: 520px) and (orientation: landscape) {
  .app {
    padding: 4px 10px;
    gap: 4px;
  }
  .app .hud-top {
    grid-template-columns: 1fr minmax(220px, 280px) 1fr;
    zoom: 0.7;
  }
  .app .hud-top .center-scoreboard {
    grid-column: auto;
    order: 0;
    width: auto;
  }
  .hud-bottom {
    zoom: 0.72;
    padding: 4px 12px;
  }
  .banter-text {
    font-size: 14px !important;
    padding: 6px 10px !important;
  }
  .banter-avatar {
    width: 40px !important;
    height: 40px !important;
  }
}

/* Pause card wide enough for "Pantalla completa ◀ Desactivada ▶" */
.pause-modal-card {
  width: min(480px, 94vw);
}
.menu-label {
  white-space: nowrap;
}

/* A small portrait next to a menu value (Tu jugador, Compañero) */
.menu-mini-face {
  display: inline-block;
  width: 30px;
  height: 30px;
  margin-right: 8px;
  border-radius: 50%;
  border: 1.5px solid rgba(251, 191, 36, 0.55);
  background-color: #0f172a;
  vertical-align: middle;
  flex: none;
}
.menu-row[data-row="torneoEnCurso"] .menu-label {
  color: #7dd3fc;
}

/* ---- Controls guide: platforms, trigger roles, PlayStation look --------- */
.pad-platforms {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 4px;
  padding: 0;
  list-style: none;
}
.pad-platforms li {
  display: grid;
  gap: 2px;
  min-width: 150px;
  max-width: 220px;
  padding: 7px 12px;
  border: 1px solid rgba(214, 182, 76, 0.22);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(214, 182, 76, 0.1), rgba(214, 182, 76, 0.03));
  text-align: left;
}
.pad-platforms b { color: #f3d98a; font-size: 12px; letter-spacing: 0.6px; }
.pad-platforms span { color: #b4c0ca; font-size: 11px; line-height: 1.35; }
.pad-svg-tag {
  fill: #f3d98a;
  font: 900 9px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 1.4px;
  text-anchor: middle;
}
/* The two triggers glow softly: LT = this guide, RT = spin */
.pad-trigger-lt, .pad-trigger-rt { animation: padTriggerGlow 2.4s ease-in-out infinite; }
.pad-trigger-rt { animation-delay: 1.2s; }
@keyframes padTriggerGlow {
  0%, 100% { stroke: #87939d; }
  50% { stroke: #f3d98a; }
}
@media (prefers-reduced-motion: reduce) {
  .pad-trigger-lt, .pad-trigger-rt { animation: none; }
}
/* PlayStation: its own face-button colours (△ ○ □ ✕) */
[data-pad-family="ps"] .pad-face-buttons circle:nth-of-type(1) { fill: #3fb68b; stroke: #c3f2df; }
[data-pad-family="ps"] .pad-face-buttons circle:nth-of-type(2) { fill: #e2555f; stroke: #ffc4c8; }
[data-pad-family="ps"] .pad-face-buttons circle:nth-of-type(3) { fill: #d47ac8; stroke: #f6cdef; }
[data-pad-family="ps"] .pad-face-buttons circle:nth-of-type(4) { fill: #5b8fe0; stroke: #c9dcff; }
/* Badges follow the controller in use: PlayStation shapes keep their own
   colours (✕ blue, ○ red, □ pink, △ green); Switch letters are neutral */
[data-pad-family="ps"] .pad-key.key-a { background: #3d6fc4; border-color: #a9c6f5; color: #fff; }
[data-pad-family="ps"] .pad-key.key-b { background: #c4434d; border-color: #f5b2b7; color: #fff; }
[data-pad-family="ps"] .pad-key.key-x { background: #b45aa8; border-color: #efc2e8; color: #fff; }
[data-pad-family="ps"] .pad-key.key-y { background: #2f9a72; border-color: #aee8d1; color: #fff; }
[data-pad-family="switch"] .pad-key.key-a,
[data-pad-family="switch"] .pad-key.key-b,
[data-pad-family="switch"] .pad-key.key-x,
[data-pad-family="switch"] .pad-key.key-y { background: #39434e; border-color: #9aa7b3; color: #f1f5f9; }
[data-pad-family="switch"] .pad-face-buttons circle { fill: #3a4450; stroke: #aab6c1; }

/* ---- New version ready (src/pwa.js) -------------------------------------- */
.update-bar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 16px;
  border: 1px solid rgba(243, 217, 138, 0.45);
  border-radius: 999px;
  background: rgba(12, 18, 27, 0.94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color: #f3e7c0;
  font-size: 13px;
  font-weight: 700;
  transform: translateX(-50%);
  animation: updateBarIn 0.4s ease-out both;
}
.update-bar.hidden { display: none; }
@keyframes updateBarIn {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translateX(-50%); }
}
/* View / Menu (Create / Options, − / +): small labels that never collide */
.pad-svg-small { font-size: 8.5px; letter-spacing: 0.2px; }

/* "Gira tu dispositivo": also the way to install it on a phone */
.rotate-install { margin-top: 22px; display: grid; gap: 10px; justify-items: center; }
.rotate-install[hidden], .rotate-install [hidden] { display: none; }
.rotate-install-ios { color: #cbd5e1; font-size: 14px; }
.rotate-install-ios b { color: #fef08a; }
