:root {
  --bg: #F5F2EC; --card: #FFFDF9; --ink: #18181C; --ink-2: #44444C; --muted: #77736B;
  --line: #E5DFD3; --soft: #EFEAE0; --red: #B2281E; --red-soft: #F6E4E1; --sage: #5F7D66; --sage-soft: #E3EBE4;
  --side: #17191F; --side-ink: #E9E6DF; --side-muted: #8D8A84;
  --r: 14px; --shadow: 0 1px 2px rgba(24,24,28,.04), 0 4px 16px rgba(24,24,28,.04);
  --serif: "Noto Serif", Georgia, serif; --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111215; --card: #1A1C21; --ink: #EDEAE3; --ink-2: #C9C5BD; --muted: #8E8A83;
    --line: #2B2D33; --soft: #23252B; --red: #D9483C; --red-soft: #3A2120; --sage: #8FB097; --sage-soft: #22302A;
    --side: #0C0D10; --shadow: none; color-scheme: dark;
  }
  .logo-mark { content: url(img/mark-light.png); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font: 600 26px/1.25 var(--serif); letter-spacing: -.01em; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- khung ---------- */
.app { display: flex; min-height: 100dvh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.wrap { max-width: 720px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 0 8px; }
.top .logo-mark { width: 30px; height: auto; }
.top .brand { font-weight: 600; letter-spacing: .22em; font-size: 14px; }
.top .grow { flex: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); position: relative; }
.icon-btn:hover { background: var(--soft); }
.icon-btn .dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 8px; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.nav a.on { color: var(--ink); }
.nav a.on svg { stroke: var(--red); }

@media (min-width: 900px) {
  .nav { display: none; }
  .side { display: flex; flex-direction: column; width: 236px; flex: none; background: var(--side); color: var(--side-ink); padding: 22px 14px; position: sticky; top: 0; height: 100dvh; }
  .side .brandrow { display: flex; align-items: center; gap: 10px; padding: 4px 10px 26px; }
  .side .brandrow img { width: 34px; }
  .side .brandrow span { letter-spacing: .24em; font-weight: 600; font-size: 14px; }
  .side a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--side-muted); text-decoration: none; font-weight: 500; }
  .side a:hover { color: var(--side-ink); background: #ffffff0d; }
  .side a.on { color: #fff; background: #ffffff14; }
  .side a.on svg { stroke: #E2584C; }
  .side .grow { flex: 1; }
  .side .focus-cta { margin: 8px 4px; }
  .main { padding: 0 32px 48px; }
  .top .logo-mark, .top .brand { display: none; }
}

/* ---------- thẻ ---------- */
.hello { padding: 8px 0 18px; }
.hello .date { font-size: 13px; color: var(--muted); margin-bottom: 4px; text-transform: capitalize; }
.hello .sub { margin-top: 6px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.card-h .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--soft); color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.sage { background: var(--sage-soft); color: var(--sage); }
.kanji { font-family: var(--serif); font-weight: 600; color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .card { margin: 0; } .grid2 { margin-bottom: 14px; } }

/* danh sách việc */
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-height: 48px; }
.row:first-of-type { border-top: 0; }
.row .t { flex: 1; min-width: 0; }
.row .t .meta { font-size: 12.5px; color: var(--muted); }
.row.done .t > span:first-child { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.chk { width: 24px; height: 24px; border-radius: 7px; border: 1.6px solid #B9B3A7; background: transparent; flex: none; display: grid; place-items: center; cursor: pointer; padding: 0; }
.chk svg { width: 15px; height: 15px; stroke: #fff; stroke-width: 2.6; fill: none; opacity: 0; }
.chk.on { background: var(--ink); border-color: var(--ink); }
.chk.on svg { opacity: 1; }
@media (prefers-color-scheme: dark) { .chk.on svg { stroke: #111; } }
.add-line { display: flex; gap: 8px; padding-top: 10px; }
.add-line input { flex: 1; }

/* chip thói quen */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 14px; border-radius: 99px; border: 1.5px solid var(--line); background: transparent; cursor: pointer; font-weight: 500; font-size: 14px; }
.chip .o { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #B9B3A7; display: grid; place-items: center; }
.chip.on { background: var(--sage-soft); border-color: transparent; color: var(--sage); }
.chip.on .o { background: var(--sage); border-color: var(--sage); }
.chip.on .o::after { content: ""; width: 6px; height: 3px; border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg) translate(1px, -1px); }
.chip.sel { background: var(--ink); color: var(--card); border-color: var(--ink); }

/* nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:hover { border-color: #CFC8BA; }
.btn.primary { background: var(--ink); color: var(--card); border-color: var(--ink); }
.btn.red { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0 10px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.side .btn.primary { background: #F5F2EC; color: #17191F; border-color: #F5F2EC; }

input[type=text], input[type=password], input[type=number], input[type=date], textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 11px; border: 1.5px solid var(--line); background: var(--card); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--ink-2); }
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
label.f > em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* tiến độ */
.bar { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.bar.sage > i { background: var(--sage); }
.goal { display: block; text-decoration: none; padding: 14px 0; border-top: 1px solid var(--line); }
.goal:first-of-type { border-top: 0; padding-top: 4px; }
.goal .gt { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.goal .gt b { font-weight: 600; }
.goal .gt span { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.vision { font: 500 18px/1.45 var(--serif); }
.pillar { display: grid; grid-template-columns: 92px 1fr 40px; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.pillar span:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

/* chấm 7 ngày */
.dots { display: flex; gap: 5px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--soft); border: 1.5px solid var(--line); }
.dots i.ok { background: var(--sage); border-color: var(--sage); }
.dots i.miss { background: transparent; border-color: #C9C2B5; }
.dots i.off { background: transparent; border: 1.5px dashed var(--line); }

/* số liệu */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.stat b { display: block; font: 600 24px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.seg { display: inline-flex; background: var(--soft); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; font-weight: 500; font-size: 13.5px; color: var(--ink-2); }
.seg.scroll { display: flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg.scroll button { white-space: nowrap; flex: none; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chart { width: 100%; height: 150px; display: block; }
.chart text { font: 11px var(--sans); fill: var(--muted); }

/* giai đoạn */
.stage { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.stage:first-of-type { border-top: 0; padding-top: 0; }
.stage-h { display: flex; gap: 10px; align-items: flex-start; }
.stage-n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 600; background: var(--soft); flex: none; margin-top: 1px; }
.stage.active .stage-n { background: var(--ink); color: var(--card); }
.stage.done .stage-n { background: var(--sage-soft); color: var(--sage); }
.stage .lessons { margin-left: 36px; }
.ltype { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* nhắc nguyên lý */
.principle { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--soft); font-size: 14px; color: var(--ink-2); margin-bottom: 14px; }
.principle .kanji { font-size: 20px; line-height: 1.1; }
.principle b { color: var(--ink); }

/* nhật ký */
.entry { padding: 12px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; padding-top: 0; }
.entry .eh { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.entry p { margin: 0; white-space: pre-wrap; }

/* sheet + toast */
.scrim { position: fixed; inset: 0; background: rgba(12,12,14,.36); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--card); border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s cubic-bezier(.2,.8,.2,1); }
.sheet .sh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet .sh h3 { font: 600 19px var(--serif); }
.sheet .actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet .actions .btn { flex: 1; }
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--card); padding: 11px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: up .2s ease; }
.toast button { background: transparent; border: 0; color: #F2A79F; font-weight: 600; cursor: pointer; padding: 0; }
@media (min-width: 900px) { .toast { bottom: 28px; } }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); }
.sync.wait i { background: #D59B2B; }
.sync.err i { background: var(--red); }

/* tập trung */
.focus { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 0 30px; }
.ring { position: relative; width: min(300px, 78vw); aspect-ratio: 1; margin: 18px 0 22px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring .bg { stroke: var(--soft); }
.ring .fg { stroke: var(--red); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring .time { position: absolute; inset: 0; display: grid; place-content: center; }
.ring .time b { font: 600 54px/1 var(--serif); font-variant-numeric: tabular-nums; }
.ring .time span { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* đăng nhập */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 360px; text-align: center; }
.login .box img.m { width: 130px; }
.login .box img.w { width: 190px; margin: 10px 0 6px; }
@media (prefers-color-scheme: dark) { .login .box img.w { filter: invert(1) hue-rotate(180deg); } }
.login form { text-align: left; margin-top: 26px; }
.err { color: var(--red); font-size: 14px; margin: 0 0 12px; }
.empty { text-align: center; padding: 18px 8px; color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 14px; margin: 4px 0 10px; }
