:root {
  --bg: #070b14;
  --bg-2: #0d1322;
  --panel: #111a2c;
  --panel-2: #172238;
  --border: rgba(148, 163, 198, 0.14);
  --text: #edf1fb;
  --muted: #8b99b5;
  --accent: #34d399;
  --accent-2: #10b981;
  --accent-glow: rgba(52, 211, 153, 0.35);
  --danger: #fb7185;
  --warn: #fbbf24;
  --info: #60a5fa;
  --radius: 20px;
  --shadow: 0 16px 40px rgba(2, 6, 16, 0.55);
  --glow: 0 0 40px var(--accent-glow);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@property --pct {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(52, 211, 153, 0.07), transparent 60%),
    radial-gradient(900px 420px at 90% 110%, rgba(96, 165, 250, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar::after {
  content: '';
  position: absolute;
  left: 18px; right: 18px; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231a;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.topbar h1 span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.sync-badge {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  opacity: 0.45;
  filter: grayscale(1);
  transition: opacity 0.3s, filter 0.3s, color 0.3s;
}
.sync-badge svg { width: 19px; height: 19px; }
.sync-badge.on { opacity: 1; filter: none; color: var(--accent); }
.streak { font-size: 14px; color: var(--warn); font-weight: 700; }

/* ---------- layout ---------- */
main {
  flex: 1;
  padding: 6px 16px 110px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.view { display: none; }
.view.active { display: block; animation: fadeUp 0.3s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(9, 13, 24, 0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 9px 4px 10px;
  cursor: pointer;
  transition: color 0.25s;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab.active svg { filter: drop-shadow(0 0 8px var(--accent-glow)); }

/* ---------- buttons ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231a;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 800;
  padding: 14px 28px;
  cursor: pointer;
  box-shadow: 0 10px 28px var(--accent-glow);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 12px 34px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary svg { width: 19px; height: 19px; }
.btn-lg { padding: 16px 34px; font-size: 17px; border-radius: 18px; }
.btn-wide { width: 100%; }
.btn-small { font-size: 13px; padding: 9px 14px; border-radius: 11px; }
.btn-secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn-secondary:hover { background: var(--panel); border-color: var(--accent); }
.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(251, 113, 133, 0.06);
  border: 1px solid rgba(251, 113, 133, 0.4);
  color: var(--danger);
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}
.btn-danger:hover { background: rgba(251, 113, 133, 0.12); }
.btn-danger svg { width: 16px; height: 16px; }

/* ---------- badges & chips ---------- */
.badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06231a;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 12px;
}
.badge-soft {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.55; }
.hidden { display: none !important; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), rgba(17, 26, 44, 0.6));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
  box-shadow: 0 8px 30px rgba(2, 6, 16, 0.35);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.panel h2 { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.empty-note { text-align: center; padding: 20px 6px 8px; }
code {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}

/* ---------- dashboard ---------- */
.hero { padding: 6px 0 4px; }
.hero-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 30px 20px 26px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.hero-glow {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 340px; height: 180px;
  background: radial-gradient(50% 50% at 50% 50%, var(--accent-glow), transparent 70%);
  pointer-events: none;
}
.ring {
  position: relative;
  width: 190px; height: 190px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--pct, 0%), rgba(148, 163, 198, 0.12) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: --pct 0.9s cubic-bezier(0.3, 0.8, 0.3, 1);
}
.ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: var(--glow);
  opacity: 0.55;
  pointer-events: none;
}
.ring-inner {
  width: 156px; height: 156px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.ring-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.ring-count { font-size: 38px; font-weight: 800; letter-spacing: -1px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.stat {
  background: linear-gradient(180deg, var(--panel), rgba(17, 26, 44, 0.6));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 4px 11px;
  text-align: center;
}
.stat-ico {
  width: 30px; height: 30px;
  margin: 0 auto 7px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: rgba(148, 163, 198, 0.08);
  border: 1px solid var(--border);
  color: var(--muted);
}
.stat-ico svg { width: 15px; height: 15px; }
.stat-ico-new { color: var(--accent); background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.25); }
.stat-ico-learn { color: var(--info); background: rgba(96, 165, 250, 0.1); border-color: rgba(96, 165, 250, 0.25); }
.stat-ico-due { color: var(--warn); background: rgba(251, 191, 36, 0.1); border-color: rgba(251, 191, 36, 0.25); }
.stat-ico-done { color: var(--accent-2); background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.25); }
.stat-value { display: block; font-size: 21px; font-weight: 800; letter-spacing: -0.3px; }
.stat-label { font-size: 11px; color: var(--muted); font-weight: 600; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 96px;
  padding-top: 8px;
}
.chart-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 5px 5px 2px 2px;
  min-height: 3px;
  position: relative;
  opacity: 0.9;
  transition: opacity 0.2s;
}
.chart-bar:hover { opacity: 1; }
.chart-bar::after {
  content: attr(data-label);
  position: absolute;
  top: -18px; left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- learning pool ---------- */
.pool-list { margin-top: 12px; }
.pool-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(148, 163, 198, 0.08);
}
.pool-item:last-child { border-bottom: none; }
.pool-pos {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  width: 32px;
  flex-shrink: 0;
}
.pool-info { display: flex; align-items: center; gap: 8px; }
.pool-term { font-weight: 700; font-size: 15px; }
.pool-state { font-size: 10px; font-weight: 800; letter-spacing: 0.6px; }

/* ---------- study ---------- */
.session-bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 198, 0.1);
  overflow: hidden;
  margin: 4px 0 12px;
}
.session-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  box-shadow: 0 0 12px var(--accent-glow);
  transition: width 0.5s cubic-bezier(0.3, 0.8, 0.3, 1);
}

.study-top {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 0 0 14px;
  flex-wrap: wrap;
}

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 24px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
  outline: none;
}
.card:focus-visible { border-color: var(--accent); }
.card-anim { animation: cardIn 0.38s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes cardIn {
  0% { opacity: 0.4; transform: translateY(14px) scale(0.985); }
  100% { opacity: 1; transform: none; }
}
.card-prompt-label {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 16px;
}
.card-prompt {
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  line-height: 1.3;
  letter-spacing: -0.3px;
  word-break: break-word;
}

.answer-block { margin-top: 22px; animation: fadeUp 0.35s ease; }
.answer-divider {
  height: 1px;
  margin-bottom: 18px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.answer-term { font-size: 22px; font-weight: 800; text-align: center; letter-spacing: -0.2px; }
.answer-defen { text-align: center; color: var(--muted); margin-top: 6px; font-size: 16px; }
.example {
  margin-top: 16px;
  padding: 14px;
  background: rgba(13, 19, 34, 0.7);
  border: 1px solid rgba(148, 163, 198, 0.1);
  border-radius: 14px;
}
.ex-de { font-size: 15px; line-height: 1.5; }
.ex-en { color: var(--muted); font-size: 14px; line-height: 1.5; margin-top: 6px; }

.grade-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}
.grade {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 8px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text);
  transition: transform 0.15s ease, border-color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.grade:active { transform: scale(0.96); }
.grade-ico { display: grid; place-items: center; }
.grade-ico svg { width: 22px; height: 22px; }
.grade-name { font-size: 16px; font-weight: 800; }
.grade-sub { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.grade-no {
  background: linear-gradient(180deg, rgba(251, 113, 133, 0.14), rgba(251, 113, 133, 0.04));
  border-color: rgba(251, 113, 133, 0.3);
}
.grade-no .grade-ico, .grade-no .grade-name { color: var(--danger); }
.grade-no:hover { border-color: var(--danger); box-shadow: 0 6px 24px rgba(251, 113, 133, 0.18); }
.grade-yes {
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.14), rgba(52, 211, 153, 0.04));
  border-color: rgba(52, 211, 153, 0.3);
}
.grade-yes .grade-ico, .grade-yes .grade-name { color: var(--accent); }
.grade-yes:hover { border-color: var(--accent); box-shadow: 0 6px 24px var(--accent-glow); }

kbd {
  background: rgba(13, 19, 34, 0.8);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-size: 11px;
  padding: 1px 6px;
  font-family: inherit;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- browse ---------- */
.search-wrap { position: relative; }
.search-ico {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--muted);
  pointer-events: none;
}
.search {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  font-size: 15px;
  padding: 12px 14px 12px 40px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12); }
.search::placeholder { color: var(--muted); }
.browse-list { margin-top: 12px; }
.browse-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid rgba(148, 163, 198, 0.08);
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 10px;
}
.browse-item:hover { background: rgba(148, 163, 198, 0.05); }
.browse-item:last-child { border-bottom: none; }
.browse-term { font-weight: 700; font-size: 15px; }
.browse-def { color: var(--muted); font-size: 13px; margin-top: 2px; }
.browse-right { display: flex; align-items: center; gap: 8px; font-size: 11px; }

/* ---------- settings ---------- */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid rgba(148, 163, 198, 0.08);
}
.setting-row:last-child { border-bottom: none; }
.setting-text { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.setting-text strong { font-size: 14.5px; }
.setting-row input[type="number"] {
  width: 64px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 11px;
  padding: 10px;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.setting-row input[type="number"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12); }

.switch {
  position: relative;
  display: inline-block;
  width: 48px; height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.25s, border-color 0.25s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.25s cubic-bezier(0.3, 0.8, 0.3, 1), background 0.25s;
}
.switch input:checked + .slider {
  background: var(--accent-2);
  border-color: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: #06231a;
}
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25); }

.sync-input { margin: 10px 0; }
.sync-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 96px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--panel-2);
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast:not(.hidden) { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 560px) {
  .card { min-height: 320px; }
  .grade-row { gap: 14px; }
}
