/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #09090b;
  --bg-card: #111113;
  --bg-card-hover: #18181b;
  --border: #27272a;
  --border-hover: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;

  --physics: #6366f1;
  --physics-bg: rgba(99, 102, 241, 0.12);
  --chemistry: #22c55e;
  --chemistry-bg: rgba(34, 197, 94, 0.12);
  --maths: #f59e0b;
  --maths-bg: rgba(245, 158, 11, 0.12);
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --destructive: #ef4444;
  --streak: #f97316;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── App Container ───────────────────────────────── */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* ── Header ──────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--accent);
  border-radius: var(--radius-sm);
  color: white;
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.25);
  padding: .45rem .85rem;
  border-radius: 999px;
  color: var(--streak);
  font-weight: 600;
  font-size: .85rem;
  transition: all .2s;
}

.streak-badge:hover { background: rgba(249, 115, 22, 0.18); }

.streak-label {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Connection Banner ───────────────────────────── */
.connection-banner {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  margin-bottom: 1.25rem;
  display: none;
}

.connection-banner.show { display: block; }

.banner-content {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.banner-content svg { color: var(--accent); flex-shrink: 0; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover { color: var(--accent-hover); }

.sign-in-btn {
  margin-left: auto;
  padding: .4rem .85rem;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(99,102,241,.4);
  background: rgba(99,102,241,.15);
  color: var(--accent);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
}

.sign-in-btn:hover { background: rgba(99,102,241,.25); }
.sign-in-btn:disabled { opacity: .6; cursor: default; }

/* ── Stats Grid ──────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: border-color .2s, background .2s;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

.stat-card.physics::before  { background: var(--physics); }
.stat-card.chemistry::before { background: var(--chemistry); }
.stat-card.maths::before    { background: var(--maths); }
.stat-card.total::before    { background: linear-gradient(90deg, var(--physics), var(--chemistry), var(--maths)); }

.stat-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}

.stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-xs);
  display: grid; place-items: center;
}

.physics .stat-icon  { background: var(--physics-bg); color: var(--physics); }
.chemistry .stat-icon { background: var(--chemistry-bg); color: var(--chemistry); }
.maths .stat-icon    { background: var(--maths-bg); color: var(--maths); }
.total .stat-icon    { background: rgba(99,102,241,.1); color: var(--accent); }

.stat-info { display: flex; flex-direction: column; gap: .1rem; }

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.03em;
}

.stat-today {
  font-size: .75rem;
  color: var(--text-dim);
  font-weight: 500;
}

/* ── Card ────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

.card-title svg { color: var(--text-muted); }

/* ── Quick Add ───────────────────────────────────── */
.quick-add-grid {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.quick-add-subject {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .85rem;
  background: rgba(255,255,255,.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .2s;
}

.quick-add-subject:hover { border-color: var(--border-hover); }

.subject-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.physics-dot   { background: var(--physics); }
.chemistry-dot { background: var(--chemistry); }
.maths-dot     { background: var(--maths); }

.subject-name {
  font-weight: 600;
  font-size: .9rem;
  min-width: 85px;
}

.quick-add-controls {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.quick-buttons { display: flex; gap: .35rem; }

.quick-btn {
  padding: .35rem .7rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.quick-btn:hover {
  border-color: var(--accent);
  background: rgba(99,102,241,.1);
  color: var(--accent);
}

.quick-btn:active { transform: scale(.95); }

.custom-add { display: flex; gap: .35rem; }

.num-input {
  width: 75px;
  padding: .35rem .55rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

.num-input::placeholder { color: var(--text-dim); }
.num-input:focus { border-color: var(--accent); }

.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num-input[type=number] { -moz-appearance: textfield; }

.add-btn {
  padding: .35rem .75rem;
  border-radius: var(--radius-xs);
  border: none;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  color: white;
}

.physics-btn   { background: var(--physics); }
.chemistry-btn { background: var(--chemistry); }
.maths-btn     { background: var(--maths); }

.add-btn:hover { opacity: .85; }
.add-btn:active { transform: scale(.95); }

/* ── Charts ──────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: .75rem;
  margin-bottom: 0;
}

.charts-grid .card { margin-bottom: 1.25rem; }

.chart-wrapper {
  position: relative;
  height: 240px;
}

/* ── Heatmap ─────────────────────────────────────── */
.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, 28px);
  gap: 4px;
}

.heatmap-cell {
  width: 28px; height: 28px;
  border-radius: 4px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  position: relative;
  cursor: default;
  transition: transform .1s;
}

.heatmap-cell:hover { transform: scale(1.2); z-index: 2; }

.heatmap-cell[data-level="1"] { background: rgba(99, 102, 241, .2); border-color: rgba(99, 102, 241, .25); }
.heatmap-cell[data-level="2"] { background: rgba(99, 102, 241, .4); border-color: rgba(99, 102, 241, .45); }
.heatmap-cell[data-level="3"] { background: rgba(99, 102, 241, .6); border-color: rgba(99, 102, 241, .65); }
.heatmap-cell[data-level="4"] { background: rgba(99, 102, 241, .85); border-color: rgba(99, 102, 241, .9); }

.heatmap-cell .tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e1e24;
  border: 1px solid var(--border);
  color: var(--text);
  padding: .3rem .55rem;
  border-radius: var(--radius-xs);
  font-size: .7rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

.heatmap-cell:hover .tooltip { display: block; }

/* ── Log List ────────────────────────────────────── */
.log-list { display: flex; flex-direction: column; gap: .4rem; max-height: 300px; overflow-y: auto; }

.log-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-xs);
  background: rgba(255,255,255,.02);
  border: 1px solid transparent;
  transition: all .15s;
}

.log-item:hover { border-color: var(--border); }

.log-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.log-subject {
  font-weight: 600;
  font-size: .85rem;
  min-width: 80px;
}

.log-count {
  font-size: .85rem;
  color: var(--text-muted);
}

.log-date {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text-dim);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  font-size: .85rem;
}

/* ── Scrollbar ───────────────────────────────────── */
.log-list::-webkit-scrollbar { width: 6px; }
.log-list::-webkit-scrollbar-track { background: transparent; }
.log-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* ── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  z-index: 100;
}

.modal-overlay.show { display: grid; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(500px, 90vw);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: .25rem;
  border-radius: var(--radius-xs);
  transition: all .15s;
}

.modal-close:hover { background: rgba(255,255,255,.08); color: var(--text); }

.modal-body { padding: 1.25rem; }

.modal-desc {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.setup-steps {
  font-size: .85rem;
  color: var(--text-muted);
  padding-left: 1.2rem;
  margin-bottom: 1.25rem;
  line-height: 1.8;
}

.setup-steps strong { color: var(--text); }
.setup-steps code {
  background: rgba(255,255,255,.08);
  padding: .1rem .4rem;
  border-radius: 4px;
  font-size: .8rem;
}

.input-group {
  margin-bottom: 1rem;
}

.input-group label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: .4rem;
}

.text-input {
  width: 100%;
  padding: .6rem .75rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

.text-input:focus { border-color: var(--accent); }

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.25rem;
  border-radius: var(--radius-xs);
  border: none;
  background: var(--accent);
  color: white;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(.97); }

/* ── Toast ───────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: .5rem;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  font-size: .85rem;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: .5rem;
  animation: toast-in .3s ease;
  min-width: 220px;
}

.toast.success { border-color: rgba(34,197,94,.35); }
.toast.error   { border-color: rgba(239,68,68,.35); }

.toast.success::before { content: '✓'; color: var(--chemistry); font-weight: 700; }
.toast.error::before   { content: '✕'; color: var(--destructive); font-weight: 700; }

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .header { flex-wrap: wrap; }
  .quick-add-subject { flex-wrap: wrap; }
  .quick-add-controls { margin-left: 0; width: 100%; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .app { padding: 1rem .75rem 2rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .quick-add-controls { flex-direction: column; align-items: flex-start; }
}
