@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Figtree:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #EDF2E9;
  --card: #FBFDF9;
  --card-raised: #FFFFFF;
  --text: #2F3B2E;
  --text-soft: #5C6B57;
  --border: #DCE5D5;
  --accent: #E8785C;
  --accent-dark: #C85F45;
  --accent-soft: #FBE3DB;
  --sage: #5A7A4A;
  --sage-dark: #3E5A34;
  --gold: #D9A441;
  --gold-soft: #F6E7C9;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-display: 'Fraunces', serif;
  --font-body: 'Figtree', sans-serif;
  --shadow: 0 8px 24px rgba(47, 59, 46, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: var(--font-body);
}

::selection { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Layout scaffolding ---------- */

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 28px 22px 100px;
  animation: fadeIn 0.35s ease;
}
.view.active { display: flex; }

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

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  line-height: 1.15;
  color: var(--sage-dark);
}

p { line-height: 1.55; margin: 0; }

/* ---------- Bottom nav ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--card-raised);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  gap: 6px;
  z-index: 40;
}
.tabbar.hidden { display: none; }

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  transition: background 0.2s, color 0.2s;
}
.tab-btn .tab-icon { font-size: 22px; }
.tab-btn.active { color: var(--sage-dark); background: var(--accent-soft); }

/* ---------- Onboarding ---------- */

.onboard-hero {
  text-align: left;
  margin-bottom: 6px;
}
.onboard-hero .eyebrow-plant {
  font-size: 40px;
  display: block;
  margin-bottom: 10px;
}
.onboard-hero h1 {
  font-size: 32px;
  max-width: 15ch;
}
.onboard-hero p {
  color: var(--text-soft);
  margin-top: 10px;
  max-width: 34ch;
}

.field {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field label {
  font-weight: 600;
  font-size: 15px;
  color: var(--sage-dark);
}
.field .hint {
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 400;
}

.field input, .field select {
  border: 2px solid var(--border);
  background: var(--card-raised);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 17px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .field select:focus { border-color: var(--sage); }

.row-2 { display: flex; gap: 12px; }
.row-2 .field { flex: 1; }

.btn-primary {
  margin-top: 26px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  text-align: center;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:active { transform: scale(0.98); background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.5; pointer-events: none; }

.btn-secondary {
  margin-top: 12px;
  background: transparent;
  color: var(--sage-dark);
  font-weight: 700;
  font-size: 16px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  text-align: center;
  border: 2px solid var(--border);
}
.btn-secondary:active { transform: scale(0.98); }

.mode-switch {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}
.mode-tab {
  flex: 1;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-soft);
  text-align: center;
  background: var(--card-raised);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mode-tab.active {
  background: var(--sage);
  border-color: var(--sage);
  color: #fff;
}

.guest-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 22px;
  font-size: 14px;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1.4;
}
.guest-toggle input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--sage);
  flex-shrink: 0;
}

.guest-badge {
  display: inline-block;
  background: var(--border);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-top: 8px;
}

.code-display {
  margin-top: 16px;
  background: var(--gold-soft);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align: center;
}
.code-display .code-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #8A6212;
}
.code-display .code-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #8A6212;
  margin-top: 6px;
}
.code-display p { color: #8A6212; }

.logout-link {
  margin-top: 30px;
  text-align: center;
  font-size: 13px;
  color: var(--text-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  align-self: center;
  width: 100%;
}

.btn-text {
  color: var(--sage-dark);
  font-weight: 700;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  align-self: flex-start;
  margin-top: 14px;
}

/* ---------- Welcome AI card (onboarding result) ---------- */

.welcome-card {
  margin-top: 22px;
  background: var(--card-raised);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--sage);
}
.welcome-card .tag { font-size: 12px; font-weight: 700; letter-spacing: 0.02em; color: var(--sage); text-transform: none; }
.welcome-card p { margin-top: 10px; font-size: 16px; }

.loading-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-soft);
  font-size: 15px;
  margin-top: 18px;
}
.spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--sage);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Home ---------- */

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.home-header h1 { font-size: 28px; }
.home-header .date-line { color: var(--text-soft); font-size: 14px; margin-top: 4px; }

.points-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gold-soft);
  color: #8A6212;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Growth path */
.growth-card {
  margin-top: 22px;
  background: var(--card-raised);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  box-shadow: var(--shadow);
}
.growth-card .level-title {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--sage-dark);
}
.growth-card .level-sub {
  font-size: 13px;
  color: var(--text-soft);
  margin-top: 2px;
}
.growth-path {
  display: flex;
  align-items: center;
  margin-top: 18px;
}
.growth-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.growth-step .dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  z-index: 2;
  transition: background 0.3s;
}
.growth-step.done .dot { background: var(--sage); }
.growth-step.current .dot { background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.growth-step .line {
  position: absolute;
  top: 17px; left: 50%;
  width: 100%;
  height: 3px;
  background: var(--border);
  z-index: 1;
}
.growth-step.done .line { background: var(--sage); }
.growth-step:last-child .line { display: none; }
.growth-step .label {
  font-size: 10px;
  color: var(--text-soft);
  margin-top: 6px;
  text-align: center;
}

.progress-bar-track {
  margin-top: 14px;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--sage);
  border-radius: 999px;
  transition: width 0.5s ease;
}
.progress-caption {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-soft);
}

/* Tip of the day */
.tip-card {
  margin-top: 16px;
  background: var(--accent-soft);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.tip-card .tip-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
}
.tip-card p { margin-top: 8px; font-size: 15px; color: var(--text); }

/* Section headers */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 30px;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 20px; }
.section-head .link-btn {
  font-size: 14px;
  font-weight: 700;
  color: var(--sage-dark);
}

/* Routine card */
.routine-card {
  background: var(--card-raised);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.routine-card .info h3 { font-size: 17px; color: var(--text); }
.routine-card .info .meta { font-size: 13px; color: var(--text-soft); margin-top: 3px; }
.routine-card .start-btn {
  background: var(--sage);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.routine-card .start-btn:active { background: var(--sage-dark); }

.empty-state {
  background: var(--card-raised);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 20px;
  text-align: center;
  color: var(--text-soft);
}
.empty-state p { font-size: 15px; }
.empty-state .plant-emoji { font-size: 34px; display: block; margin-bottom: 10px; }

/* ---------- Builder ---------- */

.exercise-row {
  background: var(--card-raised);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-top: 14px;
  position: relative;
}
.exercise-row .remove-x {
  position: absolute;
  top: 10px; right: 10px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-soft);
  font-size: 18px;
  border-radius: 50%;
}
.exercise-row .remove-x:active { background: var(--border); }

.type-toggle {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.type-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-soft);
}
.type-toggle button.active {
  border-color: var(--sage);
  background: var(--sage);
  color: #fff;
}

.add-exercise-btn {
  margin-top: 16px;
  border: 2px dashed var(--sage);
  color: var(--sage-dark);
  font-weight: 700;
  font-size: 15px;
  padding: 14px;
  border-radius: var(--radius-md);
  text-align: center;
}
.add-exercise-btn:active { background: var(--accent-soft); }

/* ---------- Session (doing a routine) ---------- */

.session-header h1 { font-size: 26px; }
.session-header .meta { color: var(--text-soft); font-size: 14px; margin-top: 4px; }

.exercise-check {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-raised);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-top: 12px;
  transition: background 0.2s;
}
.exercise-check.checked {
  background: var(--accent-soft);
}
.exercise-check .checkbox {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--sage);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  color: transparent;
  transition: background 0.2s, color 0.2s;
}
.exercise-check.checked .checkbox {
  background: var(--sage);
  color: #fff;
}
.exercise-check .ex-name { font-weight: 600; font-size: 16px; }
.exercise-check .ex-detail { font-size: 13.5px; color: var(--text-soft); margin-top: 2px; }

.finish-bar {
  margin-top: 26px;
}

/* ---------- Celebration overlay ---------- */

.celebration-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47, 59, 46, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.celebration-overlay.active { display: flex; }
.celebration-card {
  background: var(--card-raised);
  border-radius: var(--radius-lg);
  padding: 30px 26px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(.2,1.4,.4,1);
}
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.celebration-card .big-emoji { font-size: 52px; }
.celebration-card h2 { margin-top: 10px; font-size: 24px; }
.celebration-card p { margin-top: 8px; color: var(--text-soft); }
.celebration-card .points-earned {
  margin-top: 16px;
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--accent);
  font-weight: 700;
}
.level-up-banner {
  margin-top: 14px;
  background: var(--gold-soft);
  color: #8A6212;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 700;
  font-size: 14px;
}

/* ---------- Progress view ---------- */

.progress-summary {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.stat-card {
  flex: 1;
  background: var(--card-raised);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .num { font-family: var(--font-display); font-size: 26px; color: var(--sage-dark); }
.stat-card .label { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-item .h-name { font-weight: 600; font-size: 15px; }
.history-item .h-date { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.history-item .h-points { font-weight: 700; color: var(--sage); font-size: 14px; }

/* Top bar with back button for sub-views */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.back-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--card-raised);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.back-btn:active { background: var(--border); }
.topbar h1 { font-size: 20px; }
