:root {
  color-scheme: light;
  --ink: #10213f;
  --muted: #66758e;
  --line: #dce4ef;
  --soft: #f4f7fb;
  --white: #ffffff;
  --blue: #1467e5;
  --blue-dark: #084da9;
  --navy: #092d63;
  --danger: #c73535;
  --shadow: 0 18px 50px rgba(8, 33, 75, 0.14);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -0.035em; line-height: 1.08; }
h1 { font-size: clamp(2rem, 3vw, 3rem); }
h2 { font-size: 1.35rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(145deg, #3477ff, #0753b9);
  box-shadow: 0 12px 25px rgba(20, 103, 229, 0.28), inset 0 1px rgba(255,255,255,.35);
  font-size: 1.65rem;
  font-weight: 900;
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 1.1rem; }
.brand-row { display: inline-flex; align-items: center; gap: 0.7rem; text-decoration: none; font-weight: 800; }
.brand-row.light { color: #fff; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.65rem 1rem;
  color: var(--ink);
  background: #fff;
  font-weight: 750;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(20, 103, 229, .28);
  outline-offset: 2px;
}
.button-primary { color: #fff; background: linear-gradient(145deg, #2175ef, #0754bc); box-shadow: 0 8px 18px rgba(10, 85, 190, .22); }
.button-primary:hover { box-shadow: 0 11px 22px rgba(10, 85, 190, .3); }
.button-secondary { color: var(--blue-dark); border-color: #bfd4f3; background: #edf5ff; }
.button-ghost { border-color: var(--line); background: #fff; }
.button-danger { color: #a02727; border-color: #f3c5c5; background: #fff4f4; }
.button-large { min-height: 52px; padding-inline: 1.4rem; font-size: 1.04rem; }
.button-small { min-height: 36px; padding: .45rem .75rem; font-size: .86rem; }
.button-wide { width: 100%; }
.text-button { padding: .3rem; border: 0; background: transparent; font-weight: 700; }
.text-button.danger { color: var(--danger); }

label { display: grid; gap: .4rem; color: #30415f; font-size: .86rem; font-weight: 750; }
input, textarea, select {
  width: 100%;
  border: 1px solid #ccd7e6;
  border-radius: 12px;
  padding: .75rem .85rem;
  color: var(--ink);
  background: #fff;
  font-weight: 600;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, textarea:hover, select:hover { border-color: #aebed2; }
textarea { resize: vertical; }
.form-error { min-height: 1.4rem; margin: .15rem 0 0; color: var(--danger); font-size: .9rem; font-weight: 650; }

/* Join and authentication */
.join-page, .play-page {
  background:
    radial-gradient(circle at 22% 72%, rgba(114, 194, 255, .52), transparent 32%),
    radial-gradient(circle at 68% 18%, rgba(122, 178, 255, .54), transparent 30%),
    linear-gradient(145deg, #235dff 0%, #096dca 55%, #034a85 100%);
  background-attachment: fixed;
}
.join-page::before, .play-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(125deg, transparent 40%, rgba(255,255,255,.07) 40.5%, transparent 41%);
  background-size: 240px 240px;
}
.join-shell, .auth-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1.5rem;
}
.join-card, .auth-card, .player-card {
  width: min(100%, 470px);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 28px;
  padding: clamp(1.7rem, 5vw, 3rem);
  background: rgba(255,255,255,.96);
  box-shadow: 0 30px 90px rgba(0, 31, 85, .28);
  backdrop-filter: blur(18px);
}
.join-card .brand-mark, .auth-card .brand-mark { margin-bottom: 1.6rem; }
.join-card h1, .auth-card h1 { margin-bottom: .8rem; }
.join-form, .stack-form { display: grid; gap: .85rem; margin-top: 1.7rem; }
.join-form input { min-height: 58px; text-align: center; font-size: 1.25rem; letter-spacing: .08em; }
.admin-link { display: inline-block; margin-top: 1.5rem; color: var(--blue-dark); font-weight: 700; }
.auth-shell { background: #edf3fa; }
.auth-card { box-shadow: var(--shadow); }
.auth-card .brand-row { margin-bottom: 2.5rem; }
.auth-card .brand-mark { margin-bottom: 0; }
#confirm-wrap input { margin-top: .4rem; }

/* Admin */
.admin-page { overflow-x: hidden; }
.admin-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: .8rem 1.4rem;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(16px);
}
.admin-actions, .toolbar-actions, .export-actions { display: flex; align-items: center; gap: .65rem; }
.admin-body { display: grid; min-height: calc(100vh - 72px); grid-template-columns: 260px minmax(0, 1fr); }
.quiz-sidebar {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 1.5rem 1rem;
  background: #f8fafd;
}
.sidebar-heading, .questions-heading, .results-heading, .status-line, .leaderboard-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.sidebar-heading h2, .questions-heading h2, .results-heading h2 { margin-bottom: 0; }
.count-chip {
  display: inline-grid;
  min-width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  color: var(--blue-dark);
  background: #e6f1ff;
  font-size: .8rem;
  font-weight: 800;
}
.quiz-list { display: grid; gap: .55rem; margin-top: 1.25rem; }
.quiz-list-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: .85rem;
  text-align: left;
  background: transparent;
}
.quiz-list-item:hover { background: #fff; }
.quiz-list-item.active { border-color: #b8d2f6; background: #fff; box-shadow: 0 7px 18px rgba(26, 69, 128, .08); }
.quiz-list-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-list-meta { display: flex; justify-content: space-between; margin-top: .35rem; color: var(--muted); font-size: .75rem; font-weight: 650; }
.empty-editor {
  display: grid;
  width: min(530px, calc(100% - 3rem));
  align-self: center;
  justify-self: center;
  justify-items: center;
  padding: 3rem;
  text-align: center;
}
.empty-editor p { max-width: 440px; color: var(--muted); }
.empty-icon {
  display: grid;
  width: 74px;
  height: 74px;
  margin-bottom: 1.25rem;
  place-items: center;
  border-radius: 22px;
  color: var(--blue);
  background: #e5f0ff;
  font-size: 2rem;
  font-weight: 800;
}
.editor { min-width: 0; padding: 1.5rem; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.editor-toolbar h1 { margin-bottom: 0; font-size: clamp(1.55rem, 2vw, 2.1rem); }
.save-state { color: var(--muted); font-size: .82rem; font-weight: 650; }
.save-state.unsaved { color: #a75b00; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1.25rem; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 8px 28px rgba(27, 56, 94, .06); }
.editor-form-panel { padding: 1.3rem; }
.field-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1rem; }
.theme-details { margin: 1.25rem 0; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfe; }
.theme-details summary { padding: 1rem; font-weight: 800; cursor: pointer; }
.theme-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; border-top: 1px solid var(--line); padding: 1rem; }
.color-field { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.color-field input { width: 38px; height: 30px; border: 0; padding: 0; background: transparent; }
.upload-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-field span { display: grid; min-height: 42px; place-items: center; border: 1px dashed #8fadd2; border-radius: 11px; color: var(--blue-dark); background: #f2f7ff; }
.questions-heading { margin: 1.6rem 0 1rem; }
.questions-list { display: grid; gap: 1rem; }
.question-editor { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.question-editor-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .8rem 1rem; background: #f5f8fc; }
.question-number { display: inline-flex; align-items: center; gap: .6rem; font-size: .85rem; font-weight: 800; }
.question-number span { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 9px; color: #fff; background: var(--blue); }
.question-tools { display: flex; gap: .25rem; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 1.05rem; }
.icon-button:hover { color: var(--ink); background: #e7edf5; }
.icon-button.danger:hover { color: var(--danger); background: #fff0f0; }
.question-editor-body { display: grid; gap: 1rem; padding: 1rem; }
.question-main-row { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: .8rem; }
.question-image-control { display: grid; min-height: 98px; place-items: center; overflow: hidden; border: 1px dashed #9db0c9; border-radius: 12px; background: #f7f9fc; }
.question-image-control img { width: 100%; height: 100px; object-fit: cover; }
.question-image-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.question-image-control span { color: var(--blue-dark); font-size: .82rem; font-weight: 800; }
.option-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.option-editor { display: grid; grid-template-columns: 34px minmax(0, 1fr) 32px; align-items: center; gap: .5rem; border: 1px solid var(--line); border-radius: 12px; padding: .45rem; }
.correct-radio { width: 20px; height: 20px; margin: 0 auto; accent-color: var(--blue); }
.option-editor input[type="text"] { border: 0; padding: .55rem; background: transparent; }
.option-editor input[type="color"] { width: 30px; height: 30px; border: 0; padding: 0; }
.points-row { display: flex; align-items: center; gap: .6rem; }
.points-row select { width: auto; }

.publish-panel { position: sticky; top: 90px; overflow: hidden; }
.mini-preview { min-height: 220px; padding: 1rem; color: #fff; background: linear-gradient(145deg, #2864ff, #0066a8); }
.mini-question { min-height: 70px; border: 2px dashed rgba(255,255,255,.75); border-radius: 14px; padding: .7rem; color: var(--ink); background: #fff; text-align: center; font-weight: 800; }
.mini-options { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; margin-top: .7rem; }
.mini-option { overflow: hidden; border-radius: 10px; padding: .65rem; color: #fff; font-size: .72rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; box-shadow: inset 0 1px rgba(255,255,255,.22), 0 5px 10px rgba(0,0,0,.14); }
.publish-block, .results-block { display: grid; gap: .85rem; border-top: 1px solid var(--line); padding: 1.1rem; }
.status-chip { border-radius: 999px; padding: .28rem .6rem; font-size: .74rem; font-weight: 800; }
.status-chip.draft { color: #7b5a1b; background: #fff1c8; }
.status-chip.published { color: #126141; background: #dff7eb; }
.share-box { display: grid; gap: .65rem; padding-top: .4rem; }
.share-box input { padding: .6rem; font-size: .78rem; }
.compact-board { display: grid; gap: .45rem; max-height: 290px; overflow-y: auto; }
.compact-board.empty { min-height: 88px; place-items: center; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; font-size: .85rem; }
.compact-board.empty p { margin: 0; }
.compact-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: .5rem; border-bottom: 1px solid #edf1f6; padding: .55rem .2rem; }
.compact-row .rank { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 8px; background: #edf3fb; font-size: .75rem; font-weight: 800; }
.compact-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-row .score { color: var(--blue-dark); font-size: .82rem; font-weight: 850; }
.export-actions .button { flex: 1; }
.publish-panel > .button-danger { margin: 0 1.1rem 1.1rem; width: calc(100% - 2.2rem); }

.toast-region { position: fixed; z-index: 100; top: 88px; right: 1rem; display: grid; gap: .5rem; }
.toast { max-width: 340px; border: 1px solid #bfd6f5; border-radius: 12px; padding: .8rem 1rem; color: #12345e; background: #f2f8ff; box-shadow: var(--shadow); font-size: .9rem; font-weight: 700; animation: toast-in .25s ease-out; }
.toast.error { border-color: #f0bbbb; color: #902f2f; background: #fff3f3; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

/* Player */
.player-shell { position: relative; min-height: 100vh; }
.player-card { margin: auto; }
.player-card.centered { display: grid; min-height: 360px; align-content: center; justify-items: center; text-align: center; }
.player-shell > .player-card { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); }
.intro-card { text-align: center; }
.intro-card .brand-mark { margin: 0 auto 1.4rem; }
.intro-card .question-meta { display: inline-block; border-radius: 999px; padding: .4rem .8rem; color: var(--blue-dark); background: #eaf3ff; font-size: .82rem; font-weight: 800; }
.spinner { width: 44px; height: 44px; border: 4px solid #d9e5f5; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.question-screen { min-height: 100vh; color: #fff; background-position: center; background-size: cover; }
.question-topbar { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(260px, 500px); align-items: center; gap: 2rem; padding: 1rem clamp(1rem, 4vw, 3rem); background: rgba(0, 34, 84, .28); backdrop-filter: blur(10px); }
.progress-wrap { display: grid; gap: .35rem; color: rgba(255,255,255,.92); font-size: .82rem; font-weight: 800; }
.progress-track { overflow: hidden; height: 7px; border-radius: 999px; background: rgba(255,255,255,.25); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: #fff; transition: width .25s ease; }
.question-content { display: grid; width: min(1060px, 100%); min-height: calc(100vh - 76px); margin: 0 auto; align-content: center; gap: 1.5rem; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 2.2rem; }
.question-content h1 { max-width: 900px; margin: 0 auto; color: inherit; text-align: center; text-shadow: 0 3px 14px rgba(0, 35, 85, .32); }
.question-image-wrap { display: grid; width: min(540px, 78vw); height: clamp(185px, 30vh, 300px); margin: 0 auto; overflow: hidden; place-items: center; border: 4px solid #fff; border-radius: 22px; background: #fff; box-shadow: 0 18px 34px rgba(0, 34, 75, .24); }
.question-image-wrap img { width: 100%; height: 100%; object-fit: contain; }
.image-placeholder { display: grid; width: 100%; height: 100%; place-items: center; color: #b3b7bd; font-size: 5rem; font-weight: 300; }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.4rem; }
.answer-button {
  position: relative;
  display: grid;
  min-height: 92px;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: .75rem;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  padding: 1rem 1.25rem;
  color: #fff;
  text-align: left;
  box-shadow: inset 0 2px rgba(255,255,255,.17), 12px 14px 0 rgba(2, 47, 102, .2), 0 14px 30px rgba(0, 31, 77, .26);
  font-size: clamp(1.1rem, 2.1vw, 1.65rem);
  font-weight: 850;
  transition: transform .15s ease, filter .15s ease;
}
.answer-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.answer-button:active { transform: translateY(2px); }
.answer-button .answer-dot { width: 25px; height: 25px; border: 3px solid rgba(11, 49, 102, .7); border-radius: 50%; background: #fff; }
.answer-button.selected { outline: 5px solid rgba(255,255,255,.85); outline-offset: -5px; transform: scale(.985); }

.results-screen { display: grid; min-height: 100vh; grid-template-columns: minmax(300px, .8fr) minmax(430px, 1.2fr); gap: clamp(1.2rem, 4vw, 3rem); align-items: center; padding: clamp(1.2rem, 5vw, 4rem); }
.result-summary { color: #fff; text-align: center; }
.result-summary .eyebrow { color: #d9ebff; }
.score-orb { display: grid; width: 190px; height: 190px; margin: 2rem auto; place-items: center; align-content: center; border: 2px solid rgba(255,255,255,.6); border-radius: 50%; background: rgba(255,255,255,.12); box-shadow: inset 0 0 40px rgba(255,255,255,.12), 0 18px 45px rgba(0, 31, 77, .24); backdrop-filter: blur(12px); }
.score-orb span { font-size: 3rem; font-weight: 900; line-height: 1; }
.score-orb small { margin-top: .4rem; text-transform: uppercase; letter-spacing: .12em; }
.leaderboard-card { overflow: hidden; border: 1px solid rgba(255,255,255,.72); border-radius: 26px; padding: clamp(1.2rem, 3vw, 2rem); background: rgba(255,255,255,.96); box-shadow: 0 30px 80px rgba(0, 31, 77, .28); }
.leaderboard-title { margin-bottom: 1.2rem; }
.leaderboard-title h2 { margin-bottom: 0; font-size: 2rem; }
.live-pill { border-radius: 999px; padding: .35rem .7rem; color: #08653f; background: #ddf8eb; font-size: .75rem; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.leaderboard-list { display: grid; gap: .55rem; max-height: 62vh; overflow-y: auto; }
.board-row { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: .8rem; border: 1px solid #e3eaf2; border-radius: 14px; padding: .7rem .85rem; background: #fff; }
.board-row.top { border-color: #b6d2fa; background: #f1f7ff; }
.board-rank { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; color: #fff; background: #9cabc0; font-weight: 900; }
.board-row:nth-child(1) .board-rank { background: #f0ad18; }
.board-row:nth-child(2) .board-rank { background: #7d91aa; }
.board-row:nth-child(3) .board-rank { background: #b66b38; }
.board-name { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.board-sub { color: var(--muted); font-size: .76rem; font-weight: 650; }
.board-score { color: var(--blue-dark); font-weight: 900; }
.board-empty { padding: 2rem; color: var(--muted); text-align: center; }

@media (max-width: 1050px) {
  .admin-body { grid-template-columns: 220px minmax(0, 1fr); }
  .editor-grid { grid-template-columns: 1fr; }
  .publish-panel { position: static; display: grid; grid-template-columns: repeat(2, 1fr); }
  .mini-preview { min-height: 100%; }
  .publish-panel > .button-danger { align-self: end; margin-top: 1.1rem; }
}

@media (max-width: 760px) {
  .admin-header { padding-inline: .8rem; }
  .admin-header .brand-row span:last-child { display: none; }
  .admin-body { display: block; }
  .quiz-sidebar { position: static; width: 100%; height: auto; max-height: 210px; border-right: 0; border-bottom: 1px solid var(--line); }
  .quiz-list { display: flex; overflow-x: auto; padding-bottom: .35rem; }
  .quiz-list-item { min-width: 180px; background: #fff; }
  .editor { padding: 1rem; }
  .editor-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; flex-wrap: wrap; }
  .save-state { width: 100%; }
  .field-grid, .theme-controls, .option-editor-grid, .publish-panel { grid-template-columns: 1fr; }
  .question-main-row { grid-template-columns: 1fr; }
  .question-image-control { min-height: 130px; }
  .question-image-control img { height: 130px; }
  .question-topbar { grid-template-columns: 1fr; gap: .7rem; }
  .question-content { min-height: calc(100vh - 116px); }
  .question-image-wrap { width: min(540px, 92vw); }
  .answer-grid { grid-template-columns: 1fr; gap: .8rem; }
  .answer-button { min-height: 72px; box-shadow: inset 0 2px rgba(255,255,255,.17), 7px 8px 0 rgba(2, 47, 102, .2), 0 10px 20px rgba(0, 31, 77, .2); }
  .results-screen { grid-template-columns: 1fr; padding: 1.2rem; }
  .score-orb { width: 150px; height: 150px; margin: 1rem auto; }
  .leaderboard-list { max-height: 48vh; }
}

@media (max-width: 470px) {
  .admin-actions .button-ghost { padding-inline: .7rem; }
  .join-shell, .auth-shell { padding: .8rem; }
  .join-card, .auth-card, .player-card { border-radius: 22px; }
  .question-content { gap: 1rem; }
  .question-image-wrap { height: 180px; }
  .answer-button { min-height: 64px; border-radius: 16px; font-size: 1.05rem; }
  .board-row { grid-template-columns: 40px minmax(0, 1fr); }
  .board-score { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
