:root {
  color-scheme: light;
  --ink: #0b1020;
  --muted: #667085;
  --paper: #f6f7fb;
  --card: #ffffff;
  --line: #dfe3ec;
  --accent: #3157ff;
  --acid: #d9ff55;
  --danger: #c9364b;
  --shadow: 0 18px 60px rgba(31, 41, 73, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(49, 87, 255, .24); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: .75rem; font-weight: 800; letter-spacing: .15em; }
.primary, .secondary, .text-button { border: 0; border-radius: 12px; min-height: 44px; padding: 0 18px; font-weight: 750; }
.primary { background: var(--ink); color: white; }
.primary:hover { background: var(--accent); }
.secondary { border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.secondary:hover { border-color: var(--accent); color: var(--accent); }
.text-button { min-height: 38px; padding: 0 10px; background: transparent; color: var(--muted); }
.text-button:hover { color: var(--ink); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 75% 20%, rgba(49,87,255,.28), transparent 35%), var(--ink); }
.login-card { width: min(100%, 470px); padding: 42px; border: 1px solid rgba(255,255,255,.15); border-radius: 28px; background: rgba(255,255,255,.98); box-shadow: 0 35px 100px rgba(0,0,0,.35); }
.mark, .brand-mark { display: grid; place-items: center; background: var(--acid); color: var(--ink); font-weight: 950; }
.mark { width: 58px; height: 58px; margin-bottom: 32px; border-radius: 16px; font-size: 1.55rem; transform: rotate(-4deg); }
.login-card h1 { margin: 0; max-width: 360px; font-size: clamp(2rem, 7vw, 3.6rem); line-height: .98; letter-spacing: -.06em; }
.login-copy { margin: 18px 0 30px; color: var(--muted); font-size: 1rem; line-height: 1.7; }
.login-card label, .settings-dialog label { display: block; margin: 0 0 8px; font-size: .875rem; font-weight: 700; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
input, select, textarea { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }
input { min-height: 46px; padding: 0 14px; }
.form-message { min-height: 22px; margin: 10px 0 0; color: var(--danger); font-size: .875rem; }
.privacy-note { margin: 20px 0 0; color: var(--muted); font-size: .8rem; }

.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); border-bottom: 1px solid rgba(223,227,236,.85); background: rgba(246,247,251,.88); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -.03em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.topbar nav { display: flex; gap: 3px; }
.workspace { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
.capture-card { position: relative; overflow: hidden; padding: clamp(28px, 5vw, 60px); border-radius: 30px; background: var(--ink); color: white; box-shadow: var(--shadow); }
.capture-card::after { content: "Aa"; position: absolute; right: clamp(15px, 5vw, 70px); top: -42px; color: rgba(217,255,85,.09); font: 900 clamp(9rem, 24vw, 19rem)/1 Georgia, serif; pointer-events: none; }
.capture-card .eyebrow { color: var(--acid); }
.capture-card h1 { position: relative; z-index: 1; margin: 0 0 30px; font-size: clamp(2.2rem, 6vw, 5rem); line-height: .96; letter-spacing: -.065em; }
.capture-form { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; max-width: 760px; }
.capture-form input { min-height: 58px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.1); color: white; font-size: 1.1rem; backdrop-filter: blur(6px); }
.capture-form input::placeholder { color: rgba(255,255,255,.48); }
.capture-button { min-height: 58px; background: var(--acid); color: var(--ink); }
.capture-button:hover { background: white; color: var(--ink); }
.capture-status { position: relative; z-index: 1; min-height: 22px; margin: 14px 0 0; color: rgba(255,255,255,.65); font-size: .875rem; }
.capture-status.error { color: #ff9dad; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0 50px; }
.stats article { padding: 21px 23px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.stats span { display: block; color: var(--muted); font-size: .8rem; }
.stats strong { display: block; margin-top: 4px; font-size: 2rem; letter-spacing: -.05em; }
.library-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.library-head h2 { margin: 0; font-size: 2.2rem; letter-spacing: -.05em; }
.library-actions { display: flex; align-items: center; gap: 8px; }
.search input { width: min(33vw, 280px); }
.library-actions select { min-height: 44px; padding: 0 34px 0 12px; }
.word-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.word-card { position: relative; min-height: 245px; padding: 23px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease; }
.word-card:hover { transform: translateY(-3px); border-color: rgba(49,87,255,.45); box-shadow: var(--shadow); }
.word-card-head { display: flex; justify-content: space-between; gap: 16px; }
.word-card h3 { margin: 0; font: 700 1.8rem/1.1 Georgia, serif; }
.phonetic { margin: 5px 0 0; color: var(--accent); font-size: .85rem; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--muted); font-size: 1rem; }
.icon-button:hover, .icon-button.active { border-color: var(--accent); color: var(--accent); }
.translation { margin: 22px 0 7px; color: var(--ink); font-size: 1.05rem; font-weight: 750; line-height: 1.55; }
.definition { margin: 0; color: #3d465b; font-size: .9rem; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.part { display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.word-card-foot { position: absolute; right: 23px; bottom: 19px; left: 23px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mastery { display: flex; gap: 4px; }
.mastery i { width: 18px; height: 4px; border-radius: 99px; background: var(--line); }
.mastery i.on { background: var(--accent); }
.open-word { border: 0; background: transparent; color: var(--accent); font-weight: 750; }
.empty-state { padding: 70px 24px; border: 1px dashed #cbd1df; border-radius: 24px; text-align: center; }
.empty-state span { display: inline-grid; place-items: center; width: 74px; height: 74px; border-radius: 22px; background: var(--acid); font: 800 1.7rem Georgia, serif; transform: rotate(-3deg); }
.empty-state h3 { margin: 22px 0 8px; font-size: 1.4rem; }
.empty-state p { margin: 0; color: var(--muted); }

dialog { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 24px; color: var(--ink); box-shadow: 0 30px 100px rgba(11,16,32,.28); }
dialog::backdrop { background: rgba(11,16,32,.65); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; z-index: 2; top: 15px; right: 15px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--paper); color: var(--ink); font-size: 1.5rem; }
.detail-shell { padding: 38px; }
.detail-title-row { display: flex; align-items: start; justify-content: space-between; gap: 20px; padding-right: 42px; }
.detail-title-row h2 { margin: 0; font: 750 clamp(2.4rem, 9vw, 5rem)/1 Georgia, serif; letter-spacing: -.04em; }
.speak-button { white-space: nowrap; }
.chinese-meaning { margin-top: 28px; padding: 20px 22px; border-left: 4px solid var(--accent); border-radius: 0 14px 14px 0; background: #eef1ff; }
.chinese-meaning strong { display: block; font-size: 1.2rem; line-height: 1.65; }
.meaning { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.meaning h3 { margin: 0 0 14px; color: var(--accent); font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; }
.meaning ol { margin: 0; padding-left: 22px; }
.meaning li { margin: 0 0 15px; padding-left: 7px; line-height: 1.65; }
.example { display: block; margin-top: 6px; color: var(--muted); font-style: italic; }
.detail-tools { display: grid; gap: 18px; margin-top: 30px; padding: 24px; border-radius: 18px; background: var(--paper); }
.level-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.level-buttons button { min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--muted); }
.level-buttons button.active { border-color: var(--accent); background: var(--accent); color: white; }
.detail-tools textarea { min-height: 100px; resize: vertical; padding: 12px; line-height: 1.5; }
.detail-actions { display: flex; justify-content: space-between; gap: 10px; }
.danger { border: 0; background: transparent; color: var(--danger); }
.settings-dialog { width: min(480px, calc(100% - 28px)); padding: 36px; }
.settings-dialog h2 { margin: 0 0 8px; font-size: 2rem; letter-spacing: -.04em; }
.settings-dialog > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.settings-dialog form { display: grid; margin-top: 25px; }
.settings-dialog label { margin-top: 14px; }
.settings-dialog .primary { margin-top: 18px; }
.toast { position: fixed; z-index: 30; right: 20px; bottom: 20px; max-width: min(390px, calc(100% - 40px)); padding: 13px 17px; border-radius: 12px; background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 880px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .word-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-head { align-items: start; flex-direction: column; }
  .library-actions { width: 100%; flex-wrap: wrap; }
  .search { flex: 1 1 240px; }
  .search input { width: 100%; }
}

@media (max-width: 580px) {
  .topbar { min-height: 64px; padding: 0 14px; }
  .brand small { display: none; }
  .topbar .text-button { padding: 0 7px; font-size: .85rem; }
  .workspace { width: min(100% - 24px, 1180px); padding-top: 20px; }
  .capture-card { padding: 26px 20px; border-radius: 22px; }
  .capture-card h1 { font-size: 2.65rem; }
  .capture-form { grid-template-columns: 1fr; }
  .stats { gap: 7px; margin-bottom: 38px; }
  .stats article { padding: 16px; }
  .word-grid { grid-template-columns: 1fr; }
  .library-actions select, .library-actions .secondary { flex: 1; }
  .login-card { padding: 30px 22px; }
  .password-row { grid-template-columns: 1fr; }
  .detail-shell { padding: 30px 21px; }
  .detail-title-row { display: block; }
  .speak-button { margin-top: 16px; }
  .level-buttons { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
