:root {
  --hero: #1C1C40;
  --panel: #2E2D62;
  --onhero: #D6D8F5;
  --amber: #FFB627;
  --late: #FDA4AF;
  --calm: #7DD3C0;
  --bg: #F7F1E8;
  --card: #FFFFFF;
  --text: #1F1B16;
  --sub: #6B6259;
  --line: #EADFCF;
  --rose: #C2416B;
  --rose-soft: #FBE4EC;
  --indigo: #4F46E5;
  --indigo-soft: #E7E6FB;
  --teal: #0F766E;
  --teal-soft: #DDF1EE;
  --orange: #C2410C;
  --orange-soft: #FBE7DC;
  --shadow: 0 6px 22px rgba(138, 106, 64, .16);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111118; --card: #1D1D29; --text: #F2F0F7; --sub: #A9A6B8; --line: #2C2B3A;
    --rose: #F49AB8; --rose-soft: #3A2030; --indigo: #A5A0FF; --indigo-soft: #26254A;
    --teal: #7DD3C0; --teal-soft: #17302C; --orange: #FDBA8C; --orange-soft: #3A2418;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(86px + var(--safe-b));
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); }
h1, h2, h3, p { margin: 0; }

/* Hero */
.hero {
  background: linear-gradient(90deg, var(--hero) 35%, rgba(28, 28, 64, .55)), url(img/hero.webp) right center / cover, var(--hero);
  color: #fff;
  padding: calc(18px + var(--safe-t)) 18px 18px;
  border-radius: 0 0 28px 28px;
}
.hero h1 { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.hero p { color: var(--onhero); font-size: 15px; }
.panel {
  margin-top: 16px; padding: 14px; border-radius: 20px;
  background: rgba(46, 45, 98, .88); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 14px; min-height: 104px;
}
.panel .info { flex: 1; min-width: 0; }
.panel .k { color: var(--onhero); font-size: 13px; }
.panel .big { font-size: 26px; font-weight: 800; color: var(--amber); line-height: 1.15; }
.panel .s { color: var(--onhero); font-size: 13px; }
.ring { position: relative; width: 88px; height: 88px; flex: none; }
.ring svg { width: 88px; height: 88px; transform: rotate(-90deg); }
.ring .mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .mid b { font-size: 15px; color: #fff; white-space: nowrap; }
.ring .mid span { font-size: 11px; color: var(--onhero); }

main { padding: 14px 16px 0; }
.tab { display: none; }
.tab.on { display: block; }

.card {
  background: var(--card); border-radius: 22px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 18px; font-weight: 800; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .r { margin-left: auto; font-size: 13px; font-weight: 500; color: var(--sub); }
.label { font-size: 12px; letter-spacing: .8px; text-transform: uppercase; color: var(--sub); font-weight: 700; margin: 20px 6px 10px; }

/* Start buttons */
.starts { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; }
.start {
  border-radius: 18px; padding: 16px 6px 12px; text-align: center; font-weight: 800; font-size: 17px;
  background: var(--rose-soft); color: var(--rose);
}
.start.both { background: var(--rose); color: #fff; }
.start small { display: block; font-weight: 500; font-size: 12px; opacity: .85; }
.start:active, .btn:active, .opt:active { transform: scale(.97); }
.link { color: var(--indigo); font-weight: 600; font-size: 15px; padding: 12px 4px 2px; display: inline-block; }

/* Running */
.running { text-align: center; }
.running .clock { font-size: 54px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.running .side { color: var(--sub); margin-bottom: 14px; }
.pulse { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--rose); margin-right: 6px; animation: p 1.4s infinite; }
@keyframes p { 50% { opacity: .25; } }
.btn {
  display: block; width: 100%; border-radius: 16px; padding: 15px; font-weight: 800; font-size: 17px;
  background: var(--rose); color: #fff; text-align: center;
}
.btn.soft { background: var(--indigo-soft); color: var(--indigo); }
.btn.ghost { background: transparent; color: var(--sub); font-weight: 600; }
.btn.danger { background: var(--rose-soft); color: var(--rose); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.st { border-radius: 16px; padding: 10px 12px; }
.st b { display: block; font-size: 21px; font-weight: 800; white-space: nowrap; }
.st span { font-size: 12px; color: var(--sub); }
.st.r { background: var(--rose-soft); } .st.r b { color: var(--rose); }
.st.i { background: var(--indigo-soft); } .st.i b { color: var(--indigo); }
.st.t { background: var(--teal-soft); } .st.t b { color: var(--teal); }
.st.o { background: var(--orange-soft); } .st.o b { color: var(--orange); }

/* 7-day chart */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar i { display: block; width: 100%; border-radius: 8px 8px 3px 3px; background: var(--rose); opacity: .5; min-height: 4px; }
.bar.today i { opacity: 1; }
.bar.zero i { background: var(--line); opacity: 1; }
.bar em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--sub); margin-bottom: 3px; }
.days { display: flex; gap: 6px; margin-top: 6px; }
.days span { flex: 1; text-align: center; font-size: 11px; color: var(--sub); }
.days.n span { font-size: 13px; font-weight: 700; color: var(--indigo); }

/* Log */
.day-h { display: flex; align-items: baseline; gap: 8px; margin: 18px 4px 8px; }
.day-h h3 { font-size: 20px; font-weight: 800; }
.chip { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--rose-soft); color: var(--rose); }
.chip.i { background: var(--indigo-soft); color: var(--indigo); }
.entry { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.entry:last-child { border-bottom: 0; }
.entry .t { width: 64px; flex: none; font-weight: 800; font-size: 17px; line-height: 1.1; }
.entry .t small { display: block; font-weight: 500; font-size: 12px; color: var(--sub); }
.entry .m { flex: 1; min-width: 0; }
.entry .m b { display: block; font-weight: 700; }
.entry .m span { font-size: 13px; color: var(--sub); }
.entry .ml { font-weight: 800; font-size: 16px; color: var(--rose); background: var(--rose-soft); padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
.empty { text-align: center; padding: 30px 10px; color: var(--sub); }
.empty img { width: 120px; display: block; margin: 0 auto 10px; }

/* Settings */
.set { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: 0; }
.set .m { flex: 1; }
.set .m span { display: block; font-size: 13px; color: var(--sub); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { padding: 8px 12px; border-radius: 99px; background: var(--indigo-soft); color: var(--indigo); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--indigo); color: #fff; }
.note { font-size: 13px; color: var(--sub); margin-top: 10px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-radius: 24px 24px 0 0;
  padding: 8px 8px calc(8px + var(--safe-b)); box-shadow: 0 -4px 20px rgba(138, 106, 64, .14);
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 16px; color: var(--sub); font-size: 13px; font-weight: 600; }
.tabs img, .tabs .gear { width: 30px; height: 30px; filter: saturate(.3); opacity: .7; font-size: 24px; line-height: 30px; }
.tabs button.on { color: var(--text); font-weight: 800; }
.tabs button.on img, .tabs button.on .gear { filter: none; opacity: 1; }
.tabs button.on { background: rgba(255, 182, 39, .22); }

/* Sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 10; background: rgba(10, 10, 25, .45); display: flex; align-items: flex-end; }
.sheet-wrap[hidden] { display: none; }
.sheet {
  width: 100%; max-height: 92vh; overflow: auto; background: var(--card); border-radius: 26px 26px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b)); animation: up .22s ease-out;
  -webkit-user-select: text; user-select: text;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet h2 { font-size: 21px; font-weight: 800; margin-bottom: 4px; }
.sheet .sub { color: var(--sub); font-size: 14px; margin-bottom: 14px; }
.opt {
  display: flex; align-items: center; width: 100%; padding: 15px 16px; border-radius: 16px; margin-bottom: 8px;
  background: var(--rose-soft); color: var(--rose); font-weight: 800; font-size: 16px;
}
.opt span { margin-left: auto; font-weight: 500; font-size: 14px; color: var(--sub); }
.opt.i { background: var(--indigo-soft); color: var(--indigo); }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--sub); font-weight: 600; margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg);
}
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 46px; height: 46px; border-radius: 50%; background: var(--rose-soft); color: var(--rose); font-size: 24px; font-weight: 800; flex: none; }
.stepper input { text-align: center; font-size: 22px; font-weight: 800; padding: 8px; flex: 1; min-width: 0; }
.stepper .u { font-weight: 700; color: var(--sub); }
.sides .field { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sides .field > label { width: 44px; margin: 0; font-size: 15px; color: var(--text); }
.sides .stepper { flex: 1; }
.segsides { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.segsides button { padding: 10px; border-radius: 12px; background: var(--rose-soft); color: var(--rose); font-weight: 700; }
.segsides button.on { background: var(--rose); color: #fff; }
.total { text-align: center; font-size: 15px; color: var(--sub); margin: -4px 0 14px; }
.total b { color: var(--text); font-size: 18px; }

/* Toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(96px + var(--safe-b)); z-index: 20;
  background: var(--panel); color: #fff; border-radius: 16px; padding: 6px 6px 6px 16px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast[hidden] { display: none; }
.toast span { flex: 1; }
.toast button { color: var(--amber); font-weight: 800; padding: 10px 14px; }
