
:root {
  --bg: #f6f7f4;
  --panel: #fff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #d9ddd5;
  --accent: #2f6f73;
  --accent-soft: #e3f0ec;
  --danger: #9f3a38;
  --gold: #b7791f;
  --side: #fbfbf8;
  --field: #fff;
  --link: #1d4e52;
  --header: rgba(246, 247, 244, 0.94);
}
[data-theme="dark"] {
  --bg: #111816;
  --panel: #18211f;
  --ink: #edf2ef;
  --muted: #a9b6b0;
  --line: #33413c;
  --accent: #7ab7aa;
  --accent-soft: #213732;
  --danger: #f0a29d;
  --gold: #e6c36a;
  --side: #141c1a;
  --field: #101715;
  --link: #8dc9bc;
  --header: rgba(17, 24, 22, 0.94);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111816;
    --panel: #18211f;
    --ink: #edf2ef;
    --muted: #a9b6b0;
    --line: #33413c;
    --accent: #7ab7aa;
    --accent-soft: #213732;
    --danger: #f0a29d;
    --gold: #e6c36a;
    --side: #141c1a;
    --field: #101715;
    --link: #8dc9bc;
    --header: rgba(17, 24, 22, 0.94);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", sans-serif;
  padding-top: 42px;
}
button, input, select { font: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 11px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--link); }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--link); }
.sidebar-toggle {
  position: fixed;
  top: 5px;
  left: 6px;
  z-index: 31;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 900;
}
.kp-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 320px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--side);
  padding: 18px;
  transform: translateX(-104%);
  transition: transform 180ms ease;
  z-index: 30;
  box-shadow: 14px 0 32px rgba(0, 0, 0, 0.14);
}
body.sidebar-open .kp-sidebar { transform: translateX(0); }
.kp-brand { display: grid; gap: 4px; margin-bottom: 14px; }
.kp-brand strong { font-size: 20px; padding-left: 34px; }
.kp-brand span, .kp-note, .card-meta { color: var(--muted); font-size: 13px; }
.kp-link {
  display: block;
  color: var(--link);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: var(--field);
  margin-bottom: 8px;
  font-weight: 700;
}
.kp-link:hover { background: var(--accent-soft); border-color: var(--accent); }
.kp-field { display: grid; gap: 6px; margin: 12px 0; }
.kp-field input, .kp-field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 12px;
}
.kp-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.kp-actions button { flex: 1 1 120px; }
.kp-note { margin-top: 16px; }
.kp-main { margin-left: 0; min-height: 100vh; }
.kp-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 42px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
  backdrop-filter: blur(10px);
  padding: 5px 8px 5px 44px;
}
.deck-strip, .top-card-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.deck-strip {
  flex: 0 1 auto;
  width: calc(100% - 220px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.deck-strip::-webkit-scrollbar, .top-card-actions::-webkit-scrollbar { display: none; }
.deck-stat {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 2px 8px;
  line-height: 1.25;
}
.deck-stat strong { font-size: 16px; line-height: 1; }
.deck-stat em { font-style: normal; color: var(--muted); font-size: 11px; white-space: nowrap; }
.stat-unseen { border-color: #a7c7e7; }
.stat-learning { border-color: #e2c47b; }
.stat-due { border-color: #e0a39f; }
.stat-mastery { border-color: #9fcdbd; }
.stat-exam { border-color: #b8abd9; }
.exam-field small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.exam-setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}
.exam-setting-row input,
.exam-setting-row button {
  min-width: 0;
}
.exam-setting-row button {
  padding-inline: 10px;
  white-space: nowrap;
}
.top-card-actions {
  position: absolute;
  top: 5px;
  right: 8px;
  z-index: 2;
  flex: 0 1 auto;
  justify-content: flex-end;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--header);
}
.top-card-actions button {
  flex: 0 0 auto;
  height: 30px;
  padding: 3px 8px;
  font-size: 13px;
  white-space: nowrap;
}
.star-button {
  width: 32px;
  padding: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
.star-button.active { color: var(--gold); border-color: var(--gold); background: var(--panel); }
.review-panel, .card-list {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px clamp(16px, 4vw, 44px) 0;
}
.review-panel { padding-bottom: 84px; }
.card-list { padding-bottom: 80px; }
.study-card, .browse-card, .inspect-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 30px);
}
.study-card.marked, .browse-card.marked, .inspect-card.marked {
  border-color: var(--gold);
  box-shadow: inset 4px 0 0 var(--gold);
}
.study-card.linked-target, .browse-card.linked-target, .inspect-card.linked-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), inset 4px 0 0 var(--accent);
}
.study-card { min-height: 380px; display: grid; gap: 18px; }
.browse-card { margin-bottom: 14px; }
.inspect-card { margin-bottom: 14px; }
.inspect-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(0, 1.4fr);
  gap: 16px;
}
.inspect-front, .inspect-back {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--side);
}
.inspect-front h2, .inspect-back h3 {
  margin: 0 0 10px;
  line-height: 1.35;
}
.inspect-front h2 { font-size: 20px; }
.inspect-back h3 { font-size: 15px; color: var(--muted); }
.card-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--side);
}
.next-due {
  color: var(--muted);
  font-size: 14px;
}
.note-box {
  display: grid;
  gap: 7px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.note-box label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.note-box textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}
.note-box.compact textarea { min-height: 64px; }
.highlight-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.highlight-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  padding: 2px 7px;
  font-size: 12px;
}
.highlight-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}
.highlight-chip button {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  line-height: 1;
}
.user-highlight {
  background: #fff2a8;
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}
[data-theme="dark"] .user-highlight {
  background: #6f5f12;
}
.shortcut {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 5px;
  margin-right: 6px;
  font-size: 12px;
  font-weight: 800;
}
.front {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.35;
}
.blank-reveal {
  display: inline-flex;
  align-items: center;
  min-height: 1.45em;
  max-width: min(100%, 22em);
  border: 1px solid var(--link);
  border-radius: 7px;
  background: var(--field);
  color: var(--link);
  padding: 0.08em 0.45em;
  margin: 0 0.12em;
  font: inherit;
  font-size: 0.82em;
  font-weight: 800;
  vertical-align: baseline;
  cursor: pointer;
}
.blank-reveal .blank-answer {
  display: none;
  overflow-wrap: anywhere;
  text-align: left;
}
.blank-reveal.revealed {
  color: var(--text);
  border-color: var(--green);
  background: color-mix(in srgb, var(--panel) 78%, var(--green) 22%);
}
.blank-reveal.revealed .blank-placeholder { display: none; }
.blank-reveal.revealed .blank-answer { display: inline; }
.answer {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.answer.hidden { display: none; }
.rating-actions.hidden, .next-due.hidden { display: none; }
.answer p { margin: 0 0 10px; text-align: justify; }
.answer ul { margin: 0 0 10px; padding-left: 1.4em; }
.answer li { margin: 6px 0; }
.answer-section {
  border-left: 3px solid var(--line);
  padding: 2px 0 2px 12px;
  margin: 10px 0;
}
.answer-section-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  color: var(--link);
  font-size: 15px;
  font-weight: 800;
}
.answer-section-title::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}
.answer-section .answer-list { margin-bottom: 6px; }
.answer-lead {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 9px 11px;
  margin: 8px 0 10px;
  font-weight: 700;
}
.answer-flow {
  display: grid;
  gap: 6px;
  margin: 8px 0 10px;
  padding: 0;
  list-style: none;
  counter-reset: flow;
}
.answer-flow li {
  counter-increment: flow;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
}
.answer-flow li::before {
  content: counter(flow);
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--field);
  color: var(--link);
  font-size: 12px;
  font-weight: 800;
}
.answer table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.answer td, .answer th { border: 1px solid var(--line); padding: 7px 8px; vertical-align: top; }
.answer .table-wrap { overflow-x: auto; }
.textbook-ref {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 0;
  margin: 10px 0;
  font-size: 14px;
  overflow: hidden;
}
.textbook-ref summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 10px;
  cursor: pointer;
  list-style: none;
}
.textbook-ref summary::-webkit-details-marker { display: none; }
.textbook-ref summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}
.textbook-ref[open] summary::after { transform: rotate(180deg); }
.textbook-ref strong { color: var(--link); white-space: nowrap; }
.textbook-ref .ref-title { color: var(--text); font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.textbook-ref a { color: var(--link); text-decoration: none; font-weight: 800; }
.textbook-ref small { display: block; color: var(--muted); margin-top: 4px; }
.ref-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; vertical-align: middle; }
.ref-tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(47, 111, 115, 0.1);
  color: var(--link);
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.5;
}
.ref-tag.warn { background: rgba(180, 115, 20, 0.12); color: var(--gold); }
.ref-body {
  border-top: 1px solid var(--line);
  padding: 8px 10px 10px;
}
.ref-evidence { display: block; color: var(--muted); margin: 0 0 8px; font-size: 12px; line-height: 1.55; }
.ref-open { display: inline-flex; align-items: center; min-height: 28px; }
.math-inline {
  font-family: "Times New Roman", Georgia, serif;
  font-style: italic;
  white-space: nowrap;
}
sub, sup { font-size: 0.72em; line-height: 0; }
.review-actions, .rating-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.study-card .rating-actions {
  position: fixed;
  left: 50%;
  bottom: 8px;
  z-index: 21;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 16px));
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--header);
  backdrop-filter: blur(10px);
  padding: 6px;
  box-shadow: 0 -8px 26px rgba(0, 0, 0, 0.08);
}
.study-card .rating-actions::-webkit-scrollbar { display: none; }
.rating-actions button {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 2px 0;
  min-width: 130px;
  text-align: left;
}
.study-card .rating-actions button { flex: 1 0 132px; min-height: 42px; }
.rating-actions button .next-due {
  grid-column: 2;
  font-size: 12px;
}
.rating-actions button[data-rating="again"] { border-color: #e5b8b5; color: var(--danger); }
.rating-actions button[data-rating="hard"] { border-color: #e8d6a8; color: var(--gold); }
.rating-actions button[data-rating="good"], .rating-actions button[data-rating="easy"] { border-color: #b9d6cb; color: var(--link); }
.empty {
  text-align: center;
  color: var(--muted);
  padding: 70px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.kp-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--link);
  color: #fff;
  padding: 10px 14px;
  border-radius: 7px;
  opacity: 0;
  transform: translateY(8px);
  transition: 160ms ease;
  pointer-events: none;
}
.kp-toast.show { opacity: 1; transform: translateY(0); }
.selection-bubble {
  position: fixed;
  z-index: 40;
  display: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  padding: 3px;
}
.selection-bubble.show { display: block; }
.selection-bubble button {
  height: 28px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
}
@media (max-width: 860px) {
  .kp-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 320px);
    max-height: none;
    min-height: 0;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding: 18px;
    display: block;
    overflow: auto;
  }
  .kp-brand { display: grid; }
  .kp-link { display: block; }
  .kp-field { display: grid; margin: 12px 0; }
  .kp-field span, .kp-note { display: block; }
  .kp-field input, .kp-field select { height: auto; padding: 10px 12px; font-size: 16px; width: 100%; }
  .kp-actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; overflow: visible; padding: 0; }
  .kp-actions button { flex: 1 1 120px; height: auto; padding: 8px 11px; font-size: 15px; white-space: normal; }
  .review-panel, .card-list { padding-top: 14px; }
  .study-card { min-height: 0; gap: 12px; }
  .study-card, .browse-card, .inspect-card { padding: 14px; }
  .top-card-actions button {
    flex: 0 0 auto;
    min-width: auto;
    height: 30px;
    padding: 5px 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  .top-card-actions .star-button { width: 30px; padding: 0; }
  .review-actions, .rating-actions { gap: 6px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .rating-actions button, .review-actions button { flex: 0 0 auto; min-width: auto; min-height: 34px; padding: 5px 8px; font-size: 13px; white-space: nowrap; }
  .rating-actions button { grid-template-columns: auto auto; }
  .rating-actions button .next-due { display: none; }
  .study-card .rating-actions { padding: 4px; bottom: 6px; border-radius: 8px; }
  .study-card .rating-actions button {
    flex: 1 0 78px;
    width: 78px;
    min-height: 34px;
    height: 34px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
  }
  .note-box { gap: 6px; padding-top: 10px; }
  .note-box textarea { min-height: 58px; }
  .inspect-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  body { font-size: 15px; }
  .kp-sidebar { padding: 16px; }
  .kp-topbar { padding-right: 4px; gap: 4px; }
  .deck-strip { gap: 4px; width: calc(100% - 172px); }
  .top-card-actions { right: 4px; }
  .deck-stat { padding: 2px 6px; gap: 3px; }
  .deck-stat strong { font-size: 14px; }
  .deck-stat em { font-size: 10px; }
  .top-card-actions { gap: 4px; }
  .top-card-actions button { font-size: 12px; padding: 3px 6px; }
  .top-card-actions .star-button { width: 28px; }
  .review-panel, .card-list { padding: 10px 10px 0; }
  .front { font-size: 22px; }
  .card-meta { gap: 5px; }
  .badge { font-size: 12px; padding: 1px 6px; }
  .answer { padding-top: 12px; }
  .answer p { margin-bottom: 8px; }
  .shortcut { min-width: 18px; height: 18px; border-radius: 4px; font-size: 11px; margin-right: 4px; }
}
