:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ee;
  --border: #e2e1dc;
  --text: #1f1e1c;
  --text-muted: #6b6a65;
  --brand: #b45309;
  --brand-ink: #ffffff;
  --accent: #2563eb;
  --success: #15803d;
  --success-bg: #eafaf0;
  --warn: #b45309;
  --warn-bg: #fef3e2;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --max-width: 780px;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #201f1c;
    --surface-2: #2a2926;
    --border: #38362f;
    --text: #f2f1ed;
    --text-muted: #a7a59d;
    --brand: #e08a3c;
    --brand-ink: #1a1408;
    --accent: #6d9bff;
    --success: #4ade80;
    --success-bg: #10281b;
    --warn: #e08a3c;
    --warn-bg: #2c2011;
    --danger: #f87171;
    --danger-bg: #2c1414;
  }
}
:root[data-theme="dark"] {
  --bg: #171614;
  --surface: #201f1c;
  --surface-2: #2a2926;
  --border: #38362f;
  --text: #f2f1ed;
  --text-muted: #a7a59d;
  --brand: #e08a3c;
  --brand-ink: #1a1408;
  --accent: #6d9bff;
  --success: #4ade80;
  --success-bg: #10281b;
  --warn: #e08a3c;
  --warn-bg: #2c2011;
  --danger: #f87171;
  --danger-bg: #2c1414;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.boot-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 12px; color: var(--text-muted);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.app-header__logo { height: 28px; width: auto; display: block; }
.app-header__mark { color: var(--brand); font-size: 1.1rem; }
.app-header__word { color: var(--text-muted); font-size: 0.95rem; }
.app-header__nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.app-header__book { white-space: nowrap; }

.landing-brandbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.landing-brandbar__logo { height: 40px; width: auto; display: block; }
.nav-btn {
  border: none; background: transparent; color: var(--text-muted);
  padding: 8px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn.is-active { background: var(--brand); color: var(--brand-ink); }

/* ---------- Layout ---------- */
main.view {
  flex: 1; width: 100%; max-width: var(--max-width); margin: 0 auto;
  padding: 20px 16px 60px;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
h1 { font-size: 1.5rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
.text-muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 999px; font-weight: 600;
  padding: 11px 20px; font-size: 0.95rem; cursor: pointer; transition: opacity .15s;
  background: var(--brand); color: var(--brand-ink);
}
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--secondary { background: var(--surface-2); color: var(--text); }
.btn--small { padding: 6px 14px; font-size: 0.82rem; }
.btn--block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; padding: 11px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
}
textarea { min-height: 160px; resize: vertical; line-height: 1.5; }
.field { margin-bottom: 16px; }
.field-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-option {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.radio-option:has(input:checked) { border-color: var(--brand); background: var(--warn-bg); }
.radio-option input { margin: 0; }

/* ---------- Scenario card ---------- */
.scenario-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.pill {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
}
.pill--brand { background: var(--warn-bg); color: var(--brand); }
.fact-list { padding-left: 18px; margin: 8px 0; }
.fact-list li { margin-bottom: 4px; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.timer.is-low { background: var(--danger-bg); color: var(--danger); }

/* ---------- Feedback ---------- */
.band-badge {
  display: inline-block; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 1rem;
}
.band-polished, .band-strong { background: var(--success-bg); color: var(--success); }
.band-developing { background: var(--warn-bg); color: var(--warn); }
.band-needs_work, .band-rework { background: var(--danger-bg); color: var(--danger); }

table.score-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 0.9rem; }
table.score-table th, table.score-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.score-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; }
.score-pip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: 0.8rem;
  background: var(--surface-2);
}
.score-pip.s-5, .score-pip.s-4 { background: var(--success-bg); color: var(--success); }
.score-pip.s-3 { background: var(--warn-bg); color: var(--warn); }
.score-pip.s-2, .score-pip.s-1, .score-pip.s-0 { background: var(--danger-bg); color: var(--danger); }

blockquote.msg-block {
  margin: 8px 0 16px; padding: 12px 14px; background: var(--surface-2);
  border-left: 3px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0;
  white-space: pre-wrap; font-size: 0.92rem;
}
blockquote.msg-block.rewrite { border-left-color: var(--success); background: var(--success-bg); }

.recipient-reply {
  margin-top: 16px; padding: 14px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px dashed var(--border);
}
.recipient-reply__name { font-weight: 700; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }

.fix-item { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-start; }
.fix-item__num {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}

/* ---------- Progress ---------- */
.progress-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 12px; }
.stat-tile { background: var(--surface-2); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-tile__value { font-size: 1.5rem; font-weight: 800; color: var(--brand); }
.stat-tile__label { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.level-track { display: flex; gap: 6px; margin: 14px 0; }
.level-dot {
  flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2);
}
.level-dot.is-unlocked { background: var(--brand); }

ul.scenario-list { list-style: none; padding: 0; margin: 0; }
ul.scenario-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
ul.scenario-list li:last-child { border-bottom: none; }
.scenario-list__title { font-weight: 600; }
.scenario-list__sub { font-size: 0.8rem; color: var(--text-muted); }
.scenario-score { font-weight: 700; }

/* ---------- Milestone toast ---------- */
.milestone-banner {
  background: linear-gradient(135deg, var(--brand), #d97706); color: #fff;
  padding: 14px 18px; border-radius: var(--radius-lg); margin-bottom: 16px;
  font-weight: 600; display: flex; align-items: center; gap: 10px;
}

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-toggle { text-align: center; margin-top: 14px; font-size: 0.88rem; }
.auth-toggle button { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; }
.error-banner {
  background: var(--danger-bg); color: var(--danger); padding: 10px 14px;
  border-radius: var(--radius); font-size: 0.88rem; margin-bottom: 14px;
}

/* ---------- Templates ---------- */
.template-item { border-bottom: 1px solid var(--border); padding: 14px 0; }
.template-item:last-child { border-bottom: none; }
.template-item__title { font-weight: 700; margin-bottom: 6px; }
.template-item__actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 30px 16px; color: var(--text-muted); }
.skeleton { background: var(--surface-2); border-radius: var(--radius); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

@media (max-width: 480px) {
  .app-header__word { display: none; }
  .app-header__book { display: none; }
  .app-header__logo { height: 22px; }
  h1 { font-size: 1.3rem; }
}
