* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #2a3139;
  --text: #e6edf3;
  --dim: #8b949e;
  --accent1: #ff6b35;
  --accent2: #ffa600;
  --accent3: #4cc9f0;
  --accent4: #90be6d;
  --danger: #ff5c5c;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}
h1, h2, h3, summary { font-family: "Noto Serif SC", "Songti SC", serif; }
.hidden { display: none !important; }
.muted { color: var(--dim); font-size: 13px; }
.small { font-size: 12px; }

/* ---- Login gate ---- */
.gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.gate-panel {
  width: 100%; max-width: 360px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px;
}
.gate-panel h1 { font-size: 26px; margin-bottom: 4px; text-align: center; }
.gate-mark { display: block; margin: 0 auto 12px; }
.gate-sub { color: var(--dim); font-size: 14px; margin-bottom: 24px; text-align: center; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 36px; min-width: 48px; padding: 0 10px;
  background: none; border: 0; color: var(--accent3); font-size: 13px; cursor: pointer;
}
.privacy { color: var(--dim); font-size: 12px; margin-top: 16px; text-align: center; }
.gate-status { color: var(--dim); font-size: 12px; margin-top: 10px; text-align: center; min-height: 1em; }
.gate-status:not(:empty) { color: var(--danger); }

/* ---- App layout ---- */
.app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title strong { font-family: "Noto Serif SC", "Songti SC", serif; font-size: 17px; display: block; }
.sync-badge {
  font-size: 12px; color: var(--accent4);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; white-space: nowrap;
}
.sync-badge.pending { color: var(--accent2); }
.sync-badge.offline { color: var(--dim); }
.sync-badge.error { color: var(--danger); }

.page-title { font-size: 22px; margin: 22px 0 12px; }
.section-sub { font-size: 16px; margin: 24px 0 10px; }
.footnote { font-size: 12px; color: var(--dim); text-align: center; margin-top: 32px; }

/* ---- Hero ---- */
.hero {
  margin-top: 18px;
  background: linear-gradient(160deg, #161b22 0%, #1b2430 100%);
  border: 1px solid rgba(76,201,240,.35);
}
.hero-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#heroDate { font-size: 13px; color: var(--dim); }
.pill {
  font-size: 11px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--dim); white-space: nowrap;
}
.pill.done { color: #0d1117; background: var(--accent4); border-color: var(--accent4); font-weight: 700; }
.hero-weight { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.hero-weight #statWeight { font-size: 34px; font-weight: 700; }
.hero-weight small { color: var(--dim); font-size: 12px; }

/* ---- Cards & stats ---- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin-bottom: 14px;
}
.card h3 { font-size: 15px; margin-bottom: 8px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
}
.stat--walk { border-left: 3px solid var(--accent4); }
.stat--strength { border-left: 3px solid var(--accent1); }
.stat--phase { border-left: 3px solid var(--accent2); }
.stat-label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 700; }

.meter { height: 8px; background: #232a33; border-radius: 4px; overflow: hidden; margin: 10px 0 6px; }
.meter-fill { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--accent4), var(--accent3)); transition: width .6s ease; }

/* ---- Buttons / forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 20px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #1c232c; color: var(--text);
  font-size: 15px; cursor: pointer; text-decoration: none;
  margin: 6px 8px 6px 0;
}
.btn.primary { background: var(--accent1); border-color: var(--accent1); color: #0d1117; font-weight: 700; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: rgba(255,92,92,.08); }
.btn.cta { width: 100%; margin: 8px 0 18px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label, .field-label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="date"], input[type="number"], input[type="password"], textarea {
  width: 100%; min-height: 44px;
  background: #1c232c; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 16px; padding: 10px 12px;
  font-family: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent3); outline-offset: 1px; }
.field.check { display: flex; align-items: center; gap: 10px; }
.field.check input { width: 22px; height: 22px; min-height: 0; }
.field.check label { margin: 0; font-size: 14px; color: var(--text); }

.energy { display: flex; gap: 8px; flex-wrap: wrap; }
.energy-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.energy-item small { font-size: 11px; color: var(--dim); }
.energy-btn {
  width: 44px; height: 44px; border-radius: 10px;
  background: #1c232c; border: 1px solid var(--border);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.energy-btn[aria-pressed="true"] { background: var(--accent3); border-color: var(--accent3); color: #0d1117; font-weight: 700; }

/* ---- Chips ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  min-height: 36px; padding: 6px 14px; border-radius: 999px;
  background: #1c232c; border: 1px solid var(--border);
  color: var(--text); font-size: 13px; cursor: pointer;
}
.chip:hover, .chip:active { border-color: var(--accent3); color: var(--accent3); }
.chip[aria-pressed="true"] { background: var(--accent3); border-color: var(--accent3); color: #0d1117; font-weight: 700; }

.goal-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; font-size: 13px; }
.goal-row span { white-space: nowrap; color: var(--dim); }
.goal-row b { color: var(--text); font-weight: 600; }
.goal-row .meter { flex: 1; margin: 0; }
.more-inner { padding: 4px 16px 14px; }

/* ---- Edit banner ---- */
.edit-banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--accent2);
  background: rgba(255,166,0,.08); border: 1px solid rgba(255,166,0,.4);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;
}
.edit-banner b { color: var(--text); }
.edit-banner button {
  min-height: 32px; margin-left: auto; padding: 4px 12px;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--dim); font-size: 12px; cursor: pointer;
}

/* ---- Strength switch ---- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; width: 100%; cursor: pointer;
  font-size: 14px; color: var(--text);
  background: #1c232c; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px;
}
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  position: relative; flex-shrink: 0;
  width: 46px; height: 26px; border-radius: 999px;
  background: #2a3139; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--dim); transition: transform .2s, background .2s;
}
.switch-row input:checked + .switch { background: var(--accent4); }
.switch-row input:checked + .switch::after { transform: translateX(20px); background: #0d1117; }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent3); outline-offset: 2px; }

/* ---- History ---- */
.history { list-style: none; }
.h-month {
  font-size: 13px; font-weight: 700; color: var(--dim);
  margin: 14px 0 8px; display: block;
}
.history li.record-row {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap;
}
.history .h-main { font-size: 14px; }
.history .h-main b { margin-right: 8px; }
.history .h-meta { font-size: 12px; color: var(--dim); }
.history .h-pending { color: var(--accent2); font-size: 11px; margin-left: 6px; }
.history .h-actions button {
  min-height: 44px; min-width: 44px; padding: 6px 12px;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--accent3); font-size: 13px; cursor: pointer; margin-left: 6px;
}
.history .h-actions button.del { color: var(--danger); border-color: rgba(255,92,92,.4); }

/* ---- Red flags ---- */
.redflags {
  border: 1px solid var(--danger); border-radius: 12px;
  background: rgba(255,92,92,.08); padding: 0; margin-bottom: 16px;
  overflow: hidden;
}
.redflags summary {
  padding: 14px 18px; font-size: 14px; font-weight: 600; color: var(--danger);
  cursor: pointer; min-height: 44px; display: flex; align-items: center;
  list-style: none;
}
.redflags summary::before { content: "▸"; margin-right: 8px; }
.redflags[open] summary::before { content: "▾"; }
.redflags h3 { color: var(--danger); font-size: 15px; margin-bottom: 8px; }
.redflags ul { list-style: none; padding: 0 18px 14px; }
.redflags li { font-size: 14px; font-weight: 600; margin: 4px 0; }
.redflags li::before { content: "! "; color: var(--danger); font-weight: 800; }
.danger-list { list-style: none; }
.danger-list li { font-weight: 600; margin: 4px 0; }
.danger-list li::before { content: "! "; color: var(--danger); font-weight: 800; }

/* ---- Plan accordions ---- */
.acc {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; overflow: hidden;
}
.acc summary {
  padding: 14px 16px; font-size: 15px; cursor: pointer;
  min-height: 44px; display: flex; align-items: center;
  list-style: none;
}
.acc summary::before { content: "▸"; margin-right: 8px; color: var(--accent3); }
.acc[open] summary::before { content: "▾"; }
.acc ul, .acc ol { padding: 0 16px 14px 34px; font-size: 14px; color: var(--dim); }
.acc li { margin: 4px 0; }
.acc p { padding: 0 16px 14px; }
.acc a { color: var(--accent3); }
.acc b { color: var(--text); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 14px; }
.acc table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 420px; }
.acc th, .acc td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); color: var(--dim); }
.acc th { font-size: 12px; }

/* ---- Canvas ---- */
#weightChart { width: 100%; display: block; }

/* ---- Bottom nav ---- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: rgba(13,17,23,.96); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  position: relative;
  flex: 1; min-height: 56px; border: 0; background: none;
  color: var(--dim); font-size: 11px; cursor: pointer;
  font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.nav-btn[aria-selected="true"] { color: var(--accent1); font-weight: 700; }
.nav-btn[aria-selected="true"]::before {
  content: ""; position: absolute; top: 0; left: 20%; right: 20%;
  height: 3px; border-radius: 0 0 3px 3px; background: var(--accent1);
}

@media (min-width: 720px) {
  .app { padding-bottom: 96px; }
  .bottomnav {
    position: fixed;
    top: auto;
    bottom: 18px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(680px, calc(100vw - 32px));
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 16px 40px rgba(0,0,0,.36);
  }
}

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: #1c232c; border: 1px solid var(--accent3); color: var(--text);
  border-radius: 10px; padding: 10px 18px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s;
  max-width: 88vw; z-index: 30;
}
.toast.show { opacity: 1; }
.toast.error { border-color: var(--danger); }
