@font-face {
  font-family: 'InstrumentSans';
  src: url('./InstrumentSans-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'InstrumentSans';
  src: url('./InstrumentSans-Bold.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'JetBrainsMono';
  src: url('./JetBrainsMono-Regular.ttf') format('truetype');
  font-weight: 400;
}

:root {
  --bg: #fafafa;
  --bg2: #ffffff;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --rule: #e5e7eb;
  --accent: #4B3FE3;
  --accent-soft: #F2F7FF;
  --accent-text: #1A1759;
  --success: #1DC981;
  --success-soft: #E9FBF3;
  --warning: #EFAA17;
  --warning-soft: #FFF8E8;
  --danger: #F44A4A;
  --font: 'InstrumentSans', "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrainsMono', ui-monospace, monospace;
  --max: 560px;
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --ink: #f0f0f5;
  --muted: #9ca3af;
  --rule: #2d2d44;
  --accent: #7B70F4;
  --accent-soft: rgba(123, 112, 244, 0.12);
  --accent-text: #E8E6FF;
  --success: #2EE59D;
  --success-soft: rgba(46, 229, 157, 0.12);
  --warning: #F5C542;
  --warning-soft: rgba(245, 197, 66, 0.12);
  --danger: #FF6B6B;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f1a;
    --bg2: #1a1a2e;
    --ink: #f0f0f5;
    --muted: #9ca3af;
    --rule: #2d2d44;
    --accent: #7B70F4;
    --accent-soft: rgba(123, 112, 244, 0.12);
    --accent-text: #E8E6FF;
    --success: #2EE59D;
    --success-soft: rgba(46, 229, 157, 0.12);
    --warning: #F5C542;
    --warning-soft: rgba(245, 197, 66, 0.12);
    --danger: #FF6B6B;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

.page {
  position: relative;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1rem 5rem;
}

/* Header */
.page-header {
  text-align: center;
  padding: 1.25rem 0 1rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-text);
  letter-spacing: -0.02em;
}
.page-header .subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Theme toggle */
.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}
.theme-toggle .dark { display: none; }
[data-theme="dark"] .theme-toggle .dark { display: inline; }
[data-theme="dark"] .theme-toggle .light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .dark { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .light { display: none; }
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 0.6rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg2);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.tab-btn:hover { background: var(--accent-soft); }
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-text);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card-title::before {
  content: '';
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
}

/* Progress */
.progress-summary {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-box {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.875rem;
  text-align: center;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* Task list */
.task-list {}
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  user-select: none;
}
.task-item:last-child { border-bottom: none; padding-bottom: 0; }
.task-item:first-child { padding-top: 0; }
.task-check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--rule);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.task-check svg {
  width: 13px;
  height: 13px;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
}
.task-item.done .task-check {
  background: var(--success);
  border-color: var(--success);
}
.task-item.done .task-check svg {
  opacity: 1;
  transform: scale(1);
}
.task-body { flex: 1; }
.task-time {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 0.2rem;
}
.task-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  transition: color 0.2s ease;
}
.task-item.done .task-text {
  color: var(--muted);
  text-decoration: line-through;
}
.task-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
  line-height: 1.45;
}

/* Review prompts */
.prompt-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.prompt-item {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 0.875rem 1rem;
}
.prompt-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.prompt-text {
  font-size: 0.9rem;
  color: var(--accent-text);
  line-height: 1.5;
}
.textarea {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.875rem 1rem;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease;
  background: var(--bg2);
}
.textarea:focus { border-color: var(--accent); }
.save-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* English lesson */
.lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.lesson-day {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
}
.lesson-nav {
  display: flex;
  gap: 0.25rem;
}
.lesson-nav button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.25rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.lesson-nav button:hover { background: var(--accent-soft); }
.lesson-nav button:disabled { color: var(--rule); cursor: not-allowed; }
.lesson-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-text);
  margin-bottom: 0.5rem;
}
.lesson-content {
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.6;
  margin-bottom: 1rem;
}
.lesson-practice {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.lesson-practice-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lesson-practice-text {
  font-size: 0.9rem;
  color: var(--accent-text);
  line-height: 1.5;
}
.lesson-done-btn {
  width: 100%;
  padding: 0.875rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lesson-done-btn:hover { background: #3a31c4; }
.lesson-done-btn.done { background: var(--success); }

/* 5 year plan */
.timeline {
  position: relative;
  padding-left: 1.5rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 0.4rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: var(--rule);
}
.timeline-item {
  position: relative;
  margin-bottom: 1.25rem;
}
.timeline-item:last-child { margin-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: -1.3rem;
  top: 0.35rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg2);
}
.timeline-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.timeline-year {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-text);
}
.timeline-age {
  font-size: 0.75rem;
  color: var(--muted);
}
.timeline-income {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.timeline-goals {
  list-style: none;
  display: grid;
  gap: 0.4rem;
}
.timeline-goals li {
  font-size: 0.85rem;
  color: var(--ink);
  padding-left: 1rem;
  position: relative;
  line-height: 1.5;
}
.timeline-goals li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* Account book */
.import-area {
  border: 2px dashed var(--rule);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  text-align: center;
  margin-bottom: 1rem;
  transition: border-color 0.15s ease;
}
.import-area:hover { border-color: var(--accent); }
.import-input { display: none; }
.import-btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.import-btn:hover { background: #3a31c4; }
.import-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.account-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.account-stat {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}
.account-stat.income .stat-value { color: var(--success); }
.account-stat.expense .stat-value { color: var(--danger); }
.account-stat.balance .stat-value { color: var(--accent); }

.account-table-wrapper {
  overflow-x: auto;
}
.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.account-table th,
.account-table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.account-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
}
.account-table td {
  color: var(--ink);
}
.account-table .amount-income { color: var(--success); font-weight: 600; }
.account-table .amount-expense { color: var(--danger); font-weight: 600; }
.account-table .type-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}
.account-table .type-income {
  background: var(--success-soft);
  color: #0d5c3e;
}
.account-table .type-expense {
  background: rgba(244, 74, 74, 0.12);
  color: #c53030;
}
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Manual add form */
.add-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.form-input, .form-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg2);
  outline: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-btn {
  padding: 0.7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* Helper text */
.helper-card {
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  margin-top: 1.5rem;
}
.helper-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-text);
  margin-bottom: 0.5rem;
}
.helper-list {
  list-style: none;
  font-size: 0.85rem;
  color: var(--accent-text);
  line-height: 1.7;
}
.helper-list li {
  padding-left: 1rem;
  position: relative;
}
.helper-list li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* Footer */
.footer-actions {
  text-align: center;
  margin-top: 2rem;
}
.reset-btn {
  font-size: 0.75rem;
  color: var(--muted);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.5rem;
}
