:root {
  --ink: #1d1d19;
  --paper: #f3f0e8;
  --card: #fffdf8;
  --line: #ded9cc;
  --red: #d94a35;
  --blue: #326ca8;
  --muted: #77756d;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, "PingFang SC", "Noto Sans CJK SC", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.shell { min-height: 100vh; }
.topbar { height: 72px; padding: 0 4vw; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; background: rgba(243,240,232,.94); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px); }
.brand { color: var(--ink); text-decoration: none; font-family: Georgia, serif; font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.brand span { color: var(--red); font: 700 10px Inter, sans-serif; letter-spacing: 2px; margin-left: 5px; }
.top-actions { display: flex; gap: 10px; }
.layout { max-width: 1480px; margin: 0 auto; padding: 46px 4vw 80px; display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 30px; align-items: start; }
.song-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 24px; }
.eyebrow { color: var(--red); font-size: 11px; letter-spacing: 2.2px; font-weight: 800; margin: 0 0 9px; }
h1 { font-family: Georgia, "Yu Mincho", serif; font-size: clamp(30px, 4vw, 52px); margin: 0; letter-spacing: -2px; }
.artist { color: var(--muted); margin: 8px 0 0; }
.song-picker-label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; margin-bottom: 10px; }
.song-picker { min-width: 240px; background: var(--card); color: var(--ink); }
.progress-wrap { min-width: 130px; text-align: right; color: var(--muted); font-size: 13px; }
.progress { height: 3px; background: var(--line); margin-top: 9px; }
.progress span { display: block; height: 100%; background: var(--red); transition: width .25s; }
.player-card, .lesson-card, .ai-panel { background: var(--card); border: 1px solid var(--line); box-shadow: 0 12px 35px rgba(44,37,25,.05); }
.player-card { padding: 17px 20px; margin-bottom: 18px; }
.player-row { display: flex; align-items: center; gap: 12px; }
.round { border: 1px solid var(--line); background: white; border-radius: 50%; display: grid; place-items: center; }
.round.small { width: 35px; height: 35px; font-size: 25px; }
.round.small.skip { font-size: 10px; font-weight: 800; letter-spacing: -.04em; }
.round.play { width: 48px; height: 48px; color: white; background: var(--ink); border-color: var(--ink); padding-left: 3px; }
.timeline-wrap { flex: 1; min-width: 120px; }
input[type="range"] { accent-color: var(--red); width: 100%; }
.times { font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; }
.pill, select, .ghost-button, .icon-button { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 8px 11px; }
.pill.active { color: var(--red); border-color: #e8a89d; background: #fff5f2; }
.icon-button { width: 38px; height: 38px; padding: 0; font-size: 18px; }
.lesson-navigation { position: sticky; z-index: 5; top: 12px; margin: 12px 0 0; padding: 9px 12px; background: rgba(255, 253, 248, .94); border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; justify-content: space-between; gap: 16px; backdrop-filter: blur(8px); }
.lesson-navigation #lessonNavigationText { color: var(--muted); font-size: 12px; }
.lesson-card { padding: clamp(24px, 5vw, 58px); position: relative; overflow: hidden; }
.sync-notice { margin: -20px -20px 20px; padding: 11px 16px; background: #fff1d8; border: 1px solid #edd29b; color: #77561c; font-size: 12px; line-height: 1.55; }
.card-number { position: absolute; right: 22px; top: 14px; font: 700 70px Georgia, serif; color: #eeeae1; }
.japanese { font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(30px, 4.3vw, 54px); text-align: center; padding: 22px 0 6px; position: relative; line-height: 1.5; }
.line-token { display: inline; margin: 0; padding: .04em .06em; border: 0; border-radius: .14em; background: transparent; color: inherit; font: inherit; line-height: inherit; cursor: pointer; transition: color .15s ease, background .15s ease, box-shadow .15s ease; }
.line-token:hover { color: var(--red); background: #fff1ed; }
.line-token:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(201, 67, 48, .2); }
.line-token.locked { color: var(--red); background: #ffe4dc; box-shadow: inset 0 -2px 0 rgba(201, 67, 48, .35); }
.line-token.speaking { color: var(--red); background: #fff1ed; animation: speaking-pulse .75s ease-in-out infinite alternate; }
rt { color: var(--red); font-size: .34em; font-family: sans-serif; letter-spacing: .08em; }
.reading { text-align: center; color: var(--muted); letter-spacing: .14em; margin: 0 0 37px; }
.translation-grid { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.translation-grid > div { padding: 21px 25px; }
.translation-grid > div + div { border-left: 1px solid var(--line); }
.translation-grid span { color: var(--red); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.translation-grid p { margin: 8px 0 0; font-family: Georgia, serif; font-size: 18px; }
.section-block { margin-top: 34px; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.section-title > span { background: var(--ink); color: white; width: 27px; height: 27px; display: grid; place-items: center; font-family: serif; }
.section-title h2 { font: 700 18px Georgia, serif; margin: 0; }
.section-title small { color: var(--muted); margin-left: auto; }
.grammar-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grammar-item { border: 1px solid var(--line); padding: 16px; min-height: 120px; }
.grammar-item strong { color: var(--red); font-family: "Yu Mincho", serif; font-size: 19px; }
.grammar-item p { color: #57564f; font-size: 14px; line-height: 1.75; margin: 9px 0 0; }
.word-list { border-top: 1px solid var(--line); }
.word { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; display: grid; grid-template-columns: 1fr 1fr 1fr 1.5fr 46px; gap: 12px; padding: 14px 5px; text-align: left; align-items: center; }
.word:hover { background: #faf5eb; }
.word.speaking { background: #fff1ed; }
.word strong { font-family: "Yu Mincho", serif; font-size: 18px; }
.word span { color: var(--muted); font-size: 13px; }
.word .arrow { color: var(--red); }
.word-actions { display: flex; justify-content: flex-end; align-items: center; gap: 9px; }
.word-actions .speaker { color: var(--red); font-size: 18px; transform: rotate(180deg); }
.word.speaking .speaker { animation: speaking-pulse .75s ease-in-out infinite alternate; }
@keyframes speaking-pulse { from { opacity: .45; } to { opacity: 1; } }
.special-reading-notice { margin: 16px 0 -8px; color: #93612e; background: #fff7e5; border-left: 3px solid #d69637; padding: 9px 12px; font-size: 12px; line-height: 1.55; }
.special-ruby rt { color: #aa6a19; }
.note { background: #f7f1e5; border-left: 3px solid var(--red); margin-top: 28px; padding: 16px 18px; font-size: 14px; line-height: 1.7; }
.lesson-footer { margin-top: 34px; display: flex; align-items: center; justify-content: center; gap: 16px; }
.text-button { border: 0; background: transparent; color: var(--muted); }
.text-button:disabled, .primary-button:disabled { cursor: not-allowed; opacity: .35; }
.primary-button { border: 0; border-radius: 5px; background: var(--red); color: white; padding: 11px 18px; font-weight: 700; }
.mastery { display: flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.mastery button { border: 0; background: white; padding: 9px 12px; color: var(--muted); font-size: 12px; }
.mastery button + button { border-left: 1px solid var(--line); }
.mastery button.active { background: var(--ink); color: white; }
.ai-panel { position: sticky; top: 96px; min-height: 650px; max-height: calc(100vh - 120px); display: flex; flex-direction: column; }
.ai-title { padding: 22px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--line); }
.ai-orb { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: white; background: var(--blue); font-weight: 800; font-size: 12px; }
.ai-title h2 { font: 700 18px Georgia, serif; margin: 0; }
.ai-title p { color: var(--muted); margin: 4px 0 0; font-size: 11px; }
.messages { padding: 20px; overflow: auto; flex: 1; min-height: 180px; }
.message { max-width: 90%; padding: 12px 14px; margin-bottom: 12px; border-radius: 10px; line-height: 1.65; font-size: 14px; white-space: pre-wrap; }
.message.assistant { background: #edf2f7; border-bottom-left-radius: 2px; }
.message.user { background: var(--ink); color: white; margin-left: auto; border-bottom-right-radius: 2px; }
.retry-question { display: inline-block; margin: 8px 0 0 8px; padding: 4px 7px; border: 1px solid currentColor; border-radius: 12px; background: transparent; color: inherit; font-size: 11px; cursor: pointer; }
.retry-question:hover { background: rgba(255, 255, 255, .12); }
.message.assistant .retry-question:hover { background: rgba(43, 76, 112, .1); }
.quick-questions { padding: 0 18px 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.quick-questions button { color: #555; background: white; border: 1px solid var(--line); border-radius: 20px; padding: 7px 10px; font-size: 11px; }
.composer { border-top: 1px solid var(--line); padding: 15px; }
.composer textarea { width: 100%; resize: none; border: 0; outline: 0; background: transparent; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; }
.composer-footer select { border: 0; color: var(--muted); font-size: 12px; }
.composer-footer button { border: 0; border-radius: 5px; background: var(--blue); color: white; padding: 8px 13px; }
.selected-context { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--red); background: #fff1ed; padding: 6px 7px 6px 9px; font-size: 11px; border-radius: 4px; margin-bottom: 6px; }
.selected-context button { flex: 0 0 auto; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: currentColor; font-size: 17px; line-height: 1; cursor: pointer; }
.selected-context button:hover { background: rgba(201, 67, 48, .12); }
.selected-context button:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
.hidden { display: none; }
dialog { width: min(880px, 94vw); border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(15,15,13,.65); backdrop-filter: blur(4px); }
.dialog-card { background: var(--card); border-radius: 8px; padding: 28px; max-height: 90vh; overflow: auto; }
.dialog-card.compact { max-width: 620px; margin: auto; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 20px; }
.dialog-head h2 { margin: 0; }
.dialog-help, .muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
.dialog-card label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.dialog-card input, .dialog-card textarea, .dialog-card select { width: 100%; border: 1px solid var(--line); border-radius: 5px; padding: 10px; background: white; }
.editor-grid, .time-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.time-editor { grid-template-columns: 1fr auto 1fr auto; align-items: center; }
.time-editor button { border: 1px solid var(--line); background: white; padding: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 15px; }
pre { background: #20201d; color: #f6d9a8; padding: 17px; border-radius: 5px; overflow: auto; }
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .ai-panel { position: static; max-height: none; min-height: 560px; }
}
@media (max-width: 680px) {
  .layout { padding: 25px 12px 50px; }
  .song-heading { align-items: start; }
  .progress-wrap { min-width: 80px; }
  .player-row { flex-wrap: wrap; }
  .timeline-wrap { order: 5; flex-basis: 100%; }
  .lesson-card { padding: 24px 18px; }
  .translation-grid, .grammar-list { grid-template-columns: 1fr; }
  .translation-grid > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .word { grid-template-columns: 1fr 1fr; }
  .word span:nth-of-type(2), .word .arrow { display: none; }
  .lesson-navigation { top: 5px; }
  .lesson-footer { flex-wrap: wrap; }
  .mastery { order: 3; width: 100%; }
  .mastery button { flex: 1; }
  .editor-grid, .time-editor { grid-template-columns: 1fr; }
}
