:root {
  --ink: #17201d;
  --muted: #62706a;
  --line: #dce3df;
  --soft: #f4f7f5;
  --paper: #ffffff;
  --green: #176b4d;
  --green-soft: #e4f2eb;
  --blue: #245a8d;
  --amber: #9a5a13;
  --red: #a33b32;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { color-scheme: light; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button, input, select { font: inherit; }

a { color: var(--blue); }

.app-header {
  min-height: 66px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 34px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.primary-nav { display: flex; align-self: stretch; gap: 24px; }

.primary-nav a {
  color: var(--muted);
  display: flex;
  align-items: center;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  font-weight: 650;
}

.primary-nav a.active { color: var(--green); border-bottom-color: var(--green); }

.header-stats { margin-left: auto; color: var(--muted); white-space: nowrap; }

.direction-layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: calc(100vh - 67px);
}

.direction-panel {
  border-right: 1px solid var(--line);
  padding: 22px 16px 40px;
  background: var(--soft);
  position: sticky;
  top: 66px;
  height: calc(100vh - 66px);
  overflow-y: auto;
}

.panel-title {
  padding: 0 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.direction-group {
  margin: 18px 10px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.direction-item {
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.direction-item:hover { background: #e9eeeb; }
.direction-item.active { background: var(--green-soft); color: #0d553c; }
.direction-item .id { font-weight: 750; }
.direction-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.direction-item .count { color: var(--muted); font-variant-numeric: tabular-nums; }

.content-panel, .papers-page { padding: 34px 38px 70px; min-width: 0; }
.papers-page { max-width: 1320px; margin: 0 auto; }

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow { color: var(--green); font-weight: 750; margin-bottom: 5px; }
h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: 0; }
.result-count { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.toolbar {
  border-block: 1px solid var(--line);
  padding: 14px 0;
  display: flex;
  gap: 14px;
  align-items: end;
  margin-bottom: 4px;
}

.toolbar label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.toolbar label { min-width: 0; }
.toolbar .search-field { flex: 1; min-width: 210px; }

input[type="search"], select {
  height: 38px;
  border: 1px solid #c8d1cc;
  border-radius: 5px;
  background: white;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input[type="search"]:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 2px #d8ece2; }

.check-field {
  height: 38px;
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 8px !important;
  padding: 0 4px;
  color: var(--ink) !important;
  font-size: 14px !important;
}

.paper-list { border-top: 1px solid var(--line); }

.paper-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 18px;
  padding: 20px 2px;
  border-bottom: 1px solid var(--line);
}

.paper-row > div:last-child { min-width: 0; }

.score-box {
  width: 50px;
  height: 50px;
  border: 1px solid #bfd1c7;
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: var(--green);
  background: var(--green-soft);
  font-size: 21px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.score-box.score-10 { color: var(--red); background: #fae9e6; border-color: #ecc8c2; }
.score-box.score-9 { color: var(--amber); background: #fff2df; border-color: #ead2ae; }

.paper-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.42;
  font-weight: 720;
  overflow-wrap: anywhere;
}

.paper-title a { color: var(--ink); text-decoration-color: #aebbb5; text-underline-offset: 3px; }
.paper-title a:hover { color: var(--blue); }
.paper-meta { color: var(--muted); margin-top: 7px; line-height: 1.5; overflow-wrap: anywhere; }
.paper-reason { margin: 11px 0 0; line-height: 1.58; }

.paper-evidence { margin-top: 10px; }
.paper-evidence summary { color: var(--blue); cursor: pointer; font-weight: 650; }
.paper-evidence p { margin: 9px 0 0; padding-left: 14px; border-left: 3px solid var(--line); line-height: 1.55; color: #34433d; }

.repeat-count {
  width: 54px;
  height: 54px;
  align-self: start;
  border: 1px solid #c9d5cf;
  border-radius: 5px;
  display: grid;
  place-items: center;
  align-content: center;
  color: var(--green);
  background: var(--soft);
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.repeat-count span { display: block; font-size: 10px; color: var(--muted); font-weight: 650; }

.direction-matches {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.direction-match {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  width: auto;
  max-width: 100%;
  padding: 5px 8px;
  background: var(--soft);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.3;
}

.direction-match .direction-code { color: var(--green); font-weight: 750; }
.direction-match .match-score { color: var(--muted); font-weight: 800; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: 24px; }
.pagination button {
  height: 36px;
  min-width: 72px;
  border: 1px solid #c8d1cc;
  border-radius: 5px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}
.pagination button:disabled { color: #a1aaa5; cursor: default; background: var(--soft); }
.pagination span { color: var(--muted); font-variant-numeric: tabular-nums; }

.empty-state { padding: 56px 0; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .app-header { padding: 0 18px; gap: 20px; }
  .header-stats { display: none; }
  .direction-layout { display: block; }
  .direction-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 12px; overflow-x: auto; }
  .direction-panel { position: static; height: auto; overflow-y: hidden; }
  .panel-title, .direction-group { display: none; }
  .direction-list { display: flex; gap: 7px; width: max-content; }
  .direction-item { width: auto; grid-template-columns: auto auto; background: white; border: 1px solid var(--line); }
  .direction-item .name { max-width: 150px; }
  .direction-item .count { display: none; }
  .content-panel, .papers-page { padding: 26px 18px 56px; }
}

@media (max-width: 640px) {
  html, body, .app-header, .direction-layout, .content-panel, .papers-page,
  .page-heading, .toolbar, .paper-list, .paper-row {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .app-header { min-height: 58px; }
  .brand { display: none; }
  .primary-nav { width: 100%; justify-content: space-around; }
  .page-heading { flex-direction: column; align-items: start; gap: 10px; }
  h1 { font-size: 23px; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbar .search-field { flex-basis: 100%; }
  .toolbar label:not(.search-field):not(.check-field) {
    flex: 0 0 calc(50% - 7px);
    width: calc(50% - 7px);
    max-width: calc(50% - 7px);
  }
  select { width: 100%; min-width: 0; }
  .check-field { flex-basis: 100%; }
  .paper-row { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; padding: 17px 0; }
  .paper-row > div:nth-child(2) {
    width: calc(100vw - 140px);
    max-width: calc(100vw - 140px);
  }
  .score-box { width: 44px; height: 44px; font-size: 19px; }
  .paper-title { font-size: 16px; }
  .paper-title, .paper-title a, .paper-meta, .paper-reason {
    display: block;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .result-count { font-size: 13px; }
  .direction-match { font-size: 12px; }
}

/* ---------- 标记徽章（我的项目） ---------- */
.mark-badge {
  align-self: start;
  height: 30px;
  padding: 0 12px;
  border: 1px solid #c8d1cc;
  border-radius: 999px;
  background: white;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.mark-badge:hover { border-color: var(--green); color: var(--green); }
.mark-badge .mark-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; background: transparent; }
.mark-badge.is-marked { background: var(--green); border-color: var(--green); color: #fff; }
.mark-badge.is-marked:hover { background: #116147; }
.mark-badge.is-marked .mark-dot { background: #fff; border-color: #fff; }

/* ---------- 我的 Paper ---------- */
.mypaper-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 34px;
  align-items: start;
  max-width: 1560px;
  margin: 0 auto;
  padding: 34px 38px 90px;
}
.my-paper-panel { min-width: 0; }

.paper-loader {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 12px;
  align-items: center;
  margin: -8px 0 24px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}
.paper-loader small { grid-column: 2; color: var(--muted); }
#paper-file-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--green);
  border-radius: 5px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.file-button:hover { background: #116147; }

.section-block { margin-bottom: 28px; }
.section-title {
  margin: 0;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 19px;
}
.section-count { color: var(--muted); font-size: 12px; font-weight: 650; }
.section-empty { padding: 10px 2px 0; color: var(--muted); font-size: 13px; }

.paragraph-card {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.paragraph-card:hover { border-color: #b4c3bb; }
.paragraph-card.active { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }

.para-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.para-tag { color: var(--green); font-size: 12.5px; font-weight: 750; }
.para-actions { display: flex; gap: 8px; }

.trans-btn, .add-dir-btn {
  height: 27px;
  padding: 0 11px;
  border: 1px solid #c8d1cc;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.trans-btn:hover { border-color: var(--blue); color: var(--blue); }
.trans-btn:disabled { color: #929d98; border-color: var(--line); cursor: wait; }
.add-dir-btn:hover, .add-dir-btn.open { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.add-dir-btn.wide { width: 100%; height: 34px; margin-top: 12px; font-size: 13.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 5px 3px 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: #0d553c;
  font-size: 12.5px;
  font-weight: 600;
}
.chip .direction-code { font-weight: 750; }
.chip-remove {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.chip-remove:hover { opacity: 1; color: var(--red); }

.para-text { margin: 10px 0 0; color: #22302a; font-size: 14.5px; line-height: 1.68; }
.para-text.lang-zh { color: #33413b; }
.paragraph-detail-mobile { display: none; }

.dir-picker { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.dir-picker-head { margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.dir-picker-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dir-picker-list .direction-group { flex-basis: 100%; margin: 8px 2px 0; font-size: 11.5px; }
.dir-picker-list .direction-group:first-child { margin-top: 2px; }
.dir-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid #c8d1cc;
  border-radius: 5px;
  background: #fff;
  font-size: 12.5px;
  cursor: pointer;
}
.dir-option:hover { border-color: var(--green); }
.dir-option.added { border-color: var(--green); background: var(--green-soft); color: #0d553c; }
.dir-option .name { font-weight: 600; }
.dir-added { color: var(--green); font-weight: 750; }

.my-aside {
  position: sticky;
  top: 82px;
  display: grid;
  gap: 16px;
  min-width: 0;
}
.summary-card {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}
.summary-card-mobile { display: none; margin-bottom: 24px; }
.summary-label { color: var(--muted); font-size: 13px; font-weight: 750; }
.summary-num { color: var(--green); font-size: 44px; font-weight: 800; line-height: 1.18; font-variant-numeric: tabular-nums; }
.summary-num span { margin-left: 6px; color: var(--muted); font-size: 15px; font-weight: 650; }
.summary-sub { color: var(--muted); font-size: 13px; line-height: 1.5; }
.summary-breakdown { margin-top: 12px; padding-top: 10px; border-top: 1px dashed #c9d5cf; }
.summary-breakdown summary { color: var(--green); font-size: 13px; font-weight: 650; cursor: pointer; }
.summary-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #e3eae6;
  font-size: 13px;
}
.summary-row:last-child { border-bottom: 0; }
.summary-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-row .count { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-hint { margin-top: 10px; color: var(--muted); font-size: 13px; line-height: 1.55; }

.detail-panel {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.detail-head h2 { margin: 2px 0 12px; font-size: 18px; }
.ref-cards { display: grid; gap: 10px; }
.ref-card { border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.ref-card summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  font-weight: 650;
  cursor: pointer;
}
.ref-card summary::-webkit-details-marker { display: none; }
.ref-card summary::before { content: "▸"; color: var(--muted); font-size: 11px; transition: transform 0.15s; }
.ref-card[open] summary::before { transform: rotate(90deg); }
.ref-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-count { color: var(--muted); font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.ref-papers { display: grid; gap: 8px; padding: 2px 13px 12px; }
.ref-paper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.ref-paper-title { font-size: 13.5px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.ref-paper-title a { color: var(--ink); text-decoration-color: #aebbb5; text-underline-offset: 2px; }
.ref-paper-title a:hover { color: var(--blue); }
.ref-paper-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }
.score-chip {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.ref-empty { padding: 2px 0 4px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.ref-empty a { white-space: nowrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  z-index: 50;
  max-width: min(560px, 88vw);
  padding: 10px 18px;
  border-radius: 8px;
  background: #22302a;
  color: #fff;
  font-size: 13.5px;
  line-height: 1.55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .mypaper-layout { grid-template-columns: 1fr; gap: 24px; }
  .my-aside { display: none; }
  .summary-card-mobile { display: block; }
  .paragraph-detail-mobile {
    display: block;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .mypaper-layout { padding: 24px 16px 60px; }
  .paper-loader { grid-template-columns: 1fr; margin-top: 0; }
  .paper-loader small { grid-column: 1; }
  #paper-file-status { white-space: normal; overflow-wrap: anywhere; }
  .mark-text { display: none; }
  .mark-badge { padding: 0 9px; }
  .detail-panel { padding: 14px; }
  .summary-card { padding: 15px 16px; }
}
