/* Grove styles.
 *
 * Everything worth restyling lives in the tokens below: colors (light and
 * dark), type, spacing, and corners. Components below only use tokens, so a
 * new look starts here.
 */

:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeede6;
  --text: #1d221f;
  --muted: #5d6660;
  --line: #e1dfd6;
  --accent: #2f6a4f;
  --accent-text: #ffffff;
  --accent-soft: #e2eee6;
  --danger: #a1392a;
  --shadow: 0 1px 2px rgba(20, 30, 24, 0.05), 0 6px 18px rgba(20, 30, 24, 0.05);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --text-xs: 13px;
  --text-sm: 15px;
  --text-md: 17px;
  --text-lg: 20px;
  --text-xl: 25px;
  --text-2xl: 31px;
  --leading: 1.5;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --r1: 10px;
  --r2: 18px;
  --pill: 999px;

  --bar-h: 56px;
  --tab-h: 62px;
  --max: 620px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1311;
    --surface: #171c19;
    --surface-2: #202622;
    --text: #e6ebe7;
    --muted: #9aa49d;
    --line: #29302b;
    --accent: #8fc8a4;
    --accent-text: #0f1311;
    --accent-soft: #1b2a21;
    --danger: #f08b78;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1311;
  --surface: #171c19;
  --surface-2: #202622;
  --text: #e6ebe7;
  --muted: #9aa49d;
  --line: #29302b;
  --accent: #8fc8a4;
  --accent-text: #0f1311;
  --accent-soft: #1b2a21;
  --danger: #f08b78;
  --shadow: none;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: var(--text-md)/var(--leading) var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h2 { margin: 0 0 var(--s3); font: 600 var(--text-xl)/1.25 var(--font-display); }
h3 { margin: 0 0 var(--s2); font: 600 var(--text-md)/1.3 var(--font); }
p { margin: 0 0 var(--s3); }
code { font-size: var(--text-xs); }

/* ---------- frame ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--s2);
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--s4), env(safe-area-inset-right)) 0 max(var(--s4), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font: 600 var(--text-lg)/1.2 var(--font-display); }
.spacer { flex: 1; }
.back {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: calc(var(--s2) * -1);
  border: 0;
  border-radius: var(--pill);
  background: none;
  color: var(--accent);
  cursor: pointer;
}
.back svg { width: 24px; height: 24px; }
.syncpill {
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: var(--s1) var(--s3);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}
.syncpill.is-error { color: var(--danger); }

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding:
    var(--s2)
    max(var(--s4), env(safe-area-inset-right))
    calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s6))
    max(var(--s4), env(safe-area-inset-left));
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--tab-h);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar [aria-current="page"] { color: var(--accent); }

/* ---------- content ---------- */

.greeting { margin: var(--s4) 0 var(--s5); font: 600 var(--text-2xl)/1.2 var(--font-display); }
.lead { font-size: var(--text-lg); line-height: 1.45; }
.muted { color: var(--muted); }
.note { font-size: var(--text-sm); color: var(--muted); }
.error { color: var(--danger); }

.card {
  margin: 0 0 var(--s4);
  padding: var(--s5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
.card-primary { background: var(--accent-soft); border-color: transparent; box-shadow: none; }

.section-title {
  margin: var(--s6) 0 var(--s3);
  color: var(--muted);
  font: 600 var(--text-xs)/1.2 var(--font);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.section-title:first-child { margin-top: var(--s4); }

.empty { padding: var(--s7) var(--s4); color: var(--muted); text-align: center; }
.empty h2 { color: var(--text); }
.empty-inline {
  padding: var(--s4) var(--s5);
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--r2);
}
.empty-inline > :last-child { margin-bottom: 0; }

/* ---------- controls ---------- */

.actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  appearance: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-wide { width: 100%; }

.field { display: grid; gap: var(--s1); margin: var(--s3) 0; }
.field > span { color: var(--muted); font-size: var(--text-sm); }
.field input {
  min-height: 48px;
  padding: 0 var(--s4);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r1);
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}
.row > :first-child { color: var(--muted); }
.row > :last-child { text-align: right; overflow-wrap: anywhere; }
.row-link {
  width: 100%;
  background: none;
  border-width: 0 0 1px;
  border-style: solid;
  border-color: var(--line);
  text-align: left;
  cursor: pointer;
}
.row-link > :first-child { color: var(--text); }
.row-link > :last-child { color: var(--muted); }

/* A row that turns something on or off (role="switch"). */
.row-switch { align-items: center; }
.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
[aria-checked="true"] > .switch { background: var(--accent); border-color: var(--accent); }
[aria-checked="true"] > .switch::after { transform: translateX(18px); background: var(--accent-text); }

/* A piece of the room in a list: homework, a thought record, a change. */
.item { padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.item > :last-child { margin-bottom: 0; }
.item .note { margin-bottom: var(--s1); }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.struck { text-decoration: line-through; color: var(--muted); }
.tag {
  display: inline-block;
  margin-right: var(--s1);
  padding: 0 var(--s2);
  background: var(--accent-soft);
  border-radius: var(--pill);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
}
.link { padding: 0; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
.steps { margin: var(--s4) 0; padding-left: var(--s5); }
.steps li { margin-bottom: var(--s2); }
.mood { display: flex; align-items: center; gap: var(--s4); }
.mood input { flex: 1; accent-color: var(--accent); }
.mood output { min-width: 2ch; font: 600 var(--text-xl)/1 var(--font-display); text-align: right; }
.is-waiting { opacity: 0.7; pointer-events: none; }
a.btn { text-decoration: none; }

.inline-form { display: flex; align-items: flex-end; gap: var(--s2); margin: var(--s3) 0; }
.inline-form .field { flex: 1; margin: 0; }

/* A document Claude reads, shown as the plain text Claude gets. */
.doc-title { margin-top: var(--s4); font-size: var(--text-lg); }
.doc {
  margin: var(--s3) 0 var(--s5);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  font: var(--text-sm)/1.55 var(--font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--pill);
}
.segmented button {
  padding: var(--s2) var(--s4);
  border: 0;
  border-radius: var(--pill);
  background: none;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.segmented [aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.banner {
  margin: var(--s2) 0 var(--s4);
  padding: var(--s4) var(--s5);
  background: var(--surface-2);
  border-radius: var(--r2);
}
.banner > :last-child { margin-bottom: 0; }

.link-support {
  display: block;
  margin: var(--s6) auto 0;
  padding: var(--s3);
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.resources { margin: var(--s5) 0; padding: 0; list-style: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s4));
  z-index: 20;
  max-width: calc(100% - var(--s6));
  padding: var(--s3) var(--s5);
  background: var(--text);
  color: var(--bg);
  border-radius: var(--pill);
  font-size: var(--text-sm);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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