/* ================================================================== */
/* Story Quest — educator app styles                                   */
/* ================================================================== */

:root {
  color-scheme: light;
  --brand: #6d4fc4;
  --brand-dark: #57389e;
  --brand-light: #ede8fb;
  --accent: #e8912d;
  --bg: #f7f5f0;
  --panel: #ffffff;
  --input-bg: #fdfcfa;
  --ink: #2b2733;
  --muted: #7a7386;
  --border: #e3ddd2;
  --danger: #c94f4f;
  --good: #3e8e5a;
  --accent-soft-bg: #fdf3e5;
  --accent-soft-border: #f0d4ad;
  --accent-soft-ink: #9a5f14;
  --danger-soft-bg: #fbeeee;
  --danger-soft-border: #ecc8c8;
  --danger-soft-ink: #8c3535;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(43, 39, 51, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --brand: #9b82e8;
  --brand-dark: #b7a5f0;
  --brand-light: #352a56;
  --accent: #eda04b;
  --bg: #16131f;
  --panel: #221e30;
  --input-bg: #1a1626;
  --ink: #ece8f4;
  --muted: #a79dba;
  --border: #3a3352;
  --danger: #e57575;
  --good: #6fc48f;
  --accent-soft-bg: #382a15;
  --accent-soft-border: #64481f;
  --accent-soft-ink: #f0c078;
  --danger-soft-bg: #3a2126;
  --danger-soft-border: #5e3239;
  --danger-soft-ink: #f0a3a3;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle at 85% -5%, var(--brand-light), transparent 40%);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}
body.modal-open { overflow: hidden; }

button { font-family: inherit; }
h2 { font-size: 1.5rem; }
h3 { margin-bottom: 10px; }
.muted { color: var(--muted); font-weight: normal; }
.req { color: var(--danger); }

/* ------------------------------ header ----------------------------- */

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-icon { font-size: 1.4rem; }
.brand h1 {
  font-size: 1.35rem;
  background: linear-gradient(120deg, var(--brand), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { color: var(--muted); font-size: 0.85rem; font-style: italic; }
.header-actions { display: flex; align-items: center; gap: 14px; }
#autosave-indicator {
  color: var(--good); font-size: 0.8rem; opacity: 0; transition: opacity 0.4s ease;
}
#autosave-indicator.visible { opacity: 1; }

/* ---------------------------- step nav ------------------------------ */

.step-nav {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  padding: 14px 20px 0; max-width: 1060px; margin: 0 auto;
}
.step-chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 0.82rem;
  transition: all 0.15s ease;
}
.step-chip:hover { border-color: var(--brand); color: var(--brand); }
.step-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.step-chip.done { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-light); }
.step-num {
  display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center;
  border-radius: 50%; background: rgba(0,0,0,0.08); font-size: 0.7rem; margin-right: 2px;
}
.step-chip.active .step-num { background: rgba(255,255,255,0.25); }

/* ------------------------------ layout ------------------------------ */

#app { max-width: 1020px; margin: 0 auto; padding: 24px 20px 120px; }

.step-header { margin-bottom: 18px; }
.guidance { color: var(--muted); max-width: 760px; margin-top: 6px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}

/* ------------------------------ forms ------------------------------- */

.field-label { display: block; font-weight: 600; font-size: 0.88rem; margin: 2px 0 6px; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%; font-family: inherit; font-size: 0.95rem; color: var(--ink);
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand);
}
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field .muted { font-size: 0.8rem; margin-top: 5px; }
.span-2 { grid-column: span 2; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: normal; padding: 9px 0; cursor: pointer; }
.check-row input { width: auto; }

/* ------------------------------ buttons ----------------------------- */

.btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--ink);
  border-radius: 10px; padding: 9px 18px; font-size: 0.92rem; cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-dark); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); color: #fff; }
.btn-accent { background: var(--accent-soft-bg); border-color: var(--accent-soft-border); color: var(--accent-soft-ink); }
.btn-accent:hover:not(:disabled) { border-color: var(--accent); }
.btn-big { font-size: 1.05rem; padding: 13px 26px; }
.btn-small { font-size: 0.8rem; padding: 6px 12px; margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; text-decoration: underline; font-size: inherit; padding: 0; }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; color: var(--muted); font-size: 0.85rem;
}
.icon-btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ------------------------------ footer ------------------------------ */

.wizard-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  background: var(--panel); border-top: 1px solid var(--border);
  padding: 12px 28px;
}
#footer-hint { color: var(--muted); font-size: 0.85rem; text-align: center; flex: 1; transition: color 0.2s; }
#footer-hint.flash { color: var(--danger); font-weight: 600; }
#btn-back, #btn-next { min-width: 110px; }
#btn-next { background: var(--brand); border: 1px solid var(--brand); color: #fff; border-radius: 10px; padding: 10px 22px; font-weight: 600; cursor: pointer; }
#btn-next:hover { background: var(--brand-dark); }
#btn-back { background: none; border: 1px solid var(--border); border-radius: 10px; padding: 10px 22px; cursor: pointer; color: var(--muted); }
#btn-back:hover { border-color: var(--brand); color: var(--brand); }

/* ----------------------------- welcome ------------------------------ */

.welcome { max-width: 860px; margin: 0 auto; }
.welcome-hero { text-align: center; padding: 30px 0 10px; }
.welcome-badge {
  display: inline-block; background: var(--brand-light); color: var(--brand-dark);
  border-radius: 999px; padding: 6px 16px; font-size: 0.82rem; font-weight: 600; margin-bottom: 14px;
}
.welcome-hero h2 { font-size: 2.3rem; line-height: 1.15; margin-bottom: 12px; }
.welcome-sub { color: var(--muted); max-width: 640px; margin: 0 auto 24px; }
.welcome-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.resume-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: left;
  background: var(--panel); border: 1px dashed var(--brand); border-radius: var(--radius);
  padding: 14px 20px; margin: 26px auto 0; max-width: 560px;
}
.resume-meta { display: block; color: var(--muted); font-size: 0.8rem; }
.welcome-worlds, .welcome-how, .welcome-offline { margin-top: 42px; }
.welcome-offline {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 20px 24px; box-shadow: var(--shadow);
}
.welcome-offline .how-list { margin-top: 10px; }
.welcome-offline .muted { margin-top: 10px; font-size: 0.9rem; }
.offline-actions { margin: 16px 0 4px; }
code {
  background: var(--brand-light); color: var(--brand-dark);
  padding: 1px 7px; border-radius: 5px; font-size: 0.85em;
  font-family: Consolas, 'Courier New', monospace;
}
.world-strip { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.world-chip {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 220px;
  border-radius: var(--radius); padding: 14px 16px; color: #fff; box-shadow: var(--shadow);
  font-size: 0.88rem;
}
.world-chip .muted { color: rgba(255,255,255,0.75); }
.world-chip-emoji { font-size: 1.6rem; }
.how-list { margin: 12px 0 0 20px; display: grid; gap: 8px; color: var(--muted); }
.how-list strong { color: var(--ink); }

.theme-woodland { background: linear-gradient(135deg, #1d3b22, #3f7a48); }
.theme-underwater { background: linear-gradient(135deg, #093243, #1379a0); }
.theme-city { background: linear-gradient(135deg, #2e2f47, #b25a34); }
.theme-space { background: linear-gradient(135deg, #16143a, #5b4bc4); }

/* --------------------------- world cards ---------------------------- */

.world-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 18px; }
.world-card {
  text-align: left; color: #fff; border: 3px solid transparent; border-radius: var(--radius);
  padding: 20px; cursor: pointer; box-shadow: var(--shadow); position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
  display: flex; flex-direction: column; gap: 8px; font-size: 0.88rem;
}
.world-card:hover { transform: translateY(-3px); }
.world-card.selected { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(232, 145, 45, 0.25), var(--shadow); }
.world-emoji { font-size: 2.2rem; }
.world-card h3 { margin: 0; font-size: 1.2rem; }
.world-tagline { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.68rem; opacity: 0.85; }
.world-card p { opacity: 0.92; }
.world-facts { display: flex; flex-direction: column; gap: 3px; font-size: 0.78rem; opacity: 0.9; margin-top: auto; padding-top: 8px; }
.selected-tag {
  position: absolute; top: 12px; right: 12px; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 3px 12px; font-size: 0.75rem; font-weight: 700;
}
.world-detail-card { animation: fadein 0.25s ease; }
.location-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.loc-chip {
  background: var(--brand-light); color: var(--brand-dark); border-radius: 999px;
  padding: 4px 12px; font-size: 0.8rem;
}
.rank-chip { background: var(--accent-soft-bg); color: var(--accent-soft-ink); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* --------------------------- material step -------------------------- */

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px;
  text-align: center; margin-bottom: 12px; transition: all 0.15s ease; background: var(--input-bg);
}
.drop-zone.dragging { border-color: var(--brand); background: var(--brand-light); }
.drop-icon { font-size: 1.8rem; margin-bottom: 6px; }
.drop-zone .muted { font-size: 0.82rem; margin-top: 4px; }
.file-status { font-size: 0.88rem; margin-bottom: 14px; min-height: 1.2em; }

/* --------------------------- objectives ----------------------------- */

.obj-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.obj-num {
  flex: 0 0 26px; height: 26px; line-height: 26px; text-align: center;
  background: var(--brand-light); color: var(--brand-dark); border-radius: 50%;
  font-size: 0.8rem; font-weight: 700;
}
.obj-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.empty-note { padding: 10px 0; }
#suggest-note { margin-top: 10px; font-size: 0.85rem; }

/* ------------------------------ stages ------------------------------ */

.stage-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.stage-count { font-size: 0.85rem; }
.stage-card { border-left: 4px solid var(--brand); }
.stage-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stage-title { font-weight: 700; font-size: 1.05rem; }
.stage-head-btns { display: flex; gap: 6px; }
.challenge-divider {
  border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 4px;
  font-weight: 700; color: var(--brand-dark); font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.mc-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.img-preview-row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.img-preview {
  max-width: 160px; max-height: 100px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff;
}
.img-preview-fields { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.img-preview-fields input { width: 100%; }
.mc-row input[type="radio"] { width: 18px; height: 18px; accent-color: var(--good); flex: 0 0 auto; cursor: pointer; }
.empty-note-card { text-align: center; }

/* ------------------------------ publish ----------------------------- */

.rank-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.issues {
  background: var(--danger-soft-bg); border: 1px solid var(--danger-soft-border); border-radius: 10px;
  padding: 14px 18px; color: var(--danger-soft-ink); margin-bottom: 16px; font-size: 0.9rem;
}
.issues ul { margin: 6px 0 0 18px; }
.ready-note { margin-bottom: 16px; }
.publish-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.publish-card { border-left: 4px solid var(--accent); }

/* --------------------------- lesson drawer -------------------------- */

#lesson-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 90vw); z-index: 40;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -10px 0 40px rgba(43, 39, 51, 0.15);
  display: flex; flex-direction: column;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700;
}
#drawer-content {
  flex: 1; overflow: auto; padding: 16px 18px; white-space: pre-wrap;
  font-size: 0.85rem; color: var(--ink); font-family: Consolas, monospace;
}
.ghost-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; color: var(--muted); font-size: 0.85rem;
}
.ghost-btn:hover { border-color: var(--brand); color: var(--brand); }

/* --------------------------- preview modal -------------------------- */

#preview-modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(24, 20, 32, 0.75);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.preview-shell {
  background: var(--panel); border-radius: var(--radius); overflow: hidden;
  width: min(960px, 100%); height: min(720px, 100%); display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
}
.preview-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 0.9rem;
}
#preview-frame { flex: 1; border: none; width: 100%; }

/* ---------------------------- responsive ---------------------------- */

@media (max-width: 780px) {
  .world-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .rank-grid { grid-template-columns: 1fr 1fr; }
  .welcome-hero h2 { font-size: 1.7rem; }
  .app-header { padding: 12px 16px; }
  .wizard-footer { padding: 10px 14px; }
}
