:root {
  --bg: #f4f2ec;
  --card: #fbfaf6;
  --ink: #262b26;
  --quiet: #6a7068;
  --line: #e3e0d6;
  --accent: #4f7a5a;
  --accent-ink: #fff;
  --bark: #6b5444;
  --soil: #e2dccd;
  --glow: #f2d98a;
  --blossom: #f1b6c6;
  --danger: #a8545a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 45, 35, 0.06), 0 4px 16px rgba(40, 45, 35, 0.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161916;
    --card: #1f231f;
    --ink: #e6e8e1;
    --quiet: #9aa196;
    --line: #2f352e;
    --accent: #8fbf8f;
    --accent-ink: #142014;
    --bark: #b59c86;
    --soil: #2c3029;
    --glow: #c9b064;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: 0.01em; }
.muted { color: var(--quiet); font-size: 13px; }
.center { text-align: center; justify-content: center; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 760px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 20px 6px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: 0.01em; }
.brand svg { width: 26px; height: 26px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.sync-dot.ok { background: var(--accent); }
.sync-dot.syncing { background: var(--glow); }
.sync-dot.error { background: var(--danger); }
.sync-dot.offline { background: var(--quiet); }

/* Bottom tab bar on phones, top tabs on wide screens */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; color: var(--quiet); padding: 4px 10px; border-radius: 10px; cursor: pointer;
}
.tabs .ic { font-size: 18px; line-height: 1.2; }
.tabs button.on { color: var(--accent); font-weight: 600; }
@media (min-width: 820px) {
  body { padding-bottom: 40px; }
  .tabs {
    position: sticky; top: 0; bottom: auto; max-width: 760px; margin: 0 auto 8px; border: 0;
    border-bottom: 1px solid var(--line); justify-content: flex-start; gap: 4px; padding: 6px 16px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
  }
  .tabs button { flex-direction: row; gap: 6px; font-size: 14px; padding: 6px 12px; }
  .tabs .ic { font-size: 14px; }
  .tabs button.on { background: var(--card); box-shadow: var(--shadow); }
}

main { max-width: 760px; margin: 0 auto; padding: 4px 16px 24px; }
section { margin: 18px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }

.btn {
  border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.ghost.danger { color: var(--danger); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.add { margin: 12px 4px; background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }
.icon-btn { background: none; border: 0; color: var(--quiet); font-size: 20px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--line); }
.chip { border: 0; background: var(--bg); color: var(--quiet); font-size: 12px; padding: 4px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.link { background: none; border: 0; color: var(--quiet); text-decoration: underline; cursor: pointer; font-size: 13px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.spacer { flex: 1; }
.file-btn { display: inline-flex; align-items: center; }

/* Track */
.proj-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.proj-row {
  display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px 6px 6px 4px; border-left: 4px solid var(--c);
}
.proj-start { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left; cursor: pointer; padding: 4px; min-width: 0; }
.proj-start:disabled { cursor: default; }
.proj-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.proj-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-sub { color: var(--quiet); font-size: 13px; }
.start-pill { background: var(--c); color: #fff; font-weight: 600; font-size: 13px; padding: 6px 14px; border-radius: 999px; }
.is-running .start-pill { background: transparent; color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.mini-tree { width: 46px; height: 50px; flex: none; display: block; }
.mini-tree.sm { width: 38px; height: 42px; }
.mini-tree svg, .tree-wrap svg { width: 100%; height: 100%; display: block; }

.running { margin-top: 8px; }
.run-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px;
  padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background-image: linear-gradient(90deg, color-mix(in srgb, var(--c) 10%, transparent), transparent 70%);
}
.run-card.paused { opacity: 0.75; }
.run-main { width: 100%; display: flex; align-items: center; gap: 12px; background: none; border: 0; text-align: left; cursor: pointer; padding: 0; }
.run-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.run-name { font-weight: 650; }
.run-sub { color: var(--quiet); font-size: 13px; }
.run-time { font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 600; letter-spacing: 0.01em; }
.on-break .run-time { color: var(--quiet); }
.run-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.empty { text-align: center; color: var(--quiet); padding: 28px 16px; background: var(--card); border-radius: var(--radius); }

/* Forest */
.forest { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tree-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 3px; background: var(--card); border: 0;
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px 12px; cursor: pointer; text-align: left;
}
.tree-wrap { height: 150px; display: block; }
.tree-name { font-weight: 650; margin-top: 4px; }
.tree-meta { font-size: 12.5px; }
.tree-meta.quiet { color: var(--quiet); }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; display: block; margin: 3px 0; }
.bar span { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 3px; }
.bar.big { height: 8px; }
.tree-glow { animation: breathe 4s ease-in-out infinite; transform-origin: center; }
@keyframes breathe { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .tree-glow { animation: none; } }

/* Insights */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.tile-label { color: var(--quiet); font-size: 12.5px; }
.tile-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--quiet); font-size: 12px; }
.chart { width: 100%; height: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; }
.chart .axis { font-size: 10.5px; fill: var(--quiet); }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.seg { display: inline-flex; background: var(--card); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.seg button { border: 0; background: none; padding: 4px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--quiet); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.breakdown { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); font-size: 14px; }
.breakdown th, .breakdown td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.breakdown th { font-weight: 600; color: var(--quiet); font-size: 12.5px; }
.breakdown th:first-child, .breakdown td:first-child { text-align: left; }
.breakdown tr:last-child td { border-bottom: 0; }
.breakdown td { white-space: nowrap; }
@media (max-width: 560px) { .breakdown th:nth-child(3), .breakdown td:nth-child(3), .breakdown th:nth-child(5), .breakdown td:nth-child(5) { display: none; } .breakdown td:first-child { white-space: normal; } }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; flex: none; }

/* History */
.hist { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.hist-row { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 14px; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.hist-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hist-name { font-weight: 600; }
.hist-sub { color: var(--quiet); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.hist-dur { font-variant-numeric: tabular-nums; font-weight: 600; }
.hist.compact { box-shadow: none; background: transparent; margin: 8px 0; }
.tag { font-size: 11px; font-weight: 500; color: var(--quiet); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }

/* Settings */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--quiet); }
input, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; color: var(--ink); font-size: 15px;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
.sync-status { font-size: 13px; color: var(--quiet); margin-bottom: 0; }
.sync-status.error { color: var(--danger); }
.sync-status.ok { color: var(--accent); }
.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

/* Modals */
.modal-wrap {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 24, 20, 0.35);
  display: flex; align-items: flex-end; justify-content: center; padding: 12px;
}
@media (min-width: 620px) { .modal-wrap { align-items: center; } }
.modal {
  background: var(--card); border-radius: 18px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto;
  padding: 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal h2 { font-size: 18px; margin-bottom: 12px; }
.stack { display: grid; gap: 12px; }
.species-row { display: flex; gap: 12px; align-items: flex-end; }
.species-row label { flex: 1; }
.species-preview { width: 80px; height: 88px; background: var(--bg); border-radius: 12px; }
.species-preview svg { width: 100%; height: 100%; }
.colors { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.colors legend { font-size: 13px; color: var(--quiet); margin-bottom: 6px; }
.swatch { flex-direction: row; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { width: 30px; height: 30px; border-radius: 50%; background: var(--c); display: block; cursor: pointer; }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--c); }
.swatch input:focus-visible + span { outline: 2px solid var(--ink); }
.detail { text-align: center; }
.detail-tree { height: 240px; background: var(--bg); border-radius: 14px; margin-bottom: 12px; }
.detail-tree svg { height: 100%; width: 100%; }
.detail .row-btns { justify-content: center; }

/* Focus view */
.focus {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background-image: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--c) 14%, transparent), transparent 60%);
}
.focus-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; background: none; border: 0; font-size: 20px; color: var(--quiet); cursor: pointer; width: 40px; height: 40px; }
.focus-tree { width: min(62vw, 340px); height: min(42vh, 360px); }
.focus-tree svg { width: 100%; height: 100%; }
.focus-name { font-weight: 650; font-size: 18px; }
.focus-timer-wrap { position: relative; width: 210px; height: 120px; display: grid; place-items: center; }
.focus-timer-wrap .ring { position: absolute; width: 120px; height: 120px; transform: rotate(-90deg); opacity: 0.9; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 6; }
.ring-fg { fill: none; stroke: var(--c); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.focus-timer { font-size: 52px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; position: relative; }
.focus-timer-wrap:has(.ring) .focus-timer { font-size: 30px; font-weight: 500; }
.focus-sub { color: var(--quiet); }
.focus-stage { color: var(--quiet); font-size: 13px; }
.focus.on-break .focus-timer { color: var(--quiet); }

/* Toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 60; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
@media (min-width: 820px) { #toasts { bottom: 24px; } }
.toast {
  pointer-events: auto; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: 520px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); font-size: 14px; display: flex; gap: 12px; align-items: center;
  transition: opacity 0.5s, transform 0.5s;
}
.toast.out { opacity: 0; transform: translateY(8px); }
.toast .btn.ghost { color: var(--bg); }
