/* Allerac Academy: mobile-first styles. */
:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1d1b2e;
  --muted: #6b6880;
  --border: #e6e3f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  /* Brand colors from the Allerac icon (indigo -> violet -> deep indigo). */
  --brand-indigo: #6366f1;
  --brand-violet: #4c1d95;
  --brand-deep: #1e1b4b;
  --primary-soft: #eef0ff;
  --success: #16a34a;
  --success-soft: #e8f8ee;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(30, 27, 75, 0.06);
  --nav-h: 76px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.55; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
.small { font-size: 0.86rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
[hidden] { display: none !important; }

.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.eyebrow { display: inline-block; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--primary); margin-bottom: 0.5rem; }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: #efedf5; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0; font: inherit; font-weight: 650; cursor: pointer; text-decoration: none; color: var(--text); background: transparent; transition: transform 0.08s ease, background 0.15s ease; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--brand-violet); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { color: var(--muted); }
.btn-outline { border: 2px solid var(--border); background: var(--surface); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 0.9rem; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: #efedf5; }
:focus-visible { outline: 3px solid #a5b4fc; outline-offset: 2px; }

/* Loading */
.center-screen { min-height: 70vh; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 24px; text-align: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Map */
.map-page { display: grid; gap: 16px; }
.map-header { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; }
.brand img { border-radius: 50%; box-shadow: 0 2px 8px rgba(76, 29, 149, 0.18); }
.brand-name strong { font-weight: 800; color: var(--brand-violet); }
.brand-name span { font-weight: 600; color: var(--brand-deep); }
.intro p { color: var(--muted); }
.intro blockquote { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-dark); font-size: 0.9rem; }
.intro blockquote p { margin: 0; color: inherit; }
.goal-card { display: flex; gap: 16px; align-items: center; }
.goal-card h2 { margin: 0; }
.goal-text { font-weight: 600; margin: 2px 0; }
.goal-ring { --pct: 0; flex: none; width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--success) calc(var(--pct) * 1%), #e9e7f2 0); }
.goal-ring span { width: 56px; height: 56px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 800; }
.next-card { display: grid; gap: 6px; text-decoration: none; color: var(--text); border: 2px solid var(--brand-indigo); background: linear-gradient(135deg, #ffffff, #f1edff); }
.next-card .btn { justify-self: start; margin-top: 6px; }
.module-list, .lesson-path { list-style: none; margin: 0; padding: 0; }
.module-list { display: grid; gap: 14px; }
.module-number { font-size: 0.78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.module-progress { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; border-radius: 999px; background: #ece9f5; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--success); border-radius: inherit; }
.module-card.locked { opacity: 0.75; box-shadow: none; background: #fbfaff; }
.module-card.locked h3 { color: var(--muted); }
.module-summary p { margin: 8px 0 0; }
.lesson-path { margin-top: 12px; display: grid; gap: 4px; position: relative; }
.lesson-node { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 14px; text-decoration: none; color: var(--text); }
.lesson-node:hover { background: #f4f3fa; }
.node-dot { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; background: #efedf5; color: var(--muted); border: 3px solid transparent; }
.lesson-node.done .node-dot { background: var(--success); color: #fff; font-size: 1.1rem; }
.lesson-node.current .node-dot { background: var(--primary); color: #fff; border-color: #c7d2fe; box-shadow: 0 0 0 4px var(--primary-soft); }
.node-body { flex: 1; display: grid; }
.node-title { font-weight: 600; }
.node-cta { color: var(--primary); font-weight: 700; }

/* Lesson player */
.lesson-page { padding-top: 8px; }
.lesson-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 0; background: var(--bg); }
.lesson-progress { flex: 1; display: flex; gap: 4px; }
.lesson-progress span { flex: 1; height: 8px; border-radius: 999px; background: #e3e0ee; transition: background 0.25s ease; }
.lesson-progress span.filled { background: var(--success); }
.lesson-title { margin: 4px 0 12px; }
.lesson-screen.enter { animation: enter 0.25s ease; }
@keyframes enter { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.screen { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.lesson-text { font-size: 1.07rem; }
.lesson-text ul, .lesson-text ol { padding-left: 1.3rem; }
.lesson-text li { margin-bottom: 0.4rem; }
.lesson-text code { background: #f1effa; padding: 1px 6px; border-radius: 6px; font-size: 0.92em; }
.lesson-text blockquote { margin: 0 0 0.75rem; padding: 8px 14px; border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 8px; }
.problem-screen { border: 2px solid #fcd9a8; background: linear-gradient(180deg, #fffaf2, #ffffff); }
.problem-screen .eyebrow { color: var(--warn); }
.problem-text { font-size: 1.15rem; font-weight: 500; }
textarea { width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 2px solid var(--border); background: #fff; resize: vertical; }
textarea:focus { border-color: #a5b4fc; outline: none; }
.block-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.stuck-btn.pressed { border-color: #fcd9a8; background: var(--warn-soft); color: var(--warn); }
.mission-screen { border: 2px solid #c7d2fe; }
.go-deeper { margin-bottom: 16px; }
.feedback-form { display: grid; gap: 8px; margin-top: 8px; box-shadow: none; background: #fbfaff; }
.feedback-form label, .feedback-form .label { font-weight: 600; margin: 6px 0 0; }
.rating { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.rating-btn { min-height: 48px; border-radius: 12px; border: 2px solid var(--border); background: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.rating-btn.selected { border-color: var(--primary); background: var(--primary); color: #fff; }
.rating-legend { display: flex; justify-content: space-between; }
.form-error { color: #b91c1c; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.done-screen { padding: 32px 20px; }
.done-badge { font-size: 3.5rem; animation: pop 0.5s ease; }
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.done-actions { display: grid; gap: 8px; margin-top: 16px; }

.lesson-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--border); backdrop-filter: blur(8px); }
.lesson-nav .btn-primary { flex: 1; max-width: 420px; margin-left: auto; }
.tutor-fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 11; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 0; background: var(--brand-deep); color: #fff; font: inherit; font-weight: 650; box-shadow: 0 6px 18px rgba(30, 27, 75, 0.3); cursor: pointer; }

/* Selection "Explain better" */
.selection-explain { position: fixed; z-index: 30; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--primary); color: #fff; font: inherit; font-weight: 700; box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35); cursor: pointer; }

/* Tutor sheet */
.tutor-sheet { position: fixed; inset: 0; z-index: 40; }
.tutor-backdrop { position: absolute; inset: 0; background: rgba(20, 18, 40, 0.35); }
.tutor-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 82vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 30px rgba(20, 18, 40, 0.2); transform: translateY(100%); transition: transform 0.25s ease; padding-bottom: env(safe-area-inset-bottom); max-width: 640px; margin: 0 auto; }
.tutor-sheet.open .tutor-panel { transform: none; }
.tutor-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 8px; }
.tutor-header h2 { margin: 0; flex: 1; }
.tutor-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-deep); color: #fff; }
.tutor-status { margin: 0 16px 8px; padding: 12px 14px; border-radius: 14px; background: var(--warn-soft); color: var(--warn); border: 1px solid #fcd9a8; }
.tutor-status p { margin: 4px 0 0; font-size: 0.88rem; color: #92400e; }
.tutor-messages { flex: 1; overflow-y: auto; padding: 8px 16px; display: grid; gap: 10px; align-content: start; min-height: 120px; }
.tutor-empty { color: var(--muted); font-size: 0.92rem; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; }
.msg p { margin: 0; white-space: pre-wrap; }
.msg-student { justify-self: end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-tutor { justify-self: start; background: #f1effa; border-bottom-left-radius: 4px; }
.msg-tutor.pending { color: var(--muted); font-style: italic; }
.msg-system { justify-self: center; background: var(--warn-soft); color: var(--warn); font-size: 0.88rem; }
.msg-quote { margin: 0 0 6px; padding: 4px 10px; border-left: 3px solid rgba(255, 255, 255, 0.6); font-size: 0.88rem; opacity: 0.9; }
.tutor-form { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.tutor-form textarea { min-height: 48px; resize: none; }

/* Toast */
.toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 50; width: calc(100% - 32px); max-width: 480px; padding: 12px 16px; border-radius: 14px; background: var(--brand-deep); color: #fff; font-size: 0.92rem; box-shadow: 0 8px 24px rgba(20, 18, 40, 0.3); }

@media (min-width: 720px) {
  .page { padding-top: 28px; }
  h1 { font-size: 1.75rem; }
  .screen { padding: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
