:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #efebe1;
  --ink: #1f1d17;
  --ink-2: #5f5a4e;
  --ink-3: #8c8676;
  --line: #e2ddd0;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #dfeae5;
  --me: #2f5d50;
  --me-ink: #ffffff;
  --warn: #9a3b2a;
  --bar-off: #e6e1d5;
  --shadow: 0 1px 2px rgba(31, 29, 23, 0.06), 0 6px 20px rgba(31, 29, 23, 0.06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16150f;
    --surface: #201f18;
    --surface-2: #2a2920;
    --ink: #f0ece2;
    --ink-2: #b9b3a4;
    --ink-3: #8a8474;
    --line: #34322a;
    --accent: #7fb8a5;
    --accent-ink: #10201b;
    --accent-soft: #23332d;
    --me: #3f7464;
    --me-ink: #f4fbf8;
    --warn: #e08a76;
    --bar-off: #34322a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { height: 100vh; }

/* ---------- layout ---------- */
.page { max-width: 680px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 28px); }
.topbar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.wordmark { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 0; flex: 1; }
.wordmark span { color: var(--accent); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- home ---------- */
.hello { font-family: var(--serif); font-size: 30px; line-height: 1.2; margin: 28px 0 6px; font-weight: 600; letter-spacing: -0.01em; }
.sub { color: var(--ink-2); margin: 0 0 18px; }
.start { display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow); }
.start input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 10px; outline: none; font-size: 17px; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--warn); padding-left: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 6px 12px; font-size: 14.5px;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 34px 0 10px; font-weight: 650; }
.lessons { display: grid; gap: 10px; }
.lesson-card {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--ink);
}
.lesson-card:hover { border-color: var(--accent); }
.lesson-card .t { font-weight: 650; overflow-wrap: anywhere; }
.lesson-card .meta { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 14px; margin-top: 8px; }
.track { height: 6px; background: var(--bar-off); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.empty { color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.foot { color: var(--ink-3); font-size: 14px; margin-top: 30px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- lesson ---------- */
.lesson { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.lesson header {
  display: flex; align-items: center; gap: 6px; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.lesson header .title { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ring-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 4px; font-size: 14px; color: var(--ink-2); }
.ring { width: 28px; height: 28px; }
.feed { flex: 1; overflow-y: auto; padding: 18px 16px 8px; -webkit-overflow-scrolling: touch; }
.msg { margin: 0 0 14px; display: flex; }
.msg .b { max-width: 88%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.tutor .b { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.me { justify-content: flex-end; }
.msg.me .b { background: var(--me); color: var(--me-ink); border-top-right-radius: 6px; white-space: pre-wrap; }
.msg .b p { margin: 0 0 0.6em; }
.msg .b p:last-child, .msg .b ul:last-child, .msg .b ol:last-child, .msg .b pre:last-child { margin-bottom: 0; }
.msg .b ul, .msg .b ol { margin: 0 0 0.6em; padding-left: 1.3em; }
.msg .b code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.msg .b pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; margin: 0 0 0.6em; }
.msg .b pre code { background: none; padding: 0; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.err { color: var(--warn); font-size: 15px; display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px); }
.quick { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.quick .chip { font-size: 13.5px; padding: 4px 11px; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row textarea {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 14px; padding: 10px 12px; max-height: 160px; outline: none; line-height: 1.4;
}
.row textarea:focus { border-color: var(--accent); }
.send { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: 0.4; }
.send svg { width: 20px; height: 20px; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 14, 10, 0.4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; animation: fade 0.15s; }
@media (min-width: 700px) { .scrim { align-items: center; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(env(safe-area-inset-bottom) + 20px); box-shadow: var(--shadow);
}
@media (min-width: 700px) { .sheet { border-radius: 18px; } }
.sheet h2 { font-family: var(--serif); font-size: 22px; margin: 4px 0 6px; }
.sheet p { color: var(--ink-2); margin: 0 0 12px; }
.sheet .close { float: right; margin: -6px -6px 0 0; }
.menu-list { display: grid; gap: 4px; margin-top: 8px; }
.menu-list button { text-align: left; border: 0; background: transparent; padding: 12px 10px; border-radius: 10px; font-weight: 550; }
.menu-list button:hover { background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } }

.map-row { margin: 12px 0; }
.map-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.map-row .top b { font-weight: 600; }
.map-row .lvl { color: var(--ink-3); white-space: nowrap; }
.pips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 6px; }
.pips i { height: 8px; border-radius: 3px; background: var(--bar-off); }
.pips i.on { background: var(--accent); }
.focus-tag { color: var(--accent); font-size: 12.5px; font-weight: 700; margin-left: 6px; }
.legend { font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); margin-top: 16px; padding-top: 10px; }
.overall { display: flex; align-items: baseline; gap: 10px; }
.overall .pct { font-family: var(--serif); font-size: 34px; font-weight: 600; }

.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 14px; margin: 8px auto 12px; width: fit-content; }
.qr svg, .qr img { width: 220px; height: 220px; display: block; }
.copy-row { display: flex; gap: 8px; margin: 10px 0; }
.copy-row input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 9px 10px; font-size: 14px; }

.people { display: grid; gap: 10px; margin-top: 10px; }
.person { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.person .top { display: flex; justify-content: space-between; gap: 8px; }
.person .meta { color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.person .acts { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.person .acts button { border: 0; background: none; padding: 0; color: var(--accent); font-size: 14.5px; font-weight: 600; }
.person.off { opacity: 0.55; }
.field { display: flex; gap: 8px; margin-top: 10px; }
.field input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 10px; }

.center-msg { max-width: 420px; margin: 18vh auto 0; padding: 0 16px; }
.center-msg h1 { font-family: var(--serif); font-size: 28px; margin: 0 0 8px; }
.center-msg p { color: var(--ink-2); }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px; z-index: 20; }
.small { font-size: 14px; color: var(--ink-3); }
.steps { padding-left: 1.2em; color: var(--ink-2); margin: 0 0 12px; }
.steps li { margin: 4px 0; }

/* ---------- sample lesson ---------- */
.sample-card {
  display: flex; gap: 14px; align-items: center; margin-top: 26px; padding: 14px 16px;
  border-radius: var(--radius); background: var(--accent-soft); color: var(--ink); text-decoration: none;
}
.sample-card .q {
  flex: none; width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-family: var(--serif); font-size: 22px; font-weight: 700;
}
.sample-card b { display: block; }
.tfeed { margin-top: 18px; }
.tnote {
  display: block; margin: 2px 0 18px; padding: 10px 14px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 10px 10px 0; font-size: 15px; color: var(--ink-2);
}
.tnote b { display: block; color: var(--ink); font-size: 14px; margin-bottom: 2px; }
.tmap { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px 16px 6px; margin: 0 0 14px; }
.tutorial .steps li { margin: 8px 0; }
