:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.07);
}

body.dark {
  --bg: #0b1220;
  --card: #111827;
  --text: #f9fafb;
  --muted: #9ca3af;
  --line: #243041;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --shadow: 0 12px 34px rgba(0,0,0,.22);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { max-width: 780px; margin: 0 auto; padding: 0 18px 96px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 28px 2px 20px; }
h1,h2,h3,p { margin-top: 0; }
h1 { font-size: 1.4rem; margin-bottom: 3px; }
.topbar p { color: var(--muted); margin: 0; font-size: .9rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.hero { display: flex; gap: 20px; align-items: center; justify-content: space-between; padding: 26px; }
.hero h2 { margin: 6px 0 8px; font-size: 1.8rem; }
.hero p { margin: 0; color: var(--muted); }
.eyebrow { font-size: .72rem; font-weight: 800; letter-spacing: .12em; color: var(--accent); }
.primary, .ghost, .quick-actions button, .import-label { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 750; }
.primary { background: var(--accent); color: white; }
.primary:hover { background: var(--accent-2); }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.icon-btn { width: 42px; height: 42px; border-radius: 13px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.stat { padding: 18px; }
.stat span { color: var(--muted); display: block; font-size: .82rem; margin-bottom: 8px; }
.stat strong { font-size: 1.55rem; }
.quick-actions { padding: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-actions button, .import-label { background: var(--bg); color: var(--text); text-align: center; border: 1px solid var(--line); }
.view { display: none; }
.view.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 14px; }
.section-head h2 { margin: 5px 0 0; }
.form-grid { padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: flex; flex-direction: column; gap: 7px; font-weight: 650; font-size: .9rem; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 13px; padding: 12px 13px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.full { grid-column: 1 / -1; }
.check { flex-direction: row; align-items: center; gap: 9px; }
.check input { width: auto; }
.flashcard { padding: 28px; min-height: 420px; display: flex; flex-direction: column; }
.flash-top { display: flex; align-items: center; justify-content: space-between; }
.tag { font-size: .75rem; background: var(--bg); border: 1px solid var(--line); padding: 7px 10px; border-radius: 999px; color: var(--muted); }
.prompt-label { margin-top: 58px; text-align: center; color: var(--muted); letter-spacing: .15em; font-size: .7rem; font-weight: 800; }
.front-text { font-size: 2.4rem; text-align: center; font-weight: 800; margin: 15px 0 36px; line-height: 1.2; }
.reveal { align-self: center; min-width: 170px; }
.answer-area { margin-top: 10px; }
.divider { border-top: 1px solid var(--line); margin: 22px 0; }
.back-text { text-align: center; font-size: 1.7rem; font-weight: 750; }
.example { text-align: center; color: var(--muted); font-style: italic; margin: 14px auto 24px; max-width: 560px; }
.rating-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 9px; }
.rating-grid button { border-radius: 13px; padding: 11px 7px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-weight: 800; }
.rating-grid button span { display: block; font-size: .65rem; color: var(--muted); margin-top: 3px; font-weight: 600; }
.rating-grid .again { border-color: #fecaca; }
.rating-grid .hard { border-color: #fed7aa; }
.rating-grid .good { border-color: #bbf7d0; }
.rating-grid .easy { border-color: #bfdbfe; }
.empty { text-align: center; padding: 55px 25px; }
.big-check { font-size: 3rem; }
.toolbar { padding: 12px; display: grid; grid-template-columns: 1fr 180px; gap: 10px; margin-bottom: 12px; }
.words-list { display: grid; gap: 10px; }
.word-row { padding: 16px 18px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.word-row h3 { margin: 0 0 4px; font-size: 1.05rem; }
.word-row p { margin: 0; color: var(--muted); font-size: .9rem; }
.word-meta { margin-top: 9px; display: flex; gap: 7px; flex-wrap: wrap; }
.word-actions { display: flex; gap: 7px; }
.word-actions button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 11px; padding: 8px 10px; }
.status-pill { font-size: .68rem; background: var(--bg); border: 1px solid var(--line); color: var(--muted); padding: 5px 8px; border-radius: 999px; }
.progress-block { padding: 22px; }
.progress-row { display: grid; grid-template-columns: 80px 1fr 42px; gap: 10px; align-items: center; margin: 17px 0; }
.progress-row > div { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.progress-row i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; }
.bottom-nav { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); width: min(740px, calc(100% - 24px)); display: grid; grid-template-columns: repeat(5,1fr); background: color-mix(in srgb, var(--card) 94%, transparent); border: 1px solid var(--line); border-radius: 20px; padding: 8px; box-shadow: var(--shadow); backdrop-filter: blur(14px); z-index: 20; }
.nav-btn { background: transparent; border: 0; color: var(--muted); border-radius: 13px; padding: 8px 5px; font-weight: 800; font-size: 1.05rem; }
.nav-btn span { display: block; font-size: .64rem; margin-top: 3px; }
.nav-btn.active { color: var(--accent); background: var(--bg); }
.toast { position: fixed; top: 18px; left: 50%; transform: translate(-50%,-20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--card); padding: 10px 15px; border-radius: 12px; transition: .2s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.hidden { display: none !important; }
.small { padding: 9px 13px; }
dialog { border: none; border-radius: 20px; padding: 0; background: transparent; color: var(--text); width: min(520px, calc(100% - 28px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 22px; display: grid; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .hero { align-items: flex-start; flex-direction: column; }
  .hero .primary { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .toolbar { grid-template-columns: 1fr; }
  .rating-grid { grid-template-columns: repeat(2,1fr); }
  .front-text { font-size: 2rem; }
}

.top-actions { display:flex; align-items:center; gap:9px; }
.sync-status { font-size:.72rem; font-weight:800; color:var(--muted); white-space:nowrap; }
.sync-status[data-mode="ok"] { color:#16a34a; }
.sync-status[data-mode="saving"] { color:#d97706; }
.sync-status[data-mode="error"] { color:#dc2626; }
.login-screen { min-height:100vh; display:grid; place-items:center; padding:20px; }
.login-card { width:min(390px,100%); padding:30px; text-align:center; }
.login-card h2 { margin:12px 0 7px; }
.login-card p { color:var(--muted); margin-bottom:20px; }
.login-card form { display:grid; gap:10px; }
.login-mark { width:54px; height:54px; display:grid; place-items:center; margin:auto; border-radius:16px; background:var(--accent); color:white; font-size:1.5rem; font-weight:900; }
.login-error { margin:13px 0 0 !important; color:var(--danger) !important; font-size:.85rem; }
