:root {
  --bg: #0a0a0c;
  --surface: #141418;
  --surface-2: #1c1c22;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --muted: #8e8e9a;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", system-ui, sans-serif;
  --font-display: "Outfit", sans-serif;
  --nav-bottom: 72px;
  --sidebar: 260px;
  --topbar: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

.app {
  display: flex;
  min-height: 100dvh;
}

/* sidebar desktop */
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
}

.brand strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.brand span {
  font-size: 0.7rem;
  color: var(--muted);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-2);
}

.sidebar-foot { padding-top: 1rem; }

.fast-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-2);
  padding: 0.5rem 0.75rem;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 8px;
  text-align: center;
}

/* main */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-bottom) + var(--safe-b));
}

.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 12, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-open { display: none; }

.topbar-greet {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.topbar-title strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn svg { width: 20px; height: 20px; }

.upload-quick { color: var(--accent-2); }

.content {
  flex: 1;
  padding: 1rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .content { padding: 1.5rem 2rem; max-width: 800px; }
  .main-wrap { padding-bottom: 0; }
  .bottom-nav { display: none !important; }
}

@media (max-width: 899px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-open { display: grid; }
}

/* views */
.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* dashboard */
.progress-hero {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  padding: 1.25rem;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(168, 85, 247, 0.08));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.ring-wrap {
  position: relative;
  width: 100px;
  height: 100px;
  flex-shrink: 0;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: url(#ringGrad);
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.8s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-day {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.ring-of { font-size: 0.65rem; color: var(--muted); }

.progress-meta h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.days-left { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }

.stat-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.stat-pill {
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.stat-val {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
}

.stat-lbl {
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.card-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -0.5rem 0 1rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.card-head .card-title { margin-bottom: 0; }

.text-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* checklist */
.day0-banner {
  font-size: 0.85rem;
  color: var(--accent-2);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.day0-banner.hidden { display: none; }

.checklist { display: flex; flex-direction: column; gap: 0.5rem; }

.check-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.check-item:hover { background: var(--surface-2); }

.check-item input { position: absolute; opacity: 0; width: 0; height: 0; }

.check-box {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}

.check-item input:checked + .check-box {
  background: var(--accent);
  border-color: var(--accent);
}

.check-item input:checked + .check-box::after {
  content: "✓";
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.check-item input:checked ~ span:last-child {
  color: var(--muted);
  text-decoration: line-through;
}

.protocol-list {
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
}

.protocol-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  padding-left: 1rem;
  position: relative;
}

.protocol-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
}

.protocol-list li:last-child { border-bottom: none; }

/* photo strip */
.photo-strip {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}

.photo-strip::-webkit-scrollbar { display: none; }

.photo-strip .empty-hint {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 1rem 0;
}

.strip-thumb {
  width: 72px;
  height: 96px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  cursor: pointer;
}

/* upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.75rem;
  background: var(--surface-2);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent-2);
}

.upload-icon svg { width: 24px; height: 24px; }

.upload-inner p { font-size: 0.95rem; margin-bottom: 0.25rem; }
.upload-inner span { font-size: 0.75rem; color: var(--muted); }

.filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.filter-bar label {
  flex: 1;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.filter-bar select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
}

/* photo grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 500px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}

.photo-card {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-2);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  font-size: 0.65rem;
  font-weight: 600;
}

.photo-card-meta span {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-2);
}

.grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

/* log form */
.field {
  display: block;
  margin-bottom: 1rem;
}

.field span {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field textarea,
.field select,
.settings-form input,
.settings-form select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.chart-wrap {
  position: relative;
  height: 160px;
  margin-bottom: 0.5rem;
}

.chart-wrap canvas { width: 100% !important; }

.chart-empty {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 1rem;
}

.chart-empty.hidden { display: none; }

.log-history { display: flex; flex-direction: column; gap: 0.5rem; }

.log-entry {
  padding: 0.85rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.log-entry-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.log-entry-head strong { font-size: 0.9rem; }
.log-entry-head span { font-size: 0.75rem; color: var(--muted); }

.log-entry p { font-size: 0.85rem; color: var(--muted); }

/* compare */
.compare-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.compare-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.compare-stage img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.compare-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.slider-compare { margin-top: 1rem; }

.slider-compare.hidden { display: none; }

.slider-images {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.slider-images > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slider-clip {
  position: absolute;
  inset: 0;
  width: 50%;
  overflow: hidden;
}

.slider-clip img {
  position: absolute;
  inset: 0;
  width: 100vw;
  max-width: none;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.slider-input {
  width: 100%;
  margin-top: 0.75rem;
  accent-color: var(--accent);
}

/* buttons */
.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-2); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; width: auto; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.danger-card { border-color: rgba(239, 68, 68, 0.2); }

/* bottom nav mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-bottom) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.bottom-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem;
  border: none;
  background: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
}

.bottom-item svg { width: 22px; height: 22px; }

.bottom-item.active { color: var(--accent-2); }

.bottom-fab {
  flex: 0;
  margin-top: -20px;
}

.fab-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  font-size: 1.75rem;
  font-weight: 300;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45);
  line-height: 1;
}

/* modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
  width: 400px;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
}

.modal-box h3 {
  font-family: var(--font-display);
  margin-bottom: 1rem;
}

.modal-preview {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 1rem;
  background: var(--surface-2);
}

.modal-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.modal-actions .btn-primary { flex: 1; }

.lightbox {
  width: min(95vw, 500px);
  max-height: 90vh;
  padding: 0;
  border: none;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.lightbox-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 2;
}

.lightbox img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  background: #000;
}

.lightbox-info {
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.lightbox .btn-danger {
  margin: 0 1rem 1rem;
  width: calc(100% - 2rem);
}

/* toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-bottom) + 1rem + var(--safe-b));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.35s ease;
  pointer-events: none;
  white-space: nowrap;
}

@media (min-width: 900px) {
  .toast { bottom: 2rem; }
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* sync badge */
.sync-badge {
  font-size: 1rem;
  opacity: 0.35;
  transition: opacity 0.3s;
}

.sync-badge.active {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.6));
}

.hidden { display: none !important; }

/* auth screen */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin: 0.5rem 0 0.25rem;
}

.auth-brand p {
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.auth-tab {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.auth-tab.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent);
  color: var(--accent-2);
}

.auth-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1.25rem;
  margin-bottom: 0.5rem;
}

.auth-setup {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-setup ol {
  margin: 0.75rem 0 0.75rem 1.25rem;
}

.auth-setup li { margin-bottom: 0.35rem; }

.auth-setup a { color: var(--accent-2); }

.auth-setup code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.auth-setup-note {
  font-size: 0.75rem;
  margin-top: 0.75rem;
}

#app.hidden { display: none; }
