:root {
  --ink: #17202a;
  --muted: #667085;
  --paper: #fffdf7;
  --line: #d9dde6;
  --mint: #d9f4e7;
  --coral: #ff8066;
  --teal: #0e7c7b;
  --gold: #f7c948;
  --blue: #276ef1;
  --red: #d92d20;
  --shadow: 0 18px 50px rgba(23, 32, 42, 0.14);
}

body.dark {
  --ink: #ffffff;
  --muted: #d7dee9;
  --paper: #0b1220;
  --line: #748094;
  --mint: #164e3d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
  background:
    radial-gradient(circle at top left, rgba(125, 211, 252, 0.12), transparent 28rem),
    linear-gradient(135deg, #030712 0%, #111827 58%, #020617 100%);
}

body.dark .ambient-shape {
  opacity: 0.1;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 128, 102, 0.18), transparent 32rem),
    linear-gradient(135deg, #f8fbff 0%, #fff7ed 52%, #eefbf5 100%);
}

.ambient-shapes {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient-shape {
  position: absolute;
  display: block;
  opacity: 0.16;
  filter: blur(0.2px);
}

.shape-one {
  width: 210px;
  height: 210px;
  left: 4vw;
  top: 130px;
  border: 34px solid #ff8066;
  border-radius: 50%;
}

.shape-two {
  width: 170px;
  height: 170px;
  right: 5vw;
  top: 210px;
  transform: rotate(18deg);
  background: #f7c948;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.shape-three {
  width: 260px;
  height: 90px;
  left: 3vw;
  bottom: 130px;
  border: 28px solid #276ef1;
  border-radius: 999px;
  transform: rotate(-18deg);
}

.shape-four {
  width: 230px;
  height: 120px;
  right: 2vw;
  bottom: 100px;
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, #0e7c7b 0 24px, transparent 24px 42px);
  transform: rotate(14deg);
}

.shape-five {
  width: 150px;
  height: 150px;
  left: 12vw;
  top: 56%;
  background: #7c3aed;
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 34%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1040px, calc(100% - 8cm));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbar h1,
.topbar p {
  margin: 0;
}

body.auth-screen .topbar {
  display: none;
}

body.auth-screen .app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.05;
}

.lead {
  max-width: 680px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: end;
  min-height: 190px;
  padding: 28px;
  overflow: hidden;
  border: 1px solid rgba(23, 32, 42, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(255,255,255,0.86), rgba(255,255,255,0.44)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='800' height='420' viewBox='0 0 800 420'%3E%3Crect width='800' height='420' fill='%23f5f7fb'/%3E%3Cg opacity='0.88'%3E%3Ccircle cx='112' cy='90' r='42' fill='%23ff8066'/%3E%3Cpath d='M600 45h110v110H600z' fill='%230e7c7b'/%3E%3Cpath d='M470 250l65-112 65 112z' fill='%23f7c948'/%3E%3Cpath d='M132 260c32-52 78-58 118-18s85 32 124-20' fill='none' stroke='%23276ef1' stroke-width='22' stroke-linecap='round'/%3E%3Cg fill='%2317202a' font-family='Arial' font-size='44' font-weight='700'%3E%3Ctext x='88' y='155'%3E?%3C/text%3E%3Ctext x='630' y='118'%3E✓%3C/text%3E%3Ctext x='485' y='238'%3E4%3C/text%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  background-position: center;
  background-size: cover;
  box-shadow: var(--shadow);
}

.hero h2 {
  max-width: 780px;
  font-size: clamp(1.8rem, 4.2vw, 3.8rem);
}

.score-pill {
  display: grid;
  place-items: center;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
}

.score-pill span {
  display: block;
  font-size: 2.8rem;
  font-weight: 900;
}

.score-pill small {
  margin-top: -24px;
  color: #d6f7ec;
  font-weight: 700;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  grid-template-areas:
    "a a b b"
    "c c d d"
    ". center center .";
  gap: 14px 14px;
  margin-top: 16px;
  align-items: center;
  justify-content: center;
}

.category-card:nth-child(1) {
  grid-area: a;
}

.category-card:nth-child(2) {
  grid-area: b;
}

.category-card:nth-child(3) {
  grid-area: c;
}

.category-card:nth-child(4) {
  grid-area: d;
}

.category-card:nth-child(5) {
  grid-area: center;
  min-height: 132px;
  align-self: center;
  justify-self: center;
  width: min(100%, 470px);
}

.category-grid.locked {
  opacity: 0.38;
  pointer-events: none;
  filter: grayscale(0.85);
}

.locked-note {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(217, 45, 32, 0.24);
  border-radius: 8px;
  background: #fff1ef;
  color: var(--red);
  font-weight: 900;
}

.locked-note.active {
  display: block;
}

.player-card {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid rgba(23, 32, 42, 0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.84);
  box-shadow: 0 8px 24px rgba(23, 32, 42, 0.08);
}

.player-card p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.category-card {
  min-height: 132px;
  padding: 15px;
  text-align: left;
  border: 1px solid rgba(23, 32, 42, 0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.82);
  box-shadow: 0 10px 30px rgba(23, 32, 42, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.category-card:nth-child(5) .big-icon,
.category-card:nth-child(5) .category-photo {
  margin-inline: auto;
}

.category-card:nth-child(5) {
  text-align: center;
}

.category-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.category-card .big-icon,
.category-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 12px;
  border-radius: 50%;
  color: white;
  background: var(--teal);
  font-size: 1.55rem;
}

.category-photo {
  display: block;
  width: 100%;
  height: 58px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid rgba(23, 32, 42, 0.12);
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 -34px 42px rgba(0, 0, 0, 0.2);
}

.photo-popular {
  background-image:
    linear-gradient(180deg, rgba(0,0,0,0.05), rgba(0,0,0,0.35)),
    url("https://cdn.pixabay.com/photo/2017/08/26/21/51/popcorn-2684432_1280.jpg");
  background-position: center;
}

.photo-general {
  background-image:
    linear-gradient(135deg, rgba(39,110,241,0.16), rgba(0,0,0,0.16)),
    url("https://images.unsplash.com/photo-1457369804613-52c61a468e7d?auto=format&fit=crop&w=500&q=70");
}

.photo-sports {
  background-image:
    linear-gradient(180deg, rgba(0,0,0,0.02), rgba(0,0,0,0.28)),
    url("https://cdn.pixabay.com/photo/2014/10/14/20/24/soccer-488700_1280.jpg");
}

.photo-flags {
  background-image:
    linear-gradient(135deg, rgba(247,201,72,0.16), rgba(0,0,0,0.18)),
    url("https://images.unsplash.com/photo-1526778548025-fa2f459cd5c1?auto=format&fit=crop&w=500&q=70");
}

.photo-marveldc {
  background-image:
    linear-gradient(135deg, rgba(124,58,237,0.2), rgba(0,0,0,0.18)),
    url("https://images.unsplash.com/photo-1612036782180-6f0b6cd846fe?auto=format&fit=crop&w=500&q=70");
}

.category-card h3 {
  margin-bottom: 7px;
  font-size: 1.08rem;
}

.category-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.category-stage,
.question-panel,
.result-box,
.admin-layout,
.login-box,
.auth-box {
  border: 1px solid rgba(23, 32, 42, 0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.88);
  box-shadow: var(--shadow);
}

.category-stage {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 26px;
  align-items: center;
  padding: 34px;
  min-height: 260px;
}

.category-stage h2 {
  font-size: clamp(2rem, 5vw, 4.2rem);
}

.category-actions {
  display: grid;
  gap: 12px;
  min-width: 180px;
}

.quiz-head {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 800;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf5;
}

#progressBar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--coral), var(--gold), var(--teal));
  transition: width 0.25s ease;
}

.question-panel {
  padding: 34px;
}

.source-line {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

#questionText {
  font-size: clamp(1.7rem, 4vw, 3rem);
  margin-bottom: 24px;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.answer-button {
  min-height: 78px;
  padding: 18px;
  text-align: left;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.35;
}

.answer-button:hover {
  border-color: var(--blue);
}

.answer-button.correct {
  border-color: #12b76a;
  background: #dcfae6;
}

.answer-button.wrong {
  border-color: var(--red);
  background: #fee4e2;
}

.answer-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 36px;
  margin: 18px 0 8px;
  font-weight: 900;
}

.result-box {
  max-width: 760px;
  margin: 0 auto;
  padding: 38px;
  text-align: center;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 28px 0;
}

.result-stats div {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.result-stats strong {
  display: block;
  font-size: 2.2rem;
}

.result-stats span {
  color: var(--muted);
  font-weight: 800;
}

.admin-layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 640px;
  overflow: hidden;
}

.admin-sidebar {
  padding: 24px;
  background: var(--ink);
  color: white;
}

.admin-sidebar p {
  color: #d0d5dd;
  line-height: 1.55;
}

.admin-tools {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.admin-main {
  padding: 24px;
}

.editor {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.field small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: white;
  color: var(--ink);
}

.field.compact {
  margin: 0;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.question-list-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0 12px;
}

.question-list {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 6px;
}

.players-head {
  margin-top: 28px;
}

.players-list {
  max-height: 260px;
}

.question-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.question-item p {
  margin: 5px 0 0;
  color: var(--muted);
}

.item-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button,
.text-button {
  border: 0;
  border-radius: 8px;
  font-weight: 900;
}

.icon-button {
  width: 48px;
  height: 48px;
  background: white;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(23, 32, 42, 0.08);
  font-size: 1.45rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid #17202a;
  border-radius: 8px;
  background: #fff9d7;
  color: #17202a;
  box-shadow: 0 8px 22px rgba(23, 32, 42, 0.08);
  font-weight: 900;
}

.theme-toggle span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #17202a;
  color: #fff9d7;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 46px;
  padding: 12px 18px;
}

.primary-button {
  background: var(--ink);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.danger-button {
  background: #fee4e2;
  color: var(--red);
}

.text-button {
  margin-bottom: 14px;
  background: transparent;
  color: var(--teal);
  padding-left: 0;
}

.score-chip {
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--mint);
  color: #05603a;
  font-weight: 900;
  white-space: nowrap;
}

.login-box {
  max-width: 430px;
  margin: 0 auto;
  padding: 30px;
}

.auth-box {
  max-width: 460px;
  margin: 0 auto;
  padding: 34px;
}

.auth-box h2 {
  font-size: clamp(2rem, 6vw, 3.4rem);
}

.auth-box form {
  margin-top: 24px;
}

.primary-button.wide {
  width: 100%;
}

.signup-line {
  margin: 12px 0 0;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.signup-line button {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-weight: 900;
  text-decoration: underline;
}

.error-text {
  min-height: 24px;
  margin: 0 0 10px;
  color: var(--red);
  font-weight: 900;
}

body.dark .hero,
body.dark .category-card,
body.dark .player-card,
body.dark .category-stage,
body.dark .question-panel,
body.dark .result-box,
body.dark .admin-layout,
body.dark .login-box,
body.dark .auth-box {
  border-color: rgba(255, 255, 255, 0.34);
  background: #111827;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.58);
}

body.dark .field input,
body.dark .field select,
body.dark .field textarea,
body.dark .answer-button,
body.dark .question-item,
body.dark .result-stats div,
body.dark .icon-button,
body.dark .secondary-button {
  background: #f8fafc;
  color: #0f172a;
  border-color: #cbd5e1;
}

body.dark h1,
body.dark h2,
body.dark h3,
body.dark strong,
body.dark .question-item strong,
body.dark #questionText,
body.dark .category-card h3 {
  color: #ffffff;
}

body.dark p,
body.dark .lead,
body.dark .category-card p,
body.dark .question-item p,
body.dark .field span,
body.dark .source-line,
body.dark .progress-info,
body.dark #playerStatus {
  color: #d7dee9;
}

body.dark .eyebrow {
  color: #93c5fd;
}

body.dark .category-card {
  background: #f8fafc;
}

body.dark .category-card h3 {
  color: #020617;
}

body.dark .category-card p {
  color: #334155;
}

body.dark .category-photo {
  border-color: rgba(15, 23, 42, 0.18);
}

body.dark .player-card,
body.dark .category-stage,
body.dark .question-panel,
body.dark .result-box,
body.dark .login-box,
body.dark .auth-box {
  color: #ffffff;
}

body.dark .signup-line button {
  color: #93c5fd;
}

body.dark .answer-button:hover {
  border-color: #93c5fd;
}

body.dark .answer-button.correct {
  border-color: #22c55e;
  background: #16a34a;
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.22);
}

body.dark .answer-button.wrong {
  border-color: #ef4444;
  background: #dc2626;
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.22);
}

body.dark .feedback {
  color: #ffffff;
}

body.dark .theme-toggle {
  border-color: #f8fafc;
  background: #facc15;
  color: #111827;
}

body.dark .theme-toggle span {
  background: #111827;
  color: #facc15;
}

body.dark .locked-note {
  background: rgba(217, 45, 32, 0.16);
}

body.dark .primary-button,
body.dark .score-pill {
  background: #facc15;
  color: #111827;
}

body.dark .admin-sidebar {
  background: #101828;
  color: #f8fafc;
}

body.dark .admin-main {
  background: #0f172a;
}

body.dark .admin-main h3,
body.dark .admin-main label span,
body.dark .admin-sidebar h2,
body.dark .admin-sidebar .eyebrow {
  color: #ffffff;
}

body.dark .admin-sidebar p {
  color: #d7dee9;
}

body.dark .admin-tools .secondary-button {
  background: #f8fafc;
  color: #0f172a;
}

body.dark .score-pill small {
  color: #334155;
}

body.dark .admin-sidebar {
  border-right: 1px solid rgba(255,255,255,0.22);
}

body.dark .danger-button {
  background: #fee2e2;
  color: #991b1b;
}

body.dark .score-chip {
  background: #dcfce7;
  color: #14532d;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.editor .button-row {
  justify-content: flex-start;
}

.hidden,
.file-button input {
  display: none;
}

@media (max-width: 900px) {
  .answers,
  .option-grid,
  .admin-layout,
  .category-stage,
  .player-card {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: min(100% - 32px, 940px);
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "a b"
      "c d"
      "center center";
  }

  .category-card:nth-child(5) {
    min-height: 132px;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .score-pill {
    width: 112px;
    height: 112px;
  }

  .quiz-head {
    grid-template-columns: 48px 1fr;
  }

  .score-chip {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 10px 10px 28px;
  }

  body.auth-screen .app-shell {
    padding: 18px;
  }

  .hero,
  .category-stage,
  .question-panel,
  .result-box,
  .auth-box,
  .admin-main,
  .admin-sidebar {
    padding: 20px;
  }

  .topbar {
    grid-template-columns: 40px 1fr;
    gap: 10px;
    align-items: start;
    margin-bottom: 12px;
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .topbar h1 {
    font-size: 1.45rem;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .theme-toggle {
    min-height: 40px;
    padding: 0 10px;
  }

  .category-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "a"
      "b"
      "center"
      "c"
      "d";
    gap: 10px;
    margin-top: 12px;
  }

  .category-card,
  .category-card:nth-child(5) {
    width: 100%;
    min-height: 118px;
    padding: 12px;
  }

  .category-photo {
    height: 52px;
    margin-bottom: 9px;
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 14px;
    min-height: 0;
  }

  .hero h2 {
    font-size: clamp(2rem, 12vw, 3.1rem);
    line-height: 1.05;
  }

  .score-pill {
    width: 96px;
    height: 96px;
    justify-self: start;
  }

  .score-pill span {
    font-size: 2rem;
  }

  .score-pill small {
    margin-top: -18px;
  }

  .player-card {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .player-card .secondary-button {
    width: 100%;
  }

  .category-stage {
    gap: 14px;
  }

  .category-icon {
    width: 54px;
    height: 54px;
    margin-bottom: 0;
  }

  .category-stage h2 {
    font-size: 2.1rem;
  }

  .category-actions {
    min-width: 0;
  }

  .quiz-head {
    grid-template-columns: 40px 1fr;
    gap: 10px;
  }

  .score-chip {
    width: 100%;
    text-align: center;
  }

  #questionText {
    font-size: 1.45rem;
  }

  .answers {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .answer-button {
    min-height: 62px;
    padding: 14px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .button-row,
  .editor .button-row {
    justify-content: stretch;
  }

  .button-row button,
  .editor .button-row button {
    flex: 1 1 100%;
  }

  .admin-layout {
    min-height: 0;
  }

  .question-list-head {
    display: grid;
    align-items: stretch;
  }

  .question-item {
    grid-template-columns: 1fr;
  }

  .item-actions {
    justify-content: stretch;
  }

  .item-actions button {
    flex: 1;
  }

  .auth-box {
    width: 100%;
    max-width: 420px;
    padding: 24px;
  }

  .auth-box h2 {
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .ambient-shapes {
    display: none;
  }
}
