:root {
  --bg: #0f1720;
  --card: #18222e;
  --card2: #202c3a;
  --line: #2a3747;
  --text: #eef3f8;
  --muted: #8fa1b5;
  --accent: #ff8a3d;
  --accent2: #ffb347;
  --good: #3ecf8e;
  --bad: #ff6b6b;
  --eat: #4fa3ff;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45;
  padding-top: var(--safe-t);
  padding-bottom: calc(76px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }
h1 { font-size: 23px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 20px; margin: 4px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.good { color: var(--good); font-size: 13px; }
.bad { color: var(--bad); font-size: 13px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

#app { max-width: 520px; margin: 0 auto; padding: 0 16px; }
.view { display: none; padding-bottom: 16px; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.top { display: flex; align-items: flex-end; justify-content: space-between; padding: 18px 2px 10px; gap: 10px; }
.eyebrow { color: var(--accent); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; }
.chip { background: var(--card2); border: 1px solid var(--line); padding: 7px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; border: 1px solid var(--line); }
.card-title { font-weight: 650; margin-bottom: 4px; }

/* Vòng tròn */
.ring-wrap { position: relative; width: min(78vw, 300px); aspect-ratio: 1; margin: 6px auto 10px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 14; }
.ring-bg { stroke: var(--card2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring-fg.done { stroke: var(--good); }
.ring-fg.eat { stroke: var(--eat); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-time { font-size: clamp(34px, 11vw, 46px); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.ring-sub { color: var(--muted); font-size: 14px; }

.times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.time-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; text-align: left; display: flex; flex-direction: column; }
#btn-edit-start .label::after { content: " ✎"; color: var(--accent); }
.time-box .label { color: var(--muted); font-size: 12px; }
.time-box .value { font-weight: 600; font-size: 15px; }

.primary { display: block; width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #1b1006; font-weight: 700; font-size: 17px; padding: 15px; border-radius: 16px; margin: 6px 0; }
.primary.stop { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.secondary { display: inline-block; background: var(--card2); border: 1px solid var(--line); padding: 11px 16px; border-radius: 14px; font-weight: 600; text-align: center; }
.danger { background: rgba(255, 107, 107, .12); color: var(--bad); border: 1px solid rgba(255, 107, 107, .35); padding: 11px 16px; border-radius: 14px; font-weight: 600; }
.file-btn { cursor: pointer; }
.primary:active, .secondary:active, .chip:active, .round:active { transform: scale(.98); }

.stage-head { display: flex; gap: 12px; align-items: center; }
.stage-emoji { font-size: 30px; }
.stage-name { font-weight: 700; font-size: 17px; }
.stage-range { color: var(--muted); font-size: 13px; }
.stage-desc { color: #cdd8e4; }
.stage-next { color: var(--accent2); font-size: 14px; }

.round { width: 40px; height: 40px; border-radius: 50%; background: var(--card2); border: 1px solid var(--line); font-size: 22px; line-height: 1; }
.round.accent { background: var(--eat); border-color: var(--eat); color: #04121f; font-weight: 700; }
.water-dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.drop { width: 18px; height: 22px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: var(--card2); border: 1px solid var(--line); }
.drop.on { background: var(--eat); border-color: var(--eat); }
.tip p { color: #cdd8e4; }

/* Thống kê */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat-v { font-size: 20px; font-weight: 700; margin: 2px 0; }
.stat-l { color: var(--muted); font-size: 12.5px; }

.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 160px; margin-top: 8px; }
.bar-col { display: flex; flex-direction: column; align-items: center; }
.bar-val { font-size: 11px; color: var(--muted); height: 16px; }
.bar-track { position: relative; flex: 1; width: 100%; max-width: 30px; background: var(--card2); border-radius: 8px; overflow: hidden; }
.bar { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); border-radius: 8px; }
.bar.ok { background: var(--good); }
.goal-line { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(255, 255, 255, .45); }
.bar-day { font-size: 12px; color: var(--muted); margin-top: 4px; }

.list { margin-top: 12px; }
.item { display: flex; width: 100%; justify-content: space-between; align-items: center; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.item-t { font-weight: 600; font-size: 15px; }
.item-r { font-weight: 700; text-align: right; }
.item-r.ok { color: var(--good); }

.seg { display: flex; background: var(--card2); border-radius: 10px; padding: 2px; }
.seg button { padding: 4px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--line); color: var(--text); }
.body-chart svg.line { width: 100%; height: auto; margin-top: 8px; }
svg.line path { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
svg.line circle { fill: var(--accent); }
svg.line .target { stroke: var(--good); stroke-dasharray: 4 4; }
svg.line .axis { fill: var(--muted); font-size: 10px; }

/* Kiến thức */
.learn summary { font-weight: 650; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.learn summary::-webkit-details-marker { display: none; }
.learn summary::after { content: "＋"; color: var(--muted); }
.learn[open] summary::after { content: "－"; }
.learn-body { color: #cdd8e4; margin-top: 8px; }
.learn-body ul { padding-left: 20px; margin: 6px 0; }
.learn-body li { margin: 4px 0; }

/* Form */
.form { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.form label, label.form { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form input, label.form input {
  background: var(--card2); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; width: 100%; -webkit-appearance: none; appearance: none; min-height: 44px;
}

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + var(--safe-b)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 5px; background: var(--line); border-radius: 3px; margin: 4px auto 10px; }
.plan-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.plan-item { text-align: left; background: var(--card2); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.plan-item.on { border-color: var(--accent); background: rgba(255, 138, 61, .1); }
.tag { font-size: 12px; color: var(--accent2); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day { width: 42px; height: 38px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); }
.day.on { background: var(--accent); color: #1b1006; border-color: var(--accent); font-weight: 700; }

/* Tab bar */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(15, 23, 32, .92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.tabs button { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); padding: 4px 0; gap: 1px; }
.tabs button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--text); }
.tabs button.on span { filter: none; opacity: 1; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: #fff; color: #111; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.toast[hidden] { display: none; }
ol { padding-left: 20px; }
