/* ---------- tokens ---------- */
:root {
  --paper:        #f4efe6;
  --paper-soft:   #fbf7f0;
  --paper-deep:   #ebe3d5;
  --ink:          #1f1a17;
  --ink-soft:     #4a423b;
  --muted:        #7a7068;
  --hairline:     #d9d1c5;
  --hairline-soft:#e7e0d3;
  --accent:       #a4513a;   /* terracotta, used sparingly */
  --accent-soft:  #c97d62;
  --done:         #4a5a3a;   /* moss, only for "done" state */
  --skip:         #8a8079;

  --serif:    "Newsreader", Georgia, serif;
  --display:  "Fraunces", "Newsreader", Georgia, serif;
  --mono:     "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 4px;
  --pad-x: clamp(1rem, 4vw, 2.5rem);
  --max-w: 44rem;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #17140f;
    --paper-soft:   #1f1b15;
    --paper-deep:   #100d09;
    --ink:          #ece4d4;
    --ink-soft:     #c8bfae;
    --muted:        #8a8175;
    --hairline:     #3a342b;
    --hairline-soft:#2a251f;
    --accent:       #d28c70;
    --accent-soft:  #b06f54;
    --done:         #9bb281;
    --skip:         #6a6058;
    color-scheme: dark;
  }
}

/* ---------- reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  font-feature-settings: "ss01", "ss02";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
a:hover { color: var(--ink); }

::selection { background: var(--accent); color: var(--paper); }

/* ---------- layout ---------- */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2.5rem var(--pad-x) 5rem;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--hairline);
}
.masthead .title {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  font-variation-settings: "opsz" 144;
}
.masthead .meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

nav.tabs {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  margin-bottom: 2.5rem;
  flex-wrap: wrap;
}
nav.tabs button {
  font-family: var(--display);
  font-size: 1rem;
  color: var(--muted);
  padding: 0 0 0.35rem 0;
  border-bottom: 1px solid transparent;
  font-variation-settings: "opsz" 14;
  transition: color 120ms ease, border-color 120ms ease;
}
nav.tabs button:hover { color: var(--ink-soft); }
nav.tabs button.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* ---------- typography ---------- */
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; }
h1 {
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-variation-settings: "opsz" 144;
  letter-spacing: -0.015em;
  line-height: 1.05;
}
h2 {
  font-size: 1.45rem;
  font-variation-settings: "opsz" 36;
  margin-top: 2.5rem;
  margin-bottom: 0.5rem;
}
h3 {
  font-size: 1.1rem;
  font-variation-settings: "opsz" 18;
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}
.kicker {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.lede { color: var(--ink-soft); font-size: 1.05rem; max-width: 36rem; }
p { margin: 0 0 1rem; }
hr { border: 0; border-top: 1px solid var(--hairline); margin: 2rem 0; }

/* ---------- forms ---------- */
input[type="text"], input[type="date"], input[type="number"], textarea, select {
  background: var(--paper-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  width: 100%;
  font-family: var(--serif);
  transition: border-color 100ms ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ink);
}
textarea { resize: vertical; min-height: 7rem; line-height: 1.5; }
label.field {
  display: block;
  margin-bottom: 1rem;
}
label.field > span {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-variation-settings: "opsz" 14;
  font-size: 0.95rem;
  transition: opacity 120ms ease, transform 120ms ease;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--hairline);
}
.btn.ghost:hover { border-color: var(--ink); opacity: 1; }
.btn.danger {
  background: transparent;
  color: var(--accent);
  border-color: currentColor;
}
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- check rows ---------- */
.checks { list-style: none; padding: 0; margin: 0; }
.checks li {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--hairline-soft);
}
.checks li:last-child { border-bottom: 0; }
.checks .glyph {
  font-family: var(--mono);
  width: 1.1rem;
  display: inline-block;
  color: var(--muted);
  font-size: 1.05rem;
}
.checks li.is-done .glyph { color: var(--done); }
.checks li.is-skip  .glyph { color: var(--skip); font-style: italic; }
.checks .name { flex: 1; }
.checks .name.weekly::after {
  content: "weekly";
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-left: 0.6rem;
}
.checks button.toggle {
  text-align: left;
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  flex: 1;
  padding: 0.1rem 0;
}
.checks button.toggle:hover .glyph { color: var(--ink); }
.checks button.toggle:hover .name  { color: var(--ink-soft); }

/* ---------- weekly progress ---------- */
.progress-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.progress-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--hairline-soft);
}
.progress-list li:last-child { border-bottom: 0; }
.progress-list .name { font-family: var(--serif); }
.progress-list .count {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
}
.progress-list .count.hit  { color: var(--done); }
.progress-list .count.miss { color: var(--accent); }

/* ---------- 8-week overview ---------- */
.overview-grid {
  display: grid;
  grid-template-columns: 3.5rem repeat(7, 1fr);
  gap: 2px;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.overview-grid .head {
  color: var(--muted);
  text-align: center;
  padding: 0.3rem 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
}
.overview-grid .row-head {
  color: var(--muted);
  padding: 0.5rem 0.4rem 0.5rem 0;
  text-align: right;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.7rem;
}
.cell {
  aspect-ratio: 1;
  background: var(--paper-soft);
  border: 1px solid var(--hairline-soft);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: border-color 100ms ease, transform 100ms ease;
}
.cell:hover { border-color: var(--ink); }
.cell.is-today { border-color: var(--accent); }
.cell.is-future { background: transparent; cursor: default; }
.cell.is-future:hover { border-color: var(--hairline-soft); }
.cell .glyph { font-size: 0.85rem; }
.cell.is-empty .glyph { color: var(--muted); opacity: 0.4; }
.cell.is-partial .glyph { color: var(--ink-soft); }
.cell.is-full .glyph { color: var(--done); }
.cell.is-miss .glyph { color: var(--muted); }
.cell.is-skip .glyph { color: var(--skip); font-style: italic; }
.cell.has-note::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-soft);
}

.legend {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 1.5rem;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.legend .swatch { color: var(--ink-soft); }

/* ---------- plan editor ---------- */
.week-block {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  background: var(--paper-soft);
}
.week-block.is-current { border-color: var(--accent); }
.week-block header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}
.week-block h3 { margin: 0; }
.cadence-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--hairline-soft);
}
.cadence-row:last-child { border-bottom: 0; }
.cadence-row .desc {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.cadence-row .desc.off { font-style: italic; }

.day-toggle {
  display: inline-flex;
  gap: 4px;
}
.day-toggle button {
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 0.7rem;
  background: var(--paper-soft);
  color: var(--muted);
  text-transform: uppercase;
}
.day-toggle button.is-on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.day-toggle button:hover { border-color: var(--ink); }

/* ---------- dialog / panel ---------- */
.panel {
  position: fixed;
  inset: 0;
  background: rgba(31, 26, 23, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.panel .panel-body {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 32rem;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

/* ---------- toast / banner ---------- */
.banner {
  background: var(--paper-soft);
  border-left: 2px solid var(--accent);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.banner .text { color: var(--ink-soft); }

/* ---------- onboarding ---------- */
.onboarding {
  max-width: 32rem;
  margin: 0 auto;
}
.onboarding .step-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.behavior-draft {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--paper-soft);
}
.behavior-draft .row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.behavior-draft .row:last-child { margin-bottom: 0; }
.behavior-draft input[type="text"] { flex: 1; }
.behavior-draft select { max-width: 12rem; }

/* ---------- utilities ---------- */
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.stack > * + * { margin-top: 1rem; }
.tight > * + * { margin-top: 0.5rem; }
.divider {
  height: 1px;
  background: var(--hairline);
  margin: 1.5rem 0;
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- print (week journal) ---------- */
@media print {
  nav.tabs, .actions, .btn { display: none; }
  body { background: white; color: black; }
}
