:root {
  --bg: #0b0b0b;
  --card: #161616;
  --card2: #1f1f1f;
  --line: #2a2a2a;
  --ink: #f2f2f2;
  --ink2: #b5b5b5;
  --muted: #7d7d7d;
  --gold: #f0b429;
  --gold-deep: #c08a10;
  --gold-ink: #1a1200;
  --blue: #4f8ef0;
  --good: #4caf50;
  --bad: #e5533d;
  --radius: 16px;
  --tabs-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 15px; color: var(--ink2); text-transform: uppercase; letter-spacing: .06em; margin: 22px 0 10px; }
p { margin: 0; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: rgba(11,11,11,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd670, var(--gold) 55%, #8a6208);
  box-shadow: 0 0 0 2px #000, 0 0 0 3px var(--gold-deep);
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: .01em; }
.brand-date { font-size: 13px; color: var(--muted); }

.view { padding: 8px 16px 24px; max-width: 640px; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.card.gold { border-color: var(--gold-deep); background: linear-gradient(180deg, #1c1707, #141210); }
.card-title { font-weight: 700; font-size: 16px; }
.card-sub { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 700; font-size: 16px;
  background: var(--card2); color: var(--ink); border: 1px solid var(--line);
}
.btn.primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; font-size: 14px; padding: 0 14px; border-radius: 11px; }
.btn:active { transform: scale(.98); }

.big-add { margin: 18px 0 6px; }

/* readings list */
.reading {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.reading:first-child { border-top: 0; }
.reading .time { font-size: 13px; color: var(--muted); }
.reading .time b { display: block; color: var(--ink); font-size: 15px; }
.reading .vals { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 15px; }
.reading .vals span { white-space: nowrap; }
.reading .vals small { color: var(--muted); font-size: 12px; margin-left: 2px; }
.reading .mood { font-size: 26px; line-height: 1; }
.reading .note { grid-column: 2 / -1; color: var(--ink2); font-size: 14px; margin-top: -4px; }

/* day groups in history */
.day { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 6px; }
.day-head b { font-size: 15px; }
.day-head span { color: var(--muted); font-size: 13px; }

/* medicines checklist */
.med {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line);
}
.med:first-child { border-top: 0; }
.med .tick {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--muted);
  display: flex; align-items: center; justify-content: center; flex: none; font-size: 16px; color: var(--gold-ink);
}
.med.done .tick { background: var(--gold); border-color: var(--gold); }
.med .m-name { font-weight: 600; }
.med.done .m-name { color: var(--muted); text-decoration: line-through; }
.med .m-sub { color: var(--muted); font-size: 13px; }
.med .m-time { margin-left: auto; color: var(--ink2); font-size: 14px; white-space: nowrap; }
.med.due .m-time { color: var(--gold); font-weight: 700; }
.time-group { margin-top: 12px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=time],
.field select, .field textarea {
  width: 100%; min-height: 50px; padding: 10px 14px; border-radius: 12px;
  background: #0f0f0f; border: 1px solid var(--line); color: var(--ink); font-size: 18px;
}
.field textarea { min-height: 70px; resize: vertical; font-size: 16px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--gold-deep); border-color: var(--gold-deep); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.unit { font-size: 12px; color: var(--muted); font-weight: 400; }

.moods { display: flex; justify-content: space-between; gap: 6px; }
.mood-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 2px; border-radius: 12px; border: 1px solid var(--line); background: #0f0f0f;
}
.mood-btn .e { font-size: 28px; line-height: 1; }
.mood-btn .l { font-size: 11px; color: var(--muted); }
.mood-btn.on { border-color: var(--gold); background: #211a05; }
.mood-btn.on .l { color: var(--gold); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card2);
  font-size: 14px; font-weight: 600; color: var(--ink2);
}
.chip.on { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }

.times { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.time-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 6px 12px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); }
.time-pill button { color: var(--bad); font-size: 18px; line-height: 1; padding: 0 2px; }

/* stats and charts */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 800; margin-top: 2px; }
.tile .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.tile .d { font-size: 12px; color: var(--ink2); }
.tile .d.down { color: var(--good); }
.tile .d.up { color: var(--bad); }

.chart-wrap { position: relative; }
.chart { width: 100%; height: 200px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: #3a3a3a; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .target { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart .target-lbl { fill: var(--ink2); }
.chart .xh { stroke: #555; stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink2); margin: 6px 0 2px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tip {
  position: absolute; top: 6px; right: 8px; background: #000; border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 10px; font-size: 13px; color: var(--ink); pointer-events: none; display: none;
}
.empty { color: var(--muted); text-align: center; padding: 22px 8px; font-size: 15px; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: #0e0e0e; border-top: 1px solid var(--line);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--gold); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; border-top: 1px solid var(--line);
}
.sheet-card h3 { font-size: 18px; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }
.handle { width: 40px; height: 4px; border-radius: 2px; background: #3a3a3a; margin: 0 auto 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--gold); color: var(--gold-ink); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.toast.hidden { display: none; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .sub { color: var(--muted); font-size: 13px; }
.switch { width: 48px; height: 28px; border-radius: 14px; background: #333; position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #999; transition: .15s; }
.switch.on { background: var(--gold); }
.switch.on::after { left: 23px; background: #1a1200; }
.notice { background: #1c1707; border: 1px solid var(--gold-deep); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.spacer { height: 8px; }
