/* Indigo Quantum Power UI - loaded last so it sits on top of the older themes.
   Only backgrounds, borders, glows and the tab bar change; text and layout stay. */
:root {
  --qi-deep: #0b0826;
  --qi-indigo: #2a1f7a;
  --qi-indigo-2: #1c1557;
  --qi-violet: #8b5cf6;
  --qi-cyan: #22d3ee;
  --qi-line: rgba(165, 180, 252, .55);
  --qi-glow: 0 0 22px rgba(139, 92, 246, .45), 0 0 44px rgba(34, 211, 238, .12);
}

/* Page: deep indigo with a faint quantum grid over the existing artwork. */
html body.game-active::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(rgba(139, 92, 246, .07) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(90deg, rgba(139, 92, 246, .07) 1px, transparent 1px) 0 0 / 34px 34px,
    radial-gradient(ellipse at 50% -10%, rgba(99, 102, 241, .55), transparent 60%),
    linear-gradient(180deg, #120c3a, var(--qi-deep));
}

/* Every screen: indigo glass with a quantum energy edge. */
html body #main-content .panel,
html body #main-content #team-section {
  background: linear-gradient(155deg, rgba(49, 36, 140, .94), rgba(28, 21, 87, .95) 55%, rgba(14, 10, 48, .96)) !important;
  border: 2px solid var(--qi-line) !important;
  border-image: none !important;
  border-radius: 16px !important;
  box-shadow: var(--qi-glow), inset 0 1px 0 rgba(255, 255, 255, .12) !important;
  position: relative;
}
html body #main-content .panel::after,
html body #main-content #team-section::after {
  content: ""; position: absolute; left: 18px; right: 18px; top: -1px; height: 2px; border-radius: 2px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--qi-cyan), var(--qi-violet), transparent);
  opacity: .9;
}

/* Tab bar: each screen is its own glowing tab. */
html body #main-content .section-nav {
  background: linear-gradient(180deg, rgba(28, 21, 87, .96), rgba(14, 10, 48, .96)) !important;
  border: 2px solid var(--qi-line) !important;
  border-image: none !important;
  border-radius: 16px !important;
  box-shadow: var(--qi-glow) !important;
  padding: 8px !important;
  gap: 6px !important;
}
html body #main-content .section-nav .nav-tab {
  border-radius: 10px !important;
  border: 1px solid rgba(165, 180, 252, .25) !important;
  background: rgba(99, 102, 241, .12) !important;
  transition: background .2s, box-shadow .2s, transform .2s;
}
html body #main-content .section-nav .nav-tab:hover { background: rgba(139, 92, 246, .3) !important; }
html body #main-content .section-nav .nav-tab[aria-current] {
  background: linear-gradient(135deg, var(--qi-violet), #4f46e5 60%, #0e7490) !important;
  border-color: #e0e7ff !important;
  box-shadow: 0 0 16px rgba(139, 92, 246, .8), 0 0 4px rgba(34, 211, 238, .9) !important;
  transform: translateY(-1px);
}
html body #main-content .section-nav .nav-tab[aria-current],
html body #main-content .section-nav .nav-tab[aria-current] span { color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; }

/* Buttons: quantum energy fill. */
html body #main-content .panel button.primary,
html body #main-content #team-section button.primary,
html body #main-content .start-playing button.primary {
  background: linear-gradient(135deg, #7c3aed, #4f46e5 55%, #0891b2) !important;
  border: 1px solid rgba(224, 231, 255, .8) !important;
  box-shadow: 0 0 14px rgba(124, 58, 237, .55) !important;
  color: #ffffff !important; -webkit-text-fill-color: #ffffff !important;
}
html body #main-content .panel button.secondary {
  background: rgba(49, 46, 129, .75) !important;
  border: 1px solid rgba(165, 180, 252, .6) !important;
  color: #e0e7ff !important; -webkit-text-fill-color: #e0e7ff !important;
}
html body #main-content .screen-next { display: block; width: 100%; margin-top: 18px; min-height: 48px; font-size: 1rem; }

/* Start card and hero stay readable on indigo. */
html body #main-content .start-playing {
  background: linear-gradient(155deg, rgba(49, 36, 140, .92), rgba(20, 14, 64, .94)) !important;
  border: 2px solid var(--qi-line) !important;
  box-shadow: var(--qi-glow) !important;
}
html body #main-content .start-playing h2,
html body #main-content .start-playing p,
html body #main-content .start-playing small { color: #e0e7ff !important; -webkit-text-fill-color: #e0e7ff !important; }

/* World Tournament bar in the same family. */
html body .tournament-countdown {
  background: linear-gradient(90deg, #1c1557, #2a1f7a 50%, #1c1557) !important;
  border-bottom: 2px solid var(--qi-violet) !important;
  box-shadow: 0 4px 24px rgba(139, 92, 246, .35) !important;
}

@media (prefers-reduced-motion: reduce) {
  html body #main-content .section-nav .nav-tab { transition: none; }
}

/* Inner cards (contract, stats, rarity boxes) in the same indigo family. */
html body #main-content .panel .contract-card,
html body #main-content .panel .stat,
html body #main-content .panel .quest-details,
html body #main-content .panel .result-card {
  background: rgba(30, 27, 95, .8) !important;
  border: 1px solid rgba(165, 180, 252, .45) !important;
  border-image: none !important;
  border-radius: 12px !important;
  box-shadow: inset 0 0 14px rgba(99, 102, 241, .18) !important;
}

/* No light strip above or below the game: the page itself is deep indigo. */
html { background: #0b0826 !important; }

/* iPhone build: the Google Play diamond store is not offered (see src/platform-ios.js). */
html.platform-ios #store-section, html.platform-ios .nav-tab[href="#store-section"] { display: none !important; }
/* iPhone build: no online account creation until in-app account deletion exists (see src/platform-ios.js). */
html.platform-ios #online-account-form { display: none !important; }

/* Music tab: every soundtrack variant, unlocked by clearing books */
#music-section .music-library-count { font-weight: 800; color: #c7d2fe !important; -webkit-text-fill-color: #c7d2fe !important; }
#music-section .music-library-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
#music-section .music-track { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid rgba(165, 180, 252, .45); border-radius: 12px; background: rgba(30, 27, 95, .8); }
#music-section .music-track.is-playing { border-color: #22d3ee; box-shadow: 0 0 16px rgba(34, 211, 238, .45); }
#music-section .music-track.is-locked { opacity: .6; }
#music-section .music-track strong { display: block; color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; }
#music-section .music-track small { display: block; margin-top: 2px; color: #c7d2fe !important; -webkit-text-fill-color: #c7d2fe !important; }
#music-section .music-track button { flex: 0 0 auto; min-width: 110px; min-height: 44px; }
@media (max-width: 480px) { #music-section .music-track { flex-direction: column; align-items: stretch; } }

/* Restored (Sept 17 layout): the Millie quantum journey trailer plays in the
   middle of the screen behind the saga screen and the game. */
.quantum-screen-video { position: fixed; top: 50%; left: 50%; z-index: 0; display: none; width: min(100vw, 56.25vh); height: min(100vh, 177.78vw); aspect-ratio: 9 / 16; object-fit: cover; object-position: center; transform: translate(-50%, -50%); background: #020614; pointer-events: none !important; user-select: none; }
body.saga-landing-active #saga-quantum-video, body.game-active #game-quantum-video { display: block; }
body.saga-landing-active .saga-landing > :not(.quantum-screen-video) { position: relative; z-index: 1; }
body.game-active .shell { position: relative; z-index: 2; }
body.game-active .game-ambience { position: static; z-index: auto; }
/* The trailer replaces the old side/centre loops while the game is open. */
body.game-active :is(.side-video-loop, .center-video-loop) { display: none !important; }
/* Let the trailer show through the indigo glass. */
html body.game-active #main-content .panel,
html body.game-active #main-content #team-section { background: linear-gradient(155deg, rgba(49, 36, 140, .62), rgba(28, 21, 87, .66) 55%, rgba(14, 10, 48, .72)) !important; backdrop-filter: blur(4px); }

/* Restored Sept 17 audio panel: Game song, Trailer song, Karma (Book 6), Open The Eye (Book 7). */
.ambience-controls { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; max-width: min(920px, calc(100vw - 32px)); padding: 10px 12px; border: 1px solid rgba(165, 180, 252, .65); border-radius: 14px; color: #eefaff; background: rgba(20, 14, 64, .9); box-shadow: 0 10px 30px rgba(0, 0, 0, .42); backdrop-filter: blur(10px); }
.ambience-controls-compact { max-width: 230px; }
.ambience-controls-compact > :not(strong):not(.audio-panel-toggle) { display: none !important; }
.audio-panel-toggle { padding: 7px 10px; white-space: nowrap; }
.entry-splash-active .ambience-controls, .saga-landing-active .ambience-controls { z-index: 1001; }
.ambience-controls strong { color: #c7d2fe; font-size: .88rem; letter-spacing: .08em; }
.ambience-controls label { display: flex; align-items: center; gap: 7px; font-size: .75rem; font-weight: 800; }
.ambience-controls input { width: 110px; accent-color: #8b5cf6; }
.karma-soundtrack-control { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; width: 100%; padding-top: 8px; border-top: 1px solid rgba(165, 180, 252, .22); }
.karma-soundtrack-control small { flex: 1 1 320px; color: #c7d2fe; font-size: .68rem; line-height: 1.35; }
.karma-soundtrack-control button:disabled, .karma-soundtrack-control input:disabled { opacity: .55; cursor: not-allowed; }
@media (max-width: 700px) {
  .ambience-controls { left: 10px; right: 10px; bottom: 10px; justify-content: center; }
  .game-active .ambience-controls:not(.ambience-controls-compact) { top: calc(env(safe-area-inset-top, 0px) + 100px); bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 110px); overflow-x: hidden; overflow-y: auto; align-content: flex-start; overscroll-behavior: contain; }
  .game-active .ambience-controls:not(.ambience-controls-compact) .audio-panel-toggle { position: sticky; top: 0; z-index: 2; order: -1; }
}

/* "▶ Special" preview badge on every card avatar (owned or not). */
html body .card-avatar-wrap { position: relative; display: block; width: fit-content; margin: 0 auto; }
html body .avatar-special-preview {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  font: 700 11px/1.3 system-ui, sans-serif; letter-spacing: .03em;
  color: #fff !important; -webkit-text-fill-color: #fff !important;
  background: linear-gradient(135deg, #5b3cff, #b04bff); border: 1px solid #d9c8ff;
  box-shadow: 0 0 10px #8a6bff99; cursor: pointer; filter: none !important; z-index: 2;
}
html body .avatar-special-preview:hover, html body .avatar-special-preview:focus-visible { background: linear-gradient(135deg, #7a5cff, #d06bff); outline: 2px solid #fff; }
html body #special-preview-dialog,
html body #special-preview-dialog[open] {
  position: fixed !important; inset: 0 !important; margin: 0 !important; padding: 0 !important;
  width: 100vw !important; height: 100vh !important; height: 100dvh !important; max-width: none !important; max-height: none !important;
  border: 0 !important; border-radius: 0 !important; background: #000 !important; color: #fff; overflow: hidden !important;
  transform: none !important; z-index: 10000;
}
html body #special-preview-dialog:not([open]) { display: none !important; }
html body #special-preview-dialog::backdrop { background: #000; }
html body #special-preview-dialog > video {
  position: absolute; inset: 0; width: 100% !important; height: 100% !important; max-width: none !important; max-height: none !important;
  object-fit: contain; background: #000; border-radius: 0 !important; display: block;
}
html body #special-preview-dialog .special-preview-header {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 24px; background: linear-gradient(#000b, #0000); pointer-events: none; z-index: 1;
}
html body #special-preview-dialog .special-preview-header strong { display: block; font-size: 16px; text-shadow: 0 1px 4px #000; }
html body #special-preview-dialog .special-preview-note { display: block; font-size: 12px; opacity: .8; }
html body #special-preview-dialog .special-preview-close {
  pointer-events: auto; width: 44px; height: 44px; min-width: 44px; padding: 0; border-radius: 50%;
  font-size: 20px; line-height: 44px; color: #fff; background: #ffffff26; border: 1px solid #ffffff66; cursor: pointer;
}
html body #special-preview-dialog .special-preview-missing { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; margin: 0; }
html body .training-character-card .avatar-special-preview,
html body .team-avatar-wrap .avatar-special-preview { font-size: 9px; padding: 2px 6px; bottom: 2px; }
html body .team-avatar-wrap { position: relative; }
/* Sign in with Google (Google Play services) on the Account screen. */
html body .online-account-form .google-sign-in { width: 100%; margin-bottom: 4px; }
html body .online-account-form .google-sign-in[hidden], html body .online-account-form .google-sign-in-note[hidden] { display: none !important; }
html body .online-account-form .google-sign-in-note { display: block; margin-bottom: 8px; opacity: .8; }
html body .online-account-form .online-account-divider { display: block; margin: 6px 0 8px; text-align: center; opacity: .65; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }
/* Account screen links: rate the game, game website, the books. */
html body .online-account-form .game-links { margin-top: 10px; }
html body .online-account-form .game-link { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 14px; border: 1px solid #5ccfff; border-radius: 10px; color: #e8f7ff; background: #0a203e; font-weight: 700; text-decoration: none; }
html body .online-account-form .game-link:hover, html body .online-account-form .game-link:focus-visible { background: #12345f; outline: 2px solid #5ccfff; outline-offset: 2px; }

/* Book shelf in Start Quest: every player can open any book's cover and description. */
html body .book-shelf { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 12px; margin-bottom: 8px; scroll-snap-type: x proximity; }
html body .book-shelf-item {
  flex: 0 0 92px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px;
  border-radius: 12px; border: 1px solid #6f5cff66; background: #1a1450cc; color: #efeaff; cursor: pointer; scroll-snap-align: start;
  font: 600 11px/1.25 system-ui, sans-serif; text-align: center; white-space: normal;
}
html body .book-shelf-item img { width: 78px; height: 112px; object-fit: cover; object-position: right center; border-radius: 6px; box-shadow: 0 4px 12px #0008; }
html body .book-shelf-item[aria-pressed="true"] { border-color: #d9c8ff; box-shadow: 0 0 14px #9b7bff99; background: #2a1f70; }
html body .book-shelf-item:hover, html body .book-shelf-item:focus-visible { border-color: #b9a6ff; outline: none; }

/* Team strip portraits are small: show the Special badge as a round "▶" only. */
html body .team-avatar-wrap .avatar-special-preview { font-size: 0 !important; padding: 0 !important; width: 26px; height: 26px; left: 4px; bottom: 4px; transform: none; display: grid; place-items: center; border-radius: 50%; }
html body .team-avatar-wrap .avatar-special-preview::before { content: "▶"; font-size: 11px; line-height: 1; }


/* Keep audio small and its close control below the live tournament banner. */
body .ambience-controls {
  left: auto;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  box-sizing: border-box;
  max-width: min(360px, calc(100vw - 20px));
  padding: 8px;
  gap: 6px;
}
body .ambience-controls.ambience-controls-compact { max-width: min(230px, calc(100vw - 20px)); }
body .ambience-controls:not(.ambience-controls-compact),
body.game-active .ambience-controls:not(.ambience-controls-compact) {
  top: auto;
  width: min(360px, calc(100vw - 20px));
  max-height: min(420px, 50dvh, max(44px, calc(100dvh - var(--audio-banner-bottom, 110px) - env(safe-area-inset-bottom, 0px) - 24px)));
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-start;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-top: 52px;
}
body .ambience-controls:not(.ambience-controls-compact) > * { flex-shrink: 0; }
body .ambience-controls:not(.ambience-controls-compact) .audio-panel-toggle {
  position: sticky;
  top: 0;
  order: -1;
  z-index: 2;
  width: 100%;
  margin: 0;
  background: #24195d;
  box-shadow: 0 4px 8px #140e40;
}
body .ambience-controls button { min-height: 44px; padding: 6px 10px; font-size: .76rem; }
body .ambience-controls strong { font-size: .76rem; }
body .ambience-controls label { justify-content: space-between; font-size: .72rem; }
body .ambience-controls input { width: 100px; max-width: 40%; }
body .ambience-controls .karma-soundtrack-control { gap: 6px; padding-top: 6px; }
body .ambience-controls .karma-soundtrack-control small { flex-basis: 100%; font-size: .65rem; }

/* Responsive tournament access: small docks; scrollable, keyboard-accessible dialogs. */
#tournament-leaderboard-open { min-height: 44px; padding: 6px 12px; font-size: .8rem; white-space: nowrap; }
body .temporary-admin-bar { top: calc(var(--tournament-banner-bottom, 110px) + 8px); left: auto; right: max(8px, env(safe-area-inset-right, 0px)); display: block; max-width: min(300px, calc(100vw - 16px)); padding: 4px; border-width: 1px; border-radius: 10px; }
body .temporary-admin-bar[hidden] { display: none; }
#admin-panel-toggle { min-height: 44px; padding: 6px 12px; margin: 0; font-size: .8rem; }
#admin-panel-content { display: grid; gap: 8px; max-height: min(32dvh, 280px); padding: 8px 4px 4px; overflow-y: auto; overflow-wrap: anywhere; overscroll-behavior: contain; }
#admin-panel-content[hidden] { display: none; }
#admin-panel-content strong { font-size: .75rem; }
#admin-panel-content #qa-status { font-size: .72rem; line-height: 1.4; }
#admin-panel-content button { min-height: 44px; white-space: normal; font-size: .78rem; }
#tournament-admin-dialog, .tournament-board-dialog { box-sizing: border-box; width: min(94vw, 720px); max-width: calc(100vw - 16px); max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px); padding: 14px; overflow: auto; color: #eefaff; background: #17113e; border: 1px solid #a5b4fc; border-radius: 14px; overscroll-behavior: contain; }
#tournament-admin-dialog { width: min(94vw, 380px); }
#tournament-admin-dialog h2 { font-size: 1rem; margin: 0 0 10px; }
#tournament-admin-dialog > button { display: block; width: 100%; min-height: 44px; margin: 6px 0; white-space: normal; }
#tournament-admin-dialog p { font-size: .8rem; overflow-wrap: anywhere; }
#tournament-admin-dialog::backdrop, .tournament-board-dialog::backdrop { background: #050318bb; }
.tournament-board-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
.tournament-board-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: 0 0 auto; }
.tournament-board-header h2 { margin: 0; font-size: clamp(.95rem, 2vw, 1.3rem); overflow-wrap: anywhere; }
.tournament-board-header button, .tournament-board-toolbar button, .tournament-board-toolbar select { min-height: 44px; }
.tournament-board-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; flex: 0 0 auto; }
.tournament-board-dialog p { margin: 0; font-size: .78rem; overflow-wrap: anywhere; flex: 0 0 auto; }
#tournament-board-scroll { min-height: 60px; max-height: 55dvh; overflow: auto; overscroll-behavior: contain; }
.tournament-board-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .82rem; }
.tournament-board-table th { position: sticky; top: 0; background: #2a205f; text-align: left; }
.tournament-board-table th, .tournament-board-table td { padding: 9px 6px; border-bottom: 1px solid #a5b4fc44; overflow-wrap: anywhere; }
.tournament-board-table th:first-child { width: 22%; }
.tournament-board-table th:last-child { width: 26%; }
.tournament-board-table .is-current-player { background: #384877; font-weight: bold; }
#tournament-board-scroll:focus-visible, #admin-panel-toggle:focus-visible { outline: 3px solid #8fe4ff; outline-offset: 2px; }
@media (max-height: 450px) { .tournament-board-dialog { gap: 5px; padding: 8px; } #tournament-board-scroll { max-height: 38dvh; } #tournament-board-state { display: none; } }
body:not(.entry-splash-active) { padding-top: calc(var(--tournament-banner-bottom, 90px) + 8px); }
.tournament-board-header h2 { color: #eefaff !important; -webkit-text-fill-color: #eefaff !important; -webkit-text-stroke: 0 !important; text-shadow: none !important; }
.tournament-board-toolbar label { font-size: .8rem; }
.tournament-board-toolbar select { width: auto; flex: 1 1 100px; min-width: 100px; max-width: 180px; margin: 0; }
.tournament-board-toolbar button { width: auto; flex: 0 0 auto; margin: 0; }

#tournament-admin-dialog .tournament-board-header { position: sticky; top: 0; z-index: 3; padding-bottom: 8px; background: #17113e; }
#tournament-admin-dialog .tournament-board-header form { margin: 0; }
@supports not (height: 100dvh) {
  #tournament-admin-dialog, .tournament-board-dialog { max-height: calc(100vh - 24px); }
  #admin-panel-content { max-height: min(32vh, 280px); }
  #tournament-board-scroll { max-height: 55vh; }
  body .ambience-controls:not(.ambience-controls-compact), body.game-active .ambience-controls:not(.ambience-controls-compact) { max-height: min(420px, 50vh, calc(100vh - var(--audio-banner-bottom, 110px) - 24px)); }
}
