/* Design: calm dark surface, one warm accent, no decorative colour per level. */
:root {
  --bg: #0b0c10; --surface: #14171e; --surface-2: #1b1f27; --line: #262b35; --line-strong: #343a46;
  --text: #f2f3f5; --muted: #9aa1ac; --faint: #6b7280;
  --accent: #f5a524; --accent-ink: #1a1203; --accent-soft: rgb(245 165 36 / .12);
  --danger: #ff7a6b; --ok: #5fd39a;
  --radius: 18px; --radius-sm: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f4f2; --surface: #ffffff; --surface-2: #f7f7f5; --line: #e4e4e0; --line-strong: #d2d2cc;
  --text: #16181d; --muted: #5d636e; --faint: #8b919b;
  --accent: #c7740a; --accent-ink: #ffffff; --accent-soft: rgb(199 116 10 / .10);
  --danger: #c43d2f; --ok: #1f8a4c;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f4f2; --surface: #ffffff; --surface-2: #f7f7f5; --line: #e4e4e0; --line-strong: #d2d2cc;
    --text: #16181d; --muted: #5d636e; --faint: #8b919b;
    --accent: #c7740a; --accent-ink: #ffffff; --accent-soft: rgb(199 116 10 / .10);
    --danger: #c43d2f; --ok: #1f8a4c;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 750; letter-spacing: -.01em; margin: 0; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.flush { margin-top: 0; }
[hidden] { display: none !important; }

/* header like an app bar */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 0 16px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.appbar .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.appbar .actions { display: flex; gap: 8px; align-items: center; }
.eyebrow { color: var(--accent); font-size: .76rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; margin: 0 0 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card, .section + .section { margin-top: 14px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* forms */
label { display: block; font-weight: 650; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; min-height: 48px;
}
input[type=file] { font: inherit; color: var(--muted); max-width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.code-input { font-size: 1.5rem; letter-spacing: .14em; text-align: center; text-transform: uppercase; font-weight: 750; }

/* buttons */
button, .btn {
  font: inherit; font-weight: 700; border-radius: var(--radius-sm); min-height: 46px; padding: 0 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
}
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line-strong); }
button.ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 0 10px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
button.small, .btn.small { min-height: 38px; padding: 0 14px; font-size: .92rem; }
button.block { width: 100%; }
button:disabled { opacity: .45; cursor: default; }
.icon-btn { width: 40px; min-height: 40px; padding: 0; background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; }
.icon-btn svg { width: 18px; height: 18px; }

.error { color: var(--danger); font-weight: 600; min-height: 1.4em; margin: 0; }
.notice { background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }

/* segmented level filter */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin-bottom: 14px; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; font-size: .92rem;
  background: transparent; color: var(--muted); border: 1px solid var(--line); }
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.pill { display: inline-flex; align-items: center; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.pill.accent { color: var(--accent); border-color: transparent; background: var(--accent-soft); }

/* list rows inside a card (Backyard style) */
.rows { display: flex; flex-direction: column; }
.rowlink { display: flex; align-items: center; gap: 12px; padding: 14px 0; color: var(--text); text-decoration: none;
  border-top: 1px solid var(--line); }
.rows > .rowlink:first-child { border-top: 0; padding-top: 4px; }
.rows > .rowlink:last-child { padding-bottom: 2px; }
.rowlink .main { flex: 1; min-width: 0; }
.rowlink .t { font-weight: 700; display: block; }
.rowlink .m { color: var(--muted); font-size: .9rem; display: block; margin-top: 2px; }
.chev { color: var(--faint); flex: none; width: 18px; height: 18px; }
.empty { color: var(--muted); padding: 8px 0; }

/* player */
body.player { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.playerbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.playerbar .title { font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
iframe.app { flex: 1; width: 100%; border: 0; background: #fff; }
.pad { padding: 16px; }

/* teacher area */
.tabs { display: flex; gap: 4px; margin: 0 0 18px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: 999px; min-height: 38px; padding: 0 14px; font-size: .95rem; flex: none; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; }
.item .main { flex: 1 1 220px; min-width: 0; }
.item .t { font-weight: 700; }
.item .meta { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.item .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item.off { opacity: .5; }
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mover { display: flex; flex-direction: column; }
.mover button { min-height: 26px; width: 30px; padding: 0; background: transparent; color: var(--muted); border: 0; }
.mover button:disabled { opacity: .25; }
.code { font: 750 1.3rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--text); font-weight: 600;
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 0 14px; min-height: 42px; cursor: pointer; }
.checks label:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); }
.toggle input, .checks input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(540px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); overflow: auto; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog form { padding: 20px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border-radius: 0; background: transparent; color: var(--muted); min-height: 42px; border: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 560px) {
  .item .actions { flex: 1 1 100%; }
  .item .actions > button { flex: 1; }
}
#all-accounts { margin-top: 26px; }
.spread .chips { flex: 1; min-width: 0; margin-bottom: 0; }
.spread { margin-bottom: 14px; }
button, .btn { white-space: nowrap; }
.mover svg { width: 18px; height: 18px; }

/* topic page */
.titlewrap { min-width: 0; }
.backlink { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
.backlink::before { content: "‹"; font-size: 1.2rem; line-height: 1; }
.rowlink .kind { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); }
.rowlink .kind svg { width: 20px; height: 20px; }
button.kind { padding: 0; min-height: 40px; border: 0; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* player bar */
.playerbar .icon-btn { flex: none; display: inline-grid; place-items: center; }
.playerbar .tools { display: flex; gap: 6px; }
body.player.scroll { overflow: auto; height: auto; min-height: 100dvh; }
.video-wrap { max-width: 960px; width: 100%; margin: 0 auto; padding: 16px; }
.video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-wrap p { margin-top: 10px; }

/* chat */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 760px; margin: 0 auto; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--accent-soft); color: var(--text); border-bottom-right-radius: 6px; }
.msg strong { color: var(--accent); font-weight: 750; }
.msg.note { align-self: center; background: transparent; color: var(--danger); font-size: .92rem; text-align: center; }
.msg.typing { display: flex; gap: 5px; padding: 15px 16px; }
.msg.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite ease-in-out; }
.msg.typing span:nth-child(2) { animation-delay: .15s; }
.msg.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .msg.typing span { animation: none; opacity: .6; } }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 160px; border-radius: 22px; padding: 11px 16px; line-height: 1.35; }
.composer .icon-btn { width: 44px; min-height: 44px; flex: none; }
.composer .icon-btn.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.composer .send { width: 44px; min-height: 44px; padding: 0; border-radius: 999px; flex: none; }
.composer .send svg { width: 20px; height: 20px; }

.section-gap { margin-top: 18px; }

/* text pages */
.prose ul { margin: 0; padding-left: 1.2em; }
.prose li + li { margin-top: 8px; }
.prose h2 { font-size: 1.05rem; margin-top: 18px; }
.prose .card + .card { margin-top: 14px; }
.footer { margin-top: 28px; text-align: center; font-size: .85rem; }
.footer a { color: var(--muted); }

/* printable access card */
.access-card { max-width: 420px; margin: 8px auto 0; text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; }
.access-card h2 { font-size: 1.5rem; margin-bottom: 18px; }
.access-card img { display: block; margin: 0 auto 18px; width: 220px; height: 220px; background: #fff; padding: 10px; border-radius: 12px; }
.access-card .steps { text-align: left; display: inline-block; margin: 0 0 14px; padding-left: 1.2em; }
.access-card .url { font-weight: 700; margin-bottom: 4px; }
.code.big { font-size: 2rem; color: var(--accent); }
@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --line: #bbb; --accent: #000; color-scheme: light; }
  .no-print { display: none !important; }
  .access-card { border: 2px solid #000; }
  body { background: #fff; }
}
.spread label.flush { margin: 0; }

/* teacher: topic contents */
.subitems { display: flex; flex-direction: column; gap: 8px; }
.subitem { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.subitem .main { flex: 1 1 140px; min-width: 0; }
.subitem .acts { display: flex; gap: 6px; margin-left: auto; }
.subitem .mover { flex-direction: row; }
.subitem .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subitem .meta { color: var(--muted); font-size: .84rem; }
.subitem .kind { color: var(--accent); flex: none; display: grid; }
.subitem .kind svg { width: 18px; height: 18px; }
textarea.prompt { min-height: 220px; font-size: .92rem; line-height: 1.45; resize: vertical; }
.usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.usage .num { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; }
.usage .lbl { color: var(--muted); font-size: .85rem; }

/* speaking trainer (talk) */
.talk { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 760px; margin: 0 auto; }
.talk-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.talk-clock { font-size: .92rem; white-space: nowrap; min-width: 0; }
.talk-time { font-weight: 750; font-variant-numeric: tabular-nums; }
.talk-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; align-items: center; min-width: 0; margin-left: auto; }
.talk-bar button.small { padding: 0 10px; font-size: .88rem; }
/* Narrow phones: the clock drops its "Restzeit" label (kept for screen readers), then the buttons tighten up.
   flex-wrap above is only the last resort (large text settings). */
@media (max-width: 420px) {
  .talk-bar { padding: 8px 12px; gap: 4px 8px; }
  .talk-clock > .muted { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .talk-bar button.small { padding: 0 8px; }
}
@media (max-width: 360px) {
  .talk-bar { padding: 8px 10px; gap: 4px 6px; }
  .talk-actions { gap: 2px; }
  .talk-bar button.small { padding: 0 6px; font-size: .8rem; }
}
.talk button svg { width: 20px; height: 20px; flex: none; }
.talk .talk-btn svg { width: 30px; height: 30px; }
.talk-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }

.task { padding: 16px 18px; flex: none; }
.task summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; min-height: 28px; }
.task summary::-webkit-details-marker { display: none; }
.task summary .eyebrow { flex: 1; }
.task summary .chev { transition: transform .2s ease; }
.task[open] summary .chev { transform: rotate(180deg); }
.task[open] summary { margin-bottom: 10px; }
.task summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.task-goal { font-weight: 700; }
.task-points { margin: 0; padding-left: 1.2em; }
.task-points li + li { margin-top: 6px; }
.task-points li::marker { color: var(--accent); }

.talk-log { display: flex; flex-direction: column; gap: 10px; }
.talk-log:empty { display: none; }
.talk-bot { display: flex; align-items: flex-start; gap: 8px; }
.talk-bot .talk-text { flex: 1; min-width: 0; }
.talk-bot .replay { flex: none; width: 32px; min-height: 32px; padding: 0; margin: -5px -8px -5px 0; border-radius: 999px;
  background: transparent; color: var(--muted); border: 0; }
.talk-bot .replay svg { width: 16px; height: 16px; }
.talk-log.hide-bot .talk-text { filter: blur(6px); user-select: none; -webkit-user-select: none; }
.unsure { text-decoration: underline dotted var(--muted); text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.talk-legend { margin: -4px 0 0; }
.msg.hint { color: var(--muted); }
.msg.talk-restart { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.talk-dock { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface); }
.talk-btn { width: 76px; height: 76px; min-height: 76px; padding: 0; border-radius: 999px; position: relative;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: transform .12s ease; }
.talk-btn svg { width: 30px; height: 30px; }
.talk-btn:active:not(:disabled) { transform: scale(.96); }
.talk-btn.rec { box-shadow: 0 0 0 6px var(--accent-soft); }
.talk-status { margin: 0; color: var(--muted); font-size: .92rem; font-weight: 600; text-align: center; min-height: 1.4em;
  font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: no-preference) {
  .talk-btn.rec::after { content: ""; position: absolute; inset: -6px; border-radius: inherit; border: 2px solid var(--accent);
    animation: talkpulse 1.4s ease-out infinite; pointer-events: none; }
  .thinking { animation: talkthink 1.8s infinite ease-in-out; }
}
@media (prefers-reduced-motion: reduce) {
  .task summary .chev, .talk-btn { transition: none; }
}
@keyframes talkthink { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes talkpulse { from { transform: scale(1); opacity: .7; } to { transform: scale(1.35); opacity: 0; } }

.fb { flex: none; }
.fb h3 { font-size: .98rem; font-weight: 750; margin: 18px 0 8px; }
.fb-lead { font-size: 1.02rem; }
.fb-good { margin: 0; padding-left: 1.2em; }
.fb-good li + li { margin-top: 6px; }
.fb-good li::marker { color: var(--ok); }
.fb-fixes { display: flex; flex-direction: column; }
.fb-fix { padding: 12px 0; border-top: 1px solid var(--line); }
.fb-fix:first-child { border-top: 0; padding-top: 2px; }
.fb-fix p { margin: 0; }
.fb-fix .lbl { display: block; font-size: .74rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); margin-bottom: 2px; }
.fb-fix .said { color: var(--muted); }
.fb-fix .better { font-weight: 700; margin-top: 8px; }
.fb-fix .better .lbl { color: var(--accent); }
.fb-fix .why { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.fb-tip { margin: 18px 0 0; }
.fb-again { margin-top: 18px; }
/* item kind picker: five options wrap as pills instead of one segmented bar */
#it-kind { display: flex; flex-wrap: wrap; gap: 6px; border: 0; border-radius: 0; overflow: visible; }
#it-kind button { border: 1px solid var(--line-strong); border-radius: 999px; min-height: 40px; padding: 0 14px; }
#it-kind button[aria-pressed="true"] { border-color: transparent; }
.talk-intro, .talk-legend, .talk-log { flex: none; }
