:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink-primary: #0b0b0b;
  --ink-secondary: #52514e;
  --ink-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
  --danger: #d03b3b;

  --series-0: #2a78d6;
  --series-1: #1baf7a;
  --series-2: #eda100;
  --series-3: #008300;
  --series-4: #4a3aa7;
  --series-5: #e34948;
  --series-6: #e87ba4;
  --series-7: #eb6834;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink-primary: #ffffff;
    --ink-secondary: #c3c2b7;
    --ink-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;
    --danger: #e66767;

    --series-0: #3987e5;
    --series-1: #199e70;
    --series-2: #c98500;
    --series-3: #008300;
    --series-4: #9085e9;
    --series-5: #e66767;
    --series-6: #d55181;
    --series-7: #d95926;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink-primary);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.dot-0, .bar-0 { background: var(--series-0); }
.dot-1, .bar-1 { background: var(--series-1); }
.dot-2, .bar-2 { background: var(--series-2); }
.dot-3, .bar-3 { background: var(--series-3); }
.dot-4, .bar-4 { background: var(--series-4); }
.dot-5, .bar-5 { background: var(--series-5); }
.dot-6, .bar-6 { background: var(--series-6); }
.dot-7, .bar-7 { background: var(--series-7); }

/* ---------- buttons & forms ---------- */

button {
  font-family: inherit;
  cursor: pointer;
}

.primary-btn {
  background: var(--ink-primary);
  color: var(--page);
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
}
.primary-btn.full { width: 100%; }
.primary-btn:active { opacity: 0.85; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--ink-secondary);
  text-decoration: underline;
  font-size: 0.85rem;
  padding: 0;
}

.danger-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.85rem;
  padding: 4px 6px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-secondary);
  margin-bottom: 12px;
}

input, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus, textarea:focus {
  outline: 2px solid var(--series-0);
  outline-offset: 1px;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
}

/* ---------- auth view ---------- */

#auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}

.auth-card h1 {
  font-size: 1.6rem;
  text-align: center;
}

.tagline {
  text-align: center;
  color: var(--ink-secondary);
  font-size: 0.9rem;
  margin: 8px 0 20px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--ink-secondary);
  font-weight: 600;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--ink-primary);
}

/* ---------- app shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--page);
  z-index: 5;
}

.brand { font-weight: 700; font-size: 1.1rem; }

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--ink-secondary);
}

#app-view, #auth-view { max-width: 720px; margin: 0 auto; }

section { padding: 20px; }

/* ---------- hero ---------- */

.hero {
  text-align: center;
  padding: 32px 20px 12px;
}

.hero-figure {
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: proportional-nums;
}

.hero-unit {
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--ink-secondary);
  margin-left: 8px;
}

.hero-timer {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.hero-unit-sm {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-muted);
  margin-left: 6px;
  font-variant-numeric: normal;
}

.hero-label {
  color: var(--ink-secondary);
  font-size: 1rem;
  margin-top: 6px;
}

.hero-sub {
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

/* ---------- kpis ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.kpi-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}

.kpi-label {
  color: var(--ink-muted);
  font-size: 0.72rem;
}

/* ---------- chart ---------- */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin: 0 20px 20px;
  padding: 16px;
  width: auto;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.chart-head h2 { font-size: 1rem; }

.legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--ink-secondary);
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 168px;
  padding-bottom: 22px;
  position: relative;
  min-width: min-content;
}

.week-group {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  position: relative;
  flex: none;
}

.bar {
  width: 11px;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.week-month-label {
  position: absolute;
  bottom: -20px;
  left: 0;
  font-size: 0.68rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.chart-table-wrap { overflow-x: auto; }
.chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.chart-table th, .chart-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart-table th { color: var(--ink-muted); font-weight: 600; }

.chart-tooltip {
  position: fixed;
  background: var(--ink-primary);
  color: var(--page);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  pointer-events: none;
  z-index: 50;
  max-width: 220px;
}

/* ---------- timeline ---------- */

.timeline-card { padding-top: 0; }

.timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.timeline-head h2 { font-size: 1rem; }

.timeline {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.day-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.day-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-secondary);
  padding: 6px 4px;
  position: sticky;
  top: 53px;
  background: var(--page);
  z-index: 2;
}

.day-both {
  font-weight: 500;
  color: var(--ink-muted);
  font-size: 0.78rem;
}

.activity {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.activity-icon { font-size: 1.4rem; line-height: 1; }

.activity-body { flex: 1; min-width: 0; }

.activity-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  flex-wrap: wrap;
}

.activity-stats {
  color: var(--ink-secondary);
  font-size: 0.86rem;
  margin-top: 4px;
}

.activity-pace {
  color: var(--ink-muted);
  font-size: 0.76rem;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.activity-note {
  color: var(--ink-secondary);
  font-size: 0.82rem;
  margin-top: 6px;
  font-style: italic;
  overflow-wrap: anywhere;
}

.activity-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.kudos-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.82rem;
  color: var(--ink-secondary);
}
.kudos-btn.active {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.edit-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.empty-state {
  text-align: center;
  color: var(--ink-muted);
  padding: 30px 0;
}

.foot {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.78rem;
  padding: 10px 20px 32px;
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
@media (min-width: 560px) {
  .modal { align-items: center; }
}

.modal-card {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 20px;
}
@media (min-width: 560px) {
  .modal-card { border-radius: 16px; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-secondary);
  font-size: 0.9rem;
  font-weight: 600;
}
.type-btn.active {
  background: var(--ink-primary);
  color: var(--page);
  border-color: var(--ink-primary);
}

.modal-actions { margin-top: 8px; }

.widget-help {
  font-size: 0.85rem;
  color: var(--ink-secondary);
  line-height: 1.6;
  margin: 0 0 16px;
}
.widget-help code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.widget-script-area {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  resize: vertical;
  white-space: pre;
  overflow-x: auto;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-primary);
  color: var(--page);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
