/* ============================================================
   Learning Quest — styles
   Playful but clean. Per-learner theming via CSS variables set
   on <body data-theme="...">. Works light on a dark canvas.
   ============================================================ */

:root {
  --accent: #6c5ce7;
  --accent-2: #00b894;
  --accent-soft: rgba(108, 92, 231, 0.16);

  --bg: #0f1020;
  --bg-2: #171935;
  --panel: #ffffff;
  --panel-2: #f4f5fb;
  --ink: #1e2140;
  --ink-soft: #565b83;
  --line: #e6e8f4;

  --good: #00b894;
  --bad: #ff6b6b;
  --warn: #f6b93b;
  --gold: #ffd166;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 18px 45px -22px rgba(20, 16, 60, 0.55);
  --shadow-sm: 0 8px 22px -14px rgba(20, 16, 60, 0.45);
  --maxw: 940px;

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-round: "Baloo 2", "Segoe UI", system-ui, sans-serif;
}

/* Per-learner accent themes */
body[data-theme="violet"] { --accent:#6c5ce7; --accent-2:#a55eea; --accent-soft:rgba(108,92,231,.16); }
body[data-theme="ocean"]  { --accent:#0984e3; --accent-2:#00cec9; --accent-soft:rgba(9,132,227,.16); }
body[data-theme="sunset"] { --accent:#e17055; --accent-2:#fdcb6e; --accent-soft:rgba(225,112,85,.16); }
body[data-theme="forest"] { --accent:#00b894; --accent-2:#55efc4; --accent-soft:rgba(0,184,148,.16); }
body[data-theme="berry"]  { --accent:#e84393; --accent-2:#fd79a8; --accent-soft:rgba(232,67,147,.16); }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(108,92,231,.35), transparent 60%),
    radial-gradient(1000px 600px at 110% 10%, rgba(0,184,148,.28), transparent 55%),
    linear-gradient(160deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: #fff; color: var(--ink); padding: .6rem 1rem; border-radius: 0 0 10px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------- */
.app-header[hidden] { display: none; }
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem clamp(.6rem, 3vw, 1.4rem);
  background: rgba(15, 16, 32, 0.55);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.header-btn[hidden] { display: none; }
.header-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.12); color: #fff;
  border: 1px solid rgba(255,255,255,.14);
  padding: .4rem .7rem; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 700;
}
.header-btn:hover { background: rgba(255,255,255,.2); }
.header-btn.ghost { padding: .45rem .6rem; font-size: 1.05rem; }
.header-avatar { font-size: 1.3rem; line-height: 1; }
.header-name { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-stats { margin-left: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.stat-chip {
  background: rgba(255,255,255,.1); color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  padding: .3rem .6rem; border-radius: 999px; font-size: .85rem; font-weight: 700;
  white-space: nowrap;
}
.stat-chip b { color: var(--gold); }

/* ---------- Layout ---------- */
.app-main {
  max-width: var(--maxw); margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) clamp(.8rem, 3vw, 1.4rem) 4rem;
  outline: none;
}
.view { animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.panel {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(1rem, 3vw, 1.6rem);
}
.panel + .panel { margin-top: 1rem; }

.section-title { margin: 0 0 .2rem; font-size: 1.35rem; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.stack > * + * { margin-top: .8rem; }
.grid { display: grid; gap: 1rem; }
.hero-title {
  color: #fff; text-align: center; margin: .4rem 0 1.4rem;
  font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 800; letter-spacing: -.02em;
  text-shadow: 0 4px 30px rgba(0,0,0,.35);
}
.hero-sub { color: rgba(255,255,255,.85); text-align: center; margin: -1rem 0 1.6rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 800; cursor: pointer;
  padding: .8rem 1.2rem; border-radius: 14px; border: 2px solid transparent;
  background: var(--accent); color: #fff; transition: transform .08s ease, filter .15s ease, box-shadow .15s;
  box-shadow: 0 10px 20px -10px var(--accent);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.secondary { background: var(--panel-2); color: var(--ink); border-color: var(--line); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); box-shadow: none; }
.btn.big { padding: 1rem 1.5rem; font-size: 1.1rem; border-radius: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---------- Home / profile picker ---------- */
.profile-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.profile-card {
  position: relative; overflow: hidden;
  border: none; cursor: pointer; text-align: left;
  border-radius: var(--radius); padding: 1.3rem; color: #fff;
  background: linear-gradient(150deg, var(--c1), var(--c2));
  box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .2s;
  min-height: 190px; display: flex; flex-direction: column; justify-content: space-between;
}
.profile-card:hover { transform: translateY(-4px) scale(1.01); }
.profile-card .avatar { font-size: 3.2rem; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.profile-card .pname { font-size: 1.5rem; font-weight: 800; margin: .5rem 0 .1rem; }
.profile-card .pmeta { opacity: .92; font-size: .95rem; }
.profile-card .pmini { display: flex; gap: .5rem; margin-top: .7rem; flex-wrap: wrap; }
.profile-card .pmini span {
  background: rgba(255,255,255,.22); border-radius: 999px; padding: .2rem .55rem; font-size: .8rem; font-weight: 700;
}
.profile-card .spark { position: absolute; right: -10px; top: -14px; font-size: 5rem; opacity: .18; transform: rotate(12deg); }

/* Grown-up card */
.parent-card { grid-column: 1 / -1; }

/* ---------- Dashboard ---------- */
.dash-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.dash-avatar { font-size: 3rem; }
.dash-greeting h2 { margin: 0; font-size: 1.6rem; }
.level-track { margin-top: .5rem; }
.progress-bar { height: 12px; background: var(--panel-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .5s ease; }

.subject-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 1rem; }
.subject-card {
  text-align: left; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel); border-radius: var(--radius); padding: 1.1rem;
  box-shadow: var(--shadow-sm); transition: transform .12s, border-color .2s;
  display: flex; flex-direction: column; gap: .5rem;
}
.subject-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.subject-card .s-emoji { font-size: 2.1rem; }
.subject-card .s-name { font-weight: 800; font-size: 1.15rem; }
.subject-card .s-desc { color: var(--ink-soft); font-size: .9rem; }
.subject-card .s-bar { margin-top: .3rem; }
.mini-tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag { font-size: .72rem; font-weight: 700; padding: .18rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat-card { background: var(--panel-2); border-radius: var(--radius-sm); padding: 1rem; text-align: center; }
.stat-card .big { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.stat-card .lbl { color: var(--ink-soft); font-size: .85rem; }

/* ---------- Topic list ---------- */
.topic-list { display: grid; gap: .6rem; }
.topic-row {
  display: flex; align-items: center; gap: .8rem; text-align: left; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-sm);
  padding: .8rem 1rem; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .1s;
}
.topic-row:hover { border-color: var(--accent); transform: translateX(2px); }
.topic-row .t-emoji { font-size: 1.6rem; }
.topic-row .t-main { flex: 1; }
.topic-row .t-name { font-weight: 700; }
.topic-row .t-sub { font-size: .82rem; color: var(--ink-soft); }
.topic-row .t-level { font-size: .8rem; font-weight: 800; color: var(--accent); white-space: nowrap; }
.mastery-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.mastery-dot.m1 { background: var(--warn); }
.mastery-dot.m2 { background: var(--accent-2); }
.mastery-dot.m3 { background: var(--good); }

/* ---------- Quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.quiz-progress { flex: 1; }
.q-count { font-weight: 800; color: var(--ink-soft); font-size: .9rem; white-space: nowrap; }
.difficulty-pill {
  font-size: .78rem; font-weight: 800; padding: .25rem .6rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}

.question-card { text-align: center; }
.q-prompt { font-size: clamp(1.3rem, 4vw, 1.9rem); font-weight: 800; margin: .3rem 0 .3rem; line-height: 1.3; }
.q-context { color: var(--ink-soft); margin-bottom: 1rem; font-size: 1rem; }
.q-visual { margin: .8rem auto 1.1rem; max-width: 460px; }

.options { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-top: 1rem; }
.option {
  font: inherit; font-weight: 800; font-size: 1.15rem; cursor: pointer;
  padding: 1rem; border-radius: 14px; border: 2px solid var(--line); background: var(--panel-2); color: var(--ink);
  transition: transform .08s, border-color .15s, background .15s;
}
.option:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.option.correct { background: #e8fbf3; border-color: var(--good); color: #0a7d5f; }
.option.wrong { background: #ffeaea; border-color: var(--bad); color: #c0392b; }
.option:disabled { cursor: default; }

.answer-form { display: flex; gap: .6rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.answer-input {
  font: inherit; font-size: 1.4rem; font-weight: 800; text-align: center;
  padding: .7rem 1rem; border-radius: 12px; border: 2px solid var(--line); width: min(260px, 70vw);
  color: var(--ink); background: var(--panel-2);
}
.answer-input:focus { outline: none; border-color: var(--accent); }
.answer-input.correct { border-color: var(--good); background: #e8fbf3; }
.answer-input.wrong { border-color: var(--bad); background: #ffeaea; }

.feedback {
  margin-top: 1rem; padding: 1rem 1.1rem; border-radius: 14px; text-align: left;
  border: 1px solid var(--line); background: var(--panel-2); animation: fadeUp .25s ease both;
}
.feedback.ok { background: #e8fbf3; border-color: #9ae6c8; }
.feedback.no { background: #fff4f4; border-color: #f6c2c2; }
.feedback h4 { margin: 0 0 .3rem; }
.feedback .explain { color: var(--ink); }
.feedback .explain b { color: var(--accent); }
.hint-box { margin-top: .8rem; padding: .8rem 1rem; border-radius: 12px; background: #fff9e8; border: 1px solid #f6e2a8; text-align: left; }

/* Reading passage */
.passage {
  text-align: left; background: var(--panel-2); border-radius: var(--radius-sm);
  padding: 1.1rem 1.2rem; border: 1px solid var(--line); line-height: 1.7; font-size: 1.05rem;
  max-height: 46vh; overflow: auto;
}
.passage h3 { margin-top: 0; }
.passage p { margin: 0 0 .8rem; }

/* Writing workspace */
.write-prompt { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 1rem 1.1rem; text-align: left; }
.write-area {
  width: 100%; min-height: 200px; resize: vertical; font: inherit; font-size: 1.05rem; line-height: 1.6;
  padding: 1rem; border-radius: 12px; border: 2px solid var(--line); background: var(--panel-2); color: var(--ink);
}
.write-area:focus { outline: none; border-color: var(--accent); }
.checklist { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .4rem; }
.checklist li { display: flex; gap: .5rem; align-items: flex-start; padding: .5rem .7rem; border-radius: 10px; background: var(--panel-2); }
.checklist input { margin-top: .25rem; width: 18px; height: 18px; accent-color: var(--accent); }
.word-count { font-weight: 800; color: var(--accent); }

/* Handwriting */
.hw-canvas-wrap { position: relative; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background:#fff; }
.hw-canvas { display: block; width: 100%; touch-action: none; background:
  repeating-linear-gradient(#fff, #fff 38px, #dfe6ff 39px, #fff 40px); cursor: crosshair; }
.hw-guide { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; pointer-events:none;
  font-size: 6rem; color: rgba(108,92,231,.14); font-family: var(--font-round); font-weight: 800; }
.print-sheet { display: none; }

/* Learn-how-to-learn */
.strategy-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.strategy-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow-sm); }
.strategy-card .s-icon { font-size: 2rem; }
.strategy-card h3 { margin: .4rem 0 .3rem; }
.strategy-card p { color: var(--ink-soft); margin: 0; font-size: .95rem; }
.tip-banner {
  display:flex; gap:.8rem; align-items:center;
  background: rgba(255,255,255,.94); color: var(--ink);
  border: 1px dashed var(--accent); border-radius: var(--radius-sm); padding: .9rem 1.1rem;
}
.tip-banner b { color: var(--accent); }
.tip-banner .ti { font-size: 1.6rem; }

/* Badges */
.badge-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.badge {
  text-align: center; padding: 1rem .6rem; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--line);
}
.badge.locked { opacity: .45; filter: grayscale(.7); }
.badge .b-emoji { font-size: 2.4rem; }
.badge .b-name { font-weight: 800; font-size: .85rem; margin-top: .3rem; }
.badge .b-desc { font-size: .72rem; color: var(--ink-soft); }

/* Teach-me-first lesson */
.lesson-block { text-align: left; }
.lesson-block h3 { margin: .2rem 0 .3rem; color: var(--accent); }
.lesson-block p { margin: 0; line-height: 1.6; }
.worked-example { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: 1rem 1.1rem; }
.we-label { font-weight: 800; color: var(--accent); margin-bottom: .4rem; }
.we-q { font-size: 1.15rem; font-weight: 700; margin-bottom: .6rem; }
.we-steps { margin: .3rem 0 .6rem; padding-left: 1.3rem; line-height: 1.7; }
.we-steps li { margin-bottom: .2rem; }
.we-answer { font-weight: 700; }
.keywords { list-style: none; padding: 0; margin: .3rem 0; display: grid; gap: .4rem; text-align: left; }
.keywords li { background: var(--panel-2); border-radius: 10px; padding: .5rem .7rem; }
.keywords b { color: var(--accent); }
.deepen-box { display: flex; gap: .7rem; align-items: flex-start; text-align: left; background: linear-gradient(120deg, rgba(0,184,148,.12), transparent); border: 1px solid var(--good); border-radius: var(--radius-sm); padding: .9rem 1.1rem; }
.deepen-box .db-icon { font-size: 1.5rem; }
.topic-lesson-btn { background: var(--accent-soft); color: var(--accent); border: none; border-radius: 10px; padding: .5rem .6rem; font-size: 1.1rem; cursor: pointer; }
.topic-lesson-btn:hover { filter: brightness(.96); }

/* Chart (progress) */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 160px; padding: .5rem 0; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 8px 8px 0 0; min-height: 4px; position: relative; transition: height .5s; }
.bars .bar span { position: absolute; bottom: -1.4rem; left: 0; right: 0; text-align: center; font-size: .7rem; color: var(--ink-soft); }
.bars .bar b { position: absolute; top: -1.2rem; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--accent); }

/* Settings + modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,10,25,.55); display: grid; place-items: center; z-index: 60; padding: 1rem; animation: fadeUp .2s; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 1.4rem; width: min(460px, 96vw); box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; }
.field { margin: .9rem 0; }
.field label { font-weight: 700; display: block; margin-bottom: .35rem; }
.seg { display: flex; gap: .4rem; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 90px; padding: .6rem; border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2); font: inherit; font-weight: 700; cursor: pointer; color: var(--ink); }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.switch { display:flex; align-items:center; justify-content: space-between; gap:1rem; }
.toggle { position: relative; width: 52px; height: 30px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track { position:absolute; inset:0; background: var(--line); border-radius: 999px; transition: .2s; }
.toggle .track::before { content:""; position:absolute; width:24px; height:24px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.2s; box-shadow: var(--shadow-sm); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::before { transform: translateX(22px); }

.breadcrumb { display:flex; align-items:center; gap:.4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crumb-btn { background: rgba(255,255,255,.14); color:#fff; border:1px solid rgba(255,255,255,.16); border-radius: 999px; padding:.35rem .8rem; font:inherit; font-weight:700; cursor:pointer; }
.crumb-btn:hover { background: rgba(255,255,255,.24); }
.crumb-sep { color: rgba(255,255,255,.5); }
.crumb-here { color:#fff; font-weight:800; }

/* Toast + fx */
.toast-root { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 80; display: grid; gap: .5rem; width: min(420px, 92vw); }
.toast { background: #14162e; color: #fff; border-radius: 14px; padding: .8rem 1rem; box-shadow: var(--shadow); font-weight: 700; display:flex; gap:.6rem; align-items:center; animation: fadeUp .25s; border:1px solid rgba(255,255,255,.1); }
.toast.good { background: #0a7d5f; }
.toast.gold { background: #b7791f; }
.fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 70; }

/* completion screen */
.result-emoji { font-size: 4rem; }
.result-score { font-size: 3rem; font-weight: 800; color: var(--accent); }
.stars { font-size: 2rem; letter-spacing: .2rem; }

/* ---------- Login page ---------- */
.auth-wrap { min-height: calc(100dvh - 3rem); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 1rem 0; }
.auth-back { align-self: flex-start; }
.auth-card { width: min(440px, 96vw); text-align: center; }
.auth-avatar { font-size: 3.4rem; line-height: 1; }
.auth-title { margin: .3rem 0 1rem; }
.auth-form { display: grid; gap: .7rem; text-align: left; margin-top: .4rem; }
.auth-form .field { margin: 0; }
.auth-input { width: 100%; text-align: left; font-size: 1.05rem; font-weight: 600; }
.auth-error { min-height: 1.2em; color: var(--bad); font-weight: 700; text-align: center; }
.auth-foot { margin-top: .8rem; display: flex; justify-content: center; }
.auth-foot .btn { font-size: .9rem; }

/* ---------- Touch / tablet friendliness ---------- */
button, .profile-card, .topic-row, .option, .subject-card, .stat-chip, .tag { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, textarea, select { font-size: max(16px, 1rem); } /* stop iOS zoom-on-focus */

@media (pointer: coarse) {
  .btn { min-height: 48px; }
  .option { min-height: 60px; }
  .answer-input { min-height: 52px; }
  .crumb-btn, .header-btn { min-height: 42px; }
  .topic-row { padding: 1rem; }
  .topic-lesson-btn { min-width: 46px; min-height: 46px; }
  .toggle { width: 58px; height: 34px; }
}

/* Tablet portrait/landscape sizing */
@media (min-width: 680px) and (max-width: 1100px) {
  :root { --maxw: 900px; }
  .hero-title { font-size: 2.6rem; }
  .q-prompt { font-size: 2.1rem; }
  .options { grid-template-columns: repeat(2, 1fr); }
  .profile-grid { grid-template-columns: repeat(2, 1fr); }
  .parent-card { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .header-name { display: none; }
  .q-prompt { font-size: 1.5rem; }
  .options { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Print styles for handwriting worksheets */
@media print {
  body { background: #fff; }
  .app-header, .breadcrumb, .btn, .toast-root, .fx-canvas, .hw-canvas-wrap { display: none !important; }
  .print-sheet { display: block !important; }
}
