:root {
  color-scheme: light;
  --ink: #222;
  --muted: #666;
  --line: #ddd;
  --green: #333;
  --sidebar-width: 168px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: #fff; color: var(--ink); font: 14px/1.5 system-ui, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
button, input, textarea, select { border: 1px solid #bbb; border-radius: 3px; }
button { background: #f5f5f5; padding: 7px 12px; }
button:hover:not(:disabled) { background: #e9e9e9; }
:focus-visible { outline: 2px solid #555; outline-offset: 3px; }
a { color: inherit; }
h1 { font-size: 21px; font-weight: 600; margin: 0 0 20px; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 8px 0; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); padding: 20px 12px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; border-right: 1px solid var(--line); background: #fafafa; overflow-y: auto; }
.brand { margin: 0 4px 24px; font-size: 14px; font-weight: 600; text-decoration: none; }
.nav { text-align: left; border: 0; background: transparent; padding: 6px 10px; color: #666; }
.nav.active { color: #222; background: #eee; }
main { margin-left: var(--sidebar-width); min-width: 0; padding: 24px 24px 48px; }
main > section { max-width: 1120px; margin-inline: auto; }
#settings { margin-top: auto; }
.primary { background: #333; color: #fff; border-color: #333; }
.primary:hover:not(:disabled) { background: #111; }
.secondary { background: #f5f5f5; }
.text-button { padding: 0; background: transparent; border: 0; text-decoration: underline; color: #555; font-size: 13px; }
.text-button:hover:not(:disabled) { background: transparent; color: #111; }
.icon-button { border: 0; background: transparent; font-size: 22px; padding: 0 5px; }
input, textarea, select { background: #fff; padding: 8px 10px; min-width: 0; }
input::placeholder, textarea::placeholder { color: #888; }
label { display: block; margin: 16px 0 6px; font-weight: 500; }
textarea { width: 100%; resize: vertical; line-height: 1.6; }
.muted, .quality-note { color: var(--muted); font-size: 12px; }
#notice { padding: 12px; border: 1px solid #c99; background: #fff7f7; margin-bottom: 20px; }
#inspect-form { display: flex; gap: 8px; margin-bottom: 24px; }
#youtube-url { flex: 1; }
#inspection { border-bottom: 1px solid var(--line); padding: 0 0 20px; margin-bottom: 24px; }
.inspection-layout { display: flex; gap: 16px; align-items: center; }
.inspection-layout img { width: 140px; }
.inspection-layout p { color: var(--muted); font-size: 12px; }
.inspection-layout select { margin-right: 8px; max-width: 100%; }
.section-heading h1 { display: flex; align-items: baseline; gap: 8px; }
.count { font-weight: 400; font-size: 14px; color: var(--muted); }
.video-grid { display: grid; gap: 0; }
.video-card { display: flex; padding: 18px 0; border-bottom: 1px solid var(--line); gap: 20px; }
.thumbnail { position: relative; width: 240px; flex-shrink: 0; aspect-ratio: 16/9; background: #eee; align-self: flex-start; }
.thumbnail img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbnail .badge { position: absolute; top: 7px; left: 7px; }
.duration { position: absolute; right: 6px; bottom: 6px; font-size: 12px; color: #fff; background: #333; padding: 1px 4px; }
.card-body { flex: 1; min-width: 0; }
.card-body h3 { margin: 0 0 4px; font-size: 15px; font-weight: 500; }
.card-body p { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.card-body button { margin-top: 4px; }
.card-progress { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.progress-track { height: 3px; background: #eee; margin: 8px 0 12px; }
.progress-track i { display: block; height: 100%; background: #777; }
.badge { display: inline-block; padding: 2px 5px; font-size: 11px; font-weight: 400; color: #555; background: #f5f5f5; border: 1px solid var(--line); }
.empty { padding: 24px 0; color: var(--muted); font-size: 13px; }
.empty b { font-weight: 500; }
.empty p { font-size: 12px; }
.lesson-heading { display: flex; gap: 16px; align-items: baseline; margin: 12px 0 16px; }
.lesson-heading h1 { flex: 1; font-size: 16px; margin: 0; font-weight: 500; }
.lesson-heading .badge { flex-shrink: 0; }
.lesson-grid { display: flex; flex-direction: column; }
.player-shell { aspect-ratio: 16/9; min-height: 200px; background: #111; overflow: hidden; }
.player-shell iframe, .player-shell > div { display: block; width: 100%; height: 100%; border: 0; }
.phrase-transport { display: flex; align-items: center; gap: 14px; padding: 12px 0; }
.play-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#play-sentence { min-width: 155px; }
#phrase-time { color: #555; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#phrase-seek { flex: 1; min-width: 60px; width: 100%; height: 24px; padding: 0; border: 0; background: transparent; accent-color: #444; cursor: pointer; }
#phrase-seek:disabled { opacity: .5; cursor: default; }
#player-message { margin: 0; }
#player-message:empty { display: none; }
.exercise-panel { padding-top: 20px; }
.stage-header { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: #555; }
.stage-header b { font-weight: 500; }
.exercise-top { display: flex; gap: 16px; justify-content: space-between; align-items: center; margin: 10px 0 18px; }
.stage-steps { display: flex; flex-wrap: wrap; gap: 5px; }
.stage-step { width: 30px; height: 28px; padding: 0; font-size: 12px; }
.stage-step.current { background: #333; color: #fff; border-color: #333; }
.skeleton { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 5px; margin: 0 0 20px; min-height: 32px; }
.masked-token { height: 29px; min-width: 11px; padding: 3px 6px; border: 0; background: #ddd; color: transparent; font: 14px monospace; overflow: hidden; user-select: none; }
.masked-token.revealed { background: #f2f2f2; color: #222; user-select: text; }
.masked-token.learning-word { background: #eed399; box-shadow: inset 0 -2px 0 #ae7824; }
.masked-token.learning-word.revealed { color: #704b11; background: #fff0cb; }
.masked-token.learning-word:hover:not(:disabled) { background: #e7c785; }
.word-gap { width: 4px; }
.answer-footer { display: flex; justify-content: flex-end; gap: 16px; align-items: center; margin-top: 8px; }
.answer-footer > span { color: #777; font-size: 12px; }
#feedback { border: 1px solid #bbb; padding: 14px; margin-top: 18px; line-height: 1.7; background: #fafafa; }
#feedback.incorrect { border-color: #bba37f; }
#feedback h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
#next-stage { display: block; margin: 16px 0 0 auto; }
#history { margin-top: 20px; font-size: 12px; }
summary { cursor: pointer; color: #555; }
.attempt { border-top: 1px solid var(--line); padding: 12px 0; margin-top: 12px; font-size: 13px; }
.attempt time { font-size: 11px; color: var(--muted); }
.legacy-history { margin-top: 12px; }
.lesson-navigation { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 24px; }
.lesson-progress > div:first-child { display: flex; justify-content: space-between; font-size: 12px; color: #666; }
.lesson-progress b { font-weight: 500; }
.sentence-nav { display: flex; align-items: center; gap: 8px; }
.sentence-nav select { flex: 1; }
.stats { display: flex; gap: 32px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 20px; margin-bottom: 8px; }
.stat strong { display: block; font-size: 25px; font-weight: 500; }
.stat span { color: #666; font-size: 12px; }
.progress-row { display: flex; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); padding: 16px 0; }
.progress-row > div { flex: 1; }
.progress-row h3 { font-size: 14px; font-weight: 500; margin: 0; }
.progress-row p { color: #666; font-size: 12px; }
#word-search { width: 100%; max-width: 360px; }
#word-list { margin-top: 20px; }
.word-entry { border-bottom: 1px solid var(--line); padding: 18px 0; }
.word-entry-top { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.word-entry-top h2 { font-size: 18px; font-weight: 500; }
.word-entry-top .text-button { margin-left: auto; font-size: 12px; }
.learning-badge { background: #fff0cb; border-color: #dbc08d; color: #704b11; }
.word-entry summary { font-size: 12px; }
.word-source { font-size: 13px; }
.word-jump { margin-top: 12px; font-size: 12px; }
dialog { max-width: 500px; width: calc(100% - 32px); padding: 24px; border: 1px solid #aaa; border-radius: 4px; background: #fff; color: #222; }
dialog::backdrop { background: #0006; }
.dialog-close { position: absolute; right: 12px; top: 8px; }
#settings-form input { width: 100%; }
#settings-message { font-size: 13px; }
.connection { display: flex; gap: 8px; align-items: center; color: #666; font-size: 12px; margin: 16px 0; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #aaa; }
.status-dot.ready { background: #555; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 760px) {
  :root { --sidebar-width: 84px; }
  .sidebar { padding: 14px 6px; gap: 7px; }
  .brand { font-size: 11px; margin: 0 2px 14px; overflow-wrap: anywhere; }
  .nav { font-size: 11px; padding: 7px 4px; }
  main { padding: 16px 12px 32px; }
  .lesson-heading { flex-wrap: wrap; gap: 6px; }
  .lesson-heading h1 { flex-basis: 100%; font-size: 14px; }
  .phrase-transport { flex-wrap: wrap; gap: 8px; }
  .play-controls { width: 100%; }
  #play-sentence { min-width: 0; flex: 1; }
  #phrase-seek { width: auto; }
  .video-card { gap: 12px; }
  .thumbnail { width: 130px; }
  .card-body h3 { font-size: 13px; }
  .card-body p { margin-bottom: 6px; }
  .card-body button { padding: 5px 9px; font-size: 12px; }
  .thumbnail .badge { position: static; font-size: 10px; }
  .thumbnail { margin-bottom: 22px; }
  .sentence-nav { gap: 5px; }
  .sentence-nav button { padding: 8px; font-size: 12px; }
  #inspect-form { flex-wrap: wrap; }
  #youtube-url { flex-basis: 100%; }
  .inspection-layout { flex-direction: column; align-items: flex-start; }
  .inspection-layout select { display: block; margin: 10px 0; }
  .stats { gap: 16px 24px; }
  .stat { width: calc(50% - 12px); }
  .progress-row { flex-wrap: wrap; }
}

/* The lesson owns one viewport. Overflow belongs to its content panels. */
body.lesson-active { height: 100dvh; overflow: hidden; }
body.lesson-active main { height: 100dvh; padding: 12px 20px; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
body.lesson-active #notice { flex: 0 1 auto; max-height: 18dvh; overflow: auto; margin: 0; padding: 8px 12px; }
#lesson-view { width: 100%; min-height: 0; flex: 1; display: flex; flex-direction: column; }
.lesson-toolbar { display: flex; flex-shrink: 0; align-items: center; gap: 18px; margin-bottom: 8px; min-width: 0; }
.lesson-toolbar #back-library { flex-shrink: 0; }
.lesson-toolbar .lesson-heading { margin: 0; min-width: 0; flex: 1; }
.lesson-toolbar h1 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.lesson-active .lesson-grid { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; gap: 10px; }
body.lesson-active .video-area { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; }
body.lesson-active .player-shell { min-height: 0; aspect-ratio: auto; height: 100%; width: 100%; }
body.lesson-active .phrase-transport { padding: 8px 0 0; gap: 10px; }
body.lesson-active #player-message { max-height: 38px; overflow: auto; font-size: 11px; }
body.lesson-active .exercise-panel { min-height: 0; max-height: 40dvh; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 0 3px 2px; scrollbar-gutter: stable; }
body.lesson-active .exercise-top { margin: 6px 0 10px; }
body.lesson-active .skeleton { margin-bottom: 10px; }
body.lesson-active #answer { height: 56px; min-height: 42px; max-height: 100px; resize: none; padding: 6px 9px; }
body.lesson-active .answer-footer { margin-top: 5px; }
body.lesson-active #history { margin-top: 10px; }
body.lesson-active #history[open] #attempt-list { max-height: 150px; overflow-y: auto; overscroll-behavior: contain; }
body.lesson-active #feedback { margin-top: 10px; max-height: 140px; overflow-y: auto; overscroll-behavior: contain; padding: 10px; }
body.lesson-active #next-stage { margin-top: 8px; }
body.lesson-active .lesson-navigation { margin: 0; padding-top: 8px; }
body.lesson-active .lesson-progress .progress-track { margin: 4px 0 6px; }
body.lesson-active .sentence-nav button, body.lesson-active .sentence-nav select { padding-block: 5px; }
@media (max-width: 760px) {
  body.lesson-active main { padding: 8px; gap: 6px; }
  .lesson-toolbar { gap: 10px; }
  body.lesson-active .lesson-heading { flex-wrap: nowrap; }
  body.lesson-active .lesson-grid { gap: 8px; }
  body.lesson-active .phrase-transport { flex-wrap: wrap; gap: 4px 8px; }
  body.lesson-active .play-controls { width: 100%; gap: 5px; }
  body.lesson-active .play-controls button, body.lesson-active #speed { padding: 5px 6px; font-size: 11px; }
  body.lesson-active #phrase-seek { height: 18px; }
  body.lesson-active #phrase-time { font-size: 10px; }
  body.lesson-active .exercise-panel { max-height: 42dvh; }
  body.lesson-active .stage-header { font-size: 10px; }
  body.lesson-active .stage-header span { text-align: right; }
  body.lesson-active .answer-footer > span { display: none; }
  body.lesson-active .stage-step { width: 26px; height: 25px; }
  body.lesson-active .lesson-progress > div:first-child { font-size: 10px; }
  body.lesson-active .sentence-nav button { font-size: 10px; padding-inline: 5px; }
  body.lesson-active .sentence-nav select { font-size: 11px; padding-inline: 4px; }
}
@media (max-height: 600px) {
  body.lesson-active .exercise-panel { max-height: 43dvh; }
  body.lesson-active #history { margin-top: 6px; }
  body.lesson-active .stage-header { display: none; }
  body.lesson-active .exercise-top { margin: 0 0 6px; }
  body.lesson-active #answer { height: 42px; }
}
