:root {
  --bg-0: #0a0a0f;
  --bg-1: #12121a;
  --bg-2: #1a1a26;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text: #f5f5fa;
  --text-dim: #9999a8;
  --text-muted: #6b6b7c;

  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);

  --nav-h: 72px;
  --top-h: 56px;
  --strip-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse at top, #1a1530 0%, var(--bg-0) 50%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ==================== Auth ==================== */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  width: 100%; max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-card h1 { margin: 0 0 8px; font-size: 28px; font-weight: 700; }
.auth-sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text); font-size: 15px;
  outline: none; transition: border-color .15s;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; padding: 14px 16px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 15px;
  transition: transform .1s, box-shadow .15s;
}
.auth-card button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(99,102,241,.4); }
.auth-card button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.auth-msg { margin: 16px 0 0; font-size: 13px; min-height: 18px; color: var(--text-dim); }
.auth-msg.error { color: var(--danger); }
.auth-msg.success { color: var(--success); }
.auth-toggle {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-dim);
  background: none;
  padding: 8px;
  transition: color .15s;
}
.auth-toggle:hover { color: var(--text); }

/* ==================== App layout ==================== */
.app {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-bottom: var(--nav-h);
}
.app.app-has-strip { padding-bottom: calc(var(--nav-h) + var(--strip-h)); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.today-label { font-weight: 600; font-size: 15px; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.sync-indicator { font-size: 10px; color: var(--success); transition: color .2s; }
.sync-indicator.offline { color: var(--warning); }
.sync-indicator.error { color: var(--danger); }

.view {
  flex: 1;
  padding: 20px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ==================== Bottom nav ==================== */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 60;
}
.nav-btn .nav-label { font-size: 10px; }
@media (min-width: 380px) { .nav-btn .nav-label { font-size: 11px; } }
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  transition: color .15s;
}
.nav-btn .nav-icon { font-size: 22px; }
.nav-btn .nav-label { font-size: 11px; font-weight: 500; }
.nav-btn.active { color: var(--text); }
.nav-btn.active .nav-icon { transform: scale(1.1); }

/* ==================== Cards ==================== */
.card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: background .15s, border-color .15s;
}
.card:hover { background: var(--surface-hover); }

.section-title {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-dim);
  margin: 24px 0 12px;
}
.section-title:first-child { margin-top: 0; }

/* ==================== Habits ==================== */
.date-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.date-nav button {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 18px;
  transition: background .15s;
}
.date-nav button:hover { background: var(--surface-hover); }
.date-nav .date-display { font-size: 17px; font-weight: 600; }
.date-nav .date-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; text-align: center; }

.habit-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: background .15s, border-color .15s;
}
.habit-row.done {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.3);
}
.habit-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--bg-2);
  border-radius: 12px;
  font-size: 20px;
  flex-shrink: 0;
}
.habit-info { flex: 1; min-width: 0; }
.habit-label { font-weight: 600; font-size: 15px; }
.habit-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.habit-input { display: flex; align-items: center; gap: 8px; }
.habit-input input[type="number"] {
  width: 64px; padding: 8px 10px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 14px; text-align: center;
  outline: none; transition: border-color .15s;
}
.habit-input input[type="number"]:focus { border-color: var(--accent); }
.habit-input .unit { font-size: 12px; color: var(--text-dim); }

.checkbox {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  display: grid; place-items: center;
  transition: all .15s;
  flex-shrink: 0;
}
.checkbox.checked {
  background: var(--success);
  border-color: var(--success);
}
.checkbox.checked::after {
  content: '✓'; color: #fff; font-weight: 700; font-size: 16px;
}

.add-input { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.add-input .add-total {
  font-weight: 700; font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.add-input .add-unit { color: var(--text-dim); font-size: 12px; font-weight: 500; margin-left: 2px; }
.add-input .add-row { display: flex; gap: 6px; align-items: center; }
.add-input input {
  width: 80px; padding: 6px 8px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 13px; text-align: center;
  outline: none; transition: border-color .15s;
}
.add-input input:focus { border-color: var(--accent); }
.add-input button {
  background: var(--accent); color: #fff;
  padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
}

.counter { display: flex; align-items: center; gap: 4px; }
.counter button {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface);
  font-size: 18px; font-weight: 600;
  transition: background .15s;
}
.counter button:hover { background: var(--surface-hover); }
.counter .count { min-width: 28px; text-align: center; font-weight: 600; font-size: 15px; }

/* ==================== Screen Time ==================== */
.screen-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .screen-grid { grid-template-columns: 1fr; } }

.screen-card { padding: 20px; }
.screen-card .device { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.screen-card .total { font-size: 32px; font-weight: 700; margin-top: 4px; }
.screen-card .source { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.time-input-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.time-input-row input {
  width: 60px; padding: 10px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  text-align: center; font-size: 16px; outline: none;
}
.time-input-row input:focus { border-color: var(--accent); }
.time-input-row .colon { color: var(--text-dim); font-weight: 600; }
.time-input-row button {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

/* ==================== Modes ==================== */
.modes-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin-bottom: 20px;
}
.mode-card {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform .1s, border-color .15s, background .15s;
}
.mode-card:hover { transform: translateY(-2px); }
.mode-card .mode-icon { font-size: 36px; }
.mode-card .mode-label { font-weight: 600; font-size: 14px; }

.timer-fullscreen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 32px;
  padding: 40px;
  text-align: center;
  animation: fadeIn .3s ease;
}
.timer-fullscreen .timer-icon { font-size: 80px; }
.timer-fullscreen .timer-mode { font-size: 22px; font-weight: 600; color: var(--text-dim); }
.timer-fullscreen .timer-time {
  font-size: 96px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.timer-fullscreen .stop-btn {
  background: var(--danger); color: #fff;
  padding: 16px 40px; border-radius: 100px;
  font-weight: 600; font-size: 16px;
  transition: transform .1s;
}
.timer-fullscreen .stop-btn:hover { transform: scale(1.05); }

.session-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.session-icon { font-size: 20px; }
.session-info { flex: 1; }
.session-mode { font-weight: 600; font-size: 14px; }
.session-time { font-size: 12px; color: var(--text-dim); }
.session-duration { font-weight: 600; color: var(--accent); font-size: 14px; }

/* ==================== Dashboard summary ==================== */
.summary-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-bottom: 20px;
}
.summary-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 10px;
  text-align: center;
}
.summary-tile .value { font-size: 22px; font-weight: 700; }
.summary-tile .label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-size: 14px;
}

/* ==================== Sleep ==================== */
.sleep-fields, .phase-fields { display: grid; gap: 10px; margin-bottom: 14px; }
.sleep-fields { grid-template-columns: 1fr 1fr; }
.phase-fields { grid-template-columns: repeat(2, 1fr); }
.sleep-fields label, .phase-fields label {
  display: flex; flex-direction: column; gap: 4px;
}
.sleep-fields span, .phase-fields span {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em;
}
.sleep-fields input, .phase-fields input {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  color: var(--text); font-size: 15px;
  outline: none; transition: border-color .15s;
}
.sleep-fields input:focus, .phase-fields input:focus { border-color: var(--accent); }

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; padding: 12px;
  width: 100%; border-radius: 10px;
  font-weight: 600; font-size: 14px;
  margin-top: 8px;
  transition: transform .1s, box-shadow .15s;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(99,102,241,.3); }

.phase-bar {
  display: flex; height: 16px;
  border-radius: 8px; overflow: hidden;
  margin: 14px 0 8px;
  background: var(--bg-2);
}
.phase-seg { height: 100%; transition: width .3s; }
.phase-deep  { background: #4338ca; }
.phase-light { background: #6366f1; }
.phase-rem   { background: #a78bfa; }
.phase-awake { background: #f59e0b; }
.phase-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 11px; color: var(--text-dim);
  margin-bottom: 8px;
}
.phase-legend .dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; margin-right: 4px;
  vertical-align: middle;
}

.upload-label { display: block; cursor: pointer; }
.upload-cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px; font-weight: 500;
  transition: border-color .15s, color .15s, background .15s;
}
.upload-cta:hover { border-color: var(--accent); color: var(--text); background: var(--surface-hover); }
.upload-cta span:first-child { font-size: 22px; }

.ocr-status {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  transition: border-color .15s, color .15s, background .15s;
}
.ocr-status.active {
  color: var(--text);
  border-color: rgba(99, 102, 241, .4);
  background: rgba(99, 102, 241, .08);
}
.ocr-status.success {
  color: var(--success);
  border-color: rgba(16, 185, 129, .35);
  background: rgba(16, 185, 129, .08);
}
.ocr-status.warn {
  color: var(--warning);
  border-color: rgba(245, 158, 11, .35);
  background: rgba(245, 158, 11, .08);
}

.screenshot-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 12px;
}
@media (max-width: 480px) { .screenshot-grid { grid-template-columns: repeat(2, 1fr); } }
.screenshot-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-2);
}
.screenshot-item img {
  width: 100%; height: 100%; object-fit: cover;
  cursor: zoom-in;
  display: block;
}
.screenshot-del {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff; font-size: 16px; line-height: 1;
  display: grid; place-items: center;
  transition: background .15s;
}
.screenshot-del:hover { background: var(--danger); }

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  cursor: zoom-out;
  animation: fadeIn .2s ease;
}
.lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.recent-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .15s;
}
.recent-row:hover { background: var(--surface-hover); }
.recent-date { font-weight: 600; font-size: 14px; }
.recent-stats {
  display: flex; gap: 12px;
  font-size: 12px; color: var(--text-dim);
}

/* ==================== Sleep score factor bars ==================== */
.factor-bars { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.factor-row { display: flex; flex-direction: column; gap: 4px; }
.factor-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--text-dim);
}
.factor-val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.factor-track {
  height: 8px; border-radius: 4px;
  background: var(--bg-2); overflow: hidden;
}
.factor-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .3s;
}

/* ==================== Habit "over limit" state ==================== */
.habit-row.over {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}
.habit-row.over .add-total { color: var(--danger); }

/* ==================== Timeline ==================== */
.timeline-card { padding: 18px 16px 14px; }
.timeline-track {
  position: relative;
  height: 44px;
  background: var(--bg-2);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.timeline-seg {
  position: absolute;
  top: 0; bottom: 0;
  min-width: 2px;
  opacity: 0.92;
  transition: opacity .15s, transform .15s;
}
.timeline-seg:hover { opacity: 1; transform: scaleY(1.06); }
.timeline-seg.live {
  background-image: linear-gradient(135deg, transparent 25%, rgba(255,255,255,.12) 25%, rgba(255,255,255,.12) 50%, transparent 50%, transparent 75%, rgba(255,255,255,.12) 75%);
  background-size: 14px 14px;
  animation: tlMove 1.2s linear infinite;
}
@keyframes tlMove { to { background-position: 14px 0; } }
.timeline-now {
  position: absolute;
  top: -4px; bottom: -4px;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.7);
  pointer-events: none;
}
.timeline-axis {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-muted);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.timeline-legend {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  font-size: 11px; color: var(--text-dim);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.timeline-legend .dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; margin-right: 4px;
  vertical-align: middle;
}
.live-dot {
  color: var(--danger); animation: pulse 1.4s ease-in-out infinite;
  font-size: 10px; margin-left: 4px;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.hint-card {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 12px;
  line-height: 1.5;
}
.hint-card strong { color: var(--text); }

/* ==================== Active session strip ==================== */
.active-strip {
  position: fixed;
  bottom: var(--nav-h);
  left: 0; right: 0;
  height: var(--strip-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.95), rgba(139, 92, 246, 0.95));
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  z-index: 55;
  animation: stripIn .25s ease;
}
@keyframes stripIn { from { transform: translateY(100%); } to { transform: none; } }

.active-strip .active-info {
  flex: 1;
  display: flex; align-items: center; gap: 14px;
  background: none;
  text-align: left;
  padding: 4px 4px 4px 0;
  color: #fff;
}
.active-strip .active-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 20px;
}
.active-strip .active-meta { display: flex; flex-direction: column; line-height: 1.2; }
.active-strip .active-mode { font-size: 12px; font-weight: 600; opacity: 0.9; }
.active-strip .active-time {
  font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.active-strip .active-stop {
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  padding: 9px 18px;
  border-radius: 100px;
  font-size: 13px; font-weight: 600;
  transition: background .15s, transform .1s;
}
.active-strip .active-stop:hover { background: rgba(0, 0, 0, 0.5); }
.active-strip .active-stop:active { transform: scale(0.96); }

/* Session row icon gets a square colored badge */
.session-row .session-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}
