:root {
  --bg: #fafaf9; --panel: #f1f0ee; --text: #1c1917; --muted: #78716c; --line: #e2e0dc;
  --accent: #0d9488; --accent-ink: #fff; --user: #e7f5f3; --bot: #ffffff; --danger: #dc2626;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211; --panel: #1b1a18; --text: #ecebe8; --muted: #a09a93; --line: #2c2a27;
    --accent: #2dd4bf; --accent-ink: #042f2b; --user: #12302d; --bot: #1d1c1a; --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 12px; }
button:hover { border-color: var(--muted); }
button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.danger { background: var(--danger); color: #fff; border-color: transparent; font-weight: 600; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .15s, border-color .15s, color .15s, transform .1s; }
button:active { transform: scale(.95); }
.i { width: 1.25em; height: 1.25em; flex: none; }
button.icon { width: 40px; height: 40px; padding: 0; font-size: 18px; border-radius: 12px; border-color: transparent; background: transparent; color: var(--muted); }
button.icon:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
button.icon .i { width: 1.2em; height: 1.2em; }
/* toggles show their filled icon while active */
.i-on { display: none; }
button[aria-pressed="true"] .i-on, button.on .i-on { display: block; }
button[aria-pressed="true"] .i-off, button.on .i-off { display: none; }
button.toggle[aria-pressed="true"], button.toggle.on { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
button.toggle.rec[aria-pressed="true"] { background: var(--danger); color: #fff; animation: rec 1.4s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }
button.icon.send { background: var(--accent); color: var(--accent-ink); border-radius: 50%; margin-left: 4px; }
button.icon.send:hover { background: var(--accent); color: var(--accent-ink); filter: brightness(1.08); }
button.icon.send.stop { background: var(--danger); color: #fff; }
button.icon.send:disabled { opacity: .4; }
.tools { display: flex; gap: 2px; align-items: center; }
.wide { width: 100%; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
#sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 17px; }
#convList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 10px; padding: 8px 10px; cursor: pointer; color: var(--muted); }
.conv:hover, .conv.active { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv button { border: 0; background: none; padding: 2px; opacity: 0; color: var(--muted); border-radius: 6px; }
.conv button:hover { color: var(--danger); }
.conv .i { width: 1.1em; height: 1.1em; }
.conv:hover button, .conv:focus-within button { opacity: 1; }
.status { font-size: 12px; color: var(--muted); padding: 4px; }
.status.err { color: var(--danger); }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
h1 { font-size: 15px; margin: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-only { display: none; }

#live { display: flex; gap: 10px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#live figure { position: relative; margin: 0; width: 150px; border-radius: 10px; overflow: hidden; background: #000; }
#live video { width: 100%; display: block; aspect-ratio: 16/10; object-fit: cover; }
#live figcaption { position: absolute; left: 6px; bottom: 4px; font-size: 11px; color: #fff; text-shadow: 0 1px 3px #000; }
#live .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 0; }
#live .x .i { width: 14px; height: 14px; }
.live-opt { font-size: 13px; color: var(--muted); }

#messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
#empty { margin: auto; text-align: center; max-width: 420px; color: var(--muted); }
#empty h2 { color: var(--text); font-size: 20px; margin: 16px 0 6px; }
.orb { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #99f6e4, var(--accent) 55%, #115e59); box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 45%, transparent); animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .orb, .pulse { animation: none; } }

.msg { max-width: min(720px, 88%); padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); border-color: transparent; }
.msg.assistant { align-self: flex-start; background: var(--bot); }
.msg.err { border-color: var(--danger); color: var(--danger); }
.msg.speaking::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg img { max-width: 220px; max-height: 160px; border-radius: 8px; display: block; margin: 0 6px 6px 0; }
.msg .imgs { display: flex; flex-wrap: wrap; }
.msg audio { height: 34px; max-width: 240px; display: block; margin-bottom: 4px; }
.msg .tag { flex: 0 100000 auto; min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; margin-bottom: 2px; }
.msg .tag .i { width: 14px; height: 14px; }

footer { padding: 8px 16px 16px; }
#chips { display: flex; gap: 8px; flex-wrap: wrap; }
#chips:not(:empty) { margin-bottom: 8px; }
.chip { position: relative; }
.chip img { height: 56px; border-radius: 8px; display: block; }
.chip button { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; padding: 0; background: var(--bg); }
.chip button .i { width: 13px; height: 13px; }
#vadBar { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#callCost { white-space: nowrap; font-variant-numeric: tabular-nums; }
#vadBar #hideTextBtn { width: 32px; height: 32px; margin-left: auto; flex: none; }
/* "Hide the text while you talk": the conversation is hidden only while a voice session is open, so typing chats are unaffected. */
body.hide-text:has(#vadBar:not([hidden])) #messages > :not(#empty) { display: none; }
body.hide-text:has(#vadBar:not([hidden])) #messages::before { content: "Text hidden while you talk. Tap the eye to show it."; margin: auto; color: var(--muted); text-align: center; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: breathe 1.2s infinite; }
.meter { flex: 1; max-width: 200px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 60ms linear; }
.composer { display: flex; gap: 4px; align-items: flex-end; border: 1px solid var(--line); background: var(--panel); border-radius: 22px; padding: 6px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.composer .tools { padding-bottom: 0; }
.composer textarea { flex: 1; resize: none; max-height: 160px; border: 0; background: transparent; padding: 8px; outline: none; min-width: 0; }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--text); width: min(440px, 92vw); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
dialog label.row { display: flex; gap: 8px; align-items: center; }
dialog select, dialog textarea { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
dialog input[type=range] { width: 100%; }
.actions { text-align: right; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  body.menu #sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .mobile-only { display: inline-block; }
  .composer { flex-wrap: wrap; }
  .composer textarea { flex-basis: 100%; order: -1; }
  .msg { max-width: 94%; }
}

/* ---- v3: search, chat rows, live view, markdown, actions ---- */
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--bg); color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 0; font: inherit; color: var(--text); outline: none; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.none { color: var(--muted); font-size: 13px; padding: 8px 10px; }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .mini { border: 0; background: none; padding: 3px; opacity: 0; color: var(--muted); border-radius: 6px; }
.conv .mini:hover { color: var(--text); background: color-mix(in srgb, var(--text) 10%, transparent); }
.conv .mini[data-act="delete"]:hover { color: var(--danger); }
.conv:hover .mini, .conv:focus-within .mini { opacity: 1; }
.conv .rename { flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px; outline: none; }
.side-foot { display: flex; flex-direction: column; gap: 4px; }
button.link { border: 0; background: none; color: var(--muted); padding: 6px 4px; justify-content: flex-start; font-size: 13px; }
button.link:hover { color: var(--text); }
.search [data-icon], button.link .i { display: inline-flex; }

/* live view strip */
.live-opts { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.live-opts label { display: flex; gap: 6px; align-items: center; }
.live-status { display: flex; align-items: center; gap: 6px; color: var(--text); font-weight: 600; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: breathe 1.6s infinite; }
#live figure { transition: box-shadow .2s; }
#live figure.changed { box-shadow: 0 0 0 3px var(--accent); }

/* chat bubbles */
.msg .body { white-space: pre-wrap; }
.msg.assistant .body { white-space: normal; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 .7em; }
.msg .body h2, .msg .body h3, .msg .body h4, .msg .body h5 { margin: 1em 0 .4em; line-height: 1.25; }
.msg .body h2 { font-size: 1.25em; } .msg .body h3 { font-size: 1.12em; } .msg .body h4, .msg .body h5 { font-size: 1em; }
.msg .body ul, .msg .body ol { margin: 0 0 .7em; padding-left: 1.4em; }
.msg .body li { margin: .15em 0; }
.msg .body blockquote { margin: 0 0 .7em; padding: .1em .9em; border-left: 3px solid var(--accent); color: var(--muted); }
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.msg .body a { color: var(--accent); }
.msg .body code { font: .88em ui-monospace, SFMono-Regular, Menlo, monospace; background: color-mix(in srgb, var(--text) 9%, transparent); padding: .1em .35em; border-radius: 5px; }
.code { margin: 0 0 .8em; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--line); }
.code-head .copy { border: 0; background: none; font-size: 12px; padding: 4px 8px; color: var(--muted); gap: 4px; }
.code-head .copy:hover { color: var(--text); }
.code pre { margin: 0; padding: 12px; overflow-x: auto; }
.code pre code { background: none; padding: 0; font-size: 13px; white-space: pre; }
.tbl { overflow-x: auto; margin: 0 0 .8em; }
.tbl table { border-collapse: collapse; font-size: .93em; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.tbl th { background: var(--panel); }
.msg .actions { display: flex; gap: 4px; margin-top: 8px; }
.msg .act { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 3px 8px; border-radius: 8px; gap: 4px; }
.msg .act:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }
.msg .act .i { width: 14px; height: 14px; }
.msg audio { display: block; }
.note { align-self: center; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 2px 10px; border: 1px dashed var(--line); border-radius: 999px; }
.note .i { width: 14px; height: 14px; }

/* settings */
dialog h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 14px; }
.actions-row { text-align: right; margin-top: 8px; }

#guideBtn { position: relative; }
#guideBtn.set::after { content: ""; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
#guidance .actions-row { display: flex; justify-content: space-between; }

.grp { display: flex; align-items: center; gap: 4px; padding: 7px 10px; margin-top: 6px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text); }
.grp:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.grp .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp .car { width: 12px; color: var(--muted); font-size: 11px; }
.grp .n { color: var(--muted); font-weight: 400; font-size: 12px; }
.grp .mini { border: 0; background: none; padding: 3px; opacity: 0; color: var(--muted); border-radius: 6px; }
.grp .mini:hover { color: var(--text); background: color-mix(in srgb, var(--text) 10%, transparent); }
.grp:hover .mini, .grp:focus-within .mini { opacity: 1; }
.grp .i { width: 1.1em; height: 1.1em; }
.conv.in { margin-left: 14px; }
.sub { color: var(--muted); font-size: 12px; padding: 10px 10px 2px; text-transform: uppercase; letter-spacing: .05em; }
.tag { flex: 0 100000 auto; min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; margin-left: 8px; white-space: nowrap; }
#groupDlg input { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font: inherit; color: inherit; }
#groupDlg .actions-row { display: flex; justify-content: space-between; }
#moveList { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
#moveList button { justify-content: flex-start; }
#moveList button.cur { border-color: var(--accent); }
.conv .mini[data-act="move"]:hover { color: var(--text); }

header h1 { flex: 0 1 auto; min-width: 3ch; }

#login input { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font: inherit; color: inherit; }
#login .actions-row { margin: 12px 0 8px; }
#loginError { color: var(--danger); }
.account { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
#voiceTry { margin: -6px 0 10px; }

dl.usage { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0 0 12px; font-size: 13px; }
dl.usage dt { color: var(--muted); }
dl.usage dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

#notFound { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 24px; }
#notFound[hidden] { display: none; }
#notFound h2 { margin: 0; }
#notFound p { margin: 0; color: var(--muted); }
body.lost #messages, body.lost footer { display: none; }

.banner { padding: 8px 16px; font-size: 13px; background: color-mix(in srgb, var(--accent, #14b8a6) 14%, transparent); border-bottom: 1px solid var(--line); }
.banner.blocked { background: color-mix(in srgb, #dc2626 16%, transparent); }
.banner[hidden] { display: none; }
.budget { margin: 0 0 8px; font-size: 13px; }
.budget .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.budget .bar i { display: block; height: 100%; background: var(--accent, #14b8a6); }
.budget.warn .bar i { background: #d97706; }
.budget.blocked .bar i { background: #dc2626; }

.conv .cost { flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.conv .cost:empty { display: none; }

/* ---- courses: a book's units as rows of numbered lesson circles, a unit, a lesson ---- */
body.courses main > header, body.courses #live, body.courses #messages, body.courses footer { display: none; }
#courses { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.course-header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.course-header h1 { flex: 0 1 auto; min-width: 3ch; }
#courseScroll { flex: 1; overflow-y: auto; }
.course-body { max-width: 720px; margin: 0 auto; padding: 20px 16px 32px; overflow-wrap: anywhere; }
.course-body :where(a:not(.dot)) { color: inherit; }
.course-body a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.course-desc { white-space: pre-wrap; margin: 0 0 14px; }
.course-crumb { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.course-crumb a { color: var(--muted); text-decoration: none; }
.course-crumb a:hover { color: var(--text); text-decoration: underline; }
.course-meta { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.course-none { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.course-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-bottom: 18px; }
.course-bar i { display: block; height: 100%; background: var(--accent); }
.course-cap { margin: 0 0 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.course-block { margin: 0 0 18px; }
.course-empty { text-align: center; color: var(--muted); padding: 40px 0; }
.course-empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }
.course-empty p { margin: 0 0 14px; }
#courses button:disabled { opacity: .5; cursor: not-allowed; }
#courseTitle:focus { outline: none; }
#courseTitle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.course-body.loading { opacity: .55; transition: opacity .15s .2s; }
#courses button:disabled:active { transform: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* import a book */
.course-import-box { margin-top: 22px; text-align: center; }
.course-import-box .course-none { margin: 6px 0 10px; }
.course-import-box .form-error { text-align: left; }

/* the list of books */
.course-cards { display: grid; gap: 10px; }
.course-card { display: block; background: var(--bot); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; }
a.course-card:hover { border-color: var(--muted); }
.course-card h2 { margin: 0 0 2px; font-size: 16px; }
.course-card-desc { margin: 0 0 4px; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course-card .course-meta { margin: 0 0 8px; }
.course-card .course-bar { margin: 0; }
.course-card.add { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; border-style: dashed; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.course-card.add:hover { border-color: var(--accent); color: var(--text); }
.course-card.plain { margin-bottom: 18px; }
.course-card.plain .course-desc { margin: 0; }

/* a book: one compact row per unit */
.unit-row { padding: 12px 0; border-top: 1px solid var(--line); }
.unit-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.unit-title { flex: 1; min-width: 0; font-weight: 600; text-decoration: none; }
.unit-title:hover { color: var(--accent); text-decoration: underline; }
.unit-count { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.unit-count.ok { color: var(--accent); font-weight: 600; }
.unit-count .i { width: 14px; height: 14px; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { flex: none; width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; border: 2px solid var(--line); background: var(--bot); color: var(--muted); text-decoration: none; font-variant-numeric: tabular-nums; }
a.dot:hover { border-color: var(--accent); color: var(--accent); }
.dot.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
a.dot.done:hover { color: var(--accent-ink); filter: brightness(1.08); }
.dot.next { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.dot .i { width: 16px; height: 16px; }

/* a unit: its lessons */
.lesson-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lesson-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; text-decoration: none; }
.lesson-row:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.lesson-row .t { flex: 1; min-width: 0; }
.lesson-row .tag { margin-left: 0; color: var(--accent); border-color: var(--accent); }

/* a lesson */
.course-links { display: flex; flex-wrap: wrap; gap: 8px; }
.course-linkbtn { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 12px; font-size: 14px; text-decoration: none; }
a.course-linkbtn { color: var(--accent); }
a.course-linkbtn:hover { border-color: var(--accent); }
.course-linkbtn.off { color: var(--muted); border-style: dashed; }
.course-done { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--accent); }
.tutor-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tutor-row .course-none { margin: 0; }
.ex-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ex-row { display: flex; align-items: center; gap: 10px; width: 100%; box-sizing: border-box; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bot); color: inherit; font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.ex-row:hover { border-color: var(--muted); }
.ex-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ex-num { flex: none; min-width: 3ch; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
.ex-row .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ex-kind { font-size: 12px; color: var(--muted); }
.ex-status { flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.ex-status.started { color: var(--accent); font-weight: 600; }
.course-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
#coursesLink[aria-current="page"] { color: var(--text); font-weight: 600; }
body.courses .conv.active:not(:hover) { background: none; color: var(--muted); }

/* the edit dialog for a book, unit or lesson */
#courseDlg { max-height: 92vh; overflow-y: auto; width: min(520px, 94vw); }
#courseDlg input:not([type=checkbox]) { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font: inherit; color: inherit; }
#courseDlg textarea { resize: vertical; }
#courseDlg fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
#courseDlg legend { padding: 0; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
#cfLinks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.cf-link { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.cf-link input { margin-top: 0 !important; }
.cf-link .cf-title, .cf-link .cf-url { grid-column: 1; }
.cf-link .cf-remove { grid-column: 2; grid-row: 1 / span 2; width: 36px; height: 36px; }
@media (min-width: 520px) {
  .cf-link { grid-template-columns: 1fr 1.5fr auto; border: 0; padding: 0; }
  .cf-link .cf-remove { grid-column: 3; grid-row: 1; }
  .cf-link .cf-title { grid-column: 1; } .cf-link .cf-url { grid-column: 2; }
}
#courseDlg button.small { padding: 5px 10px; font-size: 13px; }
.form-error { margin: 0 0 12px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--danger); color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }
#courseDlg .actions-row { display: flex; align-items: center; gap: 8px; }
#courseDlg [hidden] { display: none !important; }
.course-add { margin-top: 14px; }
.course-error { margin: 12px 0 0; }
/* the chat header's way back to its lesson, shown on lesson chats only */
.lesson-back { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; color: var(--muted); font-size: 13px; text-decoration: none; padding: 6px 4px; border-radius: 8px; white-space: nowrap; }
.lesson-back:hover { color: var(--text); }
.lesson-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lesson-back .i { width: 16px; height: 16px; }

/* ---- an exercise: the frame, the recording, the questions by kind, and the marks after checking ---- */
.ex-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.ex-head .ex-num { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ex-stats { margin-left: auto; font-variant-numeric: tabular-nums; }
.ex-instr { font-weight: 600; }
.ex-audio-box { margin: 0 0 14px; }
.ex-audio { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bot); }
.ex-audio .ex-play { min-width: 96px; min-height: 44px; }
.ex-pos { flex: 1; min-width: 0; accent-color: var(--accent); min-height: 44px; }
.ex-time { flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-slow { min-height: 44px; font-variant-numeric: tabular-nums; }
.ex-audio-note { margin: 0; }
@media (max-width: 480px) { .ex-audio { flex-wrap: wrap; } .ex-pos { flex-basis: 100%; order: 3; } .ex-time { margin-left: auto; } }
.ex-reveal { min-height: 44px; margin: 0 0 10px; }
.ex-passage { white-space: pre-wrap; margin: 0 0 16px; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 10px 10px 0; }
.ex-words { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--radius); }
.ex-word { padding: 3px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.ex-media-error { display: inline-block; margin: 4px 0; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--danger); color: var(--danger); font-size: 13px; }
.ex-qset { border: 0; margin: 0 0 8px; padding: 0; min-width: 0; }
.ex-qs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ex-q { display: flex; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bot); }
.ex-q.right { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.ex-q.wrong { border-color: color-mix(in srgb, var(--danger) 60%, var(--line)); }
.ex-qn { flex: none; min-width: 2ch; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 2; }
.ex-qbody { flex: 1; min-width: 0; }
.ex-qtext { margin: 0 0 8px; line-height: 2; }
.ex-tf { display: flex; flex-wrap: wrap; gap: 8px; }
.ex-tf button { min-height: 44px; min-width: 96px; }
.ex-choice { border: 0; margin: 0; padding: 0; min-width: 0; }
.ex-choice legend { padding: 0; }
.ex-opts { display: grid; gap: 6px; }
.ex-opt { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.ex-opt:hover { border-color: var(--muted); }
.ex-opt:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ex-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.ex-opt input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.ex-letter { flex: none; font-weight: 700; color: var(--muted); }
.ex-opt-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ex-pic { display: block; }
.ex-pic img { display: block; max-width: 100%; max-height: 220px; border-radius: 8px; }
.ex-match { display: grid; gap: 6px; }
.ex-left { display: flex; flex-direction: column; gap: 4px; }
.ex-left .ex-qtext { margin: 0; }
.ex-select, .ex-gap { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 40px; max-width: 100%; }
.ex-select { width: 100%; }
.ex-select option:disabled, .ex-gap option:disabled { color: var(--muted); }
.ex-gaptext .ex-gap { margin: 2px 2px; vertical-align: middle; }
.ex-opts .ex-opt.right, .ex-tf button.right { border-color: var(--accent); }
.ex-opts .ex-opt.wrong, .ex-tf button.wrong { border-color: var(--danger); }
.ex-tf button.toggle.wrong[aria-pressed="true"] { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.ex-opts .ex-opt.wrong { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.ex-select.right, .ex-gap.right { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ex-select.wrong, .ex-gap.wrong { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); text-decoration: line-through; text-decoration-color: var(--danger); }
.ex-qset:disabled .ex-opt, .ex-qset:disabled .ex-opt input { cursor: default; }
#courses .ex-qset:disabled .ex-tf button { opacity: 1; cursor: default; }
#courses .ex-qset:disabled .ex-tf button[aria-pressed="false"]:not(.right) { opacity: .6; }
.ex-fb { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; }
.ex-fb p { margin: 0 0 4px; }
.ex-verdict { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.ex-q.right .ex-verdict { color: var(--accent); }
.ex-q.wrong .ex-verdict { color: var(--danger); }
.ex-answer span, .ex-spell span { font-weight: 600; }
.ex-expl { color: var(--muted); white-space: pre-wrap; }
.ex-actions { margin-top: 14px; }
.ex-actions button { min-height: 44px; }
.ex-result { margin: 10px 0 0; font-weight: 600; }
.ex-result:focus { outline: none; }
.ex-result:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.ex-error { margin: 12px 0 0; }

/* Reference blocks and the Markdown-lite text inside them */
.course-ref { min-width: 0; max-width: 100%; }
.course-ref > summary { display: flex; align-items: center; gap: 6px; margin: 0; padding: 6px 0; cursor: pointer; list-style: none; border-radius: 6px; }
.course-ref > summary::-webkit-details-marker { display: none; }
.course-ref > summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin: 0 4px 0 2px; }
.course-ref[open] > summary::before { transform: rotate(45deg); }
.course-ref > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.md { min-width: 0; max-width: 100%; overflow-wrap: anywhere; line-height: 1.55; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md .md-table { margin: 0 0 12px; }
.md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; line-height: 1.3; }
.md .md-h1 { font-size: 20px; }
.md .md-h2 { font-size: 17px; }
.md .md-h3 { font-size: 15px; }
.md .md-h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { font: .92em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }
.md blockquote { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; color: var(--muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md .md-table { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; }
.md .md-table:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.md table { border-collapse: collapse; min-width: 100%; font-size: 14px; }
.md th, .md td { text-align: left; vertical-align: top; padding: 6px 10px; border-bottom: 1px solid var(--line); overflow-wrap: normal; }
.md th { background: var(--panel); font-weight: 700; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
/* free exercises: the writing area, its photos, the reviews and the role play */
.ex-write, .ex-talk { margin-top: 18px; }
.ex-write-text { display: block; width: 100%; box-sizing: border-box; margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bot); resize: vertical; min-height: 140px; line-height: 1.5; }
.ex-write-text[readonly] { opacity: .7; }
.ex-count { margin: 4px 0 8px; font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.ex-count.over { color: var(--danger); font-weight: 600; }
.ex-photo-row { margin-top: 0; }
.ex-photo-row button, .ex-write .ex-actions button, .ex-talk button, .ex-sub button { min-height: 44px; }
.ex-photos { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; padding: 0; }
.ex-photo { position: relative; width: 96px; height: 96px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.ex-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
#courses .ex-photo-rm { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border-radius: 50%; background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--text); }
.ex-photo-note { margin: 10px 0 0; }
.ex-read { margin-top: 16px; }
.ex-read .course-cap { display: block; margin-bottom: 2px; }
.ex-wstatus { margin: 8px 0 0; font-size: 14px; color: var(--muted); min-height: 1.4em; }
.ex-history { margin-top: 20px; }
.ex-sub { margin: 0 0 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bot); min-width: 0; }
.ex-sub[open] { padding-bottom: 12px; }
.ex-sub > summary { display: flex; align-items: center; gap: 6px; padding: 10px 0; cursor: pointer; list-style: none; font-weight: 600; border-radius: 6px; }
.ex-sub > summary::-webkit-details-marker { display: none; }
.ex-sub > summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin: 0 4px 0 2px; flex: none; }
.ex-sub[open] > summary::before { transform: rotate(45deg); }
.ex-sub > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ex-sub .course-cap { margin: 8px 0 4px; }
.ex-sub-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 10px; background: var(--panel); border-radius: 8px; }
.ex-sub-review { min-width: 0; }
