:root {
  color-scheme: light dark;
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #26241f;
  --muted: #6c665a;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --correct: #2e7d32;
  --wrong: #b3261e;
  --present: #b8860b;
  --border: #e4ddcc;
  --key-bg: #e4ddcc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --card: #262420;
    --ink: #ece6d9;
    --muted: #a89f8c;
    --accent: #d9a05b;
    --accent-ink: #1b1a17;
    --correct: #7ed08a;
    --wrong: #ff8a80;
    --present: #e0b84a;
    --border: #3a362e;
    --key-bg: #3a362e;
  }
}

/* Explicit picks from the footer theme switcher (see applyTheme() in
   app.js) — an attribute selector outranks the plain :root above no
   matter which one the media query matched, so these always win once
   set. No data-theme attribute at all means "follow the system". */
:root[data-theme="light"] {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #26241f;
  --muted: #6c665a;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --correct: #2e7d32;
  --wrong: #b3261e;
  --present: #b8860b;
  --border: #e4ddcc;
  --key-bg: #e4ddcc;
}

:root[data-theme="dark"] {
  --bg: #1b1a17;
  --card: #262420;
  --ink: #ece6d9;
  --muted: #a89f8c;
  --accent: #d9a05b;
  --accent-ink: #1b1a17;
  --correct: #7ed08a;
  --wrong: #ff8a80;
  --present: #e0b84a;
  --border: #3a362e;
  --key-bg: #3a362e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, 'Iowan Old Style', serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 640px;
  padding: 2rem 1.25rem 3rem;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 1.5rem;
}

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

h1 {
  font-size: 1.6rem;
  margin: 0 0 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.menu-toggle-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 2.4rem;
  height: 2.4rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.menu-toggle-btn:hover {
  border-color: var(--accent);
}

.menu-toggle-btn.hidden {
  display: none;
}

.menu-toggle-btn[aria-expanded="true"] {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border-color: var(--accent);
}

.menu-toggle-btn span {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.15s ease, background 0.15s ease;
}

.menu-toggle-btn[aria-expanded="true"] span {
  background: var(--accent);
}

.menu-toggle-btn[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.menu-toggle-btn[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.menu-toggle-btn[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.logo-icon {
  height: 1.5em;
  width: 1.5em;
  object-fit: contain;
  vertical-align: middle;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.home-link:hover {
  opacity: 0.8;
}

.scoreboard {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.new-game-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.new-game-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.game-switcher:not(.hidden) {
  display: flex;
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  left: auto;
  min-width: 13rem;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.4rem;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s;
}

.game-switcher:not(.hidden)::before {
  content: '';
  position: absolute;
  top: -5px;
  right: 0.85rem;
  width: 10px;
  height: 10px;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: rotate(45deg);
}

.game-switcher:not(.hidden).open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.game-switch-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  padding: 0.6rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.game-switch-btn:hover:not(.active) {
  background: var(--bg);
  color: var(--ink);
}

.game-switch-icon {
  width: 1.5rem;
  height: 1.5rem;
  object-fit: contain;
  flex-shrink: 0;
}

.game-switch-btn.active {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  color: var(--accent);
}

/* Desktop: the game switcher reads as an always-visible website nav bar
   next to the logo instead of a hamburger dropdown — same markup and
   open/close JS as mobile, just laid out differently here. */
@media (min-width: 641px) {
  header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }

  .menu-toggle-btn {
    display: none !important;
  }

  .game-switcher:not(.hidden) {
    position: static;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }

  .game-switcher:not(.hidden)::before {
    display: none;
  }

  .game-switch-btn {
    width: auto;
  }

  .scoreboard {
    flex-basis: 100%;
    justify-content: center;
  }
}

.hidden { display: none !important; }

.screen {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.next-btn, .option-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.option-btn:focus:not(:focus-visible) {
  outline: none;
}

.loading {
  text-align: center;
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  padding: 2rem 0;
}

#passage-text {
  font-size: 1.25rem;
  line-height: 1.6;
  margin: 0 0 0.5rem;
  padding: 0;
  border: none;
  font-style: italic;
}

.hint {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1.5rem;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .options { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  header {
    text-align: left;
    margin-bottom: 0.85rem;
  }

  h1 {
    justify-content: flex-start;
    margin: 0;
    font-size: 1.15rem;
  }

  .logo-icon {
    height: 1.2em;
    width: 1.2em;
  }
}

.option-btn {
  text-align: left;
}

.option-btn.selected {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  border-color: var(--accent);
  border-width: 2px;
}

.option-btn.correct {
  background: color-mix(in srgb, var(--correct) 18%, var(--card));
  border-color: var(--correct);
}

.option-btn.wrong {
  background: color-mix(in srgb, var(--wrong) 18%, var(--card));
  border-color: var(--wrong);
}

.option-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.hints-block {
  margin: 1rem 0;
}

.hint-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.hint-btn:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.hint-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

.hints-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hints-list li {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.9rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

.feedback {
  margin-top: 1.25rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  text-align: center;
}

.feedback.correct { color: var(--correct); }
.feedback.wrong { color: var(--wrong); }

.next-btn {
  display: block;
  margin: 1.5rem auto 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.app-version {
  opacity: 0.6;
}

.lang-switcher {
  display: flex;
  gap: 0.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
}

.lang-switch-btn {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.lang-switch-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.lang-switch-btn.active {
  opacity: 1;
  border-color: var(--accent);
}

.theme-switcher {
  display: flex;
  gap: 0.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
  margin-left: auto;
}

.theme-switch-btn {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.theme-switch-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.theme-switch-btn.active {
  opacity: 1;
  border-color: var(--accent);
}

/* Mode select screen */

#mode-prompt {
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 0.35rem;
}

.mode-subtitle {
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--muted);
  font-size: 0.85rem;
  opacity: 0.85;
  margin: 0 0 1.1rem;
}

/* Bigger, labeled duplicate of the footer's icon-only .lang-switcher —
   same .lang-switch-btn buttons, sized up and given text so language
   choice reads clearly right on the mode-select screen. */
.mode-lang-switcher {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 0 1.5rem;
}

.mode-lang-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: auto;
  height: auto;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 1;
}

.mode-lang-btn:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.mode-lang-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  color: var(--accent);
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.5rem;
}

.mode-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  padding: 1rem 1.25rem;
  text-align: left;
  text-decoration: none;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.mode-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.mode-emoji {
  grid-row: span 2;
  width: 2.6rem;
  height: 2.6rem;
  object-fit: contain;
  align-self: center;
}

.mode-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.mode-desc {
  color: var(--muted);
  font-size: 0.88rem;
}

.how-to-play-btn {
  display: block;
  margin: 0 0 1.25rem auto;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--accent);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.how-to-play-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.how-to-play-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  padding: 1.5rem 1.75rem;
  max-width: 32rem;
  width: calc(100% - 2.5rem);
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

.how-to-play-dialog::backdrop {
  background: color-mix(in srgb, var(--bg) 85%, transparent);
}

.how-to-play-dialog h2 {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.how-to-play-dialog p {
  margin: 0 0 1.4rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

/* Diverse mode */

.category-badge {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  margin-bottom: 0.75rem;
}

.diverse-reference {
  display: none;
}

.diverse-text {
  font-size: 1.15rem;
  line-height: 1.6;
  margin: 0 0 1.5rem;
  padding: 0;
  border: none;
  font-style: italic;
  letter-spacing: 0.02em;
}

.tile-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.tile-row {
  display: flex;
  gap: 0.4rem;
}

.tile {
  width: 2.6rem;
  height: 2.6rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  text-transform: uppercase;
  color: var(--ink);
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.tile.absent {
  background: var(--key-bg);
  border-color: var(--key-bg);
  color: var(--muted);
}

/* Desktop default: the keyboard just sits inline in the card, like any
   other element — no dock chrome, no toggle. The fixed-to-viewport dock
   with the hide/show button is a mobile-only affordance (see the
   max-width: 640px query below), since only there does an on-screen
   keyboard compete for space with the puzzle above it. */
.keyboard-toggle-btn {
  display: none;
}

@media (max-width: 640px) {
  #diverse-screen {
    /* Reserves room below the puzzle so tiles/feedback/next-btn never sit
       behind the keyboard dock, which is position: fixed here and so no
       longer takes up space in normal document flow. */
    padding-bottom: 12rem;
  }

  .keyboard-dock {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 100%;
    max-width: 640px;
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 30;
  }

  .keyboard-toggle-btn {
    display: block;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--muted);
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0 auto 0.4rem;
    padding: 0.15rem 0.6rem;
  }

  .keyboard-toggle-btn:hover {
    color: var(--accent);
  }

  .keyboard-dock.keyboard-collapsed .keyboard {
    display: none;
  }
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: stretch;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  gap: 0.3rem;
  width: 100%;
}

.key-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--ink);
  padding: 0.65rem 0.25rem;
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  transition: background 0.15s ease;
  touch-action: manipulation;
}

.key-btn.wide {
  flex: 1.6;
  font-size: 0.65rem;
}

.key-btn.correct {
  background: var(--correct);
  color: #fff;
}

.key-btn.present {
  background: var(--present);
  color: #fff;
}

.key-btn.absent {
  background: var(--border);
  color: var(--muted);
  opacity: 0.6;
}

/* Perfect-round celebration */

.celebration-banner {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -12px);
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 1rem 1.75rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.celebration-banner.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 999;
}

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0.4;
  }
}

/* Versario Live (multiplayer) */

.mp-field-label {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin: 1.1rem 0 0.4rem;
}

.mp-note {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  opacity: 0.8;
  margin: -0.4rem 0 0.6rem;
}

.mp-text-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  padding: 0.75rem 1rem;
}

.mp-text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.mp-choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mp-choice-btn {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mp-choice-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--ink);
}

.mp-choice-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.mp-choice-btn:disabled {
  cursor: default;
  opacity: 0.5;
}

.mp-choice-btn:disabled:hover {
  border-color: var(--border);
  color: var(--muted);
}

.mp-tier-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.mp-tier-card {
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 0.75rem 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.mp-tier-card:hover:not(.active):not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.mp-tier-card.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
}

.mp-tier-card:disabled {
  cursor: default;
  opacity: 0.55;
}

.mp-tier-card-range {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.mp-tier-card-price {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.mp-tier-card-price-free {
  color: var(--muted);
}

.mp-tier-card-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.mp-tier-disclaimer {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.75rem;
  font-style: italic;
  color: var(--accent);
  opacity: 0.85;
  margin: 0.5rem 0 0.8rem;
}

.mp-back-btn {
  display: block;
  margin: 1.5rem auto 0;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
}

.room-code {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  color: var(--accent);
  margin: 0.5rem 0 1rem;
}

.player-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-list li {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.player-list .player-score {
  font-weight: 700;
  color: var(--accent);
}

.player-list li.winner {
  background: color-mix(in srgb, var(--accent) 30%, var(--card));
  border-color: var(--accent);
  transform: scale(1.04);
  font-weight: 700;
  animation: winner-glow 1.4s ease-in-out infinite alternate;
}

@keyframes winner-glow {
  from { box-shadow: 0 0 0 2px var(--accent), 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
  to { box-shadow: 0 0 0 3px var(--accent), 0 6px 24px color-mix(in srgb, var(--accent) 60%, transparent); }
}

.mp-drumroll {
  text-align: center;
  font-size: 1.8rem;
  margin: 2.5rem 0;
  animation: drumroll-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes drumroll-pulse {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(1.15); opacity: 1; }
}

.timer-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin: 0.5rem 0 1rem;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transition: width 1s linear, background 0.3s ease;
}

.timer-bar.urgent {
  background: var(--wrong);
}

.mp-error-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  z-index: 1100;
  padding: 1.5rem;
  text-align: center;
}

.mp-error-overlay p {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1.05rem;
  color: var(--ink);
  max-width: 24rem;
}

/* ---------- Visual templates (Versario Live) ----------
   Only ever rendered on the spectator host's TV screens (see the
   `.tv-screen` rules below, which read the --mp-* custom properties set by
   applyMpTemplate in app.js) — this picker itself is the only piece that
   shows on a normal (non-TV) screen, so a host can preview the 5 options
   before starting. A participating host's own screens and every joiner's
   screens stay in the app's normal theme regardless of which one is picked. */

.mp-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.6rem;
}

.mp-template-swatch {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0.9rem 0.5rem;
  background: linear-gradient(160deg, var(--swatch-from), var(--swatch-to));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.mp-template-swatch:hover {
  transform: translateY(-1px);
}

.mp-template-swatch.active {
  border-color: var(--accent);
}

.mp-template-swatch-name {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.35);
}

.mp-template-preview {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  padding: 1.5rem 1rem 2.25rem;
  border-radius: 14px;
  text-align: center;
  overflow: hidden;
}

.mp-template-preview-code {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  margin: 0;
}

.mp-template-preview-text {
  font-size: 0.95rem;
  font-style: italic;
  max-width: 24rem;
  margin: 0;
}

.mp-template-preview-logo {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: 2.2rem;
  height: 2.2rem;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.15));
}

/* ---------- TV mode (host spectator screens for Versario Live) ----------
   Background/text color and a faint decorative image come from the host's
   chosen visual template (--mp-bg-from/to, --mp-fg, --mp-bg-image — see
   MP_TEMPLATES/applyMpTemplate in app.js), white cards for contrast against
   whichever template is active. Not a scaled-up variant of the app's
   everyday cream theme, since this is meant to be projected on a big
   screen/TV. */

.tv-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  background:
    linear-gradient(rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.25)),
    var(--mp-bg-image, none) center / cover,
    linear-gradient(160deg, var(--mp-bg-from, #ffd6e8), var(--mp-bg-to, #ffd6e8));
  color: var(--mp-fg, #2d2a26);
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 2rem;
  overflow-y: auto;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.tv-final-title, .tv-podium-name, .tv-passage-text {
  font-family: var(--mp-font, inherit);
}

.tv-room-code-label {
  font-size: 1rem;
  opacity: 0.7;
  margin: 0;
}

.tv-room-code {
  font-size: clamp(2.2rem, 7vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  margin: 0;
  color: var(--mp-fg, #2d2a26);
  font-family: var(--mp-font, inherit);
}

.tv-waiting-text {
  font-size: 1.1rem;
  opacity: 0.85;
  margin: 0;
}

.tv-bubble-field {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.65rem;
  max-width: 60rem;
}

.tv-bubble {
  --bubble-color: #ffd6e8;
  background: #fff;
  color: #2d2a26;
  border: 3px solid var(--bubble-color);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  animation: bubble-pop 0.4s cubic-bezier(.34,1.56,.64,1);
}

@keyframes bubble-pop {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.tv-start-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.9rem 2.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  background: #2d2a26;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.12s ease;
}

.tv-start-btn:hover {
  transform: translateY(-2px) scale(1.02);
}

.tv-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: rgba(45, 42, 38, 0.65);
  font-size: 0.9rem;
  text-decoration: underline;
}

.tv-fullscreen-btn {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 950;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  background: rgba(255, 255, 255, 0.7);
  color: #2d2a26;
  backdrop-filter: blur(4px);
}

.tv-fullscreen-btn:hover,
.tv-fullscreen-btn.active {
  background: #fff;
}

.tv-round-progress {
  font-size: 1.05rem;
  font-weight: 700;
  opacity: 0.8;
}

.tv-timer-track {
  width: min(100%, 34rem);
  height: 0.85rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.tv-timer-bar {
  height: 100%;
  width: 100%;
  background: var(--mp-accent, #4a7c59);
  transition: width 0.2s linear;
}

.tv-timer-bar.urgent {
  background: #c0392b;
}

.tv-passage-text {
  font-size: clamp(1.25rem, 2.6vw, 1.75rem);
  font-style: italic;
  line-height: 1.45;
  max-width: 46rem;
  margin: 0;
}

.tv-answered-badge {
  font-size: 0.95rem;
  opacity: 0.8;
}

.tv-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  max-width: 42rem;
  width: 100%;
}

@media (max-width: 640px) {
  .tv-options { grid-template-columns: 1fr; }
}

.tv-option {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.tv-option.correct {
  background: color-mix(in srgb, var(--correct) 22%, #fff);
  border-color: var(--correct);
}

.tv-option.dim {
  opacity: 0.45;
}

.tv-final-title {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  font-weight: 800;
  margin: 0;
}

.tv-drumroll {
  font-size: clamp(1.6rem, 3.5vw, 2.3rem);
  font-weight: 700;
  animation: drumroll-pulse 0.5s ease-in-out infinite alternate;
}

.tv-leaderboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(5, auto);
  grid-auto-flow: column;
  gap: 0.65rem;
  max-width: 50rem;
  width: 100%;
}

@media (max-width: 640px) {
  .tv-leaderboard-grid { grid-template-columns: 1fr; grid-auto-flow: row; }
}

.tv-leaderboard-grid.single-col {
  grid-template-columns: 1fr;
  grid-template-rows: none;
  grid-auto-flow: row;
  width: min(100%, 24rem);
}

.tv-card {
  --bubble-color: #ffd6e8;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  color: #2d2a26;
  border: 1px solid var(--bubble-color);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.tv-card-rank {
  opacity: 0.55;
  font-size: 0.85rem;
}

.tv-card-name {
  flex: 1;
  text-align: left;
  font-size: 1rem;
}

.tv-card-score {
  font-size: 1rem;
}

/* ---------- TV final screen: top-3 podium ---------- */

.tv-podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem;
  margin: 0.5rem 0;
}

.tv-podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.tv-podium-place.visible {
  opacity: 1;
  transform: translateY(0);
}

.tv-podium-name {
  font-weight: 700;
  font-size: 1rem;
}

.tv-podium-bar {
  width: 6rem;
  border-radius: 12px 12px 0 0;
  background: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.5rem;
  font-size: 3rem;
}

.tv-podium-1 { order: 2; }
.tv-podium-1 .tv-podium-bar { height: 8rem; }
.tv-podium-2 { order: 1; }
.tv-podium-2 .tv-podium-bar { height: 5.5rem; }
.tv-podium-3 { order: 3; }
.tv-podium-3 .tv-podium-bar { height: 3.75rem; }

/* ---------- Join QR + URL + powered-by footer ---------- */

.mp-join-qr {
  display: flex;
  justify-content: center;
  margin: 0 0 0.5rem;
}

.mp-join-qr svg {
  width: 9rem;
  height: 9rem;
  border-radius: 8px;
}

.mp-join-url {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin: 0 0 1.25rem;
  word-break: break-all;
}

.mp-share-btn {
  display: block;
  margin: 0 auto 1.25rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  padding: 0.55rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.mp-share-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
}

.mp-share-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.powered-by {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.8;
}

.powered-by-logo {
  width: 1rem;
  height: 1rem;
  border-radius: 3px;
}

.tv-join-qr {
  display: flex;
  justify-content: center;
  background: #fff;
  border-radius: 12px;
  padding: 0.6rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.tv-join-qr svg {
  width: 8rem;
  height: 8rem;
  display: block;
}

.tv-join-url {
  font-size: 0.85rem;
  opacity: 0.8;
  margin: 0;
  word-break: break-all;
}

/* Single fixed element (see index.html), not per-screen, so it stays
   bottom-right consistently across every TV screen — shown/hidden
   alongside the fullscreen button in showScreen(). */
.tv-powered-by {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: #2d2a26;
  opacity: 0.7;
  background: rgba(255, 255, 255, 0.6);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.tv-powered-by-logo {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 4px;
}

.mp-template-logo {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  width: 4.5rem;
  height: 4.5rem;
  z-index: 940;
  opacity: 0.92;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.15));
  pointer-events: none;
}
