:root {
  --bg: #070a0f;
  --surface: #0d1117;
  --surface2: #111820;
  --text: #f0ece6;
  --text2: #a09890;
  --muted: #7a7570;
  --accent: #d70913;
  --accent-dim: rgba(215, 9, 19, 0.12);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --radius: 12px;
}
html.light {
  --bg: #fdf9f3;
  --surface: #f0ece6;
  --surface2: #e8e4de;
  --text: #1c1c18;
  --text2: #625e59;
  --muted: #9a9490;
  --accent-dim: rgba(215, 9, 19, 0.07);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Cabin", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 72px 20px 48px;
}

/* ── Fixed Controls ── */
#backBtn {
  position: fixed; top: 16px; left: 16px; z-index: 200;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); display: flex; align-items: center; justify-content: center;
  text-decoration: none; transition: border-color 0.2s, color 0.2s;
}
#backBtn:hover { border-color: var(--accent); color: var(--accent); }

#themeToggle {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
#themeToggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Form Container ── */
.form-container {
  width: 100%; max-width: 480px;
}
.form-container h2 {
  font-family: "Ubuntu", sans-serif;
  font-size: 26px; font-weight: 500; margin-bottom: 6px;
}
.hint {
  font-size: 14px; color: var(--text2); margin-bottom: 24px; line-height: 1.55;
}

.input-group { margin-bottom: 20px; }
.input-group label {
  display: block; font-size: 11px; font-weight: 700;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text2); margin-bottom: 8px;
}
.input-group input[type="text"],
.input-group textarea,
.input-group select {
  width: 100%; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: "Cabin", sans-serif; font-size: 15px;
  transition: border-color 0.2s; outline: none;
}
.input-group input[type="text"]:focus,
.input-group textarea:focus { border-color: var(--accent); }
.input-group textarea { resize: vertical; min-height: 90px; }

/* ── Buttons ── */
.btn {
  display: block; width: 100%; padding: 15px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  font-family: "Cabin", sans-serif; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: opacity 0.2s; margin-bottom: 12px;
  text-align: center; text-decoration: none; letter-spacing: 0.3px;
}
.btn:hover:not(:disabled) { opacity: 0.87; }
.btn:disabled { opacity: 0.35; cursor: default; }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); opacity: 1; }

.btn-back {
  display: block; width: 100%; background: transparent; color: var(--text2);
  border: none; font-family: "Cabin", sans-serif; font-size: 14px; font-weight: 500;
  cursor: pointer; padding: 8px 0; text-align: center; margin-top: 4px;
}
.btn-back:hover { color: var(--text); }

.btn-add {
  background: var(--accent-dim); color: var(--accent);
  border: 1px dashed rgba(215, 9, 19, 0.4); font-size: 14px;
}
.btn-add:hover:not(:disabled) { background: rgba(215, 9, 19, 0.18); opacity: 1; }

.btn-row { display: flex; gap: 10px; margin-bottom: 12px; }
.btn-row .btn { flex: 1; margin-bottom: 0; }

.btn-example {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border); font-size: 13px;
}
.btn-example:hover { border-color: var(--border-strong); color: var(--text); opacity: 1; }

/* ── Welcome ── */
#welcomeScreen {
  position: relative;
}
#welcomeScreen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('illustration.svg');
  background-size: 74% auto;
  background-position: center 42%;
  background-repeat: no-repeat;
  opacity: 0.1;
  z-index: 0;
  pointer-events: none;
}
.welcome-inner {
  display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; max-width: 400px; width: 100%;
  padding-top: 20px;
  position: relative; z-index: 1;
}
.welcome-illustration { display: none; }

/* Hidden on mobile, shown on desktop split layout */
.create-illustration { display: none; }

@media (min-width: 768px) {
  #welcomeScreen::before { content: none; }

  /* Shared split-screen rules */
  #welcomeScreen,
  #createSetupScreen,
  #createQuestionsScreen,
  #createEditScreen,
  #createEndingsScreen,
  #createShareScreen,
  #playCodeScreen,
  #playScreen {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 5rem;
    padding: 2rem 8%;
  }

  .welcome-inner {
    flex-shrink: 0;
    max-width: 420px;
    align-items: flex-start;
    text-align: left;
  }

  #createSetupScreen .form-container,
  #createQuestionsScreen .form-container,
  #createEditScreen .form-container,
  #createEndingsScreen .form-container,
  #createShareScreen .form-container,
  #playCodeScreen .form-container,
  #playScreen .form-container {
    flex-shrink: 0;
    max-width: 420px;
    width: 100%;
  }

  .welcome-illustration,
  .create-illustration {
    display: flex;
    flex-shrink: 0;
    align-items: center;
  }

  .welcome-illustration svg,
  .create-illustration svg { height: min(76vh, 520px); width: auto; display: block; }
}

/* Constellation animation (inline SVG only) */
@keyframes starFloat {
  0%, 100% { transform: translateY(0)     scale(1);    }
  50%       { transform: translateY(-14px) scale(1.35); }
}
@keyframes dashFlow {
  to { stroke-dashoffset: -8; }
}
.clines { animation: dashFlow 2.4s linear infinite; }
.cnode  { transform-box: fill-box; transform-origin: center; }
.n1   { animation: starFloat 3.4s ease-in-out 0s     infinite; }
.n2   { animation: starFloat 3.4s ease-in-out 0.34s  infinite; }
.n3   { animation: starFloat 3.4s ease-in-out 0.68s  infinite; }
.n4   { animation: starFloat 3.4s ease-in-out 1.02s  infinite; }
.n5   { animation: starFloat 3.4s ease-in-out 1.36s  infinite; }
.n6   { animation: starFloat 3.4s ease-in-out 1.70s  infinite; }
.n7   { animation: starFloat 3.4s ease-in-out 2.04s  infinite; }
.n8   { animation: starFloat 3.4s ease-in-out 2.38s  infinite; }
.n9   { animation: starFloat 3.4s ease-in-out 2.72s  infinite; }
.ndot { animation: starFloat 3.4s ease-in-out 3.06s  infinite; }
.welcome-eyebrow {
  font-size: 10px; font-weight: 700; letter-spacing: 4px;
  text-transform: uppercase; color: var(--accent); margin-bottom: 18px;
}
.welcome-title {
  font-family: "Ubuntu", sans-serif;
  font-size: clamp(30px, 8vw, 48px);
  font-weight: 700; font-style: normal; line-height: 1.15;
  margin-bottom: 16px;
}
.welcome-sub {
  font-size: 15px; color: var(--text2); margin-bottom: 36px; line-height: 1.65;
}
.welcome-stats {
  display: flex; gap: 36px; margin-bottom: 40px;
  padding: 20px 24px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%;
}
.welcome-stat { display: flex; flex-direction: column; align-items: center; flex: 1; }
.welcome-stat-num {
  font-family: "Ubuntu", sans-serif; font-size: 26px;
  font-weight: 700; color: var(--text); line-height: 1;
  margin-bottom: 4px;
}
.welcome-stat-lbl {
  font-size: 11px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 1px;
}
.welcome-divider {
  width: 1px; background: var(--border); align-self: stretch;
}
.welcome-btns { width: 100%; }

/* ── Questions List ── */
.q-list { width: 100%; margin-bottom: 8px; }
.q-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 8px;
}
.q-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.q-text {
  flex: 1; font-size: 14px; line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-actions { display: flex; gap: 6px; flex-shrink: 0; }
.q-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: none; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.q-btn:hover { border-color: var(--border-strong); color: var(--text); }
.q-btn.delete:hover { border-color: var(--accent); color: var(--accent); }

.q-count-label {
  font-size: 12px; color: var(--text2); margin-bottom: 14px; text-align: right;
}

.min-msg {
  font-size: 13px; color: var(--text2); text-align: center;
  padding: 10px 14px; background: var(--accent-dim);
  border-radius: 8px; margin-bottom: 14px; line-height: 1.5;
}

/* ── Category Pills ── */
.cat-pills {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.cat-pill {
  padding: 7px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text2);
  font-family: "Cabin", sans-serif; font-size: 13px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.cat-pill:hover { border-color: var(--border-strong); color: var(--text); }
.cat-pill.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}

/* ── Bank Suggestions ── */
.bank-suggestions { margin-bottom: 20px; }
.bank-hint { font-size: 12px; color: var(--text2); margin-bottom: 10px; line-height: 1.5; }
.bank-list { display: flex; flex-direction: column; gap: 6px; }
.bank-q {
  text-align: left; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2);
  font-family: "Cabin", sans-serif; font-size: 13px; cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s; line-height: 1.45;
}
.bank-q:hover { border-color: var(--border-strong); color: var(--text); }
.bank-q.selected {
  border-color: var(--accent); color: var(--text); background: var(--accent-dim);
}

/* ── Correct answer tag ── */
.correct-tag {
  display: inline-block; padding: 1px 8px;
  background: rgba(46, 204, 113, 0.12); color: #2ecc71;
  border-radius: 20px; font-size: 10px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  vertical-align: middle; margin-left: 6px;
}

/* ── Edit Question (legacy rows removed) ── */
.option-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.option-letter {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.option-row input[type="text"] {
  flex: 1; margin-bottom: 0;
  padding: 10px 14px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-family: "Cabin", sans-serif; outline: none; transition: border-color 0.2s;
}
.option-row input[type="text"]:focus { border-color: var(--accent); }
.option-radio {
  width: 18px; height: 18px; accent-color: var(--accent);
  cursor: pointer; flex-shrink: 0;
}
.correct-hint {
  font-size: 12px; color: var(--text2); margin-bottom: 14px; line-height: 1.5;
}

/* ── Endings / Pass Mark ── */
.pass-mark-wrap {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 14px; color: var(--text2); line-height: 1.8;
}
.pass-mark-wrap input[type="number"] {
  width: 58px; padding: 8px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: "Cabin", sans-serif; font-size: 15px;
  font-weight: 700; text-align: center; outline: none;
  transition: border-color 0.2s;
}
.pass-mark-wrap input[type="number"]:focus { border-color: var(--accent); }
.pass-mark-total { font-weight: 700; color: var(--text); }

/* ── Share ── */
.share-or {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0; color: var(--muted); font-size: 12px;
}
.share-or::before, .share-or::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.share-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 4px 4px 14px; margin-bottom: 8px;
}
.share-field input[type="text"] {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: "Cabin", sans-serif; font-size: 13px; min-width: 0;
}
.share-field textarea {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: "Cabin", sans-serif; font-size: 12px;
  resize: none; height: 72px; padding: 8px 0; min-width: 0;
}
.btn-copy {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 14px; border-radius: 8px; font-size: 13px;
  font-weight: 700; cursor: pointer; flex-shrink: 0;
  font-family: "Cabin", sans-serif; transition: opacity 0.2s;
}
.btn-copy:hover { opacity: 0.85; }
.copy-ok { font-size: 12px; color: #2ecc71; margin-bottom: 10px; display: none; }

/* ── Play: Header ── */
.play-header {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 20px; width: 100%;
}
.play-progress-bar {
  height: 3px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.play-progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width 0.5s ease;
}
.play-header-meta {
  display: flex; align-items: center; justify-content: space-between;
}
.play-counter { font-size: 12px; color: var(--text2); white-space: nowrap; }
.play-timer {
  font-size: 13px; font-weight: 700; color: var(--text2);
  font-variant-numeric: tabular-nums; letter-spacing: 0.5px;
}
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.play-timer.urgent { color: var(--accent); animation: timerPulse 1s ease-in-out infinite; }
.play-hearts { display: flex; gap: 3px; flex-shrink: 0; }
.heart {
  font-size: 17px; line-height: 1;
  transition: transform 0.3s, opacity 0.3s;
}
.heart.lost { opacity: 0.2; transform: scale(0.85); }

/* ── Play: Question Card ── */
.q-card {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 24px 22px; margin-bottom: 16px;
}
.q-card-label {
  font-size: 10px; font-weight: 700; letter-spacing: 3px;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
.q-card-text {
  font-family: "Ubuntu", sans-serif; font-size: 19px;
  font-weight: 400; line-height: 1.45;
}

/* ── Play: Options ── */
.options-list { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.option-btn {
  width: 100%; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: "Cabin", sans-serif; font-size: 14px;
  text-align: left; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex; align-items: center; gap: 12px;
}
.option-btn:hover:not(:disabled) { border-color: var(--border-strong); }
.option-btn .opt-letter {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.option-btn.correct { border-color: #2ecc71; background: rgba(46, 204, 113, 0.08); }
.option-btn.correct .opt-letter { background: #2ecc71; border-color: #2ecc71; color: #fff; }
.option-btn.wrong { border-color: var(--accent); background: rgba(215, 9, 19, 0.08); }
.option-btn.wrong .opt-letter { background: var(--accent); border-color: var(--accent); color: #fff; }
.option-btn:disabled { cursor: default; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease; }

/* ── Result ── */
.result-container {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; max-width: 480px; width: 100%;
  padding-top: 12px;
}
.result-icon { font-size: 60px; margin-bottom: 14px; line-height: 1; }
.result-title {
  font-family: "Ubuntu", sans-serif; font-size: 30px;
  font-weight: 500; margin-bottom: 6px;
}
.result-score { font-size: 14px; color: var(--text2); margin-bottom: 28px; line-height: 1.6; }

.result-ending {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px 22px; text-align: left;
  width: 100%; margin-bottom: 20px;
}
.result-from {
  font-size: 10px; font-weight: 700; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--accent); margin-bottom: 12px;
}
.result-message {
  font-size: 15px; line-height: 1.8; color: var(--text); white-space: pre-wrap;
}

.result-breakdown { width: 100%; margin-bottom: 20px; text-align: left; }
.breakdown-title {
  font-size: 10px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; color: var(--text2); margin-bottom: 12px;
}
.breakdown-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; gap: 12px;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-q { flex: 1; color: var(--text2); line-height: 1.4; }
.badge {
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.badge-right { background: rgba(46, 204, 113, 0.12); color: #2ecc71; }
.badge-wrong { background: rgba(215, 9, 19, 0.12); color: var(--accent); }

/* ── Review ── */
.review-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 8px; overflow: hidden;
}
.review-item-header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; cursor: pointer; user-select: none;
}
.review-item-header:hover { background: rgba(255,255,255,0.02); }
.review-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent);
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.review-q-text {
  flex: 1; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.review-chevron { color: var(--muted); transition: transform 0.2s; font-size: 16px; }
.review-item.open .review-chevron { transform: rotate(90deg); }
.review-item-body { display: none; padding: 0 14px 14px; }
.review-item.open .review-item-body { display: block; }
.review-opt {
  font-size: 13px; padding: 5px 0; color: var(--text2);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-start;
}
.review-opt:last-child { border-bottom: none; }
.review-opt.is-correct { color: #2ecc71; }

/* ── Overlays ── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.overlay-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 24px;
  width: 100%; max-width: 360px; text-align: center;
}
.overlay-icon { font-size: 44px; margin-bottom: 14px; line-height: 1; }
.overlay-card h3 {
  font-family: "Ubuntu", sans-serif; font-size: 22px;
  font-weight: 500; margin-bottom: 8px;
}
.overlay-card p { font-size: 14px; color: var(--text2); margin-bottom: 22px; line-height: 1.6; }
.overlay-btns { display: flex; gap: 10px; width: 100%; }
.overlay-btns .btn { flex: 1; margin-bottom: 0; }

/* ── Confetti ── */
#confettiCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 999; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .screen { padding: 64px 16px 40px; }
  .q-card-text { font-size: 17px; }
  .option-btn { font-size: 14px; padding: 13px 14px; }
  .welcome-title { font-size: 32px; }
  .welcome-stats { gap: 0; padding: 18px; }
  .result-title { font-size: 26px; }
}
