:root {
  --bg: #fff7fa;
  --surface: #ffffff;
  --surface-soft: #fff5f8;
  --text: #2b1b22;
  --muted: #806873;
  --border: #f0dce4;
  --primary: #d94678;
  --primary-strong: #bd2e63;
  --primary-soft: #ffe7f0;
  --success: #178164;
  --success-soft: #eaf8f3;
  --warning: #b66512;
  --warning-soft: #fff4df;
  --danger: #bd3448;
  --danger-soft: #fff0f3;
  --shadow: 0 18px 50px rgba(122, 51, 78, .09);
  --radius: 20px;
}

[data-theme="dark"] {
  --bg: #1a1015;
  --surface: #261820;
  --surface-soft: #21131a;
  --text: #fff1f6;
  --muted: #c3a6b3;
  --border: #49303b;
  --primary: #f08aaa;
  --primary-strong: #ffabc4;
  --primary-soft: #4a2031;
  --success: #69d3ae;
  --success-soft: #173a30;
  --warning: #f1b960;
  --warning-soft: #3b2b17;
  --danger: #ff91a0;
  --danger-soft: #47232b;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 32%), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.app-shell { max-width: 1460px; margin: 0 auto; padding: 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 13px; flex: 0 0 auto; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(145deg, var(--primary), #ed83a7); color: white; box-shadow: 0 10px 25px color-mix(in srgb, var(--primary) 28%, transparent); }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 42px; padding: 0 14px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 720; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.btn:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; box-shadow: 0 9px 22px color-mix(in srgb, var(--primary) 25%, transparent); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-icon { width: 42px; padding: 0; }
.btn-sm { min-height: 34px; padding: 0 11px; border-radius: 10px; font-size: 13px; }
.danger-text { color: var(--danger) !important; }
.layout { display: grid; grid-template-columns: 285px minmax(0, 1fr); gap: 22px; align-items: start; }
.sidebar { position: sticky; top: 18px; display: grid; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.overview { padding: 20px; }
.overview h2, .tips h2 { font-size: 14px; margin: 0 0 14px; color: var(--muted); font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.stat-list { display: grid; gap: 10px; }
.stat { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; border-radius: 14px; background: var(--surface-soft); border: 1px solid var(--border); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 850; letter-spacing: -.03em; }
.progress-wrap { margin-top: 17px; }
.progress-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.progress { height: 9px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #f18cad); transition: width .4s ease; }
.nav-panel { padding: 10px; max-height: min(520px, 55vh); overflow: auto; }
.nav-item { width: 100%; border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: space-between; padding: 12px 13px; border-radius: 12px; font-weight: 720; text-align: left; }
.nav-item:hover, .nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-left span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; min-width: 27px; height: 23px; padding: 0 7px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.tips { padding: 18px; }
.tips p { margin: 0; color: var(--muted); line-height: 1.65; font-size: 13px; }
kbd { padding: 2px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-soft); font-size: 11px; color: var(--text); }
.main { min-width: 0; }
.toolbar { padding: 14px; display: grid; grid-template-columns: minmax(230px, 1fr) auto auto auto; gap: 10px; margin-bottom: 16px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.control { width: 100%; min-height: 42px; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); border-radius: 12px; padding: 0 13px; }
.search-wrap .control { padding-left: 40px; }
textarea.control { min-height: 92px; padding-top: 11px; resize: vertical; line-height: 1.55; }
.list-panel { overflow: hidden; }
.list-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.list-title { display: flex; align-items: baseline; gap: 9px; }
.list-title h3 { margin: 0; font-size: 16px; }
.list-title span { color: var(--muted); font-size: 13px; }
.word-list { display: grid; }
.word-row { display: grid; grid-template-columns: minmax(190px, 1.1fr) minmax(180px, .9fr) 92px 112px 108px 42px; gap: 16px; align-items: center; padding: 17px 18px; border-bottom: 1px solid var(--border); transition: background .18s ease; }
.word-row:last-child { border-bottom: 0; }
.word-row:hover { background: var(--surface-soft); }
.word-term { min-width: 0; }
.term { font-size: 16px; font-weight: 850; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.meaning { margin-top: 5px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explanation { color: var(--muted); line-height: 1.45; font-size: 13px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.subject { font-weight: 850; font-size: 12px; letter-spacing: .04em; }
.subject-badge, .tag { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); }
.tag { font-size: 11px; margin-right: 5px; background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }
.mastery { display: grid; gap: 6px; }
.mastery-label { font-size: 12px; color: var(--muted); }
.dots { display: flex; gap: 4px; }
.dot { width: 12px; height: 6px; border-radius: 999px; background: var(--border); }
.dot.filled { background: var(--primary); }
.review-status { font-size: 12px; font-weight: 760; color: var(--muted); }
.review-status.due { color: var(--warning); }
.review-status.done { color: var(--success); }
.row-actions { display: flex; justify-content: flex-end; }
.empty { padding: 70px 24px; text-align: center; }
.empty-icon { width: 58px; height: 58px; border-radius: 18px; margin: 0 auto 16px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.empty-icon svg { width: 27px; height: 27px; }
.empty h3 { margin: 0 0 7px; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 450px; line-height: 1.6; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(34, 15, 24, .5); backdrop-filter: blur(7px); display: none; align-items: center; justify-content: center; padding: 18px; z-index: 30; }
.modal-backdrop.open { display: flex; }
.modal { width: min(760px, 100%); max-height: min(870px, calc(100vh - 36px)); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 28px 80px rgba(34, 15, 24, .3); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 20px 22px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.form-group { display: grid; gap: 7px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 800; }
.helper { color: var(--muted); font-size: 11px; line-height: 1.45; }
.required::after { content: " *"; color: var(--danger); }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 22px; border-top: 1px solid var(--border); }
.modal-foot-right { display: flex; gap: 10px; }
.review-card { text-align: center; padding: 28px; }
.review-meta { display: flex; justify-content: center; gap: 8px; margin-bottom: 18px; }
.review-term { font-size: clamp(30px, 5vw, 50px); font-weight: 900; letter-spacing: -.04em; margin: 5px 0 12px; }
.review-prompt { color: var(--muted); margin-bottom: 25px; }
.answer-box { display: none; padding: 22px; text-align: left; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 17px; margin-top: 16px; }
.answer-box.show { display: block; }
.answer-box h4 { margin: 0 0 8px; }
.answer-box p { margin: 8px 0; color: var(--muted); line-height: 1.6; }
.answer-note { margin-top: 14px !important; padding: 13px 15px; border-left: 3px solid var(--primary); border-radius: 0 10px 10px 0; background: color-mix(in srgb, var(--primary-soft) 65%, var(--surface)); color: var(--text) !important; white-space: pre-wrap; }
.rating-grid { display: none; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
.rating-grid.show { display: grid; }
.rating-grid button { min-height: 58px; display: grid; place-items: center; gap: 2px; }
.rating-grid small { font-weight: 500; color: var(--muted); }
.subject-modal { width: min(650px, 100%); }
.subject-add { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.subject-help { margin: 12px 0 18px; }
.subject-list { display: grid; gap: 9px; }
.subject-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.subject-row-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.subject-row-main input { min-width: 0; }
.subject-actions { display: flex; gap: 6px; }
.builtin-lock { color: var(--muted); font-size: 12px; }
.reassign-box { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding-top: 9px; border-top: 1px solid var(--border); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 205px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); display: none; z-index: 12; }
.menu.open { display: grid; }
.menu button { border: 0; background: transparent; color: var(--text); padding: 10px; border-radius: 9px; text-align: left; font-size: 13px; font-weight: 700; }
.menu button:hover { background: var(--surface-soft); }
.hidden-file { display: none; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 60; background: var(--text); color: var(--surface); border-radius: 12px; padding: 12px 15px; box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .24s ease; font-weight: 700; font-size: 13px; max-width: min(420px, calc(100vw - 44px)); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .topbar { align-items: flex-start; }
  .brand p { max-width: 235px; }
}
@media (max-width: 1050px) {
  .layout { grid-template-columns: 1fr; }
  .main { order: 1; }
  .sidebar { order: 2; position: static; grid-template-columns: 1.2fr .8fr; }
  .nav-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); max-height: none; }
  .word-row { grid-template-columns: minmax(180px, 1.1fr) minmax(180px, 1fr) 92px 110px 42px; }
  .word-row .review-col { display: none; }
}
@media (max-width: 760px) {
  .app-shell { padding: 14px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .brand p { max-width: none; }
  .review-label, #accountLabel, .label-hide { display: none; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-wrap { grid-column: 1 / -1; }
  .sidebar { grid-template-columns: 1fr; }
  .tips { display: none; }
  .nav-panel { grid-column: auto; grid-template-columns: repeat(2, 1fr); }
  .word-row { grid-template-columns: 1fr auto; gap: 12px; }
  .word-row .explanation, .word-row .subject-col, .word-row .mastery-col, .word-row .review-col { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: auto; }
  .rating-grid { grid-template-columns: 1fr 1fr; }
  .reassign-box { grid-template-columns: 1fr 1fr; }
  .reassign-box select { grid-column: 1 / -1; }
}
@media (max-width: 470px) {
  .top-actions { display: grid; grid-template-columns: repeat(4, auto) 1fr; }
  .top-actions .btn-primary { grid-column: auto / span 1; }
  .toolbar { grid-template-columns: 1fr; }
  .search-wrap { grid-column: auto; }
  .nav-panel { grid-template-columns: 1fr; }
  .modal-body { padding: 18px; }
  .modal-foot { align-items: stretch; flex-direction: column; }
  .modal-foot-right { display: grid; grid-template-columns: 1fr 1fr; }
  .subject-row { grid-template-columns: 1fr; }
  .subject-actions { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
