:root {
  color-scheme: light dark;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #15162b;
  --muted: #6b6f8c;
  --border: #e3e5f1;
  --accent: #6c5ce7;
  --accent-soft: rgba(108, 92, 231, 0.12);
  --accent-ink: #ffffff;
  --teal: #12b5c4;
  --hot: #ff4d6d;
  --ok: #129b4f;
  --warn: #d08a10;
  --danger: #e5484d;
  --teacher-bg: #ffffff;
  --student-bg: #6c5ce7;
  --student-ink: #ffffff;
  --mark-bg: rgba(108, 92, 231, 0.13);
  --mark-ink: #4a39d4;
  --shadow: 0 1px 2px rgba(21, 22, 43, 0.05), 0 8px 24px rgba(21, 22, 43, 0.06);
  --radius: 20px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e1a;
    --surface: #161829;
    --surface-2: #1f2238;
    --text: #eef0ff;
    --muted: #9a9fc2;
    --border: #2a2e4b;
    --accent: #8b7dff;
    --accent-soft: rgba(139, 125, 255, 0.16);
    --teal: #2dd4e4;
    --teacher-bg: #1b1e33;
    --student-bg: #6c5ce7;
    --mark-bg: rgba(139, 125, 255, 0.22);
    --mark-ink: #cfc8ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

#app { max-width: 560px; height: 100dvh; margin: 0 auto; }
.screen { height: 100dvh; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; padding: 4px 16px 24px; overscroll-behavior: contain; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--muted); font-size: 18px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.pill-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600;
}

/* ---------- home ---------- */
.hero { padding: 6px 4px 14px; }
.hero h1 { margin: 0 0 6px; font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.card.error { border-color: var(--danger); color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 7px 14px; font-size: 15px; transition: background 0.15s, border-color 0.15s;
}
.chip.on, .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.sub { margin-top: 12px; }

select, .input {
  width: 100%; min-width: 0; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
select:focus, .input:focus { border-color: var(--accent); }
select.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#targetName { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: 14px; color: var(--muted); }
.field select, .field .input, .field input[type="range"] { color: var(--text); }
.field input[type="range"] { accent-color: var(--accent); }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode {
  text-align: left; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
}
.mode .t { font-weight: 650; }
.mode .h { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.mode.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.mode:disabled { opacity: 0.45; cursor: not-allowed; }

.voices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.voices .row { grid-column: 1 / -1; margin-top: 0; }
.voice {
  display: flex; align-items: center; border: 1px solid var(--border);
  background: var(--surface-2); border-radius: 14px; overflow: hidden;
}
.voice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.voice-pick { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 9px 10px; text-align: left; min-width: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--teal)); color: #fff; font-weight: 700; font-size: 14px;
}
.voice-play {
  width: 40px; height: 40px; flex: none; border: 0; background: none; color: var(--accent); font-size: 14px;
}
.voices .row .voice-play { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.voice-play.loading { animation: blink 0.8s infinite; }
.toggle { display: flex; gap: 10px; align-items: center; margin-top: 14px; font-size: 15px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.stats { display: flex; gap: 8px; margin-bottom: 10px; }
.stat { flex: 1; background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 0; }
.danger-btn { border: 1px solid var(--danger); color: var(--danger); background: transparent; border-radius: 12px; padding: 10px 14px; width: 100%; }

.cta-bar { padding: 10px 16px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.cta {
  width: 100%; border: 0; border-radius: 16px; padding: 16px; font-size: 17px; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, var(--accent), #5a4bd8 60%, var(--teal));
  box-shadow: 0 10px 24px rgba(108, 92, 231, 0.35);
}
.cta:disabled { opacity: 0.6; }
.hint { margin: 0 0 8px; font-size: 14px; color: var(--danger); text-align: center; }

/* ---------- lesson ---------- */
.lesson-title { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 0; }
.lesson-title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.lesson-title span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.transcript {
  flex: 1; overflow-y: auto; padding: 8px 16px 16px;
  display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain;
}
.msg { max-width: 86%; padding: 10px 14px; border-radius: 20px; font-size: 16.5px; animation: rise 0.2s ease-out; }
.msg.teacher { align-self: flex-start; background: var(--teacher-bg); border: 1px solid var(--border); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.student { align-self: flex-end; background: var(--student-bg); color: var(--student-ink); border-bottom-right-radius: 6px; }
.msg.pending .body { opacity: 0.7; }
.msg.cut .body::after { content: ' …'; color: var(--muted); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; transition: filter 0.2s; }
mark.t { background: var(--mark-bg); color: var(--mark-ink); padding: 0 4px; border-radius: 6px; font-weight: 600; }
.hide-text .msg.teacher:not(.revealed) .body { filter: blur(7px); user-select: none; cursor: pointer; }
.tools { display: flex; gap: 6px; margin-top: 6px; }
.tool { border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; }
.tool:hover { color: var(--accent); }
.meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.word { font-size: 13px; padding: 3px 10px; background: var(--accent-soft); border-radius: 999px; }
.word b { color: var(--mark-ink); }
.fix {
  align-self: flex-end; max-width: 86%; font-size: 14px; background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--warn); padding: 7px 12px; border-radius: 12px;
  animation: rise 0.2s ease-out;
}
.card .fix { max-width: none; margin-top: 8px; animation: none; }
.fix s { color: var(--danger); text-decoration-thickness: 1.5px; }
.fix b { color: var(--ok); }
.fix .note { color: var(--muted); }
.note-line { align-self: center; max-width: 92%; text-align: center; font-size: 13.5px; color: var(--muted); padding: 4px 8px; }
.note-line.error { color: var(--danger); }

.dock { padding: 6px 16px max(14px, env(safe-area-inset-bottom)); }
.status { text-align: center; min-height: 22px; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.dock-row { display: flex; align-items: center; justify-content: space-between; }
.side-btn {
  width: 64px; height: 44px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600;
  display: grid; place-items: center;
}
.side-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.orb {
  --level: 0;
  position: relative; width: 108px; height: 108px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 32% 28%, #b3a8ff, var(--accent) 48%, #3d2fb8);
  box-shadow: 0 12px 32px rgba(108, 92, 231, 0.45);
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: background 0.3s, box-shadow 0.3s, filter 0.3s;
}
.orb > * { pointer-events: none; }
.orb-icon { position: relative; z-index: 2; }
.orb-ring {
  position: absolute; inset: -9px; border-radius: 50%;
  border: 3px solid currentColor; color: var(--accent); opacity: 0.35;
  transform: scale(calc(1 + var(--level) * 0.5)); transition: transform 0.07s linear, color 0.3s;
}
.orb-core {
  position: absolute; inset: 0; border-radius: 50%; opacity: 0;
  background: conic-gradient(from 0deg, transparent, rgba(255, 255, 255, 0.55), transparent 40%);
}
.orb[data-state="listening"] .orb-ring { animation: breathe 2.4s ease-in-out infinite; }
.orb[data-state="hearing"] { background: radial-gradient(circle at 32% 28%, #ffb7c5, var(--hot) 50%, #c2184b); box-shadow: 0 12px 32px rgba(255, 77, 109, 0.45); }
.orb[data-state="hearing"] .orb-ring { color: var(--hot); opacity: 0.55; }
.orb[data-state="thinking"] .orb-core { opacity: 1; animation: spin 1.1s linear infinite; }
.orb[data-state="speaking"] { background: radial-gradient(circle at 32% 28%, #9cf6fc, var(--teal) 50%, #0a7f8c); box-shadow: 0 12px 32px rgba(18, 181, 196, 0.4); }
.orb[data-state="speaking"] .orb-ring { color: var(--teal); opacity: 0.6; }
.orb[data-state="paused"], .orb[data-state="connecting"] { filter: grayscale(0.7); opacity: 0.85; }
.orb[data-state="hold"] .orb-ring { opacity: 0.2; }

.text-row { display: flex; gap: 8px; margin-top: 12px; }
.send-btn { width: 46px; flex: none; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 18px; }

/* ---------- summary ---------- */
.summary-list { margin: 0; padding-left: 20px; }
.summary-list li { margin: 4px 0; }
.spinner { width: 34px; height: 34px; margin: 40px auto 12px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }

/* ---------- sheets ---------- */
.sheet {
  width: min(560px, 100%); max-height: min(88dvh, 760px); margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 22px; } }
.sheet::backdrop { background: rgba(8, 9, 20, 0.5); }
.sheet-body { padding: 4px 18px 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 14px 0 6px; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.sheet section:last-child { border-bottom: 0; }
.sheet h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.vocab-list { list-style: none; margin: 0; padding: 0; }
.vocab-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.vocab-list li span { flex: 1; color: var(--muted); }
.vocab-list li b { color: var(--text); }
.vocab-list .empty { color: var(--muted); border: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: #20223a; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); z-index: 10;
}

@keyframes breathe { 50% { transform: scale(1.08); opacity: 0.6; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0.3; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
