:root {
  --primary: #7b2cff;
  --primary-2: #a45cff;
  --bg-start: #efe3ff;
  --bg-end: #ffffff;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --text: #1f2430;
  --muted: #697080;
  --ok: #20c05c;
  --shadow: 0 12px 34px rgba(56, 23, 112, 0.14);
  --radius: 18px;
  --font-scale: 1;
  --ui-scale: 1;
}

body.theme-dark {
  --primary: #9d4bff;
  --primary-2: #ca78ff;
  --bg-start: #2b065c;
  --bg-end: #150130;
  --surface: #2d1160;
  --surface-2: #3a1978;
  --text: #f7efff;
  --muted: #d3c2f7;
  --shadow: 0 16px 40px rgba(6, 0, 24, 0.45);
}

body.player-page.theme-dark {
  background: linear-gradient(130deg, #2d0b63 0%, #7d2eff 50%, #3a0d78 100%);
  background-size: 220% 220%;
  animation: purpleFlow 16s ease-in-out infinite;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  font-family: "Segoe UI", "Inter", Arial, sans-serif;
  font-size: calc(16px * var(--font-scale));
  color: var(--text);
  background: radial-gradient(circle at top, var(--bg-start) 0%, #f8f2ff 42%, var(--bg-end) 100%);
}

.player-page {
  overflow: hidden;
}

.app-shell {
  position: relative;
  max-width: min(1080px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(22px * var(--ui-scale));
  display: flex;
  flex-direction: column;
  gap: calc(16px * var(--ui-scale));
}

.portrait {
  aspect-ratio: 9 / 16;
}

.app-header {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  gap: 12px;
}

.brand-center {
  display: grid;
  justify-items: center;
  width: 100%;
  padding: calc(12px * var(--ui-scale)) calc(16px * var(--ui-scale));
  border-radius: 16px;
  background: linear-gradient(140deg, var(--primary), var(--primary-2));
  box-shadow: var(--shadow);
  color: #fff;
}

.brand-logo {
  max-width: min(620px, 96vw);
  max-height: 108px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 14px rgba(255, 255, 255, 0.25));
}

.brand-text {
  text-align: center;
  line-height: 1.15;
}

.brand-text small {
  opacity: 0.95;
}

.chip {
  justify-self: center;
  border-radius: 999px;
  padding: calc(10px * var(--ui-scale)) calc(16px * var(--ui-scale));
  background: #ede2ff;
  color: #4a2f84;
  font-weight: 700;
  font-size: clamp(0.95rem, 1.2vw, 1.2rem);
}

.quiz-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: calc(16px * var(--ui-scale));
  padding-top: calc(8px * var(--ui-scale));
  min-height: 0;
}

.screen-layer {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  opacity: 0;
  max-height: 0;
  pointer-events: none;
  transform: translateY(18px);
  transition: opacity 260ms ease, transform 260ms ease, max-height 260ms ease;
  overflow: hidden;
}

.screen-layer.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  max-height: 65vh;
  margin-bottom: 8px;
}

.quiz-stage.overlay-mode .screen-layer.active {
  flex: 1;
  max-height: none;
  margin-bottom: 0;
}

.quiz-stage.overlay-mode .screen-card {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.quiz-stage.overlay-mode .question-wrap,
.quiz-stage.overlay-mode .options-list {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  max-height: 0;
  margin: 0;
  overflow: hidden;
}

.screen-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  border-radius: 26px;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  color: #fff;
  padding: clamp(28px, 5vw, 52px);
  text-align: center;
  box-shadow: 0 24px 60px rgba(72, 27, 153, 0.35);
}

.screen-layer.is-cover .screen-card {
  background: linear-gradient(140deg, #5d16d1, #8b3cff 58%, #b166ff);
}

.screen-layer.is-interlude .screen-card {
  background: linear-gradient(140deg, #6f1cff, #9a4eff 58%, #b96eff);
}

.screen-layer.is-interlude .screen-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    120deg,
    rgba(255, 255, 255, 0.08) 0,
    rgba(255, 255, 255, 0.08) 18px,
    rgba(255, 255, 255, 0) 18px,
    rgba(255, 255, 255, 0) 36px
  );
  animation: shimmerMove 2s linear infinite;
}

.screen-layer.is-final .screen-card {
  background: linear-gradient(140deg, #5312bf, #7f37f3 58%, #a963ff);
}

.screen-card h2 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
}

.screen-card p {
  margin: 10px 0 0;
  font-size: clamp(1rem, 2vw, 1.3rem);
  opacity: 0.95;
}

.motion-orbs span {
  position: absolute;
  width: clamp(34px, 6vw, 72px);
  height: clamp(34px, 6vw, 72px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.4);
  animation: floatOrb 5.4s ease-in-out infinite;
}

.motion-orbs span::before {
  content: '?';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(1.1rem, 2vw, 1.8rem);
  font-weight: 800;
}

.motion-orbs span:nth-child(1) { left: 8%; top: 16%; animation-delay: 0s; }
.motion-orbs span:nth-child(2) { right: 12%; top: 20%; animation-delay: 0.8s; }
.motion-orbs span:nth-child(3) { left: 42%; bottom: 12%; animation-delay: 1.4s; }

.question-wrap {
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 40px);
  min-height: clamp(130px, 18vh, 260px);
  transition: opacity 220ms ease, transform 220ms ease, max-height 220ms ease;
}

.question-text {
  margin: 0;
  font-size: clamp(1.85rem, 3.35vw, 3.45rem);
  line-height: 1.2;
}

.options-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: calc(14px * var(--ui-scale));
  min-height: 0;
}

.option-item {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
  padding: calc(14px * var(--ui-scale)) calc(18px * var(--ui-scale));
  border-radius: 14px;
  background: var(--surface-2);
  border: 2px solid transparent;
  box-shadow: 0 4px 16px rgba(34, 20, 61, 0.08);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 280ms ease, transform 280ms ease, box-shadow 220ms ease, border-color 220ms ease;
  min-height: clamp(76px, 8vh, 126px);
}

body.theme-dark .chip {
  background: rgba(236, 214, 255, 0.22);
  color: #f4e9ff;
}

body.theme-dark .progress-track {
  background: rgba(255, 255, 255, 0.2);
}

body.theme-dark .site-footer,
body.theme-dark .status-line {
  color: #f4e9ff;
}

body.theme-dark .option-item {
  border-color: rgba(195, 168, 255, 0.24);
}

.option-item:nth-child(1) { animation-delay: 60ms; }
.option-item:nth-child(2) { animation-delay: 110ms; }
.option-item:nth-child(3) { animation-delay: 160ms; }
.option-item:nth-child(4) { animation-delay: 210ms; }

.option-letter {
  width: clamp(34px, 2.5vw, 44px);
  height: clamp(34px, 2.5vw, 44px);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(130deg, var(--primary), var(--primary-2));
  font-weight: 800;
}

.option-text {
  font-size: clamp(1.15rem, 2.25vw, 1.8rem);
  line-height: 1.25;
}

.option-item.correct {
  border-color: rgba(32, 192, 92, 0.95);
  box-shadow: 0 0 0 2px rgba(32, 192, 92, 0.25), 0 0 26px rgba(32, 192, 92, 0.35);
}

.option-item.correct .option-letter {
  background: linear-gradient(130deg, #169844, #4ade80);
}

.option-item.dim {
  opacity: 0.48;
  filter: saturate(0.8);
}

.app-footer {
  margin-top: auto;
}

.status-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 10px;
  font-size: clamp(1rem, 1.4vw, 1.35rem);
}

.timer {
  color: var(--primary);
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #ece6f7;
  overflow: hidden;
}

.progress-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(130deg, var(--primary), var(--primary-2));
  transform-origin: left center;
  transform: scaleX(0);
  will-change: transform;
}

.progress-bar.is-running {
  animation-name: progressDecay;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

.site-footer {
  margin-top: 12px;
  text-align: center;
  color: #4d2f8f;
  font-weight: 700;
  font-size: clamp(0.9rem, 1.2vw, 1.2rem);
  letter-spacing: 0.3px;
}

.app-shell[data-version="v1"] .question-text {
  font-size: clamp(1.45rem, 2.3vw, 2.4rem);
}

.app-shell[data-version="v1"] .option-text {
  font-size: clamp(1rem, 1.9vw, 1.35rem);
}

.app-shell[data-version="v1"] .question-wrap {
  min-height: clamp(90px, 12vh, 170px);
}

.app-shell[data-version="v2"] .question-wrap {
  min-height: clamp(220px, 28vh, 380px);
  padding: clamp(24px, 5vw, 52px);
}

.app-shell[data-version="v2"] .options-list {
  gap: calc(14px * var(--ui-scale));
  grid-template-rows: unset;
}

.app-shell[data-version="v2"] .quiz-stage {
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
}

.app-shell[data-version="v2"] .question-text {
  font-size: clamp(2.25rem, 4.2vw, 4.1rem);
  line-height: 1.18;
}

.app-shell[data-version="v2"] .option-text {
  font-size: clamp(1.45rem, 2.6vw, 2.2rem);
}

.app-shell[data-version="v2"] .option-item {
  min-height: clamp(92px, 9.2vh, 150px);
}

.app-shell[data-version="v2"] .chip {
  font-size: clamp(1.05rem, 1.5vw, 1.45rem);
}

.app-shell[data-version="v2"] .status-line {
  font-size: clamp(1.1rem, 1.45vw, 1.55rem);
}

.app-shell[data-version="v2"] .site-footer {
  font-size: clamp(1rem, 1.3vw, 1.3rem);
}

.app-shell[data-version="v2"] .screen-card h2 {
  font-size: clamp(2.2rem, 4vw, 3.6rem);
}

.app-shell[data-version="v2"] .screen-card p {
  font-size: clamp(1.2rem, 2.3vw, 1.9rem);
}

.fade-in {
  animation: fadeIn 300ms ease;
}

.fade-out {
  animation: fadeOut 220ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-6px); }
}

@keyframes floatOrb {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-12px) scale(1.08); }
}

@keyframes shimmerMove {
  from { transform: translateX(-40px); }
  to { transform: translateX(40px); }
}

@keyframes progressDecay {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

@keyframes purpleFlow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ADMIN */
.admin-page {
  padding: 18px;
}

.admin-shell {
  max-width: 1060px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.admin-header h1 {
  margin: 0;
  font-size: 1.95rem;
}

.admin-header h1 small {
  color: var(--muted);
  font-weight: 600;
}

.admin-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.admin-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.admin-form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid #d8dce6;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

input[type="color"] {
  padding: 4px;
  min-height: 42px;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: #9f70f1;
  box-shadow: 0 0 0 3px rgba(123, 44, 255, 0.14);
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px;
}

.row-logo {
  grid-template-columns: 1fr 220px;
}

.logo-preview-wrap {
  display: grid;
  align-content: start;
  gap: 8px;
  font-weight: 700;
  color: var(--muted);
}

.logo-preview {
  width: 100%;
  max-height: 90px;
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e3d8ff;
  padding: 8px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  background: #efe7ff;
  color: #4b2f86;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn-primary {
  background: linear-gradient(130deg, var(--primary), var(--primary-2));
  color: #fff;
}

.btn-ghost {
  background: #fff;
  border-color: #d9d7e1;
  color: #4f5869;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.list-head h2 {
  margin: 0;
}

.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 46vh;
  overflow: auto;
}

.saved-item {
  border: 1px solid #e3e7ee;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.saved-item strong {
  font-size: 1rem;
}

.saved-item small {
  color: var(--muted);
}

.saved-item button {
  justify-self: end;
}

.feedback {
  margin: 0;
  min-height: 22px;
  font-weight: 700;
}

.admin-site {
  margin: 0;
  text-align: center;
  color: #4d2f8f;
  font-weight: 700;
}

@media (max-width: 920px) {
  .options-grid,
  .row,
  .row-logo,
  .app-header {
    grid-template-columns: 1fr;
  }

  .chip {
    justify-self: start;
  }

  .screen-layer {
    max-height: 75vh;
  }

  .app-shell {
    padding: 12px;
  }
}

@media (min-width: 1800px) {
  .app-shell {
    padding: 34px;
  }

  .option-text {
    font-size: 1.75rem;
  }
}
