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

/* ── DESIGN TOKENS ── */
:root {
  /* Palette: warm indigo + soft amber */
  --indigo-50:  #EEEDFB;
  --indigo-100: #D4D2F5;
  --indigo-200: #B0ACEC;
  --indigo-400: #7B74DC;
  --indigo-500: #5C53C7;
  --indigo-600: #4840A8;
  --indigo-700: #342F82;
  --indigo-900: #1A1660;

  --amber-50:  #FFF8EC;
  --amber-100: #FDEAC8;
  --amber-200: #FAD08A;
  --amber-400: #F4A833;
  --amber-500: #E8930F;
  --amber-600: #C47A0A;

  --red-50:  #FEF0EF;
  --red-400: #E5534B;
  --red-600: #B93028;

  --green-50:  #EDFAF4;
  --green-400: #2DB87A;
  --green-600: #1A8A58;

  --bg:           #F7F6F2;
  --surface:      #FFFFFF;
  --surface-2:    #F2F1ED;
  --border:       #E3E1DB;
  --border-strong:#C8C5BC;
  --text:         #1C1A2E;
  --text-2:       #5A5770;
  --text-3:       #9896AA;

  --accent:        var(--indigo-500);
  --accent-light:  var(--indigo-50);
  --accent-border: var(--indigo-200);
  --warm:          var(--amber-500);
  --warm-light:    var(--amber-50);
  --warm-border:   var(--amber-200);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(28,26,46,0.06);
  --shadow:    0 2px 8px rgba(28,26,46,0.08);
  --shadow-lg: 0 4px 6px rgba(28,26,46,0.04), 0 12px 32px rgba(28,26,46,0.10);

  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-body:  'DM Sans', -apple-system, sans-serif;
  --font-mono:  'DM Mono', monospace;
}

/* ── BASE ── */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: flex; }
.center-layout { min-height: 100vh; align-items: center; justify-content: center; padding: 24px; }

/* ── SPINNER ── */
.spinner {
  width: 26px; height: 26px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── CARD ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.card-sm { width: 100%; max-width: 420px; padding: 36px; }
.card-md { width: 100%; max-width: 540px; padding: 40px; }

/* ── WORDMARK ── */
.wordmark { display: flex; align-items: center; gap: 9px; margin-bottom: 28px; }
.wordmark-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
}
.wordmark-mark svg { width: 14px; height: 14px; }
.wordmark-text { font-family: var(--font-serif); font-size: 17px; color: var(--text); letter-spacing: -0.01em; }

/* ── TYPOGRAPHY ── */
h1 {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 8px;
  color: var(--text);
}
h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; color: var(--text); }
h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.text-muted { color: var(--text-2); font-size: 13.5px; line-height: 1.6; }
code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: 22px 0; }

/* ── FORM ── */
.field { display: flex; flex-direction: column; gap: 5px; }
.label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.06em; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
  -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(92,83,199,0.12);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%235A5770' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
select option { background: white; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 13.5px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s; white-space: nowrap; line-height: 1;
  letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(92,83,199,0.3); }
.btn-primary:hover:not(:disabled) { background: var(--indigo-600); box-shadow: 0 4px 12px rgba(92,83,199,0.35); }

.btn-outline { background: var(--surface); color: var(--text); border: 1.5px solid var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-warm { background: var(--warm); color: #fff; box-shadow: 0 1px 3px rgba(232,147,15,0.3); }
.btn-warm:hover:not(:disabled) { background: var(--amber-600); }

.btn-danger { background: var(--red-400); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-600); }

.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; }

/* ── PROGRESS BAR ── */
.progress-section { margin-bottom: 32px; }
.progress-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.progress-meta span { font-size: 11.5px; color: var(--text-3); font-family: var(--font-mono); }
.progress-track {
  height: 5px; background: var(--border); border-radius: 99px; overflow: visible; position: relative;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--indigo-400), var(--indigo-500));
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
  position: relative;
}
.progress-fill::after {
  content: '';
  position: absolute;
  right: -1px; top: 50%;
  transform: translateY(-50%);
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--indigo-500);
  box-shadow: 0 0 0 3px var(--indigo-100);
  transition: opacity 0.3s;
}
@keyframes prog-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--indigo-100); }
  50%       { box-shadow: 0 0 0 5px var(--indigo-50); }
}
.progress-fill.pulse::after { animation: prog-pulse 0.6s ease-in-out; }

/* ── QUESTION ── */
.q-type-tag {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600; font-family: var(--font-mono);
  color: var(--accent); background: var(--accent-light); border: 1px solid var(--accent-border);
  border-radius: 99px; padding: 3px 11px; margin-bottom: 12px;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.q-text {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 22px;
}
.inline-error { font-size: 12.5px; color: var(--red-400); margin-bottom: 10px; display: none; }

/* ── WORD COUNT LIVE ── */
.word-count-live {
  font-size: 11.5px;
  font-family: var(--font-mono);
  margin-top: 6px;
  margin-bottom: 14px;
  transition: color 0.2s;
}
.wc-low    { color: var(--red-400); }
.wc-medium { color: var(--amber-500); }
.wc-good   { color: var(--green-400); }

/* ── MC OPTIONS ── */
.mc-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.mc-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 15px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.12s; background: var(--surface); user-select: none;
}
.mc-item:hover { border-color: var(--accent-border); background: var(--accent-light); }
.mc-item.selected { border-color: var(--accent); background: var(--accent-light); }
.mc-radio {
  width: 17px; height: 17px; border-radius: 50%;
  border: 1.5px solid var(--border-strong); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all 0.12s;
}
.mc-item.selected .mc-radio { border-color: var(--accent); background: var(--accent); }
.mc-radio-dot { width: 6px; height: 6px; border-radius: 50%; background: white; display: none; }
.mc-item.selected .mc-radio-dot { display: block; }
.mc-item-label { font-size: 13.5px; color: var(--text); }
.mc-item.selected .mc-item-label { color: var(--indigo-700); font-weight: 500; }

/* ── TF ── */
.tf-row { display: flex; gap: 10px; margin-bottom: 22px; }
.tf-btn {
  flex: 1; padding: 13px; border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface);
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.12s; color: var(--text-2);
}
.tf-btn:hover { border-color: var(--accent-border); background: var(--accent-light); }
.tf-btn.sel-true  { border-color: var(--green-400); background: var(--green-50); color: var(--green-600); }
.tf-btn.sel-false { border-color: var(--red-400);   background: var(--red-50);   color: var(--red-600); }

/* ── RANK ── */
.rank-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 22px; }
.rank-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: grab; user-select: none; transition: all 0.12s;
}
.rank-item:hover { background: var(--surface-2); }
.rank-item.drag-over { border-color: var(--accent); background: var(--accent-light); }
.rank-item.dragging  { opacity: 0.4; }
.rank-num { font-size: 11px; font-weight: 600; font-family: var(--font-mono); color: var(--text-3); width: 18px; text-align: center; flex-shrink: 0; }
.rank-handle { color: var(--text-3); font-size: 13px; }
.rank-label { font-size: 13.5px; color: var(--text); }

/* ── TAB WARNING ── */
#tabWarning {
  display: none; position: fixed; inset: 0;
  background: rgba(28,26,46,0.65); backdrop-filter: blur(4px);
  z-index: 9999; align-items: center; justify-content: center; padding: 24px;
}
#tabWarning.show { display: flex; }
.warn-modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px;
  max-width: 360px; width: 100%; text-align: center; box-shadow: var(--shadow-lg);
}
.warn-emoji { font-size: 32px; margin-bottom: 10px; }
.warn-badge {
  display: inline-block; font-size: 11px; font-family: var(--font-mono); font-weight: 600;
  color: var(--amber-600); background: var(--amber-50); border: 1px solid var(--amber-200);
  border-radius: 99px; padding: 3px 11px; margin-bottom: 13px; text-transform: uppercase; letter-spacing: 0.06em;
}
.warn-modal h2 { font-size: 16px; margin-bottom: 7px; }
.warn-modal p  { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 22px; }

/* ── TOAST ── */
#toast-container {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 9997; pointer-events: none;
}
.toast {
  background: var(--text); color: #fff;
  font-size: 13px; font-family: var(--font-body);
  padding: 9px 18px; border-radius: 99px;
  box-shadow: 0 4px 16px rgba(28,26,46,0.22);
  animation: toast-in 0.25s cubic-bezier(0.34,1.56,0.64,1) forwards;
  white-space: nowrap;
}
.toast.out { animation: toast-out 0.2s ease-in forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(4px); } }

/* ── CONFETTI ── */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 9998; display: none; }

/* ── COMPLETE ── */
.complete-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 52px 40px;
  max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow-lg);
}
.complete-emoji { font-size: 48px; margin-bottom: 18px; }
.complete-card h1 { font-size: 26px; margin-bottom: 10px; }
.complete-card p  { color: var(--text-2); font-size: 13.5px; line-height: 1.65; margin-bottom: 28px; }

/* ── DASHBOARD ── */
#screen-dashboard { flex-direction: column; align-items: flex-start; min-height: 100vh; }
.dash-topbar {
  width: 100%; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 32px; height: 54px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 10;
}
.dash-wordmark { display: flex; align-items: center; gap: 9px; }
.dash-wordmark-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.dash-wordmark-mark svg { width: 13px; height: 13px; }
.dash-wordmark-text { font-family: var(--font-serif); font-size: 16px; color: var(--text); }
.top-divider { width: 1px; height: 20px; background: var(--border); }
.dash-subtitle { font-size: 13px; color: var(--text-3); font-family: var(--font-body); }
.dash-actions { display: flex; align-items: center; gap: 8px; }
.dash-body { width: 100%; max-width: 920px; margin: 0 auto; padding: 32px 24px; }

/* ── TABS ── */
.tab-nav { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 28px; }
.tab-item {
  padding: 10px 18px; font-size: 13.5px; font-weight: 500; color: var(--text-3);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all 0.15s; background: none; border-top: none; border-left: none; border-right: none;
  font-family: var(--font-body);
}
.tab-item:hover { color: var(--text-2); }
.tab-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── CODE CHIP ── */
.code-chip {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
}
.code-label { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 3px; }
.code-val   { font-size: 26px; font-weight: 700; letter-spacing: 0.16em; font-family: var(--font-mono); color: var(--text); }
.code-copy  { cursor: pointer; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); font-size: 12px; color: var(--text-2); transition: all 0.12s; font-family: var(--font-body); }
.code-copy:hover { background: var(--surface-2); }

/* ── TABLE ── */
.section-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; font-family: var(--font-mono); }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--surface-2); }
th { text-align: left; padding: 10px 14px; font-size: 10.5px; font-weight: 600; color: var(--text-3); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.07em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: top; line-height: 1.45; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
/* Row highlighting */
tr.row-warn td:first-child { border-left: 3px solid var(--amber-400); }
tr.row-danger td:first-child { border-left: 3px solid var(--red-400); }
.empty-state { text-align: center; padding: 52px 24px; color: var(--text-3); font-size: 13px; }
.empty-icon { font-size: 28px; margin-bottom: 10px; }

/* ── Q EDITOR ── */
.qe-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.qe-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; transition: border-color 0.12s; }
.qe-item:hover { border-color: var(--border-strong); }
.qe-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.qe-type-tag {
  display: inline-block; font-size: 10px; font-family: var(--font-mono); font-weight: 600;
  color: var(--accent); background: var(--accent-light); border: 1px solid var(--accent-border);
  border-radius: 99px; padding: 2px 9px; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em;
}
.qe-text { font-size: 13.5px; font-weight: 500; color: var(--text); line-height: 1.4; }
.qe-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ── QUESTION BANK ── */
.bank-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.bank-filter-btn {
  padding: 5px 13px; border-radius: 99px; font-size: 12px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-2); transition: all 0.12s; font-family: var(--font-body);
}
.bank-filter-btn:hover { border-color: var(--accent-border); color: var(--accent); }
.bank-filter-btn.active { background: var(--accent-light); border-color: var(--accent-border); color: var(--accent); }
.bank-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 8px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  transition: border-color 0.12s;
}
.bank-item:hover { border-color: var(--accent-border); }
.bank-item-text { font-size: 13.5px; color: var(--text); line-height: 1.4; flex: 1; }
.bank-item-tag {
  font-size: 10px; font-family: var(--font-mono); font-weight: 600;
  color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 2px 8px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}

/* ── ADD Q PANEL ── */
.add-q-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.choice-row { display: flex; gap: 8px; align-items: center; margin-bottom: 7px; }
.choice-row input { flex: 1; }
.correct-toggle {
  font-size: 11px; font-weight: 600; font-family: var(--font-mono);
  padding: 6px 10px; border-radius: 5px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-3); white-space: nowrap; transition: all 0.12s;
}
.correct-toggle.is-correct { background: var(--green-50); border-color: var(--green-400); color: var(--green-600); }

/* ── ALERTS ── */
.alert {
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px;
  margin-bottom: 14px; display: flex; align-items: flex-start; gap: 8px;
}
.alert-info    { background: var(--accent-light); border: 1px solid var(--accent-border); color: var(--indigo-700); }
.alert-success { background: var(--green-50);     border: 1px solid var(--green-400);     color: var(--green-600); }
.alert-danger  { background: var(--red-50);       border: 1px solid var(--red-400);       color: var(--red-600); }
.alert-warn    { background: var(--amber-50);     border: 1px solid var(--amber-200);     color: var(--amber-600); }

/* ── SETTINGS ── */
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }

/* ── CONFIG SCREEN ── */
#screen-config .card-sm { max-width: 460px; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .card-sm, .card-md { padding: 26px 20px; }
  .dash-body { padding: 20px 16px; }
  .dash-topbar { padding: 0 16px; }
  .complete-card { padding: 40px 24px; }
  .stat-cards { grid-template-columns: 1fr; }
  .code-val { font-size: 22px; }
}
