:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #fafaf6;
  --border: #e6e3da;
  --text: #1d2129;
  --muted: #7a7a72;
  --accent: #b2540a;             /* 暖橘，区别于 stock 站的蓝 */
  --accent-soft: #faf0e1;
  --highlight: #fff3c4;          /* 句子高亮（朗读时） */
  --selected:  #ffe7b3;          /* 被点中句子 */
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.14);
  --radius: 6px;
}
:root.dark {
  --bg: #14130f;
  --surface: #1b1a16;
  --surface-2: #211f1a;
  --border: #322f28;
  --text: #ece9e0;
  --muted: #8f8b80;
  --accent: #d88641;
  --accent-soft: #2a2118;
  --highlight: #4a3a14;
  --selected: #5a4318;
  --shadow:    0 1px 2px rgba(0,0,0,.4);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.6;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ============================ Topbar ============================ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow);
}
.topbar .wrap {
  display: flex; align-items: center; gap: 20px;
  height: 56px;
}
.brand {
  font-weight: 700; font-size: 17px; color: var(--text);
  text-decoration: none; flex-shrink: 0;
}
.topnav { display: flex; gap: 18px; }
.topnav a {
  color: var(--muted); text-decoration: none; font-size: 14px;
  padding: 6px 0; border-bottom: 2px solid transparent;
}
.topnav a:hover, .topnav a.active {
  color: var(--accent); border-bottom-color: var(--accent);
}
.auth-area { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.hello { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.hello b { color: var(--text); }

.hamburger {
  display: none;
  background: none; border: none; color: var(--text);
  font-size: 22px; cursor: pointer; padding: 4px 8px;
}

/* ============================ Buttons ============================ */
.btn {
  padding: 7px 14px; font-size: 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.link {
  background: transparent; border-color: transparent; color: var(--accent);
  padding: 7px 4px;
}
.btn.link:hover { text-decoration: underline; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* ============================ Home ============================ */
.page-title { margin: 24px 0 16px; font-size: 22px; font-weight: 600; }
.category-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.cat-card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .1s, box-shadow .1s, border-color .1s;
  display: flex; flex-direction: column; gap: 6px;
}
.cat-card:hover {
  border-color: var(--accent); box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.cat-card .cat-name { font-size: 16px; font-weight: 600; }
.cat-card .cat-name-en { color: var(--muted); font-size: 12px; }
.cat-card .cat-count { color: var(--muted); font-size: 12px; margin-top: auto; }

.filters {
  margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap;
}
.filters select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-family: inherit;
}

.article-list {
  display: flex; flex-direction: column; gap: 8px;
}
.article-card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; text-decoration: none; color: var(--text);
  display: flex; gap: 12px; align-items: baseline;
  transition: border-color .1s, background .1s;
}
.article-card:hover { border-color: var(--accent); background: var(--surface-2); }
.article-card .ac-title { flex: 1; }
.article-card .ac-title b { font-weight: 600; }
.article-card .ac-title .zh { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.article-card .ac-meta {
  color: var(--muted); font-size: 12px; white-space: nowrap;
}
.article-card .ac-meta .level {
  display: inline-block; padding: 2px 6px; border-radius: 3px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
  margin-right: 6px;
}
.article-card .ac-meta .parts {
  display: inline-block; padding: 2px 6px; border-radius: 3px;
  background: var(--border); color: var(--muted); font-weight: 600;
  margin-right: 6px; font-size: 11px;
}

.back {
  display: inline-block; margin-top: 16px;
  color: var(--muted); text-decoration: none; font-size: 14px;
}
.back:hover { color: var(--accent); }

/* ============================ Article ============================ */
.article-view { padding-bottom: 80px; }
.article-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px; margin-top: 16px;
}
.article-main {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 32px;
  box-shadow: var(--shadow);
}
.series-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; margin-bottom: 12px;
  background: var(--accent-soft); border-radius: var(--radius);
  font-size: 13px;
}
.series-label a { color: var(--accent); text-decoration: none; }
.series-label a:hover { text-decoration: underline; }
.series-label b { color: var(--text); }
.series-nav { display: flex; gap: 6px; }
.series-nav-bottom {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border);
}
.series-nav-bottom a:first-child:not([hidden]) ~ a { margin-left: auto; }
.series-nav-bottom a:only-child { margin-left: auto; }

.article-head h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.3; }
.article-head .muted { font-size: 13px; }
.meta-sep { margin: 0 6px; }
.article-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 16px 0 20px;
  padding: 12px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.rate {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.rate input[type=range] { width: 100px; }

.article-body {
  font-size: 17px; line-height: 1.85; color: var(--text);
}
.article-body p { margin: 0 0 1em; }
.sent {
  cursor: pointer; padding: 1px 0;
  transition: background .15s;
  border-radius: 2px;
}
.sent:hover { background: var(--accent-soft); }
.sent.selected { background: var(--selected); }
.sent.speaking { background: var(--highlight); }
.word {
  cursor: pointer;
}
.word:hover { background: var(--accent-soft); border-radius: 2px; }

.article-notes {
  position: sticky; top: 72px; align-self: start;
  max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.notes-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.notes-tabs button {
  flex: 1; padding: 12px 0; border: none; background: transparent;
  cursor: pointer; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.notes-tabs button:hover { color: var(--text); }
.notes-tabs button.active {
  color: var(--accent); border-bottom-color: var(--accent); font-weight: 500;
}
.notes-body { padding: 12px 16px; font-size: 14px; line-height: 1.6; }
.notes-body .note {
  padding: 12px 0; border-bottom: 1px dashed var(--border);
}
.notes-body .note:last-child { border-bottom: none; }
.notes-body .note-head { font-weight: 600; }
.notes-body .note-body { color: var(--muted); margin-top: 4px; font-size: 13px; }
.notes-body .note-ex {
  margin-top: 6px; padding: 8px 10px;
  background: var(--surface-2); border-radius: 4px;
  font-size: 13px;
}
.notes-body .note-ex .ex-zh { color: var(--muted); font-size: 12px; margin-top: 2px; }
.notes-body .empty {
  text-align: center; padding: 32px 0; color: var(--muted); font-size: 13px;
}

/* ============================ Sentence floating toolbar ============================ */
.floating-bar {
  position: fixed; z-index: 50;
  background: var(--text); color: var(--surface);
  border-radius: 999px;
  padding: 4px 6px;
  box-shadow: var(--shadow-lg);
  display: flex; gap: 4px; align-items: center;
}
.floating-bar button {
  background: transparent; border: none; color: inherit;
  padding: 6px 12px; cursor: pointer; font-size: 13px; border-radius: 999px;
  font-family: inherit;
}
.floating-bar button:hover { background: rgba(255,255,255,.15); }
.floating-bar .close-x { padding: 4px 10px; }

/* ============================ Word popup ============================ */
.word-pop {
  position: fixed; z-index: 60;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 320px; max-width: calc(100vw - 24px);
  padding: 0;
}
.word-pop header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 8px;
}
.word-pop header b { font-size: 18px; }
.word-pop header .muted { font-size: 13px; flex: 1; }
.word-pop .wp-body {
  padding: 12px 16px; max-height: 240px; overflow-y: auto;
  font-size: 14px; line-height: 1.6;
}
.word-pop .wp-body strong { color: var(--accent); }
.word-pop footer {
  padding: 10px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
}

.close-x {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 18px; padding: 0 4px;
}
.close-x:hover { color: var(--text); }

/* ============================ Notebook ============================ */
.notebook-toolbar {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 12px; color: var(--muted); font-size: 13px;
}
.notebook-list { display: flex; flex-direction: column; gap: 8px; }
.nb-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  display: flex; gap: 12px; align-items: flex-start;
}
.nb-item.mastered { opacity: .5; }
.nb-item .nb-content { flex: 1; }
.nb-item .nb-head { font-weight: 600; }
.nb-item .nb-body { color: var(--muted); font-size: 13px; margin-top: 4px; }
.nb-item .nb-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.nb-item .nb-actions {
  display: flex; flex-direction: column; gap: 4px;
}
.nb-item .nb-actions button {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 13px; padding: 4px 6px; border-radius: 4px;
}
.nb-item .nb-actions button:hover { background: var(--accent-soft); color: var(--accent); }

/* ============================ Auth modal ============================ */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px; z-index: 100;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px; padding: 24px;
  position: relative;
}
.modal-card h3 { margin: 0 0 16px; font-size: 18px; font-weight: 600; }
.modal-card .close-x { position: absolute; top: 12px; right: 12px; font-size: 22px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); outline: none;
  font-family: inherit;
}
.field input:focus { border-color: var(--accent); }
.form-err {
  font-size: 13px; color: #d92e2e; min-height: 18px; margin-bottom: 8px;
}
.form-actions {
  display: flex; gap: 8px; align-items: center; margin-top: 4px;
}

/* ============================ Toast ============================ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 200;
  box-shadow: var(--shadow-lg);
}

/* ============================ Footer ============================ */
.foot {
  text-align: center; padding: 24px 16px;
  color: var(--muted); font-size: 12px;
}

.muted { color: var(--muted); }

/* ============================ Responsive ============================ */
@media (max-width: 800px) {
  .article-layout { grid-template-columns: 1fr; }
  .article-notes {
    position: static; max-height: none;
    margin-top: 16px;
  }
  .article-main { padding: 20px 18px; }
  .article-body { font-size: 16px; }

  .hamburger { display: block; }
  .topnav {
    display: none;
    position: absolute; top: 56px; right: 16px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 8px 16px;
    flex-direction: column; gap: 8px;
    box-shadow: var(--shadow-lg);
  }
  .topnav.open { display: flex; }
  .auth-area .btn { padding: 5px 10px; font-size: 13px; }

  .word-pop {
    position: fixed !important;
    bottom: 0 !important; left: 0 !important; right: 0 !important; top: auto !important;
    width: 100% !important; max-width: none !important;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .floating-bar { font-size: 12px; }
  .floating-bar button { padding: 6px 10px; }
}
