:root {
  --bg: #0d0f16;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #e8ecff;
  --muted: #9aa3c4;
  --accent: #7cf6f0;
  --danger: #ff8b8b;
  color-scheme: dark;
}

[data-theme="light"] {
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(0, 0, 0, 0.1);
  --text: #1a1d2e;
  --muted: #5a6380;
  --accent: #0891b2;
  --danger: #c0392b;
  color-scheme: light;
}

[data-theme="light"] body {
  background: radial-gradient(circle at 20% 20%, #dde8f5, #f0f4f8 40%),
    radial-gradient(circle at 80% 10%, #e8e0f5, transparent 40%),
    radial-gradient(circle at 50% 80%, #d8eef0, transparent 45%), #f0f4f8;
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background: rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 20% 20%, #182235, #0d0f16 40%), radial-gradient(circle at 80% 10%, #1c1232, transparent 40%), radial-gradient(circle at 50% 80%, #113034, transparent 45%), #0d0f16;
  color: var(--text);
  padding: 24px;
}

.shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 20px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 34px;
}

h2 {
  font-size: 20px;
}

p,
.muted {
  color: var(--muted);
}

.stats-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-card {
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 16px;
  background: var(--panel);
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: 1fr 1fr;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.loop-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.loop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
}

.progress-wrap {
  display: grid;
  gap: 6px;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7cf6f0, #64c6ff);
  transition: width 0.2s ease;
}

.roadmap {
  display: grid;
  gap: 8px;
}

.road-item {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.road-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.timer-box,
.recall-box,
.feynman-box,
.idea-box,
.resources-box,
.flashcard-box {
  display: grid;
  gap: 8px;
}

.timer {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

button,
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  color: #081019;
  background: linear-gradient(135deg, #7cf6f0, #64c6ff);
  cursor: pointer;
  text-decoration: none;
}

button.ghost,
.btn.ghost,
.ghost-link {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--panel-border);
}

.ghost-link {
  border-radius: 10px;
  padding: 8px 10px;
  text-decoration: none;
}

.skills-grid {
  display: grid;
  gap: 8px;
}

.skill-card {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.skill-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tag {
  font-size: 12px;
  color: var(--muted);
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.list li {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 6px;
}

.list .line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.small-btn {
  padding: 6px 10px;
  min-width: unset;
  border-radius: 10px;
  font-size: 13px;
}

.small-btn.danger {
  background: rgba(255, 139, 139, 0.2);
  color: #ffd6d6;
  border: 1px solid rgba(255, 139, 139, 0.5);
}

/* ── Todo list ── */
.todo-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.todo-item-text {
  flex: 1;
  font-size: 14px;
}

.todo-item-text.done {
  text-decoration: line-through;
  color: var(--muted);
  opacity: 0.7;
}

.todo-priority {
  font-size: 13px;
  flex-shrink: 0;
}

/* ── SM-2 Study mode ── */
.study-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
}

.study-card {
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(124, 246, 240, 0.05);
  display: grid;
  gap: 10px;
}

.study-front {
  font-size: 16px;
  font-weight: 600;
  min-height: 40px;
  padding: 4px 0;
}

.study-back {
  color: var(--muted);
  font-size: 14px;
  border-top: 1px solid var(--panel-border);
  padding-top: 8px;
}

/* ── API key collapsible ── */
.api-key-box {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
}

.api-key-box summary {
  list-style: none;
}

.api-key-box summary::-webkit-details-marker {
  display: none;
}

/* ── Notifications widget ── */
.notif-section {
  border-top: 1px solid var(--panel-border);
  padding-top: 12px;
  display: grid;
  gap: 8px;
}

/* ── Analytics panel ── */
.analytics-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.analytics-stat {
  flex: 1;
  min-width: 110px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
}

.analytics-stat .a-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.analytics-stat .a-lbl {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.chart-title {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.analytics-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 4px;
}

.bar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #7cf6f0, #64c6ff);
  min-height: 2px;
}

.bar-fill.today {
  background: linear-gradient(180deg, #ffd166, #ff9f43);
}

.bar-day {
  font-size: 10px;
  color: var(--muted);
}

.flashcard-chart {
  display: grid;
  gap: 10px;
  align-content: start;
}

.fc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.fc-label {
  min-width: 55px;
  color: var(--muted);
}

.fc-track {
  flex: 1;
  height: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.fc-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7cf6f0, #64c6ff);
}

.fc-fill.mastered {
  background: linear-gradient(90deg, #ffd166, #ff9f43);
}

.fc-val {
  min-width: 28px;
  font-size: 12px;
  color: var(--muted);
  text-align: start;
}

.horiz-chart {
  display: grid;
  gap: 6px;
}

.hc-row {
  display: grid;
  grid-template-columns: 130px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.hc-label {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hc-track {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.hc-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7cf6f0, #64c6ff);
}

.hc-val {
  font-size: 12px;
  color: var(--muted);
}

/* ── XP / Gamification ── */
.xp-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 180px;
}

.xp-level {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.xp-total {
  font-size: 11px;
  color: var(--muted);
}

.xp-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7cf6f0, #64c6ff);
  transition: width 0.4s ease;
}

.xp-next {
  font-size: 11px;
  color: var(--muted);
}

/* ── Syntax Highlighted Code Blocks ── */
pre.code-block {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: 'Fira Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  direction: ltr;
  text-align: left;
  margin: 6px 0;
}

[data-theme="light"] pre.code-block {
  background: rgba(0, 0, 0, 0.04);
}

pre.code-block code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.hl-kw { color: #7cf6f0; font-weight: 600; }
.hl-str { color: #ffd166; }
.hl-cm { color: #6b7db3; font-style: italic; }
.hl-num { color: #ff9f43; }

[data-theme="light"] .hl-kw { color: #0891b2; font-weight: 600; }
[data-theme="light"] .hl-str { color: #b76c2f; }
[data-theme="light"] .hl-cm { color: #7a8fbb; font-style: italic; }
[data-theme="light"] .hl-num { color: #e67e22; }

/* ── Activity Heatmap ── */
.heatmap-wrap {
  overflow-x: auto;
}

.hm-grid {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  grid-auto-columns: 13px;
  grid-auto-flow: column;
  gap: 3px;
  min-width: max-content;
}

.hm-cell {
  width: 13px;
  height: 13px;
  border-radius: 2px;
}

.hm-cell.l0 { background: rgba(255, 255, 255, 0.07); }
.hm-cell.l1 { background: rgba(124, 246, 240, 0.25); }
.hm-cell.l2 { background: rgba(124, 246, 240, 0.55); }
.hm-cell.l3 { background: rgba(124, 246, 240, 1); }

[data-theme="light"] .hm-cell.l0 { background: rgba(0, 0, 0, 0.07); }
[data-theme="light"] .hm-cell.l1 { background: rgba(8, 145, 178, 0.2); }
[data-theme="light"] .hm-cell.l2 { background: rgba(8, 145, 178, 0.5); }
[data-theme="light"] .hm-cell.l3 { background: rgba(8, 145, 178, 0.85); }

@media (max-width: 980px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 28px;
  }

  .hero {
    flex-direction: column;
  }

  .timer {
    font-size: 40px;
  }

  .analytics-charts {
    grid-template-columns: 1fr;
  }

  .hc-row {
    grid-template-columns: 100px 1fr 44px;
  }
}
