:root {
  color-scheme: light;
  --canvas: #f6f5f1;
  --surface: #fffdfa;
  --ink: #222538;
  --muted: #565b70;
  --line: #dfded8;
  --accent: #3c3974;
  --active: #eae7f6;
  --hero: #eae7f6;
  --button: #3c3974;
  --button-ink: #fff;
  --shadow: 0 1px 2px #22253809;
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #1a1b25;
  --surface: #222331;
  --ink: #f0eef7;
  --muted: #bdbbd0;
  --line: #383a4d;
  --accent: #d0c9ff;
  --active: #373253;
  --hero: #2d2945;
  --button: #d0c9ff;
  --button-ink: #26213d;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:where(a, button, input, select, [tabindex="0"]):focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
h1, h2, p, dl, dd { margin: 0; }

.visually-hidden, .skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip:focus { position: fixed; inset: 0 auto auto 0; z-index: 10; background: var(--surface); padding: 12px; }
.layout { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 34px;
  padding: 28px 20px 18px;
  border-inline-end: 1px solid var(--line);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 12px; font: 700 22px/1.15 Georgia, "Times New Roman", serif; }
.brand small { display: block; margin-top: 6px; color: var(--muted); font: 12px/1.2 "Segoe UI", "Microsoft YaHei UI", sans-serif; }
.monogram {
  display: grid;
  place-content: center;
  grid-auto-flow: column;
  flex: 0 0 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-ink);
  letter-spacing: -0.12em;
  padding-right: 2px;
  font-size: 22px;
}
.monogram span { transform: translateY(3px); font-size: 19px; }
.navigation { display: grid; gap: 5px; }
.navigation a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 14px;
}
.navigation a span { width: 20px; flex: 0 0 20px; text-align: center; font-size: 17px; line-height: 1; }
.navigation a[aria-current="page"] { background: var(--active); color: var(--accent); font-weight: 700; }
.navigation a:hover { background: var(--active); color: var(--accent); }
.sidebar-foot {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding: 16px 4px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.bar {
  min-height: 65px;
  padding: 8px clamp(22px, 4vw, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.breadcrumb { color: var(--muted); font-size: 13px; }
.breadcrumb span:first-child { margin: 0 6px; }
.breadcrumb span:last-child { color: var(--ink); }
.theme-button, .menu-button, .theme-options button {
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.sidebar-menu { display: none; }
.theme-button span:first-child, .menu-button span { margin-right: 3px; }
.theme-button:hover, .menu-button:hover, .theme-options button:hover { background: var(--active); }

main { max-width: 1220px; margin: 0 auto; padding: 42px clamp(22px, 4vw, 58px) 52px; }
.page-heading { margin-bottom: 24px; }
.page-date { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
h1 { font-size: clamp(30px, 4.2vw, 43px); font-weight: 700; line-height: 1.2; letter-spacing: -0.025em; }
h2 { font-size: 17px; line-height: 1.45; }

.welcome {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px 28px;
  padding: clamp(22px, 3.3vw, 38px);
  min-height: 142px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--hero);
  color: var(--accent);
}
.welcome h2 { font-size: clamp(22px, 3vw, 29px); }
.welcome p, .panel p { margin-top: 7px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  gap: 14px;
  min-height: 44px;
  padding: 10px 17px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.action:hover { text-decoration: underline; }
.primary { align-self: center; color: var(--button-ink); background: var(--button); }
.secondary { margin-top: 18px; color: var(--accent); background: var(--active); }
.metrics, .dashboard-details { display: grid; gap: 14px; margin-top: 18px; }
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dashboard-details { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
.metrics > div, .panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metrics dt { color: var(--muted); font-size: 13px; }
.metrics dd { margin-top: 11px; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.panel { padding: 22px; }
.panel .empty { display: grid; place-items: center; text-align: center; padding: 18px 0 10px; min-height: 92px; }
.page-note { min-height: 138px; }
.settings-panel { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; }
.theme-options { display: flex; gap: 8px; }
.theme-options button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--active); }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; gap: 0; overflow: visible; padding: 13px 18px; border-inline-end: 0; }
  .brand { width: fit-content; }
  .brand small { margin-top: 3px; }
  .monogram { flex-basis: 36px; height: 36px; }
  .sidebar-foot { display: none; }
  .sidebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .sidebar-menu { display: block; }
  .navigation { display: none; grid-column: 1 / -1; padding-top: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .navigation[data-open] { display: grid; }
  .bar { min-height: 57px; padding-inline: 18px; border-top: 1px solid var(--line); }


  .breadcrumb { flex: 1; }
  main { padding: 25px 18px 34px; }
}

@media (max-width: 500px) {
  .welcome { flex-direction: column; align-items: flex-start; }
  .welcome .primary { align-self: flex-start; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-details { grid-template-columns: minmax(0, 1fr); }
  .metrics > div, .panel { padding: 16px; }
}
.library-intro { margin: -11px 0 17px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.library-books { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.library-book { display: flex; flex-direction: column; }
.library-book > p { flex: 1; overflow-wrap: anywhere; }
.library-book .action { margin-top: 14px; border: 1px solid transparent; }
button:disabled { cursor: default; opacity: 0.56; }
.library-notice { min-height: 19px; margin: 10px 0; color: var(--muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.library-notice.error { color: #963b32; }
:root[data-theme="dark"] .library-notice.error { color: #ffb4aa; }
.dictionary-filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 15px 0 0;
  padding: 0;
  min-width: 0;
  border: 0;
}
.dictionary-filters label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.dictionary-filters input, .dictionary-filters select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
  color: var(--ink);
  font: inherit;
}
.dictionary-filters :disabled { opacity: 0.6; }
.dictionary-summary { padding: 8px 0; }
.dictionary-rows, .settings-books { list-style: none; margin: 0; padding: 0; }
.dictionary-rows li { border-top: 1px solid var(--line); }
.word-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.65fr) minmax(62px, auto);
  gap: 8px 13px;
  width: 100%;
  min-height: 49px;
  align-items: center;
  padding: 10px 8px;
  border: 0;
  border-radius: 6px;
  text-align: left;
  background: transparent;
}
.word-row:hover { background: var(--active); }
.headword { font-family: Georgia, "Times New Roman", serif; font-size: 18px; overflow-wrap: anywhere; }
.word-preview { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.word-book { color: var(--accent); font-size: 12px; text-align: end; }
.dictionary-pager { display: flex; justify-content: flex-end; gap: 8px; padding-top: 14px; }
.word-detail { width: min(620px, calc(100% - 32px)); max-height: 82dvh; color: var(--ink); overflow: auto; }
.word-detail::backdrop { background: #1717269c; }
.word-detail-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.word-detail-header > div { min-width: 0; }
.word-detail h2 { font: 700 clamp(28px, 6vw, 42px)/1.14 Georgia, "Times New Roman", serif; overflow-wrap: anywhere; }
.word-detail-header button { white-space: nowrap; }
.source-record { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.source-record h3 { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.word-meanings { padding: 0; margin: 0; list-style: none; display: grid; gap: 8px; }
.word-meanings li { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 9px; line-height: 1.6; overflow-wrap: anywhere; }
.word-type { color: var(--accent); background: var(--active); padding: 1px 7px; border-radius: 5px; font-size: 12px; }
.word-phrases { margin-top: 13px; color: var(--muted); font-size: 14px; }
.word-phrases summary { width: fit-content; padding: 6px 0; cursor: pointer; color: var(--accent); }
.word-phrases dt { margin-top: 10px; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.word-phrases dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.settings-library { margin-top: 14px; }
.settings-books li { display: flex; gap: 4px 12px; justify-content: space-between; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.settings-books span { color: var(--muted); }

@media (max-width: 620px) {
  .library-books { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .library-book { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 8px; align-items: center; }
  .library-book p { grid-row: 2; margin-top: 0; font-size: 12px; }
  .library-book .action { grid-column: 2; grid-row: 1 / 3; align-self: center; margin: 0; padding-inline: 10px; }
  .dictionary-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dictionary-filters label:first-of-type { grid-column: 1 / -1; }
  .word-row { grid-template-columns: minmax(0, 1fr) auto; }
  .word-preview { grid-row: 2; grid-column: 1 / -1; }
  .word-book { grid-column: 2; grid-row: 1; }
}

.study-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0;
  margin: 0;
  border: 0;
  min-width: 0;
}
.study-controls label, .study-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.study-controls select, .study-fields input {
  min-height: 44px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--canvas);
  font: inherit;
}
.study-controls select { min-width: 126px; }
.study-card { padding: clamp(16px, 3.8vw, 35px); }
.study-card-header, .study-card-header > div, .study-actions, .study-ratings, .study-move, .study-backup-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.study-card-header, .study-actions { justify-content: space-between; }
.study-card-header > div { gap: 6px 13px; color: var(--muted); font-size: 13px; }
.study-card-header > div span:first-child { color: var(--accent); font-weight: 700; }
.study-headword { margin-top: 14px; font: 700 clamp(38px, 7vw, 76px)/1.1 Georgia, "Times New Roman", serif; overflow-wrap: anywhere; }
.study-phonetics:empty { display: none; }
.study-card .action { border: 1px solid transparent; cursor: pointer; }
.study-actions { border-top: 1px solid var(--line); margin-top: 23px; padding-top: 16px; gap: 14px; }
.study-ratings :is(.action,.theme-button), .study-move .theme-button { min-height: 44px; }
.study-progress { display: block; accent-color: var(--accent); width: 100%; height: 12px; margin-top: 18px; }
.dashboard-progress p { margin-top: 9px; }
.recent-list { list-style: none; padding: 0; margin: 9px 0 0; }
.recent-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 6px 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.recent-list :is(span,time) { color: var(--muted); }
.recent-list strong { overflow-wrap: anywhere; }
.study-settings { margin-top: 14px; }
.study-settings .action { border: 1px solid transparent; }
.study-settings .library-notice { min-height: 0; margin-bottom: 0; }
.study-settings .library-notice:empty { display: none; }
.study-settings .library-notice.error { color: #963b32; }
:root[data-theme="dark"] .study-settings .library-notice.error { color: #ffb4aa; }
.study-fields { margin-top: 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.study-fields input { width: 100%; }

@media (max-width: 500px) {
  .study-ratings, .study-move { width: 100%; }
  .study-ratings > *, .study-move > * { flex: 1; text-align: center; }
  .recent-list li { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .recent-list time { grid-column: 1 / -1; }
}

.quiz-setup .action, .quiz-card .action { border: 1px solid transparent; cursor: pointer; }
.quiz-fields { max-width: 680px; margin-bottom: 16px; }
.quiz-fields select, .quiz-answer-form input {
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
  color: var(--ink);
  font: inherit;
}
.text-link { display: inline-block; margin: 8px 0 8px 12px; color: var(--accent); font-size: 14px; text-decoration: underline; }
.quiz-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
#quiz-prompt { margin: 10px 0 18px; font-size: clamp(23px, 4vw, 38px); line-height: 1.3; overflow-wrap: anywhere; }
#quiz-prompt[lang="en"] { font-family: Georgia, "Times New Roman", serif; }
.quiz-spelling { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.quiz-spelling span { font: 700 17px/1.4 Consolas, monospace; }
.quiz-answer-form, .quiz-footer { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-answer-form input { flex: 1; }
.quiz-answer-form .action { align-self: stretch; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quiz-option {
  padding: 12px;
  min-height: 44px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
  overflow-wrap: anywhere;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent); background: var(--active); }
.quiz-option[data-result] { opacity: 1; }
.quiz-option[data-result="correct"] { background: var(--active); border-color: var(--accent); }
.quiz-option[data-result="wrong"] { border-color: #b86359; }
.quiz-feedback { margin-top: 14px; padding: 13px; border-inline-start: 3px solid var(--accent); border-radius: 4px; background: var(--active); }
.quiz-feedback p { overflow-wrap: anywhere; }
.quiz-footer { margin-top: 14px; }
.quiz-footer .secondary { margin-top: 0; }
.quiz-summary, .quiz-history { margin-top: 14px; }
.word-history summary { width: fit-content; cursor: pointer; color: var(--accent); }

.stat-figures { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin-top: 14px; }
.stat-figure { margin: 0; min-width: 0; }
.stat-section { margin-top: 14px; }
.stat-key { display: flex; gap: 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.stat-key span::before { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--accent); content: ""; }
.stat-key span:nth-child(2)::before { background: #678b76; }
.stat-scroll { overflow-x: auto; }
.stat-chart { display: grid; grid-auto-columns: minmax(0,1fr); grid-auto-flow: column; gap: 2px; min-width: 0; padding-top: 14px; }
.stat-chart[data-days="30"] { min-width: 360px; }
.stat-day { display: grid; grid-template-rows: 112px 18px; min-width: 0; }
.stat-bars { display: flex; align-items: end; justify-content: center; gap: 2px; padding: 0 1px; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to top, transparent 0 calc(25% - 1px), var(--line) calc(25% - 1px) 25%); }
.stat-bar { display: block; width: min(42%, 18px); height: var(--height); border-radius: 2px 2px 0 0; background: var(--accent); }
.stat-reviewed { background: #678b76; }
.stat-correct[data-zero] { min-height: 2px; }
.stat-tick { font-size: 10px; color: var(--muted); white-space: nowrap; align-self: end; }
.stat-chart[data-days="30"] .stat-day:last-child .stat-tick { justify-self: end; }
.stat-mastery { margin: 8px 0 0; padding: 0; list-style: none; }
.stat-mastery li { display: grid; grid-template-columns: 62px minmax(0,1fr) minmax(42px,auto); align-items: center; gap: 12px; padding: 8px 0; color: var(--muted); font-size: 13px; }
.stat-mastery progress { width: 100%; height: 10px; accent-color: var(--accent); }
.stat-mastery strong { text-align: right; color: var(--accent); }
.stat-section summary { cursor: pointer; font-weight: 700; }
.stat-table { margin-top: 12px; border-collapse: collapse; width: 100%; font-size: 13px; }
.stat-table :is(th,td) { padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: right; }
.stat-table th:first-child { text-align: left; }

@media (max-width: 880px) {
  .stat-figures { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 500px) {
  .quiz-choices { grid-template-columns: minmax(0,1fr); }
  .quiz-answer-form input { min-width: 130px; }
}

[data-empty-hint]:empty { display: none; }

@media (max-width: 620px) {
  :is(.study-controls, .study-fields, .dictionary-filters, .quiz-answer-form) :is(input, select) { font-size: 16px; }
  .quiz-answer-form input { width: min(100%, 240px); }
  .library-book .action { min-height: 44px; }
}
.breadcrumb { display: flex; align-items: center; min-width: 0; }
.breadcrumb .current-profile {
  min-width: 0;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breadcrumb .current-profile:hover { text-decoration: underline; }
.breadcrumb #current-page { flex: 0 0 auto; }
.profile-list { list-style: none; padding: 0; margin: 10px 0 0; }
.profile-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.profile-list :is(strong,a) { overflow-wrap: anywhere; }
.profile-list a { padding-block: 9px; color: var(--accent); text-decoration: underline; }
.profile-list span { flex: 0 0 auto; color: var(--muted); font-size: 13px; }
.profile-create { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; margin-top: 14px; }
.profile-create label { display: grid; gap: 5px; flex: 1 1 160px; max-width: 18rem; color: var(--muted); font-size: 13px; }
.profile-create input {
  min-height: 44px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--canvas);
  font: inherit;
}
.profile-create .action { align-self: end; margin: 0; }
@media (max-width: 620px) {
  .profile-create input { font-size: 16px; }
}

#account-panel .study-fields input { max-width: 24rem; }
#account-target, #account-summary { overflow-wrap: anywhere; }
.account-fields { margin-top: 10px; }