/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Geist', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  font-feature-settings: 'ss01', 'cv01';
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
input, select, textarea {
  font-family: inherit;
  background: none;
  border: none;
  color: inherit;
  outline: none;
  font-size: inherit;
}

/* ========== COLOR SYSTEM ========== */
:root {
  --bg: #0e0d0b;
  --bg-elev: #161412;
  --surface: #1a1714;
  --surface-elev: #221e1a;
  --border: #2b2622;
  --border-strong: #3a342e;
  --text: #f5f1e8;
  --text-muted: #968d80;
  --text-dim: #6a635a;

  --flame: #ff7849;
  --flame-soft: #ff9a6a;
  --flame-glow: rgba(255, 120, 73, 0.18);

  --gold: #e8b961;
  --gold-soft: #f0cd86;

  --success: #6dd58c;
  --success-soft: #98e1b1;

  --danger: #e36b6b;
  --danger-soft: #e89090;

  --serif: 'Instrument Serif', 'Georgia', serif;
  --mono: 'Geist Mono', 'SF Mono', ui-monospace, monospace;

  --r-sm: 8px;
  --r: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
}

/* ========== LOADING SPLASH ========== */
.loading-splash {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.splash-flame {
  font-family: var(--serif);
  font-size: 48px;
  color: var(--flame);
  animation: splash-pulse 1.4s ease-in-out infinite;
}
@keyframes splash-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1); }
}

/* ========== APP LAYOUT ========== */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
}

/* ========== HEADER ========== */
.app-header {
  position: sticky;
  top: 0;
  padding: 24px 0 12px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 70%, transparent 100%);
  z-index: 10;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.header-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.streak-badge {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: all 0.2s;
}
.streak-badge.active {
  background: linear-gradient(135deg, rgba(255, 120, 73, 0.15), rgba(255, 120, 73, 0.05));
  border-color: rgba(255, 120, 73, 0.3);
  box-shadow: 0 0 24px var(--flame-glow);
}
.streak-emoji {
  font-size: 18px;
  filter: drop-shadow(0 0 8px var(--flame-glow));
}
.streak-num {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
  color: var(--flame);
  font-style: italic;
}
.streak-badge:not(.active) .streak-num { color: var(--text-muted); }
.streak-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 2px;
}

.header-nav {
  display: flex; gap: 6px;
}
.nav-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.nav-btn:active { transform: scale(0.92); }
.nav-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.nav-btn svg { width: 18px; height: 18px; }

.date-display {
  margin-top: 14px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.date-day {
  font-family: var(--serif);
  font-size: 38px;
  line-height: 1;
  font-style: italic;
}
.date-meta {
  color: var(--text-muted);
  font-size: 14px;
}

/* ========== DAY FLAGS (modafinil / iso) ========== */
.day-flags {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 16px 0 8px;
}
.flag-toggle {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.flag-toggle.active {
  background: var(--surface-elev);
  border-color: var(--flame);
  color: var(--flame-soft);
}
.flag-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.15s;
}
.flag-toggle.active .flag-dot {
  background: var(--flame);
  box-shadow: 0 0 8px var(--flame);
}

/* ========== PROGRESS BAR ========== */
.day-progress {
  margin: 18px 0 24px;
}
.progress-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
}
.progress-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.progress-count {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}
.progress-track {
  height: 4px;
  background: var(--surface);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--flame), var(--gold));
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 0 12px var(--flame-glow);
}
.progress-fill.complete {
  background: linear-gradient(90deg, var(--success), var(--gold));
}

/* ========== TIME SLOT SECTIONS ========== */
.slot-section {
  margin-bottom: 30px;
}
.slot-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.slot-name {
  font-family: var(--serif);
  font-size: 22px;
  font-style: italic;
  color: var(--text);
}
.slot-time {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding-bottom: 2px;
}
.slot-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}
.slot-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ========== ITEM CARD ========== */
.item {
  display: flex; align-items: stretch; gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 8px;
  overflow: hidden;
  transition: all 0.2s;
  position: relative;
}
.item:active { transform: scale(0.99); }
.item.taken {
  background: linear-gradient(135deg, rgba(109, 213, 140, 0.06), rgba(109, 213, 140, 0.02));
  border-color: rgba(109, 213, 140, 0.18);
}
.item-check {
  flex-shrink: 0;
  display: grid; place-items: center;
  width: 56px;
  border-right: 1px solid var(--border);
  transition: all 0.2s;
  background: rgba(0,0,0,0.15);
}
.item.taken .item-check {
  border-right-color: rgba(109, 213, 140, 0.18);
  background: rgba(109, 213, 140, 0.08);
}
.checkbox {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  position: relative;
  transition: all 0.25s;
}
.item.taken .checkbox {
  background: var(--success);
  border-color: var(--success);
}
.checkbox::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
}
.item.taken .checkbox::after { opacity: 1; }

.item-body {
  flex: 1;
  padding: 14px 14px;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.item-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}
.item.taken .item-name { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--text-muted); }
.item-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}
.item-dose { color: var(--gold); }
.item-info-btn {
  flex-shrink: 0;
  width: 40px;
  display: grid; place-items: center;
  color: var(--text-dim);
  border-left: 1px solid var(--border);
  transition: color 0.15s;
}
.item.taken .item-info-btn { border-left-color: rgba(109, 213, 140, 0.18); }
.item-info-btn:active { color: var(--text); }
.item-info-btn svg { width: 16px; height: 16px; }

/* ========== EMPTY STATE ========== */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon { font-family: var(--serif); font-size: 64px; color: var(--text-dim); font-style: italic; margin-bottom: 12px; }
.empty-state .title { font-family: var(--serif); font-size: 22px; font-style: italic; color: var(--text); margin-bottom: 8px; }
.empty-state .desc { font-size: 14px; line-height: 1.5; max-width: 320px; margin: 0 auto; }

/* ========== COMPLETION CELEBRATION ========== */
.completion-banner {
  background: linear-gradient(135deg, rgba(109, 213, 140, 0.12), rgba(232, 185, 97, 0.08));
  border: 1px solid rgba(109, 213, 140, 0.25);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  margin-bottom: 24px;
  display: flex; align-items: center; gap: 14px;
  animation: slide-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.completion-icon {
  font-family: var(--serif);
  font-size: 36px;
  font-style: italic;
  color: var(--success);
  line-height: 1;
}
.completion-text {
  font-family: var(--serif);
  font-size: 18px;
  font-style: italic;
  color: var(--text);
  line-height: 1.3;
}
.completion-text small {
  display: block;
  font-family: 'Geist', sans-serif;
  font-style: normal;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.04em;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== LOGIN PAGE ========== */
.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, rgba(255, 120, 73, 0.06), transparent 60%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px 32px;
}
.login-brand {
  font-family: var(--serif);
  font-size: 44px;
  font-style: italic;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.login-brand span { color: var(--flame); }
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}
.field {
  margin-bottom: 14px;
}
.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.field-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 15px;
  color: var(--text);
  transition: border-color 0.15s;
}
.field-input:focus { border-color: var(--flame); }
.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: all 0.15s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; }

.login-error {
  background: rgba(227, 107, 107, 0.1);
  border: 1px solid rgba(227, 107, 107, 0.3);
  color: var(--danger-soft);
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 13px;
  margin-bottom: 14px;
}

.login-foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 24px;
  line-height: 1.6;
}

/* ========== SHEET (modal bottom) ========== */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 0.2s;
  padding: 0;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%;
  max-width: 720px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  max-height: 88vh;
  overflow-y: auto;
  animation: sheet-up 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border-strong);
  border-radius: 99px;
  margin: 10px auto;
}
.sheet-header {
  padding: 4px 24px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.sheet-title {
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.sheet-close {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
}
.sheet-body { padding: 20px 24px 32px; }

/* ========== INFO SHEET ========== */
.info-tag {
  display: inline-block;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 6px;
  margin-bottom: 6px;
}
.info-tag.instant { color: var(--flame-soft); border-color: rgba(255, 154, 106, 0.3); }
.info-tag.cumulative { color: var(--gold-soft); border-color: rgba(232, 185, 97, 0.3); }
.info-tag.both { color: var(--success-soft); border-color: rgba(152, 225, 177, 0.3); }
.info-section {
  margin-top: 20px;
}
.info-section h4 {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  font-weight: 500;
}
.info-section p {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
}
.info-section p.caution {
  color: var(--flame-soft);
  background: rgba(255, 120, 73, 0.06);
  padding: 12px 14px;
  border-radius: var(--r);
  border-left: 2px solid var(--flame);
}

/* ========== SETTINGS LIST ========== */
.settings-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
}
.settings-item-body {
  flex: 1; min-width: 0;
}
.settings-item-name {
  font-size: 15px;
  font-weight: 500;
}
.settings-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
  margin-top: 2px;
}
.settings-item.disabled .settings-item-name { color: var(--text-muted); }

.toggle {
  flex-shrink: 0;
  width: 44px; height: 26px;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
}
.toggle.on { background: var(--success); }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toggle.on::after { transform: translateX(18px); }

.settings-edit-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== EDIT SUPPLEMENT FORM ========== */
.edit-form .field-label { margin-top: 14px; }
.time-slots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 6px;
  margin-top: 4px;
}
.slot-pill {
  padding: 10px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
  text-align: center;
  transition: all 0.15s;
}
.slot-pill.selected {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.freq-options {
  display: flex; flex-direction: column; gap: 6px;
}
.freq-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
}
.freq-row.selected { border-color: var(--flame); background: rgba(255, 120, 73, 0.05); }
.freq-radio {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.freq-row.selected .freq-radio { border-color: var(--flame); }
.freq-row.selected .freq-radio::after {
  content: '';
  position: absolute;
  inset: 3px;
  background: var(--flame);
  border-radius: 50%;
}
.freq-body { flex: 1; }
.freq-name { font-size: 14px; }
.freq-desc { font-size: 12px; color: var(--text-muted); }

.dow-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  margin-top: 8px;
}
.dow-btn {
  padding: 10px 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  text-align: center;
}
.dow-btn.selected { background: var(--flame); color: var(--bg); border-color: var(--flame); font-weight: 600; }

/* ========== INFO PAGE ========== */
.info-list {
  display: flex; flex-direction: column; gap: 8px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.info-card:active { transform: scale(0.99); }
.info-card-body { flex: 1; min-width: 0; }
.info-card-name { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.info-card-desc { font-size: 13px; color: var(--text-muted); line-height: 1.4; }
.info-card-arrow { color: var(--text-dim); flex-shrink: 0; }

/* ========== HISTORY PAGE ========== */
.history-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: 16px 0;
}
.history-day {
  aspect-ratio: 1;
  background: var(--surface);
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
  position: relative;
}
.history-day.complete {
  background: var(--success);
  color: var(--bg);
  font-weight: 600;
}
.history-day.partial {
  background: rgba(232, 185, 97, 0.25);
  color: var(--gold);
}
.history-day.missed {
  background: rgba(227, 107, 107, 0.18);
  color: var(--danger);
}
.history-day.future { opacity: 0.3; }
.history-day.today {
  outline: 2px solid var(--flame);
  outline-offset: -2px;
}

.legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.legend-dot.complete { background: var(--success); }
.legend-dot.partial { background: rgba(232, 185, 97, 0.5); }
.legend-dot.missed { background: rgba(227, 107, 107, 0.4); }

.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 16px 0;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
}
.stat-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stat-card .value {
  font-family: var(--serif);
  font-size: 36px;
  font-style: italic;
  line-height: 1;
}
.stat-card.streak .value { color: var(--flame); }
.stat-card.longest .value { color: var(--gold); }

/* ========== UTILITY ========== */
.muted { color: var(--text-muted); }
.serif { font-family: var(--serif); font-style: italic; }
.spacer { height: 60px; }

@media (max-width: 480px) {
  .app-shell { padding: 0 16px; }
  .date-day { font-size: 32px; }
}
