:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #15181c;
  --muted: #4b5259;
  --line: #d9d5cc;
  --brand: #1d5c3a;
  --brand-ink: #ffffff;
  --done: #1d7a46;
  --done-soft: #e3f3e8;
  --todo: #8a9097;
  --skinny: #8a4b00;
  --skinny-soft: #ffe7bf;
  --injured: #b3191f;
  --injured-soft: #ffe1e0;
  --focus: #1f5fd6;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --card: #1b1f22;
    --ink: #f2f4f5;
    --muted: #b4bbc1;
    --line: #343a3f;
    --brand: #2f7d52;
    --done: #3fae6e;
    --done-soft: #183526;
    --todo: #7d858c;
    --skinny: #ffc46b;
    --skinny-soft: #3d2a0c;
    --injured: #ff8a85;
    --injured-soft: #431819;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 640px; margin: 0 auto; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.top h1 { margin: 0; font-size: 21px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { display: block; font-size: 14px; font-weight: 500; opacity: 0.9; }
.icon-btn {
  width: 48px; height: 48px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px; background: rgb(255 255 255 / 0.14); color: inherit;
}
.icon-btn svg { width: 26px; height: 26px; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 4px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .num small { font-size: 18px; font-weight: 600; color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--line); margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--done); border-radius: 4px; }

.search { padding: 10px 16px 6px; }
.search input {
  width: 100%; height: 52px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--card);
}

/* ---------- horse rows ---------- */
.list { list-style: none; margin: 0; padding: 6px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.row {
  min-width: 0;
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 10px 10px 10px; box-shadow: var(--shadow);
}
.row.all-done { border-color: var(--done); }
.row-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  color: inherit; text-decoration: none; min-height: 58px;
}
a.icon-btn { text-decoration: none; }
.thumb {
  width: 56px; height: 56px; flex: none; border-radius: 12px; object-fit: cover;
  display: grid; place-items: center; background: var(--line); color: var(--muted); font-weight: 800; font-size: 24px;
}
.row-text { flex: 1; min-width: 0; }
.name { font-size: 20px; font-weight: 800; line-height: 1.2; }
.meta {
  font-size: 15px; color: var(--muted); line-height: 1.3; overflow: hidden;
  display: -webkit-box !important; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.tags { display: inline-flex; gap: 6px; flex-wrap: wrap; vertical-align: middle; }
.tag { font-size: 13px; font-weight: 800; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.tag.skinny { background: var(--skinny-soft); color: var(--skinny); }
.tag.injured { background: var(--injured-soft); color: var(--injured); }

.boxes { display: flex; gap: 8px; flex: none; }
.box {
  width: 58px; height: 58px; border-radius: 12px;
  border: 3px solid var(--todo); background: var(--card);
  display: grid; place-items: center; align-content: center; gap: 0;
  font-size: 13px; font-weight: 800; color: var(--muted); padding: 0;
}
.box svg { width: 26px; height: 26px; }
.box.done { background: var(--done); border-color: var(--done); color: #fff; }
.box.pending { opacity: 0.6; }
.box.none { border-style: dashed; opacity: 0.45; cursor: default; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- horse card ---------- */
.card-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--line); }
.card-photo.placeholder { display: grid; place-items: center; font-size: 72px; font-weight: 800; color: var(--muted); }
.section { padding: 14px 16px 4px; }
.section h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 8px 0 8px; }
.big-name { font-size: 30px; font-weight: 800; margin: 0; line-height: 1.15; }
.place { font-size: 18px; color: var(--muted); margin: 2px 0 8px; }
.callout { background: var(--skinny-soft); color: var(--ink); border-left: 6px solid var(--skinny); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.lines li:first-child { border-top: 0; }
.lines .what { font-weight: 700; }
.lines .amt { text-align: right; }
.blank { color: var(--muted); font-style: italic; font-weight: 400; }

.today { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.feed-btn {
  min-height: 96px; border-radius: var(--radius); border: 3px solid var(--todo); background: var(--card);
  display: grid; gap: 2px; place-items: center; align-content: center; padding: 10px; text-align: center;
}
.feed-btn .slot { font-size: 22px; font-weight: 800; }
.feed-btn .who { font-size: 15px; color: var(--muted); }
.feed-btn.done { background: var(--done); border-color: var(--done); color: #fff; }
.feed-btn.done .who { color: #fff; }
.feed-btn.none { border-style: dashed; opacity: 0.5; cursor: default; }

.history { width: 100%; border-collapse: collapse; font-size: 16px; }
.history th, .history td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.history th { font-size: 14px; color: var(--muted); border-top: 0; }
.history .miss { color: var(--muted); }

/* ---------- forms / buttons ---------- */
.stack { display: grid; gap: 14px; padding: 16px; }
label.field { display: grid; gap: 6px; font-weight: 700; font-size: 16px; }
label.field input, label.field textarea, .supp-row input {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 400; font-size: 18px;
}
label.field textarea { min-height: 88px; resize: vertical; }
.hint { font-size: 14px; color: var(--muted); font-weight: 400; }

.btn {
  min-height: 56px; padding: 0 20px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); font-weight: 800; font-size: 18px; width: 100%;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--injured); border-color: var(--injured); }
.btn:disabled { opacity: 0.5; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button, .toggle {
  min-height: 52px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); font-weight: 700;
}
.seg button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.toggle[aria-pressed="true"].skinny { background: var(--skinny-soft); border-color: var(--skinny); color: var(--skinny); }
.toggle[aria-pressed="true"].injured { background: var(--injured-soft); border-color: var(--injured); color: var(--injured); }

fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-weight: 700; font-size: 16px; padding: 0; margin-bottom: 6px; }
.supp-row { display: grid; grid-template-columns: 1.4fr 1fr 48px; gap: 8px; }
.supp-row .icon-btn { background: var(--line); color: var(--ink); width: 48px; height: 52px; }

.menu { list-style: none; margin: 0; padding: 0; }
.menu li + li { border-top: 1px solid var(--line); }
.menu a, .menu button {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  min-height: 60px; padding: 0 16px; background: none; border: 0; text-decoration: none; color: inherit; font-weight: 700; text-align: left;
}
.menu .val { color: var(--muted); font-weight: 500; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; align-content: center; gap: 16px; padding: 24px 20px; }
.login .logo { width: 84px; height: 84px; }
.login h1 { font-size: 32px; margin: 0; }
.login p { margin: 0; color: var(--muted); }
.error { color: var(--injured); font-weight: 700; margin: 0; }
.link { background: none; border: 0; color: var(--focus); font-weight: 700; padding: 12px 0; text-decoration: underline; }
@media (prefers-color-scheme: dark) { .link { color: #8ab4ff; } }

/* ---------- sheet + toast ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); z-index: 20; display: grid; align-items: end; }
.sheet {
  background: var(--card); border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; max-width: 640px; width: 100%; margin: 0 auto;
}
.sheet h2 { margin: 0; font-size: 22px; }
.sheet p { margin: 0; font-size: 18px; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 608px; margin: 0 auto; display: none; align-items: center; gap: 12px;
  background: var(--ink); color: var(--bg); padding: 10px 10px 10px 16px; border-radius: 14px; font-weight: 600;
}
#toast.show { display: flex; }
#toast span { flex: 1; }
#toast button { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 0; background: var(--bg); color: var(--ink); font-weight: 800; }

.offline { background: var(--injured); color: #fff; text-align: center; font-weight: 700; padding: 6px; font-size: 15px; }
