*, *::before, *::after { box-sizing: border-box; }
    :root {
      --bg: #0b0f1c;
      --panel: rgba(20, 26, 42, 0.92);
      --accent: #5dd1ff;
      --muted: #a2b0c7;
      --text: #f3f6ff;
      --button-base: rgba(8, 12, 24, 0.92);
      --button-border: rgba(93, 209, 255, 0.38);
      --button-glow: rgba(93, 209, 255, 0.45);
      --button-shadow: rgba(4, 8, 20, 0.6);
    }
    html, body {
      margin: 0;
      height: 100%;
      font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
      background: radial-gradient(circle at top, rgba(93,209,255,0.1), transparent 55%), var(--bg);
      color: var(--text);
      overflow: hidden;
      width: 100%;
    }
    html { scrollbar-width: none; }
    html::-webkit-scrollbar,
    body::-webkit-scrollbar {
      width: 0;
      height: 0;
      display: none;
    }
    #game-root {
      position: relative;
      display: grid;
      place-items: center;
      width: 100vw;
      height: 100vh;
      min-height: 100vh;
      /* Gameplay wallpaper with subtle dimming and vignette to avoid distraction */
      background-image:
        radial-gradient(ellipse at center, rgba(0,0,0,0) 40%, rgba(0,0,0,0.28) 100%),
        linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),
        url('../UI/gameplay_background.png');
      background-blend-mode: normal, multiply, normal;
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }

    /* Ensure the Phaser canvas stays perfectly centered */
    #game-root canvas {
      display: block;
      /* Absolute + inset + auto margins centers both axes reliably */
      position: absolute !important;
      inset: 0;
      margin: auto;
      /* Respect the container bounds */
      max-width: 100%;
      max-height: 100%;
    }

    .loading-overlay {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(5, 10, 22, 0.88);
      z-index: 60;
      transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    .loading-overlay.hidden {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }
    .loading-panel {
      width: min(480px, 90vw);
      padding: clamp(28px, 6vw, 42px);
      border-radius: 26px;
      background: linear-gradient(145deg, rgba(16, 24, 46, 0.96), rgba(10, 16, 34, 0.9));
      border: 1px solid rgba(93, 209, 255, 0.2);
      box-shadow: 0 28px 68px rgba(6, 12, 28, 0.6);
      display: grid;
      gap: 18px;
      text-align: center;
    }
    .loading-title {
      font-size: clamp(18px, 3.5vw, 22px);
      letter-spacing: 0.18rem;
      text-transform: uppercase;
      color: var(--text);
    }
    .loading-progress {
      display: flex;
      align-items: center;
      gap: 14px;
      justify-content: center;
    }
    .loading-progress-bar {
      position: relative;
      width: min(320px, 70vw);
      height: 14px;
      border-radius: 999px;
      background: rgba(93, 209, 255, 0.16);
      overflow: hidden;
    }
    .loading-progress-fill {
      position: absolute;
      inset: 0;
      width: 0%;
      border-radius: inherit;
      background: linear-gradient(90deg, rgba(93, 209, 255, 0.95), rgba(132, 255, 220, 0.95));
      transition: width 0.25s ease;
    }
    .loading-percent {
      min-width: 64px;
      font-size: 18px;
      font-variant-numeric: tabular-nums;
      color: var(--accent);
      text-align: right;
    }
    .loading-tips {
      margin: 0;
      padding: 0;
      list-style: none;
      display: grid;
      gap: 8px;
      text-align: left;
      color: var(--muted);
      font-size: 14px;
      line-height: 1.6;
    }
    .loading-tips li {
      opacity: 0;
      transform: translateY(8px);
      transition: opacity 0.3s ease, transform 0.3s ease;
    }
    .loading-tips li.visible {
      opacity: 1;
      transform: translateY(0);
    }

    /* Busy spinner overlay shown during Play -> Game transition */
    .busy-overlay {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      background: rgba(5, 10, 22, 0.72);
      z-index: 70;
      transition: opacity 0.25s ease, visibility 0.25s ease;
    }
    .busy-overlay.hidden {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }
    .busy-panel {
      display: grid;
      justify-items: center;
      gap: 12px;
      padding: 18px 22px;
      border-radius: 16px;
      background: rgba(12, 16, 28, 0.9);
      border: 1px solid rgba(93, 209, 255, 0.18);
      box-shadow: 0 18px 38px rgba(5, 10, 24, 0.55);
    }
    .busy-spinner {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      border: 4px solid rgba(255, 255, 255, 0.16);
      border-top-color: var(--accent);
      animation: busyspin 0.9s linear infinite;
    }
    .busy-text {
      font-size: 14px;
      color: var(--muted);
      letter-spacing: 0.04rem;
    }
    @keyframes busyspin { to { transform: rotate(360deg); } }

    /* Setup overlay */
    #setup {
      position: absolute;
      inset: 0;
      z-index: 5; /* stay above Phaser canvas */
      padding: clamp(32px, 8vh, 80px) clamp(16px, 4vw, 32px);
      overflow: hidden;
      background-image: url('../UI/main_menu_background.png');
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      /* Ensure the wallpaper reads through the UI */
      background-color: transparent;
    }
    #setup::before {
      content: '';
      position: absolute;
      inset: 0;
      /* Remove dark overlay so the wallpaper is fully visible */
      background: none;
      opacity: 0;
      pointer-events: none;
      z-index: 0;
    }
    /* Gentle brightening so the wallpaper reads even on darker displays */
    #setup::after {
      content: '';
      position: absolute;
      inset: 0;
      background:
        radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.08), transparent 60%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
      pointer-events: none;
      z-index: 0;
    }
    #setup .setup-container {
      height: 100%;
    }
    .menu-shell {
      position: relative;
      z-index: 1;
      width: min(840px, 94vw);
      max-width: 840px;
      max-height: min(92vh, 860px);
      /* Show wallpaper fully; rely on blur + button panels for readability */
      background: transparent;
      border: 1px solid rgba(93,209,255,0.18);
      border-radius: 28px;
      padding: clamp(28px, 6vw, 44px);
      /* Softer shadow so it doesn't look like a giant dark box */
      box-shadow: 0 12px 26px rgba(5, 10, 24, 0.28);
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: clamp(28px, 5vw, 40px);
      margin: 0 auto;
      text-align: center;
      overflow: hidden;
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }
    .menu-shell::before {
      content: '';
      position: absolute;
      inset: -40px;
      background: radial-gradient(circle at top, rgba(93, 209, 255, 0.12), transparent 70%);
      opacity: 1;
      pointer-events: none;
    }
    .menu-shell::-webkit-scrollbar { display: none; }
    .menu-shell.showing-pane {
      gap: clamp(24px, 5vw, 36px);
    }
    .menu-header {
      text-align: center;
      display: grid;
      gap: 8px;
      justify-items: center;
      position: relative;
    }
    .menu-logo {
      display: inline-block;
      margin: 0;
      font-size: clamp(32px, 6vw, 48px);
      font-weight: 800;
      letter-spacing: 0.28rem;
      text-transform: uppercase;
      color: transparent;
      background: linear-gradient(120deg, #5dd1ff, #c9f1ff 55%, #f5d8ff);
      -webkit-background-clip: text;
      background-clip: text;
      text-shadow: 0 14px 30px rgba(5, 10, 24, 0.6);
    }
    .mode-label {
      display: inline-flex;
      align-items: center;
      min-height: 24px;
      padding: 4px 10px;
      border-radius: 999px;
      border: 1px solid rgba(93, 209, 255, 0.24);
      background: rgba(8, 12, 24, 0.42);
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 0.08rem;
      text-transform: uppercase;
    }
    .menu-buttons {
      width: min(540px, 100%);
      display: grid;
      gap: 16px;
    }
    .is-hidden { display: none !important; }
    .menu-button {
      appearance: none;
      position: relative;
      border: 1px solid var(--button-border);
      background: linear-gradient(145deg, var(--button-base), rgba(16, 28, 50, 0.96));
      color: var(--text);
      border-radius: 20px;
      padding: 18px 24px 18px 60px;
      font-size: 18px;
      font-weight: 700;
      letter-spacing: 0.08rem;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      text-align: left;
      gap: 12px;
      box-shadow: 0 20px 40px var(--button-shadow), 0 0 0 1px rgba(255, 255, 255, 0.03);
      backdrop-filter: blur(18px);
    }
    .menu-button::before {
      content: '';
      position: absolute;
      left: 20px;
      top: 50%;
      transform: translateY(-50%);
      width: 26px;
      height: 26px;
      background-repeat: no-repeat;
      background-position: center;
      background-size: contain;
      opacity: 0.95;
      transition: transform 0.15s ease, opacity 0.15s ease;
      pointer-events: none;
      filter: drop-shadow(0 0 8px var(--button-glow));
    }
    .menu-button[data-pane="match"]::before { background-image: url('../UI/Icons/shield_icon.png'); }
    .menu-button[data-pane="arena"]::before { background-image: url('../UI/Icons/arena_icon.png'); }
    .menu-button[data-pane="settings"]::before { background-image: url('../UI/Icons/settings_icon.png'); }
    .menu-button[data-pane="help"]::before { background-image: url('../UI/Icons/help_icon.png'); }
    .menu-button:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 3px;
    }
    .menu-button:hover {
      transform: translateY(-2px);
      border-color: rgba(93, 209, 255, 0.75);
      box-shadow: 0 14px 30px var(--button-shadow), 0 0 20px rgba(93, 209, 255, 0.35);
    }
    .menu-button.active {
      background: linear-gradient(145deg, rgba(93, 209, 255, 0.14), rgba(15, 26, 56, 0.98));
      border-color: rgba(93, 209, 255, 0.85);
      box-shadow: 0 22px 42px var(--button-shadow), 0 0 18px rgba(93, 209, 255, 0.35);
    }
    .menu-button:hover::before,
    .menu-button.active::before {
      transform: translateY(-50%) scale(1.08);
      opacity: 1;
    }

    .menu-panel {
      width: 100%;
      max-width: 100%;
      display: none;
      gap: 18px;
      justify-items: center;
      margin: 0 auto;
      padding: 0;
      background: transparent;
      border: none;
      box-shadow: none;
      overflow: visible;
    }
    .menu-panel.active { display: grid; }
    .menu-panel::-webkit-scrollbar { display: none; }
    .menu-panel[data-pane="help"] {
      align-content: start;
      overflow-x: hidden;
      overflow-y: auto;
      max-height: calc(80vh - 220px);
      padding-right: 4px;
    }
    .menu-panel[data-pane="help"]::-webkit-scrollbar {
      width: 8px;
    }
    .menu-panel[data-pane="help"]::-webkit-scrollbar-thumb {
      background: linear-gradient(180deg, rgba(93, 209, 255, 0.4), rgba(93, 209, 255, 0.15));
      border-radius: 999px;
    }
    .pane-title {
      font-size: 22px;
      font-weight: 700;
      letter-spacing: 0.1rem;
      text-align: center;
      text-transform: uppercase;
    }
    .pane-subtitle {
      font-size: 13px;
      color: var(--muted);
      text-align: center;
    }

    /* Settings tabs (Sound / Screen) */
    .settings-tabs {
      display: inline-flex;
      gap: 8px;
      padding: 8px;
      border-radius: 14px;
      background: rgba(15, 18, 30, 0.6);
      border: 1px solid #2a3046;
    }
    .settings-tab-btn {
      appearance: none;
      border: 1px solid rgba(255, 255, 255, 0.15);
      background: rgba(14, 18, 32, 0.7);
      color: var(--text);
      padding: 10px 26px;
      border-radius: 999px;
      font-weight: 700;
      letter-spacing: 0.08rem;
      cursor: pointer;
      transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    }
    .settings-tab-btn:hover {
      transform: translateY(-1px);
      background: rgba(18, 26, 48, 0.88);
      box-shadow: inset 0 0 0 1px rgba(93, 209, 255, 0.25), 0 10px 30px rgba(1, 4, 12, 0.6);
    }
    .settings-tab-btn:focus-visible {
      outline: 3px solid rgba(93, 209, 255, 0.9);
      outline-offset: 3px;
    }
    .settings-tab-btn.active {
      background: linear-gradient(135deg, rgba(93, 209, 255, 0.95), rgba(76, 146, 243, 0.9));
      color: #021220;
      border-color: rgba(255, 255, 255, 0.35);
      box-shadow: 0 14px 32px rgba(5, 11, 27, 0.55), 0 0 26px rgba(93, 209, 255, 0.35);
    }

    .settings-section { width: 100%; display: grid; gap: 14px; justify-items: center; }
    .settings-section[hidden] { display: none !important; }

    /* Toggle switch for fullscreen */
    .switch-group { display: grid; gap: 8px; justify-items: center; }
    .switch {
      --w: 56px; --h: 30px;
      position: relative;
      display: inline-flex;
      align-items: center;
      gap: 10px;
      cursor: pointer;
      user-select: none;
    }
    .switch input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
    .switch-slider {
      position: relative;
      width: var(--w);
      height: var(--h);
      border-radius: 999px;
      background: #20263a;
      border: 1px solid #2a3046;
      transition: background .15s ease, border-color .15s ease;
    }
    .switch-slider::after {
      content: '';
      position: absolute;
      top: 50%; left: 4px;
      width: calc(var(--h) - 8px);
      height: calc(var(--h) - 8px);
      border-radius: 50%;
      background: linear-gradient(180deg, #eaf6ff, #c7e9ff);
      box-shadow: 0 4px 10px rgba(5, 10, 24, 0.45);
      transform: translate(0, -50%);
      transition: transform .18s ease;
    }
    .switch input[type="checkbox"]:checked + .switch-slider {
      background: rgba(93,209,255,0.22);
      border-color: rgba(93,209,255,0.5);
    }
    .switch input[type="checkbox"]:checked + .switch-slider::after {
      transform: translate(calc(var(--w) - var(--h)), -50%);
    }
    .switch-state { font-size: 12px; color: var(--muted); min-width: 28px; text-align: left; }

    .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
    .field, select, input[type="range"] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #2a3046; background: #0f111a; color: var(--text); }
    .field-group { display: grid; gap: 6px; justify-items: center; }
    .field-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
    .range-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
    .slider-group { display: grid; gap: 6px; }
    .vol-cycler {
      appearance: none;
      border: 1px solid rgba(255, 255, 255, 0.2);
      background: linear-gradient(145deg, rgba(26, 36, 58, 0.95), rgba(9, 12, 24, 0.95));
      color: var(--text);
      border-radius: 16px;
      padding: 14px 30px;
      font-size: 16px;
      font-weight: 700;
      letter-spacing: 0.08rem;
      min-width: 160px;
      box-shadow: 0 16px 30px rgba(4, 9, 24, 0.8);
      text-transform: uppercase;
      transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    }
    .vol-cycler:hover {
      transform: translateY(-1px);
      border-color: rgba(93, 209, 255, 0.7);
      background: linear-gradient(145deg, rgba(46, 72, 122, 0.9), rgba(10, 14, 28, 0.95));
      box-shadow: 0 20px 40px rgba(4, 9, 24, 0.85);
    }
    .vol-cycler:focus-visible {
      outline: 3px solid rgba(93, 209, 255, 0.85);
      outline-offset: 4px;
    }
    .slider-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
    .pill { padding: 4px 10px; border-radius: 999px; background: rgba(93,209,255,0.12); border: 1px solid #2a3046; display: inline-flex; align-items: center; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
    .small { font-size: 12px; color: var(--muted); }

    .match-layout { display: grid; gap: 28px; justify-items: center; width: 100%; max-width: 100%; margin: 0 auto; }
    .count-control { display: grid; gap: 10px; justify-items: center; text-align: center; }
    .size-stepper { display: inline-flex; align-items: center; gap: 14px; padding: 10px 16px; border-radius: 14px; border: 1px solid #252c42; background: rgba(15,18,30,0.92); box-shadow: inset 0 0 0 1px rgba(93,209,255,0.06); margin: 0 auto; }
    .step-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid #2a3046; background: #121726; color: var(--text); font-size: 24px; font-weight: 700; display: grid; place-items: center; cursor: pointer; transition: background .15s ease, transform .15s ease; }
    .step-btn:hover { background: #1b2236; transform: translateY(-1px); }
    .step-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
    .step-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
    .step-btn:disabled:hover { background: #121726; transform: none; }
    .step-value { min-width: 52px; text-align: center; font-size: 28px; font-weight: 800; letter-spacing: 0.04rem; }

    .match-hub,
    .team-pane {
      width: 100%;
      max-width: 100%;
      display: grid;
      gap: 24px;
      justify-items: center;
    }
    .match-hub {
      text-align: center;
    }
    .match-hub[hidden],
    .team-pane[hidden] {
      display: none !important;
    }
    .team-hub-buttons {
      width: 100%;
      display: flex;
      justify-content: center;
      gap: 16px;
      flex-wrap: wrap;
    }
    .team-pane-btn {
      flex: 1 1 220px;
      max-width: 260px;
      padding: 18px 24px;
      border-radius: 16px;
      border: 1px solid rgba(255,255,255,0.18);
      background: rgba(16, 21, 36, 0.9);
      color: var(--text);
      font-size: 18px;
      font-weight: 700;
      letter-spacing: 0.06rem;
      cursor: pointer;
      display: grid;
      gap: 6px;
      justify-items: center;
      transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
      text-transform: uppercase;
    }
    .team-pane-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 10px 24px rgba(3, 9, 24, 0.45);
      background: rgba(25, 32, 52, 0.95);
    }
    .team-pane-btn:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 3px;
    }
    .team-pane-btn .team-pane-btn-name {
      font-size: 20px;
      font-weight: 800;
      letter-spacing: 0.08rem;
    }
    .team-pane-btn.active {
      background: rgba(45, 58, 92, 0.95);
      border-color: rgba(93,209,255,0.4);
      box-shadow: 0 14px 28px rgba(5, 13, 30, 0.5);
    }
    .team-pane {
      text-align: center;
    }
    .team-pane .field-group {
      width: min(320px, 100%);
    }
    .team-pane .field-group .field {
      text-align: center;
    }
    .team-roster {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
      width: 100%;
      margin: 0 auto;
      min-width: 0;
      --card-gap: 16px;
    }
    .team-roster-body {
      --nav-size: 44px;
      --body-gap: 16px;
      display: grid;
      grid-template-columns: var(--nav-size) 1fr var(--nav-size);
      align-items: center;
      justify-items: center;
      gap: var(--body-gap);
      width: 100%;
      max-width: 100%;
      margin: 0 auto;
    }
    .roster-nav { width: var(--nav-size); height: var(--nav-size); border-radius: 14px; border: 1px solid #2a3046; background: rgba(15,17,26,0.7); color: var(--text); font-size: 20px; font-weight: 700; display: grid; place-items: center; cursor: pointer; transition: background .15s ease, transform .15s ease, opacity .15s ease; }
    .roster-nav:hover:not(:disabled) { background: rgba(28,34,54,0.95); transform: translateY(-1px); }
    .roster-nav:disabled { opacity: 0.35; cursor: not-allowed; }
    .roster-nav:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
    .roster-window {
      width: 100%;
      min-width: 0;
      overflow: hidden;
    }
    .roster-track { display: flex; gap: var(--card-gap); transform: translateX(0); transition: transform .25s ease; width: 100%; }
    .player-card {
      position: relative;
      flex: 0 0 calc((100% - var(--card-gap) * 2) / 3);
      max-width: calc((100% - var(--card-gap) * 2) / 3);
      min-width: 140px;
      border-radius: 22px;
      padding: 22px 20px;
      display: grid;
      gap: 18px;
      justify-items: center;
      text-align: center;
      background: linear-gradient(160deg, rgba(23, 31, 52, 0.88), rgba(11, 15, 30, 0.72));
      border: 1px solid rgba(93, 209, 255, 0.22);
      box-shadow: 0 26px 46px rgba(5, 11, 24, 0.4);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      isolation: isolate;
      overflow: hidden;
    }
    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
      .player-card { background: linear-gradient(160deg, rgba(23, 31, 52, 0.92), rgba(11, 15, 30, 0.86)); }
    }
    .player-card::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 22px;
      background: radial-gradient(circle at top, rgba(93,209,255,0.18), transparent 70%);
      opacity: 0.7;
      pointer-events: none;
    }
    .character-portrait {
      position: relative;
      width: min(144px, calc(100% - 8px));
      height: min(144px, calc(100% - 8px));
      border-radius: 28px;
      display: grid;
      place-items: center;
      background: radial-gradient(circle at 30% 18%, rgba(93,209,255,0.15), transparent 70%), rgba(12, 18, 30, 0.92);
      box-shadow: 0 24px 42px rgba(5,12,30,0.45);
      border: 2px solid rgba(93,209,255,0.32);
      overflow: hidden;
    }
    .character-portrait[data-attack-style="melee"] { border-color: rgba(255, 163, 102, 0.45); }
    .character-portrait[data-attack-style="ranged"] { border-color: rgba(125, 196, 255, 0.45); }
    .character-portrait img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transform: none;
      filter: drop-shadow(0 18px 28px rgba(5, 12, 24, 0.35));
    }
    .portrait-fallback {
      font-size: 48px;
      color: rgba(243,246,255,0.85);
      text-shadow: 0 8px 20px rgba(5, 12, 24, 0.6);
    }
    .player-card-body { position: relative; z-index: 1; display: grid; gap: 12px; width: 100%; }
    .team-tag {
      font-size: 12px;
      letter-spacing: 0.08rem;
      text-transform: uppercase;
      color: #d4e7ff;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      min-height: 32px;
      padding: 6px 12px;
      white-space: nowrap;
      overflow: hidden;
      transition: font-size .15s ease;
      background: rgba(12, 18, 30, 0.72);
      border: 1px solid rgba(93,209,255,0.22);
      border-radius: 999px;
    }
    .team-tag.size-sm { font-size: 11px; }
    .team-tag.size-xs { font-size: 10.5px; }
    .team-tag.size-xxs { font-size: 10px; }
    .team-tag.size-xxxs { font-size: 9.5px; }
    .player-card .field { text-align: center; font-weight: 600; }
    .legend-line {
      font-size: 12px;
      line-height: 1.35;
      color: var(--muted);
      margin: 6px 0 8px;
      min-height: 1em;
    }
    .attack-chip {
      font-size: 12px;
      letter-spacing: 0.04rem;
      text-transform: uppercase;
      padding: 4px 12px;
      border-radius: 999px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      font-weight: 600;
      background: rgba(93,209,255,0.18);
      color: #d8ecff;
    }
    .attack-chip.attack-melee { background: rgba(255, 163, 102, 0.2); color: #ffe2cd; }
    .attack-chip.attack-ranged { background: rgba(125, 196, 255, 0.22); color: #dff2ff; }
    .player-name-row {
      width: 100%;
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto;
      align-items: center;
      gap: 12px;
    }
    .player-name-row .field { width: 100%; }
    .char-arrow { width: 38px; height: 38px; border-radius: 50%; border: 1px solid #2a3046; background: #13192a; color: var(--text); font-size: 18px; display: grid; place-items: center; cursor: pointer; transition: background .15s ease, transform .15s ease; }
    .char-arrow:hover { background: #1d243a; transform: translateY(-1px); }
    .char-arrow:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
    @media (max-width: 640px) {
      .team-roster { --card-gap: 12px; }
      .team-roster-body {
        --nav-size: 38px;
        --body-gap: 12px;
        width: 100%;
        max-width: 480px;
      }
      .player-card { min-width: 0; }
    }

.quick-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
/* Position quick actions at top of team pane */
.team-pane .quick-actions.top { margin: 12px 0 16px; }
/* Hide old footer container now that actions moved up */
.team-pane-footer { display: none !important; }
/* Inline controls row: [Go To Team] [Team Name] [Randomize] */
.team-controls-row {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  justify-content: center;
  margin: 12px 0 16px;
}
.team-controls-row .action-btn { white-space: nowrap; }
.team-controls-row .field-group { width: min(360px, 100%); }
    .team-pane-footer {
      width: 100%;
      display: flex;
      justify-content: center;
    }
    .team-pane-footer .quick-actions {
      width: 100%;
      justify-content: center;
      flex-wrap: nowrap;
    }
    .action-btn {
      user-select: none;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      gap: 8px;
      padding: 14px 26px;
      border-radius: 18px;
      background: linear-gradient(135deg, rgba(93, 209, 255, 0.95), rgba(47, 116, 217, 0.95));
      color: #041016;
      font-weight: 700;
      border: none;
      cursor: pointer;
      box-shadow: 0 16px 36px rgba(93, 209, 255, 0.35);
      transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    }
    .action-btn:hover:not(:disabled) {
      transform: translateY(-1px);
      box-shadow: 0 20px 40px rgba(76, 162, 255, 0.45);
    }
    .action-btn.secondary {
      background: rgba(13, 17, 29, 0.85);
      border: 1px solid rgba(255, 255, 255, 0.2);
      color: var(--text);
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 12px 24px rgba(5, 7, 16, 0.5);
    }
    .action-btn.ghost {
      background: rgba(11, 13, 24, 0.55);
      border: 1px solid rgba(255, 255, 255, 0.12);
      color: var(--text);
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(14px);
    }
    .action-btn.danger { background: #ff6b6b; color: #230606; }
    .action-btn.danger:hover:not(:disabled) { box-shadow: 0 12px 30px rgba(255, 107, 107, 0.45); }
    .action-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }

    .arena-carousel {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 18px;
      flex-wrap: wrap;
      row-gap: 14px;
    }
    .arena-nav {
      width: 52px;
      height: 52px;
      border-radius: 50%;
      border: 1px solid rgba(93,209,255,0.24);
      background: rgba(15, 20, 36, 0.92);
      color: var(--text);
      font-size: 24px;
      font-weight: 700;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
      flex-shrink: 0;
    }
    .arena-nav:hover,
    .arena-nav:focus-visible {
      border-color: rgba(93,209,255,0.6);
      background: rgba(20, 30, 52, 0.95);
      box-shadow: 0 18px 32px rgba(5, 12, 30, 0.45);
    }
    .arena-nav:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
    .arena-card {
      position: relative;
      display: grid;
      gap: 12px;
      padding: 18px;
      border-radius: 20px;
      border: 1px solid rgba(93,209,255,0.14);
      background: linear-gradient(150deg, rgba(16, 24, 42, 0.9), rgba(9, 14, 28, 0.9));
      color: var(--text);
      cursor: pointer;
      box-shadow: 0 18px 32px rgba(5, 12, 30, 0.45);
      transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
      text-align: center;
      justify-items: center;
      font-family: inherit;
      border: none;
      min-width: min(320px, 70vw);
      max-width: min(420px, 80vw);
      flex: 1;
      overflow: hidden;
      isolation: isolate;
    }
    .arena-card::after {
      content: '';
      position: absolute;
      inset: 2px;
      border-radius: inherit;
      background: linear-gradient(120deg, rgba(93,209,255,0.3), rgba(255,255,255,0.06));
      opacity: 0;
      transform: translateX(-130%) skewX(-10deg);
      filter: blur(0.8px);
      pointer-events: none;
      z-index: 1;
    }
    .arena-card:hover {
      transform: translateY(-4px);
      box-shadow: 0 24px 38px rgba(5, 12, 30, 0.55);
    }
    .arena-card.active {
      border-color: rgba(93,209,255,0.5);
      box-shadow: 0 28px 44px rgba(5, 12, 30, 0.6);
    }
    .arena-card:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 4px;
    }
    .arena-card .arena-thumb,
    .arena-card .arena-name,
    .arena-card .arena-status {
      position: relative;
      z-index: 2;
    }
    .arena-card.arena-transitioning .arena-thumb,
    .arena-card.arena-transitioning .arena-name,
    .arena-card.arena-transitioning .arena-status {
      will-change: transform, opacity, filter;
    }
    .arena-card.arena-swap-out .arena-thumb,
    .arena-card.arena-swap-out .arena-name,
    .arena-card.arena-swap-out .arena-status {
      animation: arenaCardFadeOut .18s cubic-bezier(0.4,0,0.2,1) forwards;
    }
    .arena-card.arena-swap-out.arena-dir-next .arena-thumb,
    .arena-card.arena-swap-out.arena-dir-next .arena-name,
    .arena-card.arena-swap-out.arena-dir-next .arena-status {
      animation: arenaCardSlideOutNext .22s cubic-bezier(0.37,0,0.63,1) forwards;
    }
    .arena-card.arena-swap-out.arena-dir-prev .arena-thumb,
    .arena-card.arena-swap-out.arena-dir-prev .arena-name,
    .arena-card.arena-swap-out.arena-dir-prev .arena-status {
      animation: arenaCardSlideOutPrev .22s cubic-bezier(0.37,0,0.63,1) forwards;
    }
    .arena-card.arena-swap-in .arena-thumb,
    .arena-card.arena-swap-in .arena-name,
    .arena-card.arena-swap-in .arena-status {
      animation: arenaCardFadeIn .3s cubic-bezier(0.22,1,0.36,1) forwards;
    }
    .arena-card.arena-swap-in.arena-dir-next .arena-thumb,
    .arena-card.arena-swap-in.arena-dir-next .arena-name,
    .arena-card.arena-swap-in.arena-dir-next .arena-status {
      animation: arenaCardSlideInNext .34s cubic-bezier(0.22,1,0.36,1) forwards;
    }
    .arena-card.arena-swap-in.arena-dir-prev .arena-thumb,
    .arena-card.arena-swap-in.arena-dir-prev .arena-name,
    .arena-card.arena-swap-in.arena-dir-prev .arena-status {
      animation: arenaCardSlideInPrev .34s cubic-bezier(0.22,1,0.36,1) forwards;
    }
    .arena-card.arena-energize::after {
      animation: arenaCardSweep .62s ease-out forwards;
    }
    .arena-thumb {
      display: block;
      width: 100%;
      aspect-ratio: 16 / 9;
      border-radius: 16px;
      overflow: hidden;
      box-shadow: 0 14px 28px rgba(5, 12, 24, 0.45);
      background: rgba(0,0,0,0.35);
    }
    .arena-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transform: scale(1.02);
    }
    .arena-name {
      font-size: 18px;
      font-weight: 700;
      letter-spacing: 0.05rem;
    }
    .arena-status {
      font-size: 12px;
      color: var(--muted);
      letter-spacing: 0.08rem;
      text-transform: uppercase;
    }
    .arena-card.active .arena-status { color: var(--accent); }
    .arena-meta {
      font-size: 13px;
      color: var(--muted);
      text-align: center;
    }
    @keyframes arenaCardFadeOut {
      0% { opacity: 1; transform: translateY(0) scale(1); filter: saturate(1) blur(0); }
      100% { opacity: 0; transform: translateY(18px) scale(0.95); filter: saturate(0.65) blur(12px); }
    }
    @keyframes arenaCardFadeIn {
      0% { opacity: 0; transform: translateY(-18px) scale(1.04); filter: saturate(1.25) blur(14px); }
      50% { opacity: 1; }
      100% { opacity: 1; transform: translateY(0) scale(1); filter: saturate(1) blur(0); }
    }
    @keyframes arenaCardSweep {
      0% { opacity: 0; transform: translateX(-140%) skewX(-12deg); }
      40% { opacity: 0.55; }
      100% { opacity: 0; transform: translateX(120%) skewX(12deg); }
    }
    @keyframes arenaCardSlideOutNext {
      0% { opacity: 1; transform: translate(0,0) scale(1); filter: saturate(1) blur(0); }
      100% { opacity: 0; transform: translateX(-60px) scale(0.96); filter: saturate(0.6) blur(10px); }
    }
    @keyframes arenaCardSlideOutPrev {
      0% { opacity: 1; transform: translate(0,0) scale(1); filter: saturate(1) blur(0); }
      100% { opacity: 0; transform: translateX(60px) scale(0.96); filter: saturate(0.6) blur(10px); }
    }
    @keyframes arenaCardSlideInNext {
      0% { opacity: 0; transform: translateX(60px) scale(1.02); filter: saturate(1.25) blur(14px); }
      60% { opacity: 1; }
      100% { opacity: 1; transform: translateX(0) scale(1); filter: saturate(1) blur(0); }
    }
    @keyframes arenaCardSlideInPrev {
      0% { opacity: 0; transform: translateX(-60px) scale(1.02); filter: saturate(1.25) blur(14px); }
      60% { opacity: 1; }
      100% { opacity: 1; transform: translateX(0) scale(1); filter: saturate(1) blur(0); }
    }

    .menu-footer {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 16px;
      width: 100%;
      flex-wrap: nowrap;
    }
    .menu-footer .menu-back {
      min-width: 160px;
    }
    .menu-shell:not(.showing-pane) .menu-footer .menu-back {
      display: none;
    }
    .helper-actions {
      margin-top: 20px;
    }
    .play-button {
      padding: 18px 38px;
      font-size: 18px;
      letter-spacing: 0.08rem;
      border-radius: 32px;
      background: linear-gradient(145deg, rgba(93, 209, 255, 0.95), rgba(68, 141, 255, 0.95));
      color: #021220;
      font-weight: 900;
      border: 1px solid rgba(255, 255, 255, 0.4);
      cursor: pointer;
      box-shadow: 0 28px 52px rgba(72, 173, 255, 0.45), 0 0 30px rgba(93, 209, 255, 0.35);
      transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
      text-transform: uppercase;
      backdrop-filter: blur(12px);
    }
    .play-button:disabled,
    .play-button.is-loading {
      cursor: wait;
      opacity: 0.65;
      box-shadow: 0 12px 22px rgba(73, 168, 255, 0.25);
      transform: none !important;
    }
    .play-button:hover { transform: translateY(-2px); box-shadow: 0 32px 60px rgba(72, 173, 255, 0.45), 0 0 38px rgba(93, 209, 255, 0.35); border-color: rgba(255, 255, 255, 0.65); }
    .play-button:focus-visible { outline: 3px solid rgba(255,255,255,0.7); outline-offset: 4px; }
    @media (max-width: 720px) {
      .team-pane-footer .quick-actions {
        flex-wrap: wrap;
      }
      .menu-footer {
        flex-wrap: wrap;
      }
      .menu-footer .menu-back {
        width: min(220px, 100%);
      }
    }
    .helper-text { display: grid; gap: 12px; font-size: 14px; line-height: 1.6; color: #c8d4ec; }
    .helper-text strong { color: #5dd1ff; }
    .helper-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
    .helper-list.compact { gap: 6px; padding-left: 18px; font-size: 14px; color: #e3e9f7; }

    /* Help panel refresh */
    .help-hero {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 16px;
      align-items: center;
      padding: 18px 18px 16px;
      text-align: left;
      border-radius: 18px;
      border: 1px solid rgba(93, 209, 255, 0.25);
      background: linear-gradient(135deg, rgba(36, 52, 78, 0.55), rgba(14, 24, 46, 0.85));
      box-shadow: 0 16px 38px rgba(3, 8, 18, 0.5);
    }
    .help-hero-text { display: grid; gap: 6px; text-align: left; }
    .help-lede { margin: 0; color: #d7e3fb; font-size: 15px; line-height: 1.5; max-width: 720px; }
    .help-tag {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      border-radius: 999px;
      background: rgba(93, 209, 255, 0.12);
      color: #7fe0ff;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      font-size: 12px;
      border: 1px solid rgba(93, 209, 255, 0.25);
      width: max-content;
    }
    .help-hero-pill {
      display: grid;
      gap: 4px;
      padding: 10px 12px;
      background: rgba(2, 8, 18, 0.6);
      border-radius: 12px;
      border: 1px solid rgba(255, 255, 255, 0.06);
      min-width: 210px;
      text-align: right;
    }
    .help-hero-pill .label { color: #9fb4d4; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
    .help-hero-pill .value { color: #f5fbff; font-weight: 700; font-size: 14px; }
    .help-grid {
      margin-top: 18px;
      display: grid;
      gap: 14px;
      grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
      grid-auto-rows: 1fr;
      align-items: stretch;
    }
    .help-card {
      background: rgba(18, 24, 40, 0.9);
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-radius: 16px;
      padding: 14px 16px;
      display: grid;
      gap: 12px;
      align-content: start;
      text-align: left;
      box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
      position: relative;
      overflow: hidden;
    }
    .help-card::after {
      content: '';
      position: absolute;
      inset: 0;
      background: radial-gradient(circle at 10% 10%, rgba(93, 209, 255, 0.08), transparent 35%);
      pointer-events: none;
    }
    .help-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
    .help-pill {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 10px;
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.06);
      color: #f6fbff;
      font-weight: 700;
      font-size: 13px;
      border: 1px solid rgba(255, 255, 255, 0.08);
    }
    .help-chip {
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 0.02em;
      padding: 6px 10px;
      border-radius: 12px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      color: #dfe8fb;
      background: rgba(255, 255, 255, 0.06);
      text-transform: uppercase;
    }
    .help-chip.good { color: #9ef2c1; border-color: rgba(158, 242, 193, 0.4); background: rgba(54, 124, 88, 0.32); }
    .help-chip.spicy { color: #ffc89d; border-color: rgba(255, 200, 157, 0.45); background: rgba(124, 70, 32, 0.28); }
    .help-chip.support { color: #bcd6ff; border-color: rgba(188, 214, 255, 0.45); background: rgba(64, 92, 134, 0.32); }
    .help-chip.muted { color: #d7def0; border-color: rgba(255, 255, 255, 0.18); background: rgba(40, 48, 68, 0.35); }
    .help-card p { margin: 0; color: #dce6fa; line-height: 1.5; }
    .help-facts {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
      gap: 6px;
      color: #9fb4d4;
      font-size: 13px;
    }
    .help-checklist {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
      gap: 8px;
      color: #dfe7f9;
      line-height: 1.5;
      font-size: 14px;
    }
    .help-checklist strong { color: #fff; }
    .help-card-wide { grid-column: span 2; }
    .help-card-wide .helper-actions { margin-top: 12px; }
    .help-steps {
      margin: 0;
      padding-left: 18px;
      display: grid;
      gap: 6px;
      color: #dfe7f9;
      line-height: 1.5;
      font-size: 14px;
    }
    .help-stat { display: grid; gap: 4px; padding: 6px 0; }
    .help-stat-label { font-weight: 700; color: #f5fbff; }
    .help-bar {
      position: relative;
      background: rgba(255, 255, 255, 0.08);
      border-radius: 999px;
      height: 10px;
      overflow: hidden;
      border: 1px solid rgba(255, 255, 255, 0.06);
    }
    .help-bar span {
      display: block;
      height: 100%;
      background: linear-gradient(90deg, #5dd1ff, #acf2ff);
      border-radius: 999px;
      text-indent: -9999px;
    }
    .help-bar.danger span { background: linear-gradient(90deg, #ff8a7a, #ffbd94); }
    .help-stat-meta { font-size: 12px; color: #a7bbda; }
    .help-stat.note { color: #dfe7f9; font-size: 13px; line-height: 1.5; }
    .help-tags {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }
    .tag {
      padding: 6px 10px;
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.08);
      font-size: 12px;
      color: #dfe7f9;
    }
    .help-shortcuts {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
      gap: 8px;
    }
    .shortcut {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 10px;
      border-radius: 12px;
      border: 1px solid rgba(255, 255, 255, 0.08);
      background: linear-gradient(135deg, rgba(93, 209, 255, 0.12), rgba(10, 16, 34, 0.7));
      font-weight: 700;
      letter-spacing: 0.04em;
      color: #f5fbff;
    }
    @media (max-width: 840px) {
      .help-hero { grid-template-columns: 1fr; }
      .help-hero-pill { text-align: left; }
      .help-card-wide { grid-column: span 1; }
    }

    /* Help modal refinements */
    .help-modal-grid {
      display: grid;
      gap: 12px;
      grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    .help-mini-card {
      padding: 12px;
      border-radius: 12px;
      border: 1px solid rgba(255, 255, 255, 0.08);
      background: rgba(17, 22, 38, 0.95);
      box-shadow: 0 10px 22px rgba(0, 0, 0, 0.3);
      display: grid;
      gap: 6px;
      font-size: 14px;
      color: #dce6fa;
    }
    .help-modal-actions {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
      gap: 12px;
      align-items: start;
    }
    .help-subtitle {
      font-weight: 800;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      color: #bcd6ff;
      margin-bottom: 6px;
      font-size: 12px;
    }

    #credits { margin: -8px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

    /* In-game HTML prompts (minimal) */
    #ui-hud { position: absolute; inset: 0; pointer-events: none; }
    .in-game-controls {
      position: absolute;
      top: 20px;
      right: 20px;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      gap: 12px;
      pointer-events: none;
      z-index: 20;
    }
    .control-toggles {
      display: flex;
      gap: 12px;
      pointer-events: auto;
    }
    /* Ensure visual order from right to left: settings, choose-next, teacher, exit fullscreen */
    .exitfs-toggle { order: 1; }
    .teacher-toggle { order: 2; }
    .choose-toggle { order: 2.5; }
    .settings-toggle { order: 3; }
    .icon-toggle {
      pointer-events: auto;
      width: 48px;
      height: 48px;
      border-radius: 50%;
      border: 1px solid rgba(93, 209, 255, 0.35);
      background: rgba(16, 21, 36, 0.92);
      color: var(--text);
      display: grid;
      place-items: center;
      font-size: 0; /* hide glyph content */
      cursor: pointer;
      box-shadow: 0 12px 24px rgba(5, 8, 18, 0.45);
      transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    }
    .icon-toggle > [aria-hidden="true"] { display: none; }
    .icon-toggle::before {
      content: '';
      width: 24px;
      height: 24px;
      display: block;
      background-repeat: no-repeat;
      background-position: center;
      background-size: contain;
    }
    #teacherToggle::before { background-image: url('../UI/Icons/teacher_mode_icon.png'); }
    #chooseTurnToggle::before { background-image: url('../UI/Icons/shield_icon.png'); }
    #settingsToggle::before { background-image: url('../UI/Icons/settings_icon.png'); }
    /* Exit Fullscreen toggle: hidden by default, visible in fullscreen */
    #exitFsToggle { display: none; }
    #exitFsToggle::before {
      background-image: url('../UI/Icons/fullscreen_icon.png');
    }
    #game-root:fullscreen #exitFsToggle,
    #game-root:-webkit-full-screen #exitFsToggle {
      display: grid;
    }
    .icon-toggle:hover {
      transform: translateY(-1px);
      background: rgba(28, 34, 54, 0.96);
      box-shadow: 0 16px 30px rgba(5, 8, 18, 0.5);
    }
    .icon-toggle:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 3px;
    }
    .teacher-toggle.active,
    .choose-toggle.active {
      background: rgba(93, 209, 255, 0.16);
      border-color: rgba(255, 213, 79, 0.75);
      color: #ffd54f;
      box-shadow: 0 16px 30px rgba(255, 213, 79, 0.25);
    }
    .settings-popover {
      pointer-events: auto;
      min-width: 220px;
      padding: 16px;
      border-radius: 18px;
      background: rgba(9, 12, 24, 0.96);
      border: 1px solid rgba(255, 255, 255, 0.1);
      box-shadow: 0 18px 38px rgba(5, 8, 18, 0.55);
      display: grid;
      gap: 10px;
    }
    .settings-popover[hidden] {
      display: none;
    }
    .settings-menu-btn {
      width: 100%;
      border: 1px solid rgba(255, 255, 255, 0.14);
      background: rgba(20, 26, 42, 0.9);
      color: var(--text);
      border-radius: 12px;
      padding: 12px 16px;
      font-size: 15px;
      font-weight: 600;
      letter-spacing: 0.04rem;
      cursor: pointer;
      text-align: left;
      display: inline-flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    }
    .settings-menu-btn:hover {
      transform: translateY(-1px);
      background: rgba(28, 34, 54, 0.96);
      box-shadow: 0 10px 24px rgba(3, 9, 24, 0.45);
    }
    .settings-menu-btn:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 3px;
    }
    .settings-menu-btn.danger {
      color: #ff9a9a;
      border-color: rgba(255, 106, 106, 0.35);
      background: rgba(52, 20, 20, 0.9);
    }
    .settings-menu-btn.danger:hover {
      background: rgba(74, 26, 26, 0.92);
      box-shadow: 0 10px 24px rgba(68, 20, 20, 0.35);
    }
    .settings-modal {
      position: absolute;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.55);
      pointer-events: auto;
      z-index: 25;
    }
    .settings-modal.active {
      display: flex;
    }
    .settings-modal-panel {
      width: min(420px, 94vw);
      padding: 24px;
      border-radius: 22px;
      background: rgba(9, 12, 24, 0.96);
      border: 1px solid rgba(255, 255, 255, 0.12);
      box-shadow: 0 24px 48px rgba(5, 8, 18, 0.55);
      display: grid;
      gap: 20px;
    }
    .settings-modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 16px;
    }
    .settings-modal-title {
      margin: 0;
      font-size: 20px;
      font-weight: 700;
      letter-spacing: 0.06rem;
    }
    .settings-modal-close {
      border: none;
      background: rgba(16, 21, 36, 0.9);
      color: var(--text);
      width: 38px;
      height: 38px;
      border-radius: 50%;
      display: grid;
      place-items: center;
      font-size: 22px;
      cursor: pointer;
      transition: background 0.15s ease, transform 0.15s ease;
    }
    .settings-modal-close:hover {
      background: rgba(28, 34, 54, 0.96);
      transform: translateY(-1px);
    }
    .settings-modal-close:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 2px;
    }
    .settings-modal-body {
      display: grid;
      gap: 16px;
    }
    .settings-modal-footer {
      font-size: 12px;
      color: var(--muted);
      text-align: center;
    }
    .settings-modal-footer.modal-actions {
      display: flex;
      justify-content: flex-end;
      gap: 12px;
    }
    .lesson-question-overlay {
      position: absolute;
      inset: 0;
      z-index: 82;
      display: grid;
      place-items: center;
      padding: 18px;
      background: rgba(5, 10, 22, 0.74);
    }
    .lesson-question-overlay[hidden] {
      display: none;
    }
    .lesson-question-panel {
      width: min(520px, 94vw);
      display: grid;
      gap: 18px;
      padding: 22px;
      border-radius: 18px;
      border: 1px solid rgba(93, 209, 255, 0.28);
      background: rgba(12, 18, 32, 0.96);
      box-shadow: 0 26px 60px rgba(0, 0, 0, 0.42);
    }
    .lesson-question-kicker {
      color: var(--accent);
      font-size: 12px;
      font-weight: 800;
      letter-spacing: 0.14rem;
      text-transform: uppercase;
    }
    .lesson-question-title {
      margin: 4px 0 0;
      font-size: 22px;
      color: var(--text);
    }
    .lesson-question-body {
      display: grid;
      gap: 12px;
    }
    .lesson-question-text {
      margin: 0;
      color: #e5f5ff;
      font-size: 18px;
      line-height: 1.45;
    }
    .lesson-choice-list {
      display: grid;
      gap: 10px;
    }
    .lesson-choice-btn {
      width: 100%;
      justify-content: flex-start;
      text-align: left;
    }
    .lesson-choice-btn.active {
      border-color: rgba(132, 255, 220, 0.75);
      box-shadow: 0 0 0 2px rgba(132, 255, 220, 0.16);
    }
    .lesson-answer-label[hidden],
    .lesson-answer-input[hidden] {
      display: none;
    }
    .lesson-question-feedback {
      min-height: 20px;
      color: #ffd6a6;
      font-size: 14px;
    }
    .lesson-question-actions {
      display: flex;
      justify-content: flex-end;
      gap: 12px;
    }
    .help-modal-body {
      display: grid;
      gap: 12px;
      font-size: 15px;
      line-height: 1.5;
      max-height: 62vh;
      overflow-y: auto;
      padding-right: 4px;
    }
    .visually-hidden {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }
    #banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: rgba(23,25,35,.9); border: 1px solid #303650; pointer-events: none; }

    /* Dice overlay */
    #dice-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.7); z-index: 80; }
    #dice-overlay[data-mode="select"] #dice-panel { display: flex; }
    #dice-overlay[data-mode="rolling"] #dice-panel { display: none; }
    #dice-overlay[data-mode="select"] #dice-roller { display: none; }
    #dice-overlay[data-mode="rolling"] #dice-roller { display: flex; }
    #dice-panel { width: min(780px, 96vw); background: var(--panel); border: 1px solid #2a3046; border-radius: 20px; padding: 24px; box-shadow: 0 18px 50px rgba(2, 4, 12, 0.75); display: flex; flex-direction: column; gap: 16px; }
    .dice-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    .dice-panel-title { font-weight: 800; font-size: 1.15rem; letter-spacing: 0.4px; }
    #dice-grid {
      display: flex;
      gap: 10px;
      margin-top: 6px;
      justify-content: center;
      flex-wrap: nowrap;
      overflow: hidden;
      padding: 2px 0 6px 0;
    }
    .die-choice { all: unset; cursor: pointer; border-radius: 16px; border: 1.5px solid transparent; background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(0,0,0,0.35)); padding: 10px; min-height: 104px; min-width: 90px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease; }
    .die-choice:focus-visible { outline: 2px solid rgba(255,255,255,0.8); outline-offset: 2px; }
    .die-choice:hover { border-color: rgba(255,255,255,0.3); }
    .die-choice.selected { border-color: var(--accent); box-shadow: 0 12px 18px rgba(0,0,0,0.45); transform: translateY(-2px); }
    .die-face { width: 64px; aspect-ratio: 1 / 1; border-radius: 18px; background: linear-gradient(180deg, #1d2235, #0f121e 70%); border: 1px solid rgba(255,255,255,0.06); box-shadow: inset 0 6px 20px rgba(10,13,22,0.8), 0 10px 20px rgba(0,0,0,0.6); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 6px; padding: 12px; transition: transform 0.3s ease, box-shadow 0.3s ease; }
    .die-face .pip { width: 10px; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.08); box-shadow: inset 0 0 3px rgba(255,255,255,0.25); justify-self: center; align-self: center; opacity: 0; transition: opacity 0.15s ease; }
    .die-face .pip.visible { opacity: 1; background: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.9), inset 0 0 6px rgba(255,255,255,0.35); }
    #dice-controls { margin-top: 10px; display: flex; justify-content: flex-end; }
    .dice-controls-right { display: flex; gap: 8px; }
    .die-face.die-pill { width: 42px; padding: 8px; border-radius: 14px; gap: 4px; }
    .die-face.die-drop-face { width: 90px; padding: 14px; border-radius: 20px; }
    .die-face.die-final { width: 110px; padding: 16px; border-radius: 24px; }
    .die-face.lucky { background: radial-gradient(circle at 30% 30%, rgba(120,255,196,0.35), rgba(0,0,0,0.65)), linear-gradient(180deg, #0d3221, #071c13); border-color: rgba(130,255,205,0.7); box-shadow: 0 12px 30px rgba(40,255,180,0.25), inset 0 8px 20px rgba(18,70,54,0.9); }
    .die-face.unlucky { background: radial-gradient(circle at 30% 30%, rgba(255,120,120,0.2), rgba(0,0,0,0.7)), linear-gradient(180deg, #2d0e0e, #1a0505); border-color: rgba(255,120,120,0.6); box-shadow: 0 12px 30px rgba(255,80,80,0.25), inset 0 8px 18px rgba(50,12,12,0.9); }
    #dice-roller { width: min(640px, 94vw); padding: 26px; border-radius: 24px; border: 1px solid rgba(255,255,255,0.15); box-shadow: 0 24px 68px rgba(3, 5, 14, 0.8); background: linear-gradient(160deg, rgba(9, 13, 26, 0.96), rgba(4, 8, 18, 0.92)); display: none; align-items: center; justify-content: center; text-align: center; }
    .dice-roller-shell { width: 100%; display: flex; flex-direction: column; gap: 20px; align-items: center; justify-content: center; }
    .dice-roller-lede { letter-spacing: 0.08em; color: rgba(255,255,255,0.75); text-transform: uppercase; }
    .dice-drop-stage { width: 100%; min-height: 200px; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; overflow: hidden; }
    .dice-drop { opacity: 0; will-change: transform, opacity; }
    .dice-drop.right { animation: diceDropRight 1.5s cubic-bezier(0.22, 1.42, 0.52, 1); }
    .dice-drop.left { animation: diceDropLeft 1.5s cubic-bezier(0.22, 1.42, 0.52, 1); }
    @keyframes diceDropRight {
      0% { opacity: 0; transform: translateX(180%) translateY(-40%) rotate(-10deg) scale(0.8); }
      25% { opacity: 1; transform: translateX(12%) translateY(22%) rotate(-4deg) scale(1.02); }
      50% { transform: translateX(-6%) translateY(-18%) rotate(3deg) scale(1.08); }
      70% { transform: translateX(0%) translateY(0%) rotate(0deg) scale(1); }
      90% { opacity: 1; transform: translateX(-6%) translateY(6%) rotate(2deg) scale(0.95); }
      100% { opacity: 0; transform: translateX(180%) translateY(14%) rotate(-6deg) scale(0.82); }
    }
    @keyframes diceDropLeft {
      0% { opacity: 0; transform: translateX(-180%) translateY(-40%) rotate(10deg) scale(0.8); }
      25% { opacity: 1; transform: translateX(-12%) translateY(22%) rotate(4deg) scale(1.02); }
      50% { transform: translateX(6%) translateY(-18%) rotate(-3deg) scale(1.08); }
      70% { transform: translateX(0%) translateY(0%) rotate(0deg) scale(1); }
      90% { opacity: 1; transform: translateX(6%) translateY(6%) rotate(-2deg) scale(0.95); }
      100% { opacity: 0; transform: translateX(-180%) translateY(14%) rotate(6deg) scale(0.82); }
    }
    .dice-final { display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; min-height: 140px; }
    .dice-final-face { min-height: 180px; display: flex; align-items: center; justify-content: center; margin: 0 auto; width: 100%; }
    .dice-final-drop { animation: diceFinalDrop 1.2s cubic-bezier(0.18, 0.9, 0.32, 1.1) forwards; display: inline-flex; align-items: center; justify-content: center; margin: 0 auto; }
    @keyframes diceFinalDrop {
      0% { opacity: 0; transform: translateY(-170%) scale(0.7); }
      55% { opacity: 1; transform: translateY(0%) scale(1); }
      75% { transform: translateY(-18px) scale(1.06); }
      100% { opacity: 1; transform: translateY(0) scale(1.1); }
    }
    .dice-final-status { font-size: 1rem; font-weight: 600; letter-spacing: 0.04em; text-align: center; }
    .dice-final-status.lucky { color: #9ff5b8; }
    .dice-final-status.unlucky { color: #ff9a8f; }

    /* Fullscreen support */
    #game-root:fullscreen,
    #game-root:-webkit-full-screen {
      width: 100vw;
      height: 100vh;
    }

    #game-root:fullscreen .in-game-controls,
    #game-root:-webkit-full-screen .in-game-controls {
      z-index: 10000;
    }
