/* Arabic Mobile Kahoot — Design System & Styles */

/* Self-hosted Cairo (variable). Replaces the render-blocking Google Fonts
   @import, which serialised the font request behind the stylesheet download. */
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('/fonts/cairo-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF,
    U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('/fonts/cairo-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('/fonts/cairo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font-arabic: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Primary Kahoot palette */
  --color-red: #E21B3C;
  --color-red-dark: #B5122C;
  --color-blue: #1368CE;
  --color-blue-dark: #0D4E9E;
  --color-yellow: #D89E00;
  --color-yellow-dark: #A57800;
  --color-green: #26890C;
  --color-green-dark: #1C6708;

  /* Neutrals */
  --bg-dark: #0E1322;
  --bg-card: rgba(26, 34, 56, 0.85);
  --bg-card-hover: rgba(36, 48, 78, 0.95);
  --border-color: rgba(255, 255, 255, 0.12);
  --text-main: #FFFFFF;
  --text-muted: #94A3B8;
  --accent-gold: #FBBF24;
  --accent-purple: #8B5CF6;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --focus-ring: 0 0 0 3px #0E1322, 0 0 0 6px var(--accent-gold);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font-arabic);
  touch-action: manipulation;
}

/* The `hidden` attribute must beat any `display` rule further down this file.
   Without this, components like .host-control-bar and .answered-strip that set
   `display: flex` stay visible even when JS marks them hidden. */
[hidden] {
  display: none !important;
}

body {
  direction: rtl;
  text-align: right;
  background: radial-gradient(circle at top, #1E293B, var(--bg-dark));
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

/* Chrome is non-selectable; content the user may want to copy is not.
   The old blanket `user-select: none` on body blocked copying question text. */
.app-header,
.btn,
.answer-card,
.avatar-item,
.podium-container,
.host-control-bar,
.timer-circle {
  user-select: none;
  -webkit-user-select: none;
}

/* Visible focus for keyboard users everywhere. */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  right: -9999px;
  top: 8px;
  z-index: 10001;
  background: var(--accent-gold);
  color: #0E1322;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 800;
  text-decoration: none;
}
.skip-link:focus {
  right: 8px;
}

#app-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  position: relative;
}

#main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 14px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.5px;
}

.brand-logo .logo-badge {
  background: linear-gradient(135deg, var(--color-red), var(--color-yellow));
  color: #FFF;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  transform: scale(1.05);
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.25s ease-out forwards;
}

.screen.active {
  display: flex;
}

.screen:focus {
  outline: none;
}

.screen-centered {
  justify-content: center;
  align-items: center;
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-divider {
  text-align: center;
  margin: 8px 0 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Forms */
.input-group {
  margin-bottom: 14px;
  border: none;
}

.input-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.field-error {
  font-size: 0.82rem;
  font-weight: 700;
  color: #FCA5A5;
  margin-top: 6px;
}

.form-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 1.05rem;
  color: #FFF;
  outline: none;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(19, 104, 206, 0.25);
}

.form-input[aria-invalid='true'] {
  border-color: var(--color-red);
}

.select-strong {
  font-weight: 700;
}

.pin-input {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 6px;
  text-align: center;
  color: var(--accent-gold);
}

.radio-row {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.setting-toggle-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

.toggle-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

.setting-toggle-card input[type='checkbox'],
.setting-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-green);
  cursor: pointer;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: var(--transition);
  margin-bottom: 10px;
  color: white;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-compact {
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 0;
}

.btn-primary {
  background: linear-gradient(135deg, #1368CE, #0D4E9E);
  box-shadow: 0 4px 14px rgba(19, 104, 206, 0.35);
}

.btn-success {
  background: linear-gradient(135deg, #26890C, #1C6708);
  box-shadow: 0 4px 14px rgba(38, 137, 12, 0.35);
}

.btn-danger {
  background: linear-gradient(135deg, #E21B3C, #B5122C);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.button-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.button-row .btn {
  flex: 1;
}

/* Avatars */
.avatar-fieldset {
  border: none;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.avatar-item {
  font-size: 1.75rem;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 8px 0;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  color: inherit;
  line-height: 1.2;
}

.avatar-item.selected {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.15);
  transform: scale(1.1);
}

/* Quiz list */
.quiz-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
  padding-left: 2px;
  /* Fade at the bottom edge so it reads as scrollable. */
  mask-image: linear-gradient(to bottom, #000 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 88%, transparent 100%);
}

.quiz-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
  text-align: right;
  color: inherit;
  width: 100%;
}

.quiz-card:hover {
  border-color: var(--color-blue);
  background: rgba(30, 41, 59, 0.8);
}

.quiz-card.selected {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.12);
}

.quiz-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.quiz-card-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.quiz-card-title {
  font-weight: 700;
  font-size: 1rem;
}

.quiz-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.quiz-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.card-action-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.95rem;
  padding: 6px 8px;
  cursor: pointer;
}

.card-action-btn.danger {
  color: var(--color-red);
}

/* Lobby */
.pin-display-box {
  background: linear-gradient(135deg, rgba(19, 104, 206, 0.2), rgba(226, 27, 60, 0.2));
  border: 2px dashed var(--accent-gold);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  margin-bottom: 14px;
}

.pin-display-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.pin-display-code {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 5px;
  color: var(--accent-gold);
  margin: 4px 0 10px;
  user-select: all;
}

.lobby-share-row {
  margin-bottom: 4px;
}

.qr-code-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px auto 0;
  padding: 10px;
  background: white;
  border-radius: var(--radius-md);
  width: fit-content;
}

.qr-code-wrapper:empty {
  display: none;
}

.lobby-quiz-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.lobby-quiz-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.lobby-players-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.lobby-players-grid:empty {
  display: none;
}

.player-pill {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 0;
}

.player-pill.is-host {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.14);
}

.player-pill.disconnected {
  opacity: 0.5;
}

.player-pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-kick-btn {
  background: none;
  border: none;
  color: var(--color-red);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 18px 8px;
}

.waiting-note {
  text-align: center;
  color: var(--accent-gold);
  font-weight: 700;
  padding: 10px;
  font-size: 0.92rem;
}

/* Countdown */
.countdown-label {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--text-muted);
}

.countdown-num {
  font-size: 6rem;
  font-weight: 900;
  color: var(--accent-gold);
  animation: pulseUrgent 0.8s infinite alternate;
}

/* Question */
.question-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 12px;
}

.question-progress-bar {
  height: 100%;
  background: var(--accent-gold);
  width: 100%;
}

.question-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.question-counter-pill {
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.9rem;
}

.score-pill {
  background: rgba(251, 191, 36, 0.16);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 0.9rem;
  margin-inline-start: auto;
  margin-inline-end: 8px;
}

.timer-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 3px solid var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--accent-gold);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.timer-circle.urgent {
  border-color: var(--color-red);
  color: var(--color-red);
  animation: pulseUrgent 0.5s infinite alternate;
}

@keyframes pulseUrgent {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

.question-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 14px;
  text-align: center;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.question-image {
  max-height: 22vh;
  max-width: 100%;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.question-text {
  /* Scales down on small screens instead of pushing the answer grid off-screen. */
  font-size: clamp(1rem, 4.2vw, 1.25rem);
  font-weight: 800;
  line-height: 1.45;
  user-select: text;
  -webkit-user-select: text;
}

/* Answers */
.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.answer-card {
  min-height: 96px;
  border-radius: var(--radius-lg);
  border: 3px solid transparent;
  padding: 12px;
  color: white;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  text-align: right;
}

.answer-card:active {
  transform: scale(0.96);
}

.answer-card.disabled {
  pointer-events: none;
}

/* Replaces the inline `box-shadow` that app.js used to write directly. */
.answer-card.selected {
  border-color: #FFFFFF;
  transform: scale(1.02);
}

.answer-card.dimmed {
  opacity: 0.45;
}

.answer-card.is-correct {
  border-color: #FFFFFF;
  box-shadow: 0 0 0 4px rgba(38, 137, 12, 0.6);
}

.answer-card-red { background: linear-gradient(135deg, var(--color-red), var(--color-red-dark)); }
.answer-card-blue { background: linear-gradient(135deg, var(--color-blue), var(--color-blue-dark)); }
.answer-card-yellow { background: linear-gradient(135deg, var(--color-yellow), var(--color-yellow-dark)); }
.answer-card-green { background: linear-gradient(135deg, var(--color-green), var(--color-green-dark)); }

.answer-card-shape {
  font-size: 1.2rem;
  opacity: 0.9;
}

.answer-card-text {
  font-size: clamp(0.88rem, 3.6vw, 1.02rem);
  line-height: 1.35;
  word-break: break-word;
}

.answer-count {
  position: absolute;
  inset-inline-start: 10px;
  top: 10px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: var(--radius-full);
  padding: 2px 9px;
  font-size: 0.8rem;
  font-weight: 800;
}

.answered-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  background: rgba(38, 137, 12, 0.18);
  border: 1px solid var(--color-green);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
}

/* Result */
.result-banner {
  border-radius: var(--radius-lg);
  padding: 20px 14px;
  text-align: center;
  margin-bottom: 14px;
}

.result-banner.correct {
  background: linear-gradient(135deg, rgba(38, 137, 12, 0.4), rgba(38, 137, 12, 0.85));
  border: 2px solid var(--color-green);
}

.result-banner.wrong {
  background: linear-gradient(135deg, rgba(226, 27, 60, 0.4), rgba(226, 27, 60, 0.85));
  border: 2px solid var(--color-red);
}

.result-banner.neutral {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.25), rgba(71, 85, 105, 0.7));
  border: 2px solid var(--text-muted);
}

.result-title {
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 4px;
}

.points-earned-pill {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-gold);
}

.streak-flame {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  margin-top: 8px;
}

.result-rank {
  margin-top: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  opacity: 0.9;
}

.correct-answer-card {
  text-align: center;
  border-color: var(--color-green);
  background: rgba(38, 137, 12, 0.14);
}

.correct-answer-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.correct-answer-text {
  font-size: 1.15rem;
  font-weight: 800;
  color: #86EFAC;
  user-select: text;
  -webkit-user-select: text;
}

/* Answer distribution — the data was already on the wire, just never drawn. */
.distribution-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.dist-shape {
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  font-weight: 800;
}

.dist-track {
  flex: 1;
  height: 22px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.dist-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 2px;
}

.dist-fill.c0 { background: linear-gradient(90deg, var(--color-red), var(--color-red-dark)); }
.dist-fill.c1 { background: linear-gradient(90deg, var(--color-blue), var(--color-blue-dark)); }
.dist-fill.c2 { background: linear-gradient(90deg, var(--color-yellow), var(--color-yellow-dark)); }
.dist-fill.c3 { background: linear-gradient(90deg, var(--color-green), var(--color-green-dark)); }

.dist-count {
  width: 34px;
  text-align: left;
  font-weight: 800;
  flex-shrink: 0;
}

/* Leaderboard */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-row {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.leaderboard-row.top-1 {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.15);
}

.leaderboard-row.is-you {
  border-color: var(--color-blue);
  background: rgba(19, 104, 206, 0.22);
}

.player-info-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.rank-badge {
  font-size: 1.1rem;
  font-weight: 800;
  width: 26px;
  flex-shrink: 0;
}

.rank-delta {
  font-size: 0.75rem;
  font-weight: 800;
  margin-inline-start: 4px;
}

.rank-delta.up { color: #4ADE80; }
.rank-delta.down { color: #FCA5A5; }

.score-badge {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-gold);
  flex-shrink: 0;
}

/* Stagger-in for leaderboard rows. */
.fade-in-stagger {
  opacity: 0;
  animation: slideInRight 0.4s ease-out forwards;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.pulse-wait {
  display: inline-block;
  animation: pulseWait 1.5s infinite alternate ease-in-out;
}

@keyframes pulseWait {
  0% { transform: scale(0.95); opacity: 0.7; }
  100% { transform: scale(1.15); opacity: 1; }
}

/* Podium */
.podium-heading {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent-gold);
  text-align: center;
  margin-bottom: 8px;
}

.podium-container {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  height: 220px;
  margin: 12px 0;
}

.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 31%;
}

.podium-avatar {
  font-size: 2.2rem;
  margin-bottom: 4px;
}

.podium-name {
  font-weight: 800;
  font-size: 0.85rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.podium-pillar {
  width: 100%;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: white;
  padding-top: 8px;
}

.podium-score {
  font-size: 0.8rem;
  font-weight: 700;
}

.podium-pillar.rank-1 { height: 130px; background: linear-gradient(180deg, #FBBF24, #B45309); font-size: 1.8rem; }
.podium-pillar.rank-2 { height: 95px; background: linear-gradient(180deg, #94A3B8, #475569); font-size: 1.5rem; }
.podium-pillar.rank-3 { height: 70px; background: linear-gradient(180deg, #D97706, #78350F); font-size: 1.3rem; }

.personal-summary {
  background: rgba(19, 104, 206, 0.2);
  border: 2px solid var(--color-blue);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  margin-bottom: 12px;
}

.personal-summary strong {
  color: var(--accent-gold);
  font-size: 1.3rem;
}

.full-standings {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin-bottom: 12px;
}

.full-standings summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
}

.full-standings .leaderboard-list {
  margin-top: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.podium-actions {
  margin-top: auto;
  flex-direction: column;
}

/* Host control bar */
.host-control-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(14, 19, 34, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
}

.host-bar-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
}

.host-bar-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.host-bar-btn.danger {
  border-color: var(--color-red);
  color: #FCA5A5;
}

body.host-bar-visible #app-container {
  padding-bottom: 78px;
}

/* Presenter mode: the observer host gets a display screen, not a player UI. */
body.presenter #app-container {
  max-width: 900px;
}

body.presenter .question-text {
  font-size: clamp(1.4rem, 3.4vw, 2.4rem);
}

body.presenter .answer-card {
  min-height: 120px;
  cursor: default;
  pointer-events: none;
}

body.presenter .answer-card-text {
  font-size: clamp(1rem, 2vw, 1.4rem);
}

body.presenter .score-pill,
body.presenter .answered-strip {
  display: none;
}

/* Connection banner */
.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: var(--color-red);
  color: white;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
}

.connection-banner.visible {
  max-height: 60px;
  padding: 9px 12px;
  padding-top: max(9px, env(safe-area-inset-top));
}

/* Toasts */
.toast-region {
  position: fixed;
  bottom: 24px;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.toast-msg {
  background: #E21B3C;
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
  max-width: 90vw;
  text-align: center;
}

.toast-msg.toast-success { background: #26890C; }
.toast-msg.toast-info { background: #1368CE; }
.toast-msg.leaving { animation: slideDown 0.25s ease forwards; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
  to { transform: translateY(20px); opacity: 0; }
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: rgba(6, 10, 20, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: #151C2F;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 10px;
}

.modal-message {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 18px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.modal-actions .btn {
  margin-bottom: 0;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  cursor: pointer;
}

.setting-row-column {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.setting-label {
  font-weight: 600;
}

/* Builder */
.builder-question-card {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 10px;
}

.builder-q-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.builder-q-title {
  color: var(--accent-gold);
  font-weight: 800;
}

.builder-q-tools {
  display: flex;
  gap: 6px;
  align-items: center;
}

.builder-q-tools .form-input {
  padding: 4px 8px;
  font-size: 0.85rem;
  width: auto;
}

.builder-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.builder-opt-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.builder-opt-input input[type='radio'] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-green);
  flex-shrink: 0;
}

.builder-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.noscript-note {
  padding: 20px;
  text-align: center;
  font-weight: 700;
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 380px) {
  .answer-card { min-height: 84px; padding: 10px; }
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
  .pin-display-code { font-size: 2rem; }
}

/* Landscape phones: the portrait stack does not fit. */
@media (max-height: 520px) and (orientation: landscape) {
  #app-container { max-width: 900px; }
  .app-header { display: none; }
  .question-box { min-height: 0; padding: 10px; margin-bottom: 8px; }
  .answers-grid { grid-template-columns: repeat(4, 1fr); }
  .answer-card { min-height: 72px; }
  .podium-container { height: 150px; }
  .podium-pillar.rank-1 { height: 84px; }
  .podium-pillar.rank-2 { height: 62px; }
  .podium-pillar.rank-3 { height: 46px; }
}

/* Tablet and desktop: a laptop host previously got a 500px column. */
@media (min-width: 768px) {
  #app-container { max-width: 720px; }
  .answer-card { min-height: 120px; }
  .lobby-players-grid { grid-template-columns: repeat(3, 1fr); }
  .podium-container { height: 280px; }
  .podium-pillar.rank-1 { height: 170px; }
  .podium-pillar.rank-2 { height: 125px; }
  .podium-pillar.rank-3 { height: 92px; }
  .podium-actions { flex-direction: row; }
  .modal-actions { flex-direction: row-reverse; }
  .modal-actions .btn { flex: 1; }
}

@media (min-width: 1100px) {
  #app-container { max-width: 860px; }
}

/* --- Reduced motion ------------------------------------------------------
   Honours both the OS setting and the in-app override. The old build had no
   reduced-motion support at all. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

[data-reduce-motion] *,
[data-reduce-motion] *::before,
[data-reduce-motion] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* The progress bar is information, not decoration, so keep it usable when
   motion is reduced — it just stops being animated. */
[data-reduce-motion] .fade-in-stagger {
  animation: none !important;
  opacity: 1 !important;
}
