:root {
  --bg-page: #141822;
  --bg-deep: #0d0f15;
  --bg-card: #111f50;
  --bg-card-raised: #16224f;
  --gold: #ffc806;
  --gold-border: #ffd700;
  --glow: rgba(0, 87, 255, 0.5);
  --white: #ffffff;
  --white-dim: rgba(255, 255, 255, 0.65);
  --good: #3fbf5f;
  --bad: #e0483f;
}

* {
  box-sizing: border-box;
}

/* Generic utility — component-specific .hidden rules below take precedence
   via higher specificity where they exist; this is the fallback for anything
   that doesn't have one (e.g. .btn.hidden). */
.hidden {
  display: none;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Roboto", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(0, 87, 255, 0.12), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(255, 200, 6, 0.06), transparent 45%),
    linear-gradient(180deg, var(--bg-deep), var(--bg-page));
  color: var(--white);
  display: flex;
  justify-content: center;
  padding: 24px 16px 60px;
}

.tavern {
  width: 100%;
  max-width: 720px;
}

.tavern-header {
  text-align: center;
  margin-bottom: 24px;
}

.tavern-header .logo {
  display: block;
  max-width: 320px;
  width: 60%;
  margin: 0 auto 6px;
}

.tagline {
  margin: 0;
  color: var(--gold);
  font-family: "Aladin", cursive;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  opacity: 0.9;
}

.screen {
  background: rgba(1, 8, 22, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 0 12px var(--glow), 0 10px 30px rgba(0, 0, 0, 0.4);
}

.screen.hidden {
  display: none;
}

.screen h2 {
  margin-top: 0;
  text-align: center;
  color: var(--gold);
  font-family: "Aladin", cursive;
  font-weight: 400;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

/* Timer setting */

.timer-setting {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.timer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--white-dim);
  font-size: 0.95rem;
  cursor: pointer;
}

.timer-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Custom round generator */

.custom-round-panel {
  margin-top: 8px;
}

.custom-round-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.custom-round-form input[type="text"] {
  flex: 1 1 240px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--white);
  font-family: inherit;
  font-size: 16px; /* iOS Safari auto-zooms on focus below 16px */
}

.custom-round-form input[type="text"]::placeholder {
  color: var(--white-dim);
}

.custom-round-form select {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--white);
  font-family: inherit;
  font-size: 0.95rem;
}

.custom-round-status {
  margin-top: 12px;
  text-align: center;
  color: var(--white-dim);
  font-style: italic;
}

.custom-round-status.hidden {
  display: none;
}

/* Play history */

.history-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
}

.history-panel h3 {
  text-align: center;
  color: var(--gold);
  font-family: "Aladin", cursive;
  font-weight: 400;
  font-size: 1.4rem;
  margin: 0 0 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px 12px;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-topic {
  color: var(--white);
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  color: var(--white-dim);
  font-size: 0.8rem;
  text-transform: capitalize;
}

.history-score {
  flex-shrink: 0;
  color: var(--gold);
  font-weight: bold;
  font-size: 0.95rem;
}

.history-empty {
  text-align: center;
  color: var(--white-dim);
  font-style: italic;
  margin: 0;
}

/* Game HUD */

.game-hud {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  font-weight: bold;
}

.hud-item {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.hud-button {
  color: var(--gold);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.hud-button:hover {
  border-color: var(--gold-border);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.35);
}

/* Confirm modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

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

.modal-box {
  background: var(--bg-card-raised);
  border: 1px solid var(--gold-border);
  border-radius: 14px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 20px rgba(255, 200, 6, 0.25), 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-title {
  margin: 0 0 10px;
  color: var(--gold);
  font-family: "Aladin", cursive;
  font-weight: 400;
  font-size: 1.6rem;
}

.modal-message {
  margin: 0 0 20px;
  color: var(--white-dim);
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.timer-bar-track {
  width: 100%;
  height: 10px;
  background: var(--bg-deep);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.timer-bar-track.hidden {
  display: none;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #0057ff, var(--gold));
  transition: width 1s linear, background-color 0.3s ease;
}

.timer-bar.low {
  background: linear-gradient(90deg, var(--bad), #ff7a52);
}

.question-category {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--gold);
  margin: 0 0 8px;
  text-align: center;
}

h2.question-text {
  text-align: center;
  margin: 0 0 20px;
  font-family: "Roboto", "Helvetica Neue", sans-serif;
  font-weight: 500;
  color: var(--white);
  font-size: 1.3rem;
  line-height: 1.4;
}

.choices {
  display: grid;
  gap: 10px;
}

.choice-btn {
  background: var(--bg-card);
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 14px 16px;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease, border-color 0.08s ease, background 0.2s ease;
}

.choice-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--gold-border);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-btn.correct {
  background: var(--good);
  border-color: var(--good);
  color: white;
}

.choice-btn.incorrect {
  background: var(--bad);
  border-color: var(--bad);
  color: white;
}

.choice-btn.reveal-correct {
  background: var(--good);
  border-color: var(--good);
  color: white;
  outline: 2px solid var(--gold-border);
}

.feedback {
  margin-top: 18px;
  text-align: center;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  padding-top: 16px;
}

.feedback.hidden {
  display: none;
}

.feedback-result {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 0 0 8px;
}

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

.feedback-result.incorrect {
  color: #ff8a8a;
}

.feedback-tidbit {
  font-style: italic;
  color: var(--white-dim);
  margin: 0 0 16px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 12px rgba(255, 200, 6, 0.4);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--gold);
  color: var(--bg-deep);
}

.btn-secondary {
  background: transparent;
  color: var(--white);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Results */

.results-summary {
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--white);
}

.results-breakdown {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
  max-height: 420px;
  overflow-y: auto;
}

.result-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.result-row.incorrect {
  border-color: rgba(255, 138, 138, 0.25);
}

.result-row .mark {
  flex-shrink: 0;
  font-weight: bold;
  line-height: 1.5;
}

.result-row.correct .mark {
  color: var(--good);
}

.result-row.incorrect .mark {
  color: #ff8a8a;
}

.result-row .result-question {
  margin: 0;
  color: var(--white);
  line-height: 1.5;
}

.result-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.result-answer {
  margin: 0;
  color: var(--white-dim);
}

.result-answer strong {
  color: var(--white);
  font-weight: 600;
}

.result-tidbit {
  margin: 4px 0 0;
  font-style: italic;
  color: var(--white-dim);
}

.results-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Multiplayer entry point */

.mp-entry {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

/* Multiplayer landing (create/join) */

.mp-landing-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.mp-option-card {
  flex: 1 1 240px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mp-option-card h3 {
  margin: 0 0 4px;
  text-align: center;
  color: var(--gold);
  font-family: "Aladin", cursive;
  font-weight: 400;
  font-size: 1.3rem;
}

.mp-option-card input[type="text"] {
  background: var(--bg-deep);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--white);
  font-family: inherit;
  font-size: 16px; /* iOS Safari auto-zooms on focus below 16px */
}

.mp-option-card input[type="text"]::placeholder {
  color: var(--white-dim);
}

.mp-code-input {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-align: center;
}

/* Multiplayer lobby */

.lobby-code-box {
  text-align: center;
  margin-bottom: 20px;
}

.lobby-code-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--gold);
}

.lobby-code-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 4px 0;
}

.lobby-code-box strong {
  font-family: "Aladin", cursive;
  font-weight: 400;
  font-size: 2.4rem;
  letter-spacing: 0.2em;
  color: var(--white);
}

.btn-copy {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: var(--gold);
  font-size: 1.1rem;
  line-height: 1;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.btn-copy:hover {
  border-color: var(--gold-border);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.35);
}

.lobby-hint {
  margin: 0;
  color: var(--white-dim);
  font-size: 0.85rem;
}

.lobby-player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.lobby-player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.lobby-player-row > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.lobby-player-row > span:last-child {
  flex-shrink: 0;
}

.lobby-host-badge {
  background: var(--gold);
  color: var(--bg-deep);
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 999px;
  padding: 3px 10px;
}

.mp-host-timer-toggle {
  justify-content: flex-start;
  margin: 2px 0;
}

/* Multiplayer: topic submission */

.mp-topic-hint {
  text-align: center;
  color: var(--white-dim);
  margin: 0 0 20px;
}

.mp-topic-form {
  margin-bottom: 16px;
}

.player-status-badge {
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 999px;
  padding: 3px 10px;
}

.player-status-badge.ready {
  background: var(--good);
  color: var(--white);
}

.player-status-badge.pending {
  background: rgba(255, 255, 255, 0.1);
  color: var(--white-dim);
}

.player-status-badge.reconnecting {
  background: var(--gold);
  color: var(--bg-deep);
}

/* Multiplayer: round ready */

.topic-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.topic-summary-row .history-topic {
  flex: 1;
}

.question-preview-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.question-preview-row .question-preview-text {
  flex: 1;
  color: var(--white);
}

.question-preview-row .question-preview-source {
  flex-shrink: 0;
  color: var(--gold);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Multiplayer: synchronized gameplay */

.choice-btn.selected-pending {
  border-color: var(--gold-border);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.35);
}

.score-badge {
  background: var(--gold);
  color: var(--bg-deep);
  font-size: 0.8rem;
  font-weight: bold;
  border-radius: 999px;
  padding: 3px 10px;
}

/* Conjuring spinner (round generation — solo + multiplayer) */

.conjure-spinner {
  position: relative;
  width: 48px;
  height: 48px;
  margin: 14px auto 0;
}

.conjure-spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid rgba(255, 200, 6, 0.15);
  border-top-color: var(--gold);
  border-right-color: var(--gold-border);
  animation: conjure-spin 0.9s linear infinite;
}

.conjure-spinner-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  animation: conjure-pulse 1.4s ease-in-out infinite;
}

@keyframes conjure-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes conjure-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}

/* Phase 4: reconnection */

.mp-reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  text-align: center;
  padding: 10px;
  background: var(--gold);
  color: var(--bg-deep);
  font-weight: bold;
}

/* Daily pack streak + stats */

.btn-link {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-link:hover {
  color: var(--gold-border);
}

.stats-modal-box {
  max-width: 420px;
}

.stats-summary {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 20px;
}

.stats-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats-summary-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--gold);
  line-height: 1.1;
}

.stats-summary-label {
  font-size: 0.75rem;
  color: var(--white-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.stats-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-bar-label {
  width: 42px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.85rem;
  color: var(--white-dim);
  white-space: nowrap;
}

.stats-bar-row.perfect .stats-bar-label {
  color: var(--gold);
  font-weight: bold;
}

.stats-bar-track {
  flex: 1;
  background: var(--bg-deep);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stats-bar-fill {
  min-width: 22px;
  background: linear-gradient(90deg, #0057ff, var(--gold));
  color: var(--bg-deep);
  font-size: 0.75rem;
  font-weight: bold;
  text-align: right;
  padding: 2px 6px;
  white-space: nowrap;
  border-radius: 6px;
}

.stats-bar-row.perfect .stats-bar-fill {
  background: var(--gold);
}
