:root {
  --paper: #f7f7f4;
  --surface: #ffffff;
  --ink: #1e2523;
  --muted: #6f7773;
  --line: #dfe2dc;
  --green: #226a53;
  --green-soft: #dcebe5;
  --coral: #d85e48;
  --coral-soft: #f6dfda;
  --mustard: #b77a13;
  --mustard-soft: #f5e8c9;
  --blue: #376ba4;
  --blue-soft: #dde8f3;
  --shadow: 0 12px 32px rgba(37, 44, 40, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input { font: inherit; }
button { color: inherit; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }

.app-shell { min-width: 0; min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px 24px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 9px 30px; color: var(--ink); text-decoration: none; font-weight: 750; font-size: 18px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; background: var(--green); color: white; border-radius: 7px 7px 7px 2px; font-family: Georgia, serif; }
.side-nav { display: grid; gap: 6px; }
.nav-item { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 12px; border: 0; border-radius: 6px; padding: 0 12px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.nav-item:hover { background: var(--paper); color: var(--ink); }
.nav-item.is-active { background: var(--green-soft); color: var(--green); font-weight: 700; }
.nav-item .nav-count { margin-left: auto; min-width: 22px; height: 22px; display: grid; place-items: center; border-radius: 11px; background: var(--surface); font-size: 12px; }
.history-block { margin-top: 34px; min-height: 160px; }
.side-label { margin: 0 12px 12px; color: #919792; font-size: 12px; font-weight: 700; }
.history-list { display: grid; gap: 2px; }
.history-item { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 8px 12px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; text-align: left; }
.history-item:hover { background: var(--paper); }
.history-item span { font-weight: 650; }
.history-item small { color: var(--muted); }
.empty-history { color: #9ba09d; font-size: 13px; padding: 8px 12px; }
.daily-progress { margin-top: auto; padding: 15px 12px 4px; border-top: 1px solid var(--line); }
.progress-copy { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.progress-copy strong { color: var(--ink); }
.progress-track { height: 5px; margin-top: 10px; overflow: hidden; background: var(--line); border-radius: 3px; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--coral); transition: width .3s ease; }

.main-content { width: 100%; min-width: 0; max-width: 1220px; margin: 0 auto; padding: 34px 56px 70px; }
.view-section, .result { min-width: 0; }
.topbar { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 26px; font-weight: 600; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
.icon-button { flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
.icon-button:hover { border-color: var(--green); color: var(--green); }
.mobile-menu { display: none; }

.search-section { margin-top: 30px; }
.search-box { height: 64px; display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 7px 8px 7px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.search-box:focus-within { border-color: var(--green); box-shadow: 0 12px 32px rgba(34, 106, 83, .12); }
.search-box > svg { color: var(--muted); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 17px; }
.search-box button { height: 48px; display: inline-flex; align-items: center; gap: 9px; padding: 0 20px; border: 0; border-radius: 6px; background: var(--green); color: white; font-weight: 700; cursor: pointer; }
.search-box button:disabled { opacity: .65; cursor: wait; }
.suggestions { min-height: 34px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 11px 2px 0; color: var(--muted); font-size: 12px; }
.suggestions button { border: 1px solid var(--line); border-radius: 12px; padding: 4px 9px; background: var(--surface); cursor: pointer; }
.suggestions button:hover { border-color: var(--coral); color: var(--coral); }
.search-message { min-height: 18px; margin: 4px 2px 0; color: var(--coral); font-size: 12px; }

.empty-state { min-height: 460px; display: grid; grid-template-columns: minmax(280px, 470px) minmax(260px, 430px); align-items: center; justify-content: center; gap: 44px; padding: 34px 0 0; }
.empty-state img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; mix-blend-mode: multiply; }
.empty-state h2 { max-width: 430px; margin: 10px 0 14px; font-family: Georgia, "Songti SC", serif; font-size: 34px; line-height: 1.25; font-weight: 600; letter-spacing: 0; }
.empty-state p:last-child { max-width: 420px; color: var(--muted); line-height: 1.8; }

.result { margin-top: 24px; }
.word-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 6px 2px 24px; }
.word-line { display: flex; align-items: center; gap: 14px; }
.word-line h2 { margin: 0; font-family: Georgia, serif; font-size: 48px; line-height: 1.1; font-weight: 600; letter-spacing: 0; overflow-wrap: anywhere; }
.sound-button { width: 36px; height: 36px; color: var(--green); }
.word-heading .word-meta { display: flex; align-items: center; margin: 8px 0 0; color: var(--muted); }
.meaning-line { display: flex; align-items: flex-start; gap: 10px; margin-top: 14px; }
.meaning-line strong { max-width: 720px; color: var(--ink); font-size: 18px; line-height: 1.55; }
.meaning-line span { flex: 0 0 auto; margin-top: 3px; padding: 3px 6px; border-radius: 3px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 750; }
.english-meaning { max-width: 760px; margin: 5px 0 0; color: var(--muted); font-family: Georgia, serif; font-size: 13px; line-height: 1.5; }
.dot { width: 3px; height: 3px; margin: 0 10px; border-radius: 50%; background: var(--coral); }
.save-button, .outline-button { height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font-weight: 700; }
.save-button:hover, .outline-button:hover { border-color: var(--green); color: var(--green); }
.save-button.is-saved { background: var(--green-soft); border-color: transparent; color: var(--green); }

.method-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.method-tab { min-height: 54px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.method-tab span { margin-right: 7px; color: #a6aaa7; font-size: 11px; }
.method-tab:hover { color: var(--ink); }
.method-tab.is-active { border-bottom-color: var(--coral); color: var(--ink); font-weight: 750; }

.method-content { background: var(--surface); border: 1px solid var(--line); border-top: 0; box-shadow: var(--shadow); }
.method-panel { display: none; min-height: 400px; padding: 34px 38px 40px; }
.method-panel.is-active { display: block; animation: reveal .25s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.panel-heading h3 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 600; letter-spacing: 0; }
.method-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 7px; }
.method-icon.coral { background: var(--coral-soft); color: var(--coral); }
.method-icon.mustard { background: var(--mustard-soft); color: var(--mustard); }
.method-icon.green { background: var(--green-soft); color: var(--green); }
.method-icon.blue { background: var(--blue-soft); color: var(--blue); }
.method-icon.ink { background: #e4e5e2; color: var(--ink); }

.morpheme-row { display: flex; align-items: stretch; gap: 8px; overflow-x: auto; padding-bottom: 5px; }
.morpheme { min-width: 145px; flex: 1; padding: 18px; border-left: 3px solid var(--coral); background: var(--paper); }
.morpheme:nth-child(2) { border-color: var(--mustard); }
.morpheme:nth-child(3) { border-color: var(--green); }
.morpheme strong { display: block; font-family: Georgia, serif; font-size: 25px; }
.morpheme small { display: block; margin: 4px 0 12px; color: var(--muted); }
.morpheme p { margin: 0; line-height: 1.65; font-size: 14px; }
.join-sign { display: grid; place-items: center; color: var(--muted); font-size: 20px; }
.logic-box { display: flex; gap: 12px; margin-top: 22px; padding: 17px 18px; background: var(--green-soft); color: #184d3d; line-height: 1.75; }
.logic-box svg { flex: 0 0 auto; margin-top: 4px; }
.logic-box p { margin: 0; }
.root-panel-heading .source-badge { margin-left: auto; }
.source-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 11px; font-weight: 750; white-space: nowrap; }
.source-badge[data-confidence="verified"] { border-color: #9fcbb9; background: var(--green-soft); color: var(--green); }
.source-badge[data-confidence="inferred"] { border-color: #e1bf75; background: var(--mustard-soft); color: #7d5512; }
.source-badge[data-confidence="unavailable"] { background: var(--paper); }

.visual-scene { display: grid; grid-template-columns: 54px 1fr; gap: 18px; padding: 24px; border: 1px solid var(--line); background: var(--paper); }
.scene-number { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%; background: var(--mustard); color: white; font-family: Georgia, serif; font-size: 24px; }
.visual-scene h4 { margin: 1px 0 10px; font-size: 18px; }
.visual-scene p { margin: 0; color: #4e5551; line-height: 1.9; }
.memory-hook { display: flex; gap: 16px; margin: 20px 0 0; padding: 0 4px; line-height: 1.7; }
.memory-hook strong { flex: 0 0 auto; color: var(--coral); }

.flashcard { position: relative; width: min(100%, 590px); height: 235px; display: block; margin: 0 auto 30px; padding: 0; border: 0; background: transparent; perspective: 900px; cursor: pointer; }
.flash-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); backface-visibility: hidden; transition: transform .5s ease; box-shadow: 0 8px 20px rgba(37, 44, 40, .07); }
.flash-face small { position: absolute; top: 16px; left: 18px; color: var(--muted); }
.flash-front strong { font-family: Georgia, serif; font-size: 42px; }
.flash-front em { margin-top: 8px; color: var(--green); font-style: normal; }
.flash-front > span { position: absolute; bottom: 15px; color: var(--muted); font-size: 12px; }
.flash-back { transform: rotateY(180deg); }
.flash-back strong { margin-bottom: 14px; color: var(--coral); font-size: 23px; }
.flash-back > span { max-width: 470px; line-height: 1.7; }
.flashcard.is-flipped .flash-front { transform: rotateY(180deg); }
.flashcard.is-flipped .flash-back { transform: rotateY(360deg); }
.review-timeline { display: grid; grid-template-columns: repeat(4, 1fr); position: relative; gap: 12px; }
.review-step { padding-top: 20px; border-top: 2px solid var(--line); }
.review-step::before { content: ""; display: block; width: 10px; height: 10px; margin-top: -26px; margin-bottom: 14px; border: 3px solid var(--surface); border-radius: 50%; background: var(--green); box-shadow: 0 0 0 1px var(--green); }
.review-step strong, .review-step span { display: block; }
.review-step span { margin-top: 4px; color: var(--muted); font-size: 12px; }

.context-list { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.context-item { padding: 20px; border: 1px solid var(--line); border-top: 3px solid var(--blue); }
.context-item:nth-child(2) { border-top-color: var(--coral); }
.context-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.context-item blockquote { margin: 15px 0 10px; font-family: Georgia, serif; font-size: 18px; line-height: 1.55; }
.context-item p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.context-item mark { padding: 1px 3px; background: var(--mustard-soft); color: inherit; }
.collocation-line { display: flex; align-items: center; gap: 16px; margin-top: 22px; }
.collocation-line > div { display: flex; flex-wrap: wrap; gap: 8px; }
.collocation-line span { padding: 6px 10px; border-radius: 4px; background: var(--paper); color: var(--green); font-size: 13px; }

.teach-script { counter-reset: script; display: grid; gap: 12px; margin-bottom: 22px; }
.teach-part { counter-increment: script; display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 16px 18px; background: var(--paper); line-height: 1.75; }
.teach-part::before { content: counter(script); width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: white; font-family: Georgia, serif; }
.teach-part p { margin: 1px 0 0; }

.word-network { margin-top: 24px; padding: 30px 32px 34px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.network-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.network-heading .panel-heading { margin: 0; }
.network-heading > p { margin: 0; color: var(--muted); font-size: 12px; }
.relation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 24px; }
.relation-group { min-width: 0; border: 1px solid var(--line); background: var(--paper); }
.relation-group summary { min-height: 46px; display: flex; align-items: center; gap: 9px; padding: 0 14px; cursor: pointer; list-style: none; font-weight: 750; }
.relation-group summary::-webkit-details-marker { display: none; }
.relation-group summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 20px; font-weight: 400; }
.relation-group[open] summary::after { content: "−"; }
.relation-group summary small { color: var(--muted); font-weight: 500; }
.relation-words { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 14px 16px; }
.relation-word { min-height: 32px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--green); cursor: pointer; }
.relation-word:hover, .relation-word:focus-visible { border-color: var(--green); outline: 0; }
.relation-word.is-extra { display: none; }
.relation-group.is-expanded .relation-word.is-extra { display: inline-flex; }
.relation-more { border: 0; padding: 5px 3px; background: transparent; color: var(--blue); cursor: pointer; font-size: 12px; }
.relation-empty { padding: 2px 14px 16px; color: var(--muted); font-size: 13px; }
.network-empty { grid-column: 1 / -1; padding: 26px; background: var(--paper); color: var(--muted); text-align: center; }
.confusable-section { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.section-title { display: flex; align-items: center; gap: 10px; }
.section-title > svg { color: var(--coral); }
.section-title strong, .section-title span { display: block; }
.section-title span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.confusable-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.confusable-card { padding: 18px; border-left: 3px solid var(--coral); background: var(--paper); }
.confusable-card header { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.confusable-card header button { border: 0; padding: 0; background: transparent; color: var(--ink); cursor: pointer; font-family: Georgia, serif; font-size: 22px; font-weight: 700; }
.confusable-card header span { padding: 3px 6px; border-radius: 3px; background: var(--coral-soft); color: var(--coral); font-size: 10px; }
.confusable-card p { margin: 5px 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.confusable-card .difference { color: var(--ink); }
.data-footer { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.7; }
.data-footer a { color: var(--green); }

.review-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 48px 0 22px; border-bottom: 1px solid var(--line); }
.review-header h2 { margin: 5px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 34px; letter-spacing: 0; }
.review-header > p { max-width: 380px; margin: 0; color: var(--muted); }
.review-list { display: grid; gap: 10px; padding-top: 20px; }
.review-row { display: grid; grid-template-columns: 1fr 1fr auto auto; align-items: center; gap: 18px; padding: 17px 18px; border: 1px solid var(--line); background: var(--surface); }
.review-row strong { font-family: Georgia, serif; font-size: 20px; }
.review-row span { color: var(--muted); }
.review-row button { border: 0; padding: 8px; background: transparent; color: var(--green); cursor: pointer; }
.review-empty { padding: 70px 20px; color: var(--muted); text-align: center; }
.sidebar-scrim { display: none; }

body.dark { --paper: #171b1a; --surface: #202523; --ink: #edf0ec; --muted: #a6ada8; --line: #38403c; --green-soft: #233f35; --coral-soft: #49302b; --mustard-soft: #443a24; --blue-soft: #293b4e; --shadow: 0 12px 32px rgba(0,0,0,.22); color-scheme: dark; }
body.dark .empty-state img { mix-blend-mode: normal; opacity: .86; }
body.dark .logic-box { color: #bde0d2; }
body.dark .source-badge[data-confidence="inferred"] { color: #ecd39b; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: 248px; transition: transform .25s ease; box-shadow: var(--shadow); }
  body.menu-open .sidebar { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; display: block; visibility: hidden; opacity: 0; background: rgba(14, 18, 16, .35); z-index: 15; transition: .25s ease; }
  body.menu-open .sidebar-scrim { visibility: visible; opacity: 1; }
  .main-content { padding: 26px 28px 60px; }
  .mobile-menu { display: grid; }
  .topbar { justify-content: flex-start; }
  .topbar > div:nth-child(2) { min-width: 0; flex: 1; }
  .empty-state { grid-template-columns: 1fr 1fr; gap: 24px; }
  .context-list { grid-template-columns: 1fr; }
  .relation-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main-content { padding: 18px 16px 44px; }
  .topbar h1 { font-size: 20px; }
  .topbar .eyebrow { display: none; }
  .search-section { margin-top: 22px; }
  .search-box { height: auto; min-height: 58px; grid-template-columns: 20px minmax(0, 1fr) 46px; padding-left: 14px; }
  .search-box button { width: 42px; height: 42px; padding: 0; justify-content: center; }
  .search-box button span { display: none; }
  .suggestions { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .suggestions > * { flex: 0 0 auto; }
  .suggestions, .method-tabs { scrollbar-width: none; }
  .suggestions::-webkit-scrollbar, .method-tabs::-webkit-scrollbar { display: none; }
  .empty-state { min-height: 0; grid-template-columns: 1fr; padding-top: 22px; }
  .empty-state img { max-height: 245px; }
  .empty-state h2 { font-size: 27px; }
  .word-heading { align-items: flex-start; }
  .word-line { gap: 9px; }
  .word-line h2 { font-size: 31px; }
  .meaning-line { margin-top: 11px; }
  .meaning-line strong { font-size: 16px; }
  .save-button { width: 42px; padding: 0; }
  .save-button span { display: none; }
  .method-tabs { display: flex; overflow-x: auto; }
  .method-tab { flex: 0 0 132px; }
  .method-panel { min-height: 470px; padding: 25px 18px 30px; }
  .panel-heading h3 { font-size: 19px; }
  .root-panel-heading { align-items: flex-start; flex-wrap: wrap; }
  .root-panel-heading .source-badge { margin-left: 58px; margin-top: -8px; }
  .morpheme-row { align-items: stretch; }
  .morpheme { min-width: 170px; }
  .join-sign { display: none; }
  .visual-scene { grid-template-columns: 1fr; padding: 19px; }
  .memory-hook { display: block; }
  .memory-hook strong { display: block; margin-bottom: 5px; }
  .flashcard { height: 255px; }
  .review-timeline { grid-template-columns: 1fr 1fr; row-gap: 24px; }
  .collocation-line { align-items: flex-start; flex-direction: column; }
  .review-header { display: block; }
  .review-header > p { margin-top: 12px; }
  .review-row { grid-template-columns: 1fr auto; }
  .review-row > span { grid-column: 1 / -1; grid-row: 2; }
  .word-network { padding: 24px 18px 28px; }
  .network-heading { align-items: flex-start; flex-direction: column; }
  .relation-group:not([open]) .relation-words { display: none; }
  .confusable-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
