@layer reset, base, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, ol, ul { margin: 0; }
  button { font: inherit; }
}

@layer base {
  :root {
    --ink: #172320;
    --muted: #72807b;
    --faint: #a0aaa6;
    --paper: #f2f5f1;
    --panel: #ffffff;
    --panel-soft: #f7f9f6;
    --line: #d9e0db;
    --accent: #0e7771;
    --accent-soft: #dcefeb;
    --warm: #b06d22;
    --warm-soft: #f6e9d5;
    --rose: #a64f48;
    --rose-soft: #f4e4e1;
    --shadow: 0 10px 30px rgba(23, 35, 32, .06);
    --body-size: 18px;
  }
  body {
    min-width: 320px;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.65;
  }
  body.is-dark {
    --ink: #e8efeb; --muted: #a3b3ad; --faint: #70817a; --paper: #16201d;
    --panel: #1e2b27; --panel-soft: #24332e; --line: #34453f;
    --accent: #73cbc0; --accent-soft: #234b45; --warm: #e7b26b;
    --warm-soft: #4b3a26; --rose: #e28e84; --rose-soft: #4c2e2d;
    --shadow: 0 12px 30px rgba(0, 0, 0, .22);
  }
  button { border: 0; cursor: pointer; }
  button:focus-visible, a:focus-visible { outline: 2px solid var(--warm); outline-offset: 3px; }
  .reading-progress { position: fixed; z-index: 50; inset: 0 0 auto; height: 3px; background: transparent; }
  .reading-progress span { display: block; width: 0; height: 100%; background: var(--accent); }
}

@layer components {
  .app-shell { min-height: 100vh; }
  .topbar {
    position: sticky; top: 0; z-index: 30; height: 68px; display: grid; grid-template-columns: 1fr auto 1fr;
    align-items: center; padding: 0 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 90%, transparent);
    backdrop-filter: blur(14px);
  }
  .brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
  .brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; color: #fff; background: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: 0; }
  .brand strong, .brand small { display: block; line-height: 1.15; }
  .brand strong { font-size: 13px; letter-spacing: 0; }
  .brand small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: 0; }
  .topbar-center { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
  .status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
  .topbar-actions { display: flex; justify-content: flex-end; gap: 7px; }
  .blog-link { display: inline-flex; align-items: center; gap: 5px; min-height: 34px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--accent); background: var(--panel); font-size: 11px; font-weight: 800; text-decoration: none; }
  .blog-link:hover { color: #fff; border-color: var(--accent); background: var(--accent); }
  .icon-button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 6px 9px; color: var(--muted); background: transparent; font-size: 12px; }
  .icon-button:hover, .icon-button[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
  .icon-button:first-letter { font-size: 17px; }

  .workspace { display: grid; grid-template-columns: 230px minmax(500px, 760px) 290px; justify-content: center; gap: 30px; width: min(1400px, calc(100% - 44px)); margin: 0 auto; }
  .left-rail, .insight-panel { min-width: 0; }
  .left-rail { padding: 34px 0; }
  .rail-heading, .insight-header { margin-bottom: 18px; }
  .rail-heading span, .insight-header span { display: block; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0; }
  .rail-heading strong, .insight-header strong { display: block; margin-top: 3px; font-size: 17px; }
  #sectionNav { display: grid; gap: 2px; }
  .nav-link { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 8px 10px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; font-size: 12px; line-height: 1.35; }
  .nav-link span:first-child { color: var(--faint); font-variant-numeric: tabular-nums; }
  .nav-link:hover, .nav-link.is-active { border-left-color: var(--accent); color: var(--ink); background: var(--panel); }
  .rail-divider { height: 1px; margin: 24px 10px 14px 0; background: var(--line); }
  .rail-tool { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 10px; color: var(--muted); background: transparent; text-align: left; font-size: 12px; }
  .rail-tool:hover { color: var(--accent); background: var(--panel); }
  .rail-tool span { display: grid; place-items: center; width: 19px; height: 19px; color: var(--accent); border: 1px solid currentColor; border-radius: 50%; font-size: 13px; }

  .reading-pane { min-width: 0; padding-bottom: 90px; }
  .article-intro { position: relative; isolation: isolate; overflow: hidden; padding: 70px 24px 50px; border-bottom: 1px solid var(--line); color: #fff; background: #213b4a url("assets/concrete-materials-new.jpg") center 48% / cover no-repeat; }
  .article-intro::before { content: ""; position: absolute; z-index: -1; inset: 0; background: rgba(10, 25, 31, .68); }
  .intro-overline { margin-bottom: 17px; color: #a9e0d9; font-size: 10px; font-weight: 850; letter-spacing: 0; }
  .article-intro h1 { max-width: 680px; font-family: Georgia, "Times New Roman", serif; font-size: 68px; font-weight: 500; line-height: .98; letter-spacing: 0; }
  .article-intro h1 em { color: #9edbd3; font-style: normal; }
  .article-intro p { max-width: 610px; margin-top: 24px; color: #dfe9e6; font-size: 16px; line-height: 1.7; }
  .intro-meta { display: flex; gap: 20px; margin-top: 23px; color: #c7d5d1; font-size: 11px; }
  .intro-meta span + span::before { content: ""; display: inline-block; width: 4px; height: 4px; margin: 0 20px 2px 0; border-radius: 50%; background: var(--warm); }
  .reading-toolbar { position: sticky; top: 68px; z-index: 15; display: flex; align-items: center; gap: 18px; min-height: 56px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 93%, transparent); backdrop-filter: blur(12px); }
  .toolbar-group { display: flex; align-items: center; gap: 4px; }
  .toolbar-label { margin-right: 5px; color: var(--faint); font-size: 10px; }
  .view-button, .small-button { min-height: 30px; padding: 5px 9px; color: var(--muted); background: transparent; border-radius: 4px; font-size: 11px; }
  .view-button:hover, .view-button.is-active, .small-button:hover { color: var(--accent); background: var(--accent-soft); }
  .small-button { min-width: 31px; border: 1px solid var(--line); }
  .toolbar-hint { margin-left: auto; color: var(--faint); font-size: 10px; }

  .passage-section { scroll-margin-top: 126px; padding: 48px 0 12px; }
  .passage-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
  .passage-title-wrap { display: flex; align-items: center; gap: 12px; }
  .paragraph-number { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 6px; color: #fff; background: var(--accent); font-size: 11px; font-weight: 850; }
  .category-people .paragraph-number { background: var(--rose); }
  .category-purpose .paragraph-number { background: var(--warm); }
  .passage-heading h2 { font-family: Georgia, "Songti SC", serif; font-size: 23px; font-weight: 500; line-height: 1.2; }
  .section-original { margin-top: 5px; color: var(--faint); font-family: Georgia, "Times New Roman", serif; font-size: 11px; line-height: 1.4; }
  .sentence-count { margin-top: 4px; color: var(--muted); font-size: 11px; }
  .category-label { padding: 4px 8px; color: var(--accent); background: var(--accent-soft); border-radius: 3px; font-size: 10px; font-weight: 800; }
  .category-people .category-label { color: var(--rose); background: var(--rose-soft); }
  .category-purpose .category-label { color: var(--warm); background: var(--warm-soft); }
  .sentence-list { display: grid; gap: 8px; }
  .sentence-card { position: relative; padding: 20px; border: 1px solid transparent; border-radius: 7px; background: transparent; scroll-margin-top: 134px; transition: border-color .18s, background .18s, box-shadow .18s; }
  .sentence-card:hover, .sentence-card.is-selected { border-color: var(--line); background: var(--panel); box-shadow: var(--shadow); }
  .sentence-meta { display: flex; align-items: center; gap: 8px; min-height: 22px; margin-bottom: 9px; }
  .sentence-number { display: grid; place-items: center; width: 32px; height: 22px; border-radius: 3px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 850; }
  .category-people .sentence-number { color: var(--rose); background: var(--rose-soft); }
  .category-purpose .sentence-number { color: var(--warm); background: var(--warm-soft); }
  .quiz-ref { padding: 3px 6px; color: var(--rose); background: var(--rose-soft); border-radius: 3px; font-size: 9px; font-weight: 800; white-space: nowrap; }
  .quiz-ref:hover { color: #fff; background: var(--rose); }
  .sentence-role { margin-left: auto; color: var(--faint); font-size: 10px; }
  .en-line { margin: 0; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: var(--body-size); line-height: 1.8; }
  .en-line mark { padding: 1px 3px; border-radius: 3px; color: inherit; background: var(--warm-soft); }
  .en-line mark.structure { color: var(--accent); background: var(--accent-soft); }
  .en-line mark.contrast { color: var(--rose); background: var(--rose-soft); }
  .en-line mark.key { color: #8a5b08; background: var(--warm-soft); }
  .en-line mark.time { color: var(--warm); background: var(--warm-soft); }
  .cn-line { margin: 13px 0 0; padding-left: 13px; border-left: 2px solid var(--line); color: var(--muted); font-size: 14px; line-height: 1.75; }
  .sentence-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
  .note-block { padding: 12px 14px; background: var(--panel-soft); }
  .note-block.vocabulary { border-top: 2px solid var(--accent); }
  .note-block.grammar { border-top: 2px solid var(--rose); }
  .note-label { display: block; margin-bottom: 7px; color: var(--accent); font-size: 10px; font-weight: 850; }
  .note-block.grammar .note-label { color: var(--rose); }
  .note-list { display: grid; gap: 5px; padding: 0; list-style: none; }
  .note-list li { color: var(--muted); font-size: 12px; line-height: 1.55; }
  .note-list strong { color: var(--ink); }
  .ielts-note { margin-top: 10px; padding: 10px 12px; border-left: 2px solid var(--rose); color: var(--rose); background: var(--rose-soft); font-size: 12px; line-height: 1.6; }
  .ielts-note b { margin-right: 7px; font-size: 10px; letter-spacing: 0; }
  .save-button, .note-button { margin-left: 4px; color: var(--faint); background: transparent; font-size: 17px; line-height: 1; }
  .note-button { font-size: 15px; }
  .note-button:hover { color: var(--accent); }
  .save-button.is-saved { color: var(--warm); }
  .inline-note { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--warm); color: var(--muted); background: var(--warm-soft); font-size: 11px; }
  .inline-note span { color: var(--warm); font-weight: 800; }
  .inline-note p { margin-top: 3px; }
  .view-english .cn-line, .view-english .sentence-notes, .view-english .ielts-note { display: none; }
  .view-bilingual .sentence-notes, .view-bilingual .ielts-note { display: none; }

  .question-studio { scroll-margin-top: 125px; margin-top: 55px; padding: 36px 0 20px; border-top: 1px solid var(--line); }
  .question-studio-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
  .question-studio-heading h2 { margin-top: 3px; font-family: Georgia, serif; font-size: 30px; font-weight: 500; }
  .question-studio-heading p { margin-top: 5px; color: var(--muted); font-size: 12px; }
  .answer-toggle { padding: 8px 12px; color: #fff; background: var(--accent); border-radius: 4px; font-size: 11px; font-weight: 800; }
  .question-tabs { display: flex; gap: 4px; margin-top: 24px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .question-tab { padding: 7px 10px; color: var(--muted); background: transparent; border-radius: 4px; font-size: 11px; }
  .question-tab.is-active { color: var(--accent); background: var(--accent-soft); }
  #questionList { display: grid; gap: 6px; margin-top: 12px; }
  .question-row { display: grid; grid-template-columns: 34px 1fr 112px; gap: 12px; align-items: start; padding: 14px 12px; border-bottom: 1px solid var(--line); }
  .question-row.is-question-target { background: color-mix(in srgb, var(--accent-soft) 72%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
  .question-row > b { color: var(--faint); font-size: 12px; }
  .question-row p { color: var(--muted); font-size: 12px; line-height: 1.55; }
  .question-row .question-en { color: var(--ink); font-family: Georgia, "Times New Roman", serif; }
  .question-row .question-cn { margin-top: 5px; color: var(--muted); }
  .question-row strong { display: block; color: var(--accent); font-size: 12px; }
  .question-answer { display: block; margin-top: 10px; filter: blur(6px); user-select: none; transition: filter .15s; }
  .question-answer strong + strong { margin-top: 9px; }
  .answers-visible .question-answer { filter: none; user-select: text; }
  .answer-chip { display: grid; place-items: center; min-height: 30px; padding: 4px 7px; color: #fff; background: var(--accent); border-radius: 4px; font-size: 10px; font-weight: 850; text-align: center; }

  .is-focus .left-rail, .is-focus .insight-panel { display: none; }
  .is-focus .workspace { grid-template-columns: minmax(0, 760px); }

  .insight-panel { position: sticky; top: 68px; align-self: start; padding: 34px 0; }
  .selection-card, .progress-card, .saved-card, .key-card { padding: 18px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
  .selection-card { min-height: 214px; }
  .card-kicker { color: var(--accent); font-size: 9px; font-weight: 850; letter-spacing: 0; }
  .selection-empty { margin-top: 25px; color: var(--faint); font-size: 13px; line-height: 1.8; }
  .selection-number { color: var(--accent); font-size: 12px; font-weight: 850; }
  .selection-content h2 { margin-top: 5px; font-family: Georgia, serif; font-size: 16px; font-weight: 500; }
  .selection-content p { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.6; }
  .selection-rule { height: 1px; margin: 14px 0 12px; background: var(--line); }
  .selection-content b { color: var(--accent); font-size: 10px; }
  .maimemo-button { display: inline-flex; align-items: center; gap: 7px; margin-top: 15px; padding: 7px 9px; border: 1px solid var(--accent); border-radius: 4px; color: var(--accent); background: transparent; font-size: 11px; font-weight: 800; }
  .maimemo-button:hover:not(:disabled) { color: #fff; background: var(--accent); }
  .maimemo-button:disabled { cursor: wait; opacity: .6; }
  .maimemo-button span { font-size: 16px; line-height: .8; }
  .maimemo-status { min-height: 18px; margin-top: 6px !important; color: var(--faint) !important; font-size: 10px !important; }
  .maimemo-status.is-success { color: var(--accent) !important; }
  .maimemo-status.is-error { color: var(--rose) !important; }
  .progress-card, .saved-card, .key-card { margin-top: 10px; }
  .progress-card-heading { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
  .progress-card-heading strong { color: var(--accent); font-size: 13px; }
  .progress-track { height: 5px; margin-top: 13px; overflow: hidden; background: var(--accent-soft); border-radius: 99px; }
  .progress-track span { display: block; width: 0; height: 100%; background: var(--accent); border-radius: inherit; transition: width .2s; }
  .progress-card p { margin-top: 8px; color: var(--faint); font-size: 10px; }
  .saved-card button { display: flex; justify-content: space-between; width: 100%; margin-top: 12px; padding: 8px 0 0; border-top: 1px solid var(--line); color: var(--accent); background: transparent; font-size: 11px; text-align: left; }
  .saved-card button span { font-size: 15px; }
  .key-card { padding-bottom: 13px; }
  .arc-step { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; margin-top: 14px; color: var(--muted); font-size: 11px; }
  .arc-step i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
  .arc-step:nth-child(3) i { background: var(--rose); }
  .arc-step:nth-child(4) i { background: var(--warm); }
  .arc-step small { color: var(--faint); font-size: 9px; }

  .modal-backdrop { position: fixed; z-index: 60; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(10, 21, 18, .5); }
  .modal-backdrop[hidden] { display: none; }
  .modal { position: relative; width: min(680px, 100%); max-height: min(720px, 90vh); overflow: auto; padding: 28px; background: var(--panel); box-shadow: 0 24px 70px rgba(0,0,0,.2); }
  .modal h2 { margin-top: 6px; font-family: Georgia, serif; font-weight: 500; }
  .modal-close { position: absolute; top: 14px; right: 16px; color: var(--muted); background: transparent; font-size: 24px; }
  .glossary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin-top: 20px; }
  .glossary-item { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
  .glossary-item strong { color: var(--ink); }
  .saved-item { display: block; width: 100%; padding: 13px 0; border-bottom: 1px solid var(--line); color: var(--muted); background: transparent; text-align: left; font-size: 12px; }
  .saved-item b { display: block; color: var(--accent); font-size: 10px; }

  @media (max-width: 1180px) {
    .workspace { grid-template-columns: 190px minmax(0, 1fr); width: min(920px, calc(100% - 36px)); }
    .insight-panel { display: none; }
  }
}

@layer responsive {
  @media (max-width: 720px) {
    .topbar { grid-template-columns: 1fr auto; height: 60px; padding: 0 14px; }
    .topbar-center { display: none; }
    .blog-link { width: 34px; justify-content: center; padding: 6px; font-size: 16px; }.blog-link b { display: none; }
    .brand strong { font-size: 12px; }
    .icon-button span { display: none; }
    .workspace { display: block; width: calc(100% - 28px); }
    .left-rail { position: sticky; top: 60px; z-index: 20; overflow-x: auto; padding: 0; border-bottom: 1px solid var(--line); background: var(--paper); scrollbar-width: none; }
    .left-rail::-webkit-scrollbar { display: none; }
    .rail-heading, .rail-divider, .rail-tool { display: none; }
    #sectionNav { display: flex; width: max-content; padding: 7px 0; }
    .nav-link { display: block; min-width: 42px; padding: 5px 10px; border: 0; border-bottom: 2px solid transparent; text-align: center; }
    .nav-link span:last-child { display: none; }
    .nav-link.is-active { border-bottom-color: var(--accent); }
    .reading-pane { padding-bottom: 50px; }
    .article-intro { padding: 42px 0 32px; }
    .article-intro h1 { max-width: 340px; font-size: 42px; letter-spacing: 0; }
    .article-intro p { font-size: 14px; }
    .reading-toolbar { top: 106px; gap: 8px; min-height: 49px; overflow: auto; }
    .toolbar-hint { display: none; }
    .passage-section { padding-top: 34px; }
    .passage-heading { display: block; }
    .category-label { display: inline-block; margin: 12px 0 0 43px; }
    .sentence-card { padding: 17px 12px; }
    .sentence-role { display: none; }
    .sentence-notes { grid-template-columns: 1fr; }
    .en-line { font-size: 17px; line-height: 1.8; }
    .cn-line { font-size: 13px; }
    .glossary-grid { grid-template-columns: 1fr; }
    .question-row { grid-template-columns: 28px 1fr; }
    .answer-chip { grid-column: 2; width: 112px; }
  }
}
