@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,500;0,600;1,500&family=Caveat:wght@600&family=Nunito:wght@400;500;600;700&display=swap');

:root {
  --bg: #FBF6EF;
  --surface: #FFFDF9;
  --surface-alt-1: #F3ECDF;
  --surface-alt-2: #FCEFE3;
  --surface-alt-2-border: #F0DCC2;
  --border: #EEE4D2;
  --border-lt: #E6DBC5;
  --badge-bg: #EFE7D6;
  --ink: #4A4038;
  --ink-soft: #6B6255;
  --muted: #8A8073;
  --muted-strong: #7A6E54;
  --heading: #3A3226;
  --dotted-line: #C9BC9E;
  --placeholder: #A89C86;
  --handwritten: #9C7A4E;
  --entry-ink: #8A4E3A;
  --accent: #7C8B6F;
}

[data-theme="dark"] {
  --bg: #1C1A17;
  --surface: #26231F;
  --surface-alt-1: #2A2520;
  --surface-alt-2: #2E2620;
  --surface-alt-2-border: #4A3D30;
  --border: #3A3630;
  --border-lt: #332E28;
  --badge-bg: #332C22;
  --ink: #EDE6DA;
  --ink-soft: #C9BFAE;
  --muted: #8A8175;
  --muted-strong: #A69A80;
  --heading: #F2ECDD;
  --dotted-line: #5A5448;
  --placeholder: #6E6558;
  --handwritten: #D9A876;
  --entry-ink: #E0A47E;
  --accent: #8FA878;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

button, input, textarea, select { font-family: inherit; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(1.1rem + env(safe-area-inset-top)) 1.3rem 1.1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 10;
}
header .left { display: flex; align-items: center; gap: 10px; }
header h1 { font-size: 16px; margin: 0; font-weight: 700; color: var(--heading); }
.icon-btn { background: none; border: none; color: var(--ink-soft); font-size: 18px; cursor: pointer; }

main { max-width: 460px; margin: 0 auto; padding: 1.3rem 1.3rem calc(2.5rem + env(safe-area-inset-bottom)); min-width: 0; }

/* Library */
.legend { display: flex; gap: 16px; margin-bottom: 1rem; font-size: 12px; color: var(--ink-soft); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.progress-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 1rem 1.1rem; margin-bottom: 1.1rem; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.progress-card .num { font-size: 20px; font-weight: 700; }
.progress-card .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.progress-bar-track { flex: 1; height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.day-cell {
  aspect-ratio: 1; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; background: var(--surface); border: 1px solid var(--border); color: var(--ink-soft); cursor: pointer; min-width: 0;
}
.day-cell.dreamed { background: #E3DBF3; border-color: #B8A4DE; color: #5B4788; }
.day-cell.present { background: #DCE6D0; border-color: #9CB584; color: #45611F; }

/* Day page */
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); background: none; border: none; cursor: pointer; margin-bottom: 0.8rem; }
.day-badge { display: inline-block; background: var(--badge-bg); border-radius: 999px; padding: 5px 14px; font-size: 12.5px; font-weight: 600; color: var(--muted-strong); margin-bottom: 0.7rem; }
.hero { display: flex; align-items: center; gap: 14px; margin-bottom: 1.3rem; min-width: 0; }
.hero-text { flex: 1; min-width: 0; }
.day-title { font-family: 'Lora', serif; font-size: 28px; font-weight: 600; margin: 0 0 8px; color: var(--heading); overflow-wrap: anywhere; }
.day-intro { font-size: 13.5px; line-height: 1.65; color: var(--ink-soft); margin: 0; overflow-wrap: anywhere; }
.hero-art { width: 96px; height: 96px; flex-shrink: 0; }

.status-card { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0; }
.status-col { flex: 1; min-width: 0; }
.status-col + .status-col { border-left: 1px solid var(--border); padding-left: 14px; margin-left: 4px; }
.status-label { font-size: 12px; color: var(--ink-soft); margin: 0 0 10px; font-weight: 700; }
.mood-row { display: flex; gap: 5px; }
.mood-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; cursor: pointer; border: 2px solid transparent; }
.mood-dot.selected { border-color: var(--ink); }
.leaf-row { display: flex; gap: 4px; font-size: 16px; cursor: pointer; }
.leaf { opacity: 0.3; }
.leaf.filled { opacity: 1; }
.presence-count { font-size: 12px; color: var(--ink-soft); margin-top: 8px; }

.dd-toggle-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.dd-row { display: flex; gap: 8px; }
.dd-btn { flex: 1; padding: 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); font-weight: 700; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; }
.dd-btn.selected.yes { background: #E3DBF3; border-color: #B8A4DE; color: #5B4788; }
.dd-btn.selected.no { background: #DCE6D0; border-color: #9CB584; color: #45611F; }

.pages-card { background: var(--surface-alt-1); border-radius: 18px; padding: 1.1rem 1.1rem 0.3rem; margin-bottom: 1rem; min-width: 0; }
.pages-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.pages-head .label { font-family: 'Lora', serif; font-size: 16px; font-weight: 600; color: var(--heading); display: flex; align-items: center; gap: 7px; }
.pages-note { font-family: 'Caveat', cursive; font-size: 15px; color: var(--handwritten); text-align: right; line-height: 1.15; }
.prompt-row { display: flex; gap: 12px; padding: 0.8rem 0; border-top: 1px solid var(--border-lt); min-width: 0; }
.prompt-row:first-of-type { border-top: none; }
.prompt-icon { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; background: #E7E3DC; }
.prompt-body { flex: 1; min-width: 0; }
.prompt-q { font-family: 'Lora', serif; font-size: 15px; color: var(--heading); margin: 0 0 3px; overflow-wrap: anywhere; }
.prompt-hint { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.paper-line {
  border: none; border-bottom: 1px dotted var(--dotted-line); background: transparent;
  width: 100%; font-size: 16px; font-weight: 700; color: var(--entry-ink); padding: 4px 0; outline: none;
}
.paper-line::placeholder { font-size: 13px; font-weight: 400; color: var(--placeholder); }

.tomorrow-card { display: flex; align-items: center; gap: 12px; background: var(--surface-alt-2); border-radius: 16px; padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0; }
.tomorrow-text { font-family: 'Caveat', cursive; font-size: 18px; color: var(--handwritten); flex-shrink: 0; max-width: 130px; line-height: 1.2; }
.tomorrow-input {
  flex: 1; min-width: 0; border: 1px solid var(--surface-alt-2-border); background: var(--surface); border-radius: 12px;
  padding: 10px 12px; font-size: 14.5px; font-weight: 700; outline: none; color: var(--entry-ink);
}
.tomorrow-input::placeholder { font-weight: 400; color: var(--placeholder); }

.quote-card { background: #565B45; color: #F3EFE2; border-radius: 18px; padding: 1.2rem 1.3rem; text-align: center; margin-bottom: 1.1rem; }
.quote-card .moon { font-size: 15px; margin-bottom: 8px; opacity: 0.85; }
.quote-card p { font-family: 'Lora', serif; font-style: italic; font-size: 15px; margin: 0 0 6px; line-height: 1.5; overflow-wrap: anywhere; }
.quote-card .attr { font-size: 11.5px; opacity: 0.7; }

.nav-row { display: flex; align-items: center; gap: 10px; }
.nav-link { font-size: 13px; font-weight: 700; color: var(--muted-strong); background: none; border: none; cursor: pointer; padding: 0; }
.nav-link:disabled { opacity: 0.3; cursor: default; }
.progress-track { flex: 1; height: 4px; background: var(--border-lt); border-radius: 999px; overflow: hidden; }
.progress-track-fill { height: 100%; background: var(--accent); }

.hidden { display: none !important; }

/* Ground-yourself entry card */
.ground-entry {
  width: 100%; display: flex; align-items: center; gap: 12px;
  background: #565B45; color: #F3EFE2; border: none; border-radius: 16px;
  padding: 1rem 1.1rem; margin-bottom: 1.1rem; cursor: pointer; text-align: left;
}
.ground-entry-icon { font-size: 22px; }
.ground-entry-title { display: block; font-weight: 700; font-size: 14px; }
.ground-entry-sub { display: block; font-size: 12px; opacity: 0.75; margin-top: 2px; }

/* Grounding flow */
.ground-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 2rem 1.4rem; text-align: center; margin-bottom: 1.2rem;
}
.ground-icon { font-size: 30px; margin-bottom: 10px; }
.ground-title { font-family: 'Lora', serif; font-size: 24px; color: var(--heading); margin: 0 0 10px; }
.ground-body { font-size: 14px; line-height: 1.6; color: var(--ink-soft); margin: 0 0 1.4rem; }
.ground-cta {
  margin-top: 1.3rem; padding: 12px 28px; border-radius: 999px; border: none;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13.5px; cursor: pointer;
}
.ground-fields { display: flex; flex-direction: column; gap: 10px; }
.ground-field {
  border: 1px solid var(--border); background: var(--bg); border-radius: 12px;
  padding: 10px 12px; font-size: 14px; font-weight: 700; color: var(--entry-ink); outline: none; text-align: center;
}
.ground-field::placeholder { font-weight: 400; color: var(--placeholder); }

.breathing-wrap { display: flex; flex-direction: column; align-items: center; margin: 1rem 0 1.4rem; }
.breathing-circle {
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, #DCE6D0 0%, #B9C4A2 100%);
  transition: transform 4s ease-in-out;
  transform: scale(0.7);
}
.breathing-circle.inhale { transform: scale(1.15); }
.breathing-circle.exhale { transform: scale(0.7); }
.breathing-label { margin-top: 14px; font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.ground-progress { display: flex; justify-content: center; gap: 6px; }
.ground-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.ground-dot.active { background: var(--accent); width: 18px; border-radius: 999px; }
.ground-dot.done { background: #B9C4A2; }

.backup-modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 17, 12, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 1.2rem; z-index: 100;
}
.backup-modal {
  position: relative; width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--border-lt); border-radius: 18px;
  padding: 1.4rem 1.3rem 1.2rem; box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}
.backup-modal h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.backup-modal-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer;
}
.backup-panel, .backup-modal { display: flex; flex-direction: column; }
.backup-hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 0 0 10px; }
.backup-btn { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 10px; padding: 9px; font-size: 13px; cursor: pointer; text-align: center; margin-bottom: 8px; }
.backup-btn.secondary { background: var(--surface-alt-1); color: var(--ink-soft); border-color: var(--border); }
.backup-status { font-size: 12px; color: var(--accent); min-height: 14px; margin: 6px 0 0; }

.insight-card {
  border-radius: 16px; padding: 1rem 1.1rem; margin-bottom: 1.1rem;
  border: 1px solid var(--border); background: var(--surface-alt-1);
  border-left: 4px solid var(--accent);
}
.insight-card.fact { border-left-color: #B8A4DE; background: color-mix(in srgb, #E3DBF3 35%, var(--surface-alt-1)); }
.insight-card.exercise { border-left-color: #9CB584; background: color-mix(in srgb, #DCE6D0 35%, var(--surface-alt-1)); }
.insight-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--muted-strong); margin: 0 0 6px; }
.insight-text { font-size: 13.5px; line-height: 1.6; color: var(--ink-soft); margin: 0; }
