:root {
  --ink: #18201b;
  --muted: #657067;
  --line: #dce2dc;
  --soft: #f3f6f2;
  --paper: #ffffff;
  --green: #177245;
  --green-dark: #0f5734;
  --green-soft: #dceee3;
  --yellow: #f0c85a;
  --coral: #d9684f;
  --blue: #346a8a;
  --shadow: 0 16px 40px rgba(24, 32, 27, 0.09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  letter-spacing: 0;
}
button, input, select { font: inherit; letter-spacing: 0; }
button, a, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button, select { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 28px;
  padding: 0 clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; width: max-content; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: block;
  border-radius: 5px;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar nav { display: flex; align-items: center; gap: 28px; color: var(--muted); font-size: 14px; }
.topbar nav a:hover { color: var(--ink); }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-size: 12px;
  font-weight: 800;
}

main > section { scroll-margin-top: 72px; }
.overview-band {
  min-height: 520px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  gap: clamp(40px, 7vw, 112px);
  align-items: center;
  padding: clamp(58px, 7vw, 96px) clamp(24px, 7vw, 112px);
  background: var(--soft);
  border-bottom: 1px solid var(--line);
}
.kicker, .section-index {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 {
  max-width: 680px;
  margin-bottom: 14px;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(42px, 5vw, 70px);
  line-height: 1.05;
  font-weight: 500;
}
.overview-note { max-width: 600px; margin-bottom: 42px; color: var(--muted); font-size: 16px; line-height: 1.7; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); max-width: 760px; }
.summary-stat { min-width: 0; padding: 0 22px; border-left: 1px solid #cdd5ce; }
.summary-stat:first-child { padding-left: 0; border-left: 0; }
.summary-stat span, .summary-stat small { display: block; color: var(--muted); font-size: 12px; }
.summary-stat strong { display: block; margin: 8px 0 5px; font-size: clamp(24px, 2.5vw, 36px); line-height: 1; font-weight: 650; }
.today-panel { padding-left: clamp(24px, 4vw, 58px); border-left: 1px solid #cdd5ce; }
.panel-heading, .section-heading, .dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading h2, .section-heading h2, .dialog-heading h2 { margin: 0; font-size: 25px; font-weight: 650; }
.session-state { padding: 5px 8px; border: 1px solid #b9c3ba; border-radius: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.session-mini { display: grid; gap: 1px; margin: 24px 0; background: #d4dbd5; border: 1px solid #d4dbd5; }
.session-mini-row { min-height: 46px; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; background: var(--paper); }
.session-mini-row strong { font-size: 13px; }
.session-mini-row span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.session-mini-row b { color: var(--green); font-size: 12px; }
.session-empty { padding: 26px 12px; color: var(--muted); background: var(--paper); font-size: 13px; line-height: 1.6; }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 9px 15px;
  color: var(--ink);
  background: var(--paper);
  font-weight: 650;
  font-size: 13px;
}
.button:hover { border-color: #aeb9b0; background: #fafbfa; }
.button-primary { border-color: var(--green); color: white; background: var(--green); }
.button-primary:hover { border-color: var(--green-dark); background: var(--green-dark); }
.button-primary:disabled { border-color: #cbd2cc; color: #89928b; background: #e6eae6; cursor: not-allowed; }
.button-quiet { min-height: 34px; padding: 7px 12px; background: transparent; }
.button-block { width: 100%; }
.button-danger { border-color: #efc4bb; color: #a53521; background: #fff8f6; }

.heatmap-band, .builder-band, .library-band { padding: clamp(54px, 6vw, 84px) clamp(24px, 7vw, 112px); }
.heatmap-band { border-bottom: 1px solid var(--line); }
.section-heading { align-items: end; margin-bottom: 30px; }
.heatmap-legend { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.heatmap-legend i, .heatmap span {
  width: 11px;
  height: 11px;
  display: block;
  border: 1px solid rgba(24, 32, 27, 0.06);
  border-radius: 2px;
  background: #ebefeb;
}
[data-level="1"] { background: #b9ddc5 !important; }
[data-level="2"] { background: #73b98d !important; }
[data-level="3"] { background: #36845a !important; }
[data-level="4"] { background: #155f3a !important; }
.heatmap-summary { margin-bottom: 18px; color: var(--muted); font-size: 13px; }
.heatmap-scroll { overflow-x: auto; padding: 2px 0 8px; }
.heatmap-months { min-width: 750px; height: 18px; margin-left: 32px; display: grid; grid-template-columns: repeat(12, 1fr); color: var(--muted); font-size: 10px; }
.heatmap-layout { min-width: 782px; display: flex; align-items: flex-start; gap: 10px; }
.weekday-labels { width: 22px; height: 89px; display: grid; grid-template-rows: repeat(3, 1fr); padding-top: 12px; color: var(--muted); font-size: 10px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 11px); grid-auto-columns: 11px; grid-auto-flow: column; gap: 3px; }
.heatmap span[data-future="true"] { visibility: hidden; }

.daily-accuracy { scroll-margin-top: 92px; margin-top: 38px; padding-top: 34px; border-top: 1px solid var(--line); }
.daily-accuracy-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.daily-accuracy-heading h3 { margin: 0; font-size: 22px; font-weight: 650; }
.daily-range-label select { min-height: 38px; border: 1px solid var(--line); border-radius: 5px; padding: 7px 34px 7px 11px; color: var(--ink); background: var(--paper); }
.daily-accuracy-summary { margin: 14px 0 18px; color: var(--muted); font-size: 13px; }
.daily-accuracy-list { display: grid; border-top: 1px solid var(--line); }
.daily-accuracy-row { min-height: 70px; display: grid; grid-template-columns: minmax(150px, 0.7fr) minmax(180px, 1.4fr) minmax(170px, 0.8fr); align-items: center; gap: 28px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.daily-date strong, .daily-date span, .daily-result strong, .daily-result span { display: block; }
.daily-date strong { font-size: 14px; }
.daily-date span { margin-top: 3px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.daily-progress { height: 8px; overflow: hidden; border-radius: 999px; background: #e8ede8; }
.daily-progress i { height: 100%; display: block; border-radius: inherit; background: var(--green); }
.daily-result { text-align: right; }
.daily-result strong { color: var(--green); font-size: 21px; font-variant-numeric: tabular-nums; }
.daily-result span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.daily-accuracy-row.is-empty { opacity: 0.58; }
.daily-accuracy-row.is-empty .daily-progress i { display: none; }
.daily-empty { margin: 0; padding: 44px 14px; border-bottom: 1px solid var(--line); color: var(--muted); text-align: center; font-size: 13px; }

.builder-band { background: #1c2921; color: white; }
.builder-band .section-index { color: #85c69c; }
.builder-band .button-quiet { border-color: #4a5a50; color: #eef4ef; }
.builder-tools { display: flex; gap: 8px; }
.training-mode {
  width: min(620px, 100%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: -8px 0 24px;
}
.training-mode button {
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  border: 1px solid #48574e;
  border-radius: 5px;
  padding: 10px 14px;
  color: #b7c2ba;
  background: transparent;
  text-align: left;
}
.training-mode button strong { color: #eef4ef; font-size: 14px; }
.training-mode button span { font-size: 11px; }
.training-mode button.active { border-color: #9bcbaa; background: #2a3b31; box-shadow: inset 3px 0 #85c69c; }
.part-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid #48574e; }
.part-column { min-width: 0; padding: 24px; border-left: 1px solid #48574e; }
.part-column:first-child { border-left: 0; }
.part-label { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.part-label strong { font-family: Georgia, serif; font-size: 30px; font-weight: 500; }
.part-label span { color: #aab7ae; font-size: 11px; }
.part-select { width: 100%; min-height: 44px; border: 1px solid #59685f; border-radius: 4px; padding: 0 36px 0 11px; color: white; background: #26352c; }
.part-preview { min-height: 94px; padding-top: 18px; }
.part-preview h3 { min-height: 38px; margin: 0 0 12px; font-size: 14px; line-height: 1.45; font-weight: 600; }
.single-picker { display: block; }
.single-part-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid #48574e; }
.single-part-tabs button { min-height: 44px; border: 0; border-left: 1px solid #48574e; color: #aab7ae; background: transparent; font-weight: 750; }
.single-part-tabs button:first-child { border-left: 0; }
.single-part-tabs button.active { color: #17241c; background: #dce9df; }
.single-part-column { max-width: 620px; border-left: 0; }
.preview-placeholder { color: #89988e; font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; min-height: 22px; border-radius: 3px; padding: 3px 7px; font-size: 10px; font-weight: 750; }
.frequency-high { color: #6c250f; background: #ffd9c8; }
.frequency-mid { color: #72560d; background: #f5e5a7; }
.frequency-low { color: #3d596a; background: #dceaf1; }
.status-done { color: #0d5231; background: #d9f0e1; }
.status-undone { color: #606b63; background: #e8ece8; }
.builder-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 22px; }
.builder-footer p { margin: 0; color: #b7c2ba; font-size: 13px; }
.builder-band .button-primary { border-color: #f0f5f1; color: #1c2921; background: #f0f5f1; }
.builder-band .button-primary:hover { background: #dce9df; }
.builder-band .button-primary:disabled { border-color: #405047; color: #819087; background: #314138; }

.library-heading { align-items: center; }
.search-field input { width: min(320px, 42vw); min-height: 42px; border: 1px solid var(--line); border-radius: 5px; padding: 9px 12px; color: var(--ink); background: var(--paper); }
.search-field input:focus, select:focus, .part-select:focus { outline: 3px solid rgba(23, 114, 69, 0.15); border-color: var(--green); }
.filters { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.segmented button { min-height: 36px; border: 0; border-left: 1px solid var(--line); padding: 7px 13px; color: var(--muted); background: white; }
.segmented button:first-child { border-left: 0; }
.segmented button.active { color: white; background: var(--ink); }
.filters select { min-height: 38px; border: 1px solid var(--line); border-radius: 5px; padding: 7px 34px 7px 11px; color: var(--ink); background: white; }
.table-wrap { overflow-x: auto; border-top: 2px solid var(--ink); }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 15px 14px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
td { font-size: 13px; }
.article-cell { display: flex; align-items: center; gap: 12px; }
.article-number { width: 42px; flex: 0 0 42px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.article-title { font-weight: 650; }
.article-part { margin-top: 3px; color: var(--muted); font-size: 11px; }
.score { font-variant-numeric: tabular-nums; font-weight: 700; }
.row-link { color: var(--green); font-weight: 700; white-space: nowrap; }
.row-link:hover { text-decoration: underline; }
.empty-row { padding: 44px 14px; color: var(--muted); text-align: center; }
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; color: var(--muted); font-size: 12px; }

dialog { width: min(440px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 6px; padding: 0; color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(18, 25, 20, 0.45); }
dialog form { padding: 25px; }
dialog p { margin: 22px 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.close-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: white; font-size: 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; border-radius: 4px; padding: 11px 16px; color: white; background: var(--ink); box-shadow: var(--shadow); font-size: 13px; transition: 180ms ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

/* Score History Styles */
.score-history-band { padding: 72px clamp(20px, 4vw, 64px); border-top: 1px solid var(--line); }
.score-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 32px; margin: 42px 0; }
.score-stat { text-align: center; }
.score-stat span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.score-stat strong { display: block; color: var(--green); font-size: 38px; font-weight: 800; line-height: 1; }
.score-history-list { display: grid; gap: 20px; }
.score-history-list .empty-state { padding: 64px 18px; color: var(--muted); text-align: center; }
.score-record { border: 1px solid var(--line); border-radius: 8px; padding: 22px 26px; background: var(--paper); transition: box-shadow 0.2s; }
.score-record:hover { box-shadow: 0 4px 12px rgba(24, 32, 27, 0.06); }
.score-record-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.score-record-title { display: flex; align-items: center; gap: 12px; }
.score-record-number { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.score-record-date { color: var(--ink); font-weight: 650; font-size: 15px; }
.score-record-band { text-align: right; }
.score-record-band strong { display: block; color: var(--green); font-size: 32px; font-weight: 800; line-height: 1; }
.score-record-band span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.score-record-details { display: flex; gap: 24px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.score-record-parts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.part-score { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 6px; background: var(--soft); text-align: center; }
.part-label { color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
.part-result { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 700; }
.part-accuracy { color: var(--green); font-size: 12px; font-weight: 650; }


@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar nav { display: none; }
  .overview-band { grid-template-columns: 1fr; gap: 52px; }
  .today-panel { max-width: 660px; padding-left: 0; border-left: 0; }
  .part-picker { grid-template-columns: repeat(2, 1fr); }
  .part-column:nth-child(3) { border-left: 0; border-top: 1px solid #48574e; }
  .part-column:nth-child(4) { border-top: 1px solid #48574e; }
}

@media (max-width: 640px) {
  .topbar { height: 64px; padding: 0 16px; }
  .brand small, #exportButton { display: none; }
  main > section { scroll-margin-top: 64px; }
  .overview-band, .heatmap-band, .builder-band, .library-band, .score-history-band { padding-left: 18px; padding-right: 18px; }
  .overview-band { min-height: 0; padding-top: 48px; padding-bottom: 54px; }
  h1 { font-size: 43px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); gap: 24px 0; }
  .summary-stat:nth-child(3) { padding-left: 0; border-left: 0; }
  .section-heading { align-items: flex-start; }
  .heatmap-legend { display: none; }
  .daily-accuracy-heading { align-items: flex-start; }
  .daily-accuracy-row { grid-template-columns: 1fr auto; gap: 10px 20px; padding: 14px 0; }
  .daily-progress { grid-column: 1 / -1; grid-row: 2; }
  .daily-result { grid-column: 2; grid-row: 1; }
  .builder-heading, .library-heading { flex-direction: column; align-items: stretch; }
  .builder-tools { width: 100%; }
  .builder-tools .button { flex: 1; }
  .training-mode { grid-template-columns: 1fr; }
  .part-picker { grid-template-columns: 1fr; }
  .part-column { border-left: 0; border-top: 1px solid #48574e; }
  .part-column:first-child { border-top: 0; }
  .builder-footer { align-items: stretch; flex-direction: column; }
  .builder-footer .button { width: 100%; }
  .search-field input { width: 100%; }
  .filters { align-items: stretch; flex-wrap: wrap; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding-left: 8px; padding-right: 8px; }
  .filters select { flex: 1; min-width: 140px; }
  .score-summary { grid-template-columns: repeat(2, 1fr); gap: 24px; }
  .score-record { padding: 18px; }
  .score-record-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .score-record-band { text-align: left; }
  .score-record-parts { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .toast { transition: none; }
}
