:root {
  --bg: #f6f5f2; --surface: #ffffff; --ink: #1d1c1a; --ink-2: #5b5852; --muted: #8b877f;
  --line: #e6e3dc; --accent: #2f6f5e; --accent-ink: #ffffff; --accent-soft: #e3efe9;
  --bar: #3d8a74; --bar-hi: #24584a; --busy: #ece9e2;
  --good: #2e7d4f; --bad: #b3422f; --warn: #a66a00;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513; --surface: #1d1f1c; --ink: #ecebe6; --ink-2: #b4b1a9; --muted: #85827a;
    --line: #2d302b; --accent: #6cc3a6; --accent-ink: #0d1a15; --accent-soft: #1f3129;
    --bar: #5fb497; --bar-hi: #8fd8bf; --busy: #2a2c28;
    --good: #6cc38b; --bad: #ec7d69; --warn: #e0a84a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: .7rem; }
label input, label textarea, label select { margin-top: .25rem; }
button {
  border: 1px solid var(--line); background: var(--surface); padding: .5rem .9rem;
  border-radius: 10px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .55; cursor: wait; }

/* layout */
.shell { max-width: 1080px; margin: 0 auto; padding: 0 16px 96px; }
header.top { display: flex; align-items: center; gap: 1rem; padding: 18px 0 10px; }
header.top h1 { font-size: 1.25rem; letter-spacing: -.01em; }
header.top .mod { color: var(--muted); font-size: .9rem; }
header.top .spacer { flex: 1; }
nav.tabs { display: flex; gap: .25rem; }
nav.tabs a {
  text-decoration: none; color: var(--ink-2); padding: .45rem .8rem; border-radius: 999px; font-size: .92rem;
}
nav.tabs a.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
@media (max-width: 720px) {
  nav.tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  nav.tabs a { font-size: .82rem; padding: .45rem .6rem; }
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
@media (max-width: 860px) { .grid > * { grid-column: span 12 !important; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card > h2 { margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.card > h2 .right { margin-left: auto; font-weight: 400; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .6rem; }
.pill { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--busy); color: var(--ink-2); }
.pill.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.notice { border-left: 3px solid var(--warn); padding: .5rem .8rem; background: color-mix(in srgb, var(--warn) 8%, transparent); border-radius: 6px; font-size: .9rem; }
.err { color: var(--bad); }
.hidden { display: none !important; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat .v { font-size: 1.5rem; font-weight: 650; letter-spacing: -.02em; }
.stat .l { font-size: .8rem; color: var(--muted); }

/* plan list */
.day { display: grid; grid-template-columns: 74px 1fr; gap: .6rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.day:first-child { border-top: 0; }
.day .d { font-weight: 600; font-size: .9rem; }
.day .d span { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.day.today .d { color: var(--accent); }
.sess { padding: .45rem .6rem; border-radius: 10px; background: var(--accent-soft); margin-bottom: .35rem; }
.sess .t { font-weight: 600; }
.sess .meta { font-size: .8rem; color: var(--ink-2); }
.sess details { font-size: .88rem; color: var(--ink-2); }
.sess details summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
.sess.done { background: color-mix(in srgb, var(--good) 12%, transparent); }
.sess.missed { background: var(--busy); opacity: .75; }
.sess.missed .t { text-decoration: line-through; }
.rest { color: var(--muted); font-size: .88rem; padding: .3rem 0; }
.busy { font-size: .78rem; color: var(--muted); }

/* activity list */
.acts { list-style: none; margin: 0; padding: 0; }
.acts li { padding: .55rem 0; border-top: 1px solid var(--line); }
.acts li:first-child { border-top: 0; }
.acts .n { font-weight: 550; }
.acts .note { font-size: .85rem; color: var(--ink-2); font-style: italic; }

/* chart */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--bar); }
.chart .bar.cur { fill: var(--bar-hi); }
.chart .hit:hover + .bar, .chart .bar:hover { fill: var(--bar-hi); }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.tip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--ink); color: var(--bg);
  font-size: .8rem; padding: .35rem .55rem; border-radius: 8px; white-space: nowrap;
}

/* gym form */
.sets { width: 100%; border-collapse: collapse; }
.sets th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 500; padding: 0 .25rem .25rem; }
.sets td { padding: .2rem .25rem; }
.sets td:nth-child(2), .sets td:nth-child(3), .sets td:nth-child(4) { width: 18%; }
.sets td:last-child { width: 2rem; }
.sets input { padding: .45rem .5rem; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--ink); font-size: .92rem; }
.check input { width: auto; margin: 0; }

/* chat */
.chatlog { display: flex; flex-direction: column; gap: .6rem; max-height: 60vh; overflow-y: auto; padding: .25rem; }
.msg { padding: .6rem .8rem; border-radius: 12px; max-width: 88%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.chatform { display: flex; gap: .5rem; margin-top: .8rem; }
.chatform textarea { min-height: 2.6rem; height: 2.6rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.chips button { font-size: .82rem; padding: .25rem .6rem; border-radius: 999px; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.loginbox { width: 100%; max-width: 340px; }
.loginbox h1 { margin-bottom: 1rem; }
.loginbox button { width: 100%; margin-top: .3rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 60;
  background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; font-size: .9rem;
  max-width: calc(100vw - 32px);
}
code.feed { word-break: break-all; font-size: .8rem; background: var(--bg); padding: .3rem .5rem; border-radius: 6px; display: block; }
#gymForm .row label:first-child { flex: 1.7; }
