:root {
  --bg: #f2f3f8;
  --bg-elevated: #ffffff;
  --text: #14151a;
  --text-dim: #6b6f7d;
  --border: rgba(20, 21, 26, 0.08);
  --accent: #4f46e5;
  --accent-2: #06b6d4;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --good: #16a34a;
  --warn-bg: #fff7e6;
  --warn-border: #f5c451;
  --warn-text: #7a5b00;
  --shadow: 0 1px 2px rgba(20, 21, 26, 0.06), 0 4px 16px rgba(20, 21, 26, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14;
    --bg-elevated: #161925;
    --text: #f1f2f6;
    --text-dim: #9a9db0;
    --border: rgba(255, 255, 255, 0.09);
    --accent: #818cf8;
    --accent-2: #22d3ee;
    --accent-text: #0b0d14;
    --danger: #f87171;
    --good: #4ade80;
    --warn-bg: #241d05;
    --warn-border: #6b5300;
    --warn-text: #f5d67a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; }

.topbar {
  padding: calc(var(--safe-top) + 14px) 20px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.topbar-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

main#view {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px calc(96px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + var(--safe-bottom));
  z-index: 10;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 6px 0 4px;
  border-radius: 10px;
  cursor: pointer;
}
.tab-btn svg { width: 24px; height: 24px; fill: currentColor; }
.tab-btn span { font-size: 11px; font-weight: 600; }
.tab-btn.active { color: var(--accent); }

/* ---- shared ---- */
.card {
  background: var(--bg-elevated);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 22px 4px 10px;
}
.section-title:first-child { margin-top: 4px; }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13.5px;
  line-height: 1.4;
}
.banner b { display: block; margin-bottom: 2px; }

/* ---- progress ring ---- */
.ring-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 4px 18px;
}
.ring { width: 74px; height: 74px; flex-shrink: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .track { stroke: var(--border); }
.ring .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.ring-label {
  font-size: 15px;
  font-weight: 700;
}
.ring-label small { display: block; font-weight: 500; color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

/* ---- checklist items ---- */
.checklist { display: flex; flex-direction: column; gap: 2px; }
.check-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.check-item:last-child { border-bottom: none; }
.check-circle {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.check-circle svg { width: 14px; height: 14px; fill: none; stroke: var(--accent-text); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.15s; }
.check-item.done .check-circle { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.check-item.done .check-circle svg { opacity: 1; transform: scale(1); }
.check-body { flex: 1; min-width: 0; }
.check-name { font-size: 15px; font-weight: 600; line-height: 1.35; }
.check-item.done .check-name { color: var(--text-dim); text-decoration: line-through; text-decoration-thickness: 1.5px; text-decoration-color: var(--text-dim); }
.check-time { font-size: 12px; color: var(--accent); font-weight: 700; margin-bottom: 1px; }
.check-detail { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }
.check-note { font-size: 12px; color: var(--text-dim); background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 6px; line-height: 1.45; }

/* ---- week tab ---- */
.day-chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 16px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.day-chip {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.day-chip.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text); border-color: transparent; }
.day-chip .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--good); margin-left: 6px; vertical-align: middle; }

/* ---- guide / accordion ---- */
.accordion { border-bottom: 1px solid var(--border); }
.accordion:last-child { border-bottom: none; }
.accordion-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 14px 4px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.accordion-head .chev { transition: transform 0.2s; color: var(--text-dim); flex-shrink: 0; }
.accordion.open .accordion-head .chev { transform: rotate(90deg); }
.accordion-body { display: none; padding: 0 4px 16px; font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }
.accordion.open .accordion-body { display: block; }
.ex-item { margin-bottom: 14px; }
.ex-item:last-child { margin-bottom: 0; }
.ex-name { color: var(--text); font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.ex-avoid { color: var(--danger); font-weight: 600; }

table.exp-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.exp-table th, table.exp-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.exp-table th { color: var(--text-dim); font-weight: 700; font-size: 11px; text-transform: uppercase; }
table.exp-table td:first-child { font-weight: 700; color: var(--text); }

.note-list { margin: 0; padding-left: 18px; }
.note-list li { margin-bottom: 8px; }

/* ---- progress tab ---- */
.progress-entry { display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.progress-entry:last-child { border-bottom: none; }
.progress-thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex-shrink: 0; background: var(--bg); }
.progress-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 22px; }
.progress-meta { flex: 1; min-width: 0; }
.progress-date { font-size: 13px; font-weight: 700; }
.progress-note { font-size: 13px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; white-space: pre-wrap; }
.progress-weight { font-size: 12px; color: var(--accent); font-weight: 700; margin-top: 3px; }
.progress-del { background: none; border: none; color: var(--text-dim); font-size: 18px; padding: 4px 6px; cursor: pointer; }

.empty-state { text-align: center; color: var(--text-dim); font-size: 13.5px; padding: 30px 20px; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + var(--safe-bottom));
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
  cursor: pointer;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.modal-sheet {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.field-label { font-size: 12.5px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin: 14px 0 6px; }
.field-label:first-of-type { margin-top: 0; }
textarea, input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
.photo-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13.5px;
}
.photo-pick img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn {
  flex: 1;
  padding: 13px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-text); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 30;
  box-shadow: var(--shadow);
}

.install-banner {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 600;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.install-banner button {
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
