:root {
  --bg: #0b1220;
  --bg-elevated: #111827;
  --surface: #151d2e;
  --surface-2: #1a2438;
  --border: rgba(148, 163, 184, 0.14);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-2: #818cf8;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --physics: #60a5fa;
  --biology: #34d399;
  --math: #fbbf24;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(56, 189, 248, 0.12), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(129, 140, 248, 0.12), transparent 45%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 18px);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #0b1220;
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.25);
}
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
}
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  color: var(--muted);
}
.sync-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.sync-pill.on .dot { background: var(--success); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15); }

/* Subject switcher */
.subject-switch {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 8px;
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.subject-chip {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 8px;
  font-weight: 700;
  font-size: 0.85rem;
  transition: 0.15s ease;
}
.subject-chip.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow);
}
.subject-chip[data-subject="Physics"].active { color: var(--physics); }
.subject-chip[data-subject="Biology"].active { color: var(--biology); }
.subject-chip[data-subject="Math"].active { color: var(--math); }

/* Widgets grid */
.widgets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (min-width: 720px) {
  .widgets { grid-template-columns: repeat(4, 1fr); }
}
.widget {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  min-height: 96px;
}
.widget .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 6px;
}
.widget .value {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}
.widget .sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.widget.accent-physics { border-color: rgba(96, 165, 250, 0.35); }
.widget.accent-biology { border-color: rgba(52, 211, 153, 0.35); }
.widget.accent-math { border-color: rgba(251, 191, 36, 0.35); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: #082f49;
}
.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn-danger {
  background: rgba(251, 113, 133, 0.12);
  color: var(--danger);
  border: 1px solid rgba(251, 113, 133, 0.25);
}
.btn-success {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.25);
}
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Task / topic cards */
.task-list, .topic-list, .paper-list { display: flex; flex-direction: column; gap: 10px; }
.task-card, .topic-card, .paper-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.task-card.done { opacity: 0.65; border-color: rgba(52, 211, 153, 0.35); }
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}
.badge.physics { background: rgba(96, 165, 250, 0.15); color: var(--physics); }
.badge.biology { background: rgba(52, 211, 153, 0.15); color: var(--biology); }
.badge.math { background: rgba(251, 191, 36, 0.15); color: var(--math); }
.badge.weak { background: rgba(251, 113, 133, 0.12); color: var(--danger); }
.badge.due { background: rgba(251, 191, 36, 0.12); color: var(--warn); }
.badge.new { background: rgba(56, 189, 248, 0.12); color: var(--primary); }
.badge.done { background: rgba(52, 211, 153, 0.12); color: var(--success); }

.today-date {
  margin: 4px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.01em;
}

.badge-legend .badge {
  vertical-align: middle;
  margin-right: 2px;
}

.task-title, .topic-title {
  margin: 8px 0 4px;
  font-weight: 750;
  font-size: 1.02rem;
}
.reason, .meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
}
.progress {
  height: 8px;
  background: rgba(148, 163, 184, 0.12);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 12px;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-2), var(--primary));
}

/* Forms */
.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; }
.conf-val { min-width: 3rem; text-align: right; font-weight: 800; color: var(--primary); }

/* Charts */
.chart-box {
  position: relative;
  width: 100%;
  height: 220px;
  margin-top: 4px;
}
.chart-box.sm { height: 180px; }
.chart-grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 720px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
}

/* Focus timer */
.timer-display {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: center;
  margin: 8px 0 12px;
  font-variant-numeric: tabular-nums;
}
.timer-ring {
  width: 100%;
  max-width: 220px;
  margin: 0 auto 12px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, var(--surface) 62%, transparent 63%),
    conic-gradient(var(--primary) var(--p, 0%), rgba(148,163,184,0.15) 0);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 50;
}
.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  font-weight: 700;
}
.nav-item .ico { font-size: 1.15rem; line-height: 1; }
.nav-item.active {
  color: var(--primary);
  background: rgba(56, 189, 248, 0.08);
}

/* Views */
.view { display: none; }
.view.active { display: block; animation: fade 0.18s ease; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.4);
}

/* Modal */
dialog {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(94vw, 440px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
}
dialog::backdrop { background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(4px); }
.modal-body { padding: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.checks label { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; color: var(--muted); }

/* Lists helpers */
.stack { display: flex; flex-direction: column; gap: 10px; }
.hero-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 8px;
}
.hero-line h2 { margin: 0; font-size: 1.25rem; }
.pill-note {
  font-size: 0.78rem;
  color: var(--muted);
  background: rgba(148,163,184,0.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
}
.disclaimer {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 16px;
  line-height: 1.5;
}
.import-grid {
  display: grid;
  gap: 10px;
}
@media (min-width: 640px) {
  .import-grid { grid-template-columns: 1fr 1fr 1fr; }
}
.pack-card {
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.pack-card strong { display: block; margin-bottom: 4px; }
.pack-card span { color: var(--muted); font-size: 0.8rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 80;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.section-title {
  margin: 18px 0 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.balance-bars { display: flex; flex-direction: column; gap: 8px; }
.balance-row { display: grid; grid-template-columns: 72px 1fr 40px; gap: 8px; align-items: center; font-size: 0.85rem; }
.balance-track {
  height: 10px;
  background: rgba(148,163,184,0.12);
  border-radius: 999px;
  overflow: hidden;
}
.balance-track > i {
  display: block;
  height: 100%;
  border-radius: 999px;
}
.balance-track .physics { background: var(--physics); }
.balance-track .biology { background: var(--biology); }
.balance-track .math { background: var(--math); }

.hidden { display: none !important; }
