/* ============ Tokens ============ */
:root {
  --paper: #FAF7F0;
  --card: #FFFFFF;
  --sunk: #F3EEE4;
  --ink: #1F1D1A;
  --ink-2: #5F5A51;
  --ink-3: #969083;
  --line: #EAE4D8;
  --line-2: #D8D0C0;
  --edge: #1F1D1A;
  --btn-shadow: 0 3px 0 var(--edge);
  --accent: #FF6B3D;
  --accent-2: #F0552A;
  --accent-soft: #FFE7DC;
  --good: #1E9A61;
  --good-soft: #DCF3E6;
  --bad: #DC4349;
  --bad-soft: #FCE3E3;
  --hl: #FFE16A;
  --hl-soft: #FFF5C7;
  --mark: rgba(255, 225, 106, .9);
  --shadow: 0 1px 0 rgba(31, 29, 26, .03), 0 10px 28px -16px rgba(31, 29, 26, .18);
  --r: 20px;
  --r-sm: 13px;
  --font-d: 'Bricolage Grotesque', ui-rounded, system-ui, sans-serif;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --tab-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161512; --card: #201E1A; --sunk: #2A2722; --ink: #F3EFE6; --ink-2: #BDB6A8; --ink-3: #868074;
    --line: #322F29; --line-2: #45413A; --edge: #000; --btn-shadow: 0 3px 0 #000;
    --accent-soft: #3A2419; --good-soft: #17301F; --bad-soft: #3A1C1D; --hl-soft: #3A3317; --mark: rgba(255, 225, 106, .32);
    --shadow: 0 10px 28px -16px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161512; --card: #201E1A; --sunk: #2A2722; --ink: #F3EFE6; --ink-2: #BDB6A8; --ink-3: #868074;
  --line: #322F29; --line-2: #45413A; --edge: #000; --btn-shadow: 0 3px 0 #000;
  --accent-soft: #3A2419; --good-soft: #17301F; --bad-soft: #3A1C1D; --hl-soft: #3A3317; --mark: rgba(255, 225, 106, .32);
  --shadow: 0 10px 28px -16px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4, h5 { font-family: var(--font-d); margin: 0; letter-spacing: -.02em; line-height: 1.15; }
h1 { font-size: clamp(28px, 6vw, 38px); font-weight: 800; }
h2 { font-size: 21px; font-weight: 700; }
h3 { font-size: 19px; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.xs { width: 15px; height: 15px; }
mark { background: linear-gradient(transparent 58%, var(--mark) 58%, var(--mark) 92%, transparent 92%); color: inherit; padding: 0 .08em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ============ Layout ============ */
#app { min-height: 100dvh; }
.main-wrap { min-height: 100dvh; padding-bottom: calc(var(--tab-h) + var(--safe-b) + 24px); }
#view { outline: none; padding: 8px 16px 0; max-width: 1080px; margin: 0 auto; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.logo { display: flex; align-items: center; gap: 9px; text-decoration: none; font-family: var(--font-d); font-weight: 800; font-size: 22px; letter-spacing: -.03em; }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }
.logo-mark svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.streak-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px 5px 7px; border-radius: 999px;
  background: var(--card); border: 1.5px solid var(--line); font-weight: 800; font-family: var(--font-d); font-size: 16px; text-decoration: none;
}
.streak-pill .flame { width: 20px; height: 20px; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px; border: 0; background: transparent; color: var(--ink);
  text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--sunk); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b)); padding: 6px 6px calc(6px + var(--safe-b));
  background: var(--card); border-top: 1.5px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink-3); font-size: 11.5px; font-weight: 700; border-radius: 14px; max-width: 96px;
}
.tab .tab-ico { width: 52px; height: 30px; display: grid; place-items: center; border-radius: 999px; transition: background .15s; }
.tab.on { color: var(--ink); }
.tab.on .tab-ico { background: var(--hl); color: #1F1D1A; }

.sidebar { display: none; }

@media (min-width: 900px) {
  .topbar, .tabbar { display: none; }
  .main-wrap { margin-left: 248px; padding-bottom: 48px; }
  #view { padding: 36px 40px 0; }
  .sidebar {
    display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: 248px; padding: 26px 16px 20px;
    border-right: 1.5px solid var(--line); background: var(--paper); z-index: 10;
  }
  .sidebar .logo { padding: 0 10px 26px; }
  .side-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 13px; text-decoration: none;
    color: var(--ink-2); font-weight: 650; margin-bottom: 2px;
  }
  .side-link:hover { background: var(--sunk); color: var(--ink); }
  .side-link.on { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
  .side-link.on svg { color: var(--accent); }
  .side-foot { margin-top: auto; }
  .side-streak {
    display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 16px; background: var(--card);
    border: 1.5px solid var(--line); text-decoration: none; margin-bottom: 10px;
  }
  .side-streak .flame { width: 34px; height: 34px; }
  .side-streak b { font-family: var(--font-d); font-size: 26px; line-height: 1; display: block; }
  .mobile-only { display: none !important; }
}
@media (max-width: 899px) { .desktop-only { display: none !important; } }

/* ============ Page head ============ */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin: 6px 0 20px; }
.page-head .eyebrow { font-weight: 700; color: var(--ink-3); font-size: 14px; margin-bottom: 4px; }
.page-head p.sub { color: var(--ink-2); margin-top: 6px; }
.page-head .actions { margin-left: auto; display: flex; gap: 10px; }

/* ============ Cards ============ */
.card { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card-label { font-size: 12.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.card-label .spacer { flex: 1; }
.card-label a, .card-label button { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 700; color: var(--ink-2); background: none; border: 0; padding: 0; text-decoration: none; }
.card-label a:hover, .card-label button:hover { color: var(--ink); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px;
  font: 700 15px/1.1 var(--font); border-radius: 14px; border: 1.5px solid var(--edge); background: var(--card); color: var(--ink);
  box-shadow: var(--btn-shadow); transition: transform .07s ease, box-shadow .07s ease, background .15s; text-decoration: none; user-select: none; white-space: nowrap;
}
.btn:hover { background: var(--sunk); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.good { background: var(--good); color: #fff; }
.btn.good:hover { background: #188553; }
.btn.dark { background: var(--ink); color: var(--paper); }
.btn.ghost { border-color: var(--line-2); box-shadow: none; background: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.ghost:active { transform: none; }
.btn.danger { color: var(--bad); border-color: var(--line-2); box-shadow: none; background: transparent; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.big { padding: 16px 18px; font-size: 17px; border-radius: 16px; }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.link-btn:hover { color: var(--ink); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 25; width: 58px; height: 58px;
  border-radius: 18px; border: 1.5px solid var(--edge); background: var(--accent); color: #fff; box-shadow: var(--btn-shadow);
  display: grid; place-items: center;
}
.fab:active { transform: translateY(3px); box-shadow: none; }
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }
@media (min-width: 900px) { .fab { display: none; } }

/* ============ Chips ============ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 2px 18px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 999px; flex: none;
  border: 1.5px solid var(--line-2); background: var(--card); font-weight: 700; font-size: 14.5px; color: var(--ink-2); white-space: nowrap;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip .x { margin-left: 2px; opacity: .6; display: inline-grid; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--ink-3)); flex: none; display: inline-block; }
.chip.on .dot { box-shadow: 0 0 0 2px var(--paper); }

.seg { display: inline-flex; background: var(--sunk); border-radius: 14px; padding: 4px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 14.5px; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 0 0 1.5px var(--line); }
.seg.block { display: flex; }
.seg.block button { flex: 1; }

/* ============ Forms ============ */
.field { display: block; margin-bottom: 16px; }
.field > span, .field-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 7px; color: var(--ink-2); }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field textarea, .field select {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm); border: 1.5px solid var(--line-2); background: var(--card);
  font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; }
.input:focus, .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--hl-soft); }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 6px; }

/* ============ Today ============ */
.today-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.today-grid > .card { margin: 0; }
@media (min-width: 900px) {
  .today-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
}
.col { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.col > .card { margin: 0; }
@media (max-width: 899px) {
  .today-grid .col { display: contents; }
  .today-grid .checkin { order: 0; }
  .today-grid .streak-card { order: 1; }
  .today-grid .col > *:not(.checkin):not(.streak-card) { order: 2; }
}

.heads-up {
  display: flex; align-items: center; gap: 12px; padding: 13px 15px; border-radius: 16px; margin-bottom: 14px;
  background: var(--hl-soft); border: 1.5px solid color-mix(in srgb, var(--hl) 70%, var(--line)); text-decoration: none; width: 100%; text-align: left;
}
.heads-up .hu-ico { width: 36px; height: 36px; border-radius: 11px; background: var(--hl); color: #1F1D1A; display: grid; place-items: center; flex: none; }
.heads-up b { display: block; font-size: 15px; }
.heads-up span { font-size: 14px; color: var(--ink-2); }
.heads-up.sunday { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.heads-up.sunday .hu-ico { background: var(--accent); color: #fff; }

.checkin h2 { margin-bottom: 14px; font-size: 23px; }
.checkin .chips { margin-bottom: 16px; }
.checkin-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.logged { display: flex; align-items: center; gap: 14px; }
.logged .big-check { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; flex: none; background: var(--good); color: #fff; }
.logged .big-check svg { width: 30px; height: 30px; stroke-width: 3; }
.logged.no .big-check { background: var(--sunk); color: var(--ink-2); }
.logged h2 { font-size: 21px; margin-bottom: 2px; }
.logged .actions-col { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.pop { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.4); } to { transform: scale(1); } }
.backfill { margin-top: 14px; padding-top: 12px; border-top: 1.5px dashed var(--line); font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.streak-card .streak-top { display: flex; align-items: center; gap: 14px; }
.flame { width: 48px; height: 48px; flex: none; }
.flame.cold path:first-child { fill: var(--line-2); }
.flame.cold path:last-child { fill: var(--sunk); }
.streak-num { font-family: var(--font-d); font-weight: 800; font-size: 54px; line-height: .9; letter-spacing: -.04em; }
.streak-label { font-weight: 700; color: var(--ink-2); font-size: 15px; }
.streak-best { margin-left: auto; text-align: right; font-size: 13px; color: var(--ink-3); font-weight: 700; }
.streak-best b { display: block; font-family: var(--font-d); font-size: 22px; color: var(--ink); }
.week-dots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 18px 0 12px; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; color: var(--ink-3); }
.wd i {
  width: 100%; max-width: 40px; aspect-ratio: 1; border-radius: 12px; display: grid; place-items: center; font-style: normal;
  background: var(--sunk); color: var(--ink-3);
}
.wd i svg { width: 18px; height: 18px; stroke-width: 3; }
.wd.yes i { background: var(--good); color: #fff; }
.wd.no i { background: var(--bad-soft); color: var(--bad); }
.wd.rest i { background: transparent; border: 1.5px dashed var(--line-2); font-size: 11px; }
.wd.miss i { background: transparent; border: 1.5px solid var(--line-2); }
.wd.future i { background: transparent; border: 1.5px dotted var(--line-2); }
.wd.today { color: var(--ink); }
.wd.today i { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink); }
.streak-hint { font-size: 14.5px; color: var(--ink-2); }
.milestone-bar { height: 8px; background: var(--sunk); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.milestone-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s; }

/* ============ Item rows ============ */
.item-list { display: flex; flex-direction: column; }
.item-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1.5px solid var(--line);
  cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; border-radius: 0;
}
.item-row:last-child { border-bottom: 0; }
.item-row:hover .item-title { text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row.done .item-title { text-decoration: line-through; color: var(--ink-3); }
.item-meta { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink-2); margin-top: 2px; }
.item-when { text-align: right; flex: none; }
.item-when .when { display: block; font-weight: 700; font-size: 14px; }
.item-when .in { font-size: 12.5px; color: var(--ink-3); font-weight: 600; }
.item-when .in.soon { color: var(--accent-2); font-weight: 800; }
.item-when .in.late { color: var(--bad); font-weight: 800; }
.check {
  width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line-2); background: var(--card); display: grid; place-items: center; flex: none; color: transparent; padding: 0;
}
.check:hover { border-color: var(--good); }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.check svg { width: 16px; height: 16px; stroke-width: 3.2; }
.type-badge {
  width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: none; font-family: var(--font-d);
  font-weight: 800; font-size: 13px; background: var(--c-soft, var(--sunk)); color: var(--c, var(--ink));
}
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px; background: var(--sunk); color: var(--ink-2); }
.tag.test { background: var(--accent-soft); color: var(--accent-2); }
.group-label { font-size: 13px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); margin: 22px 0 4px; display: flex; align-items: center; gap: 8px; }
.group-label .count { background: var(--sunk); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.group-label.late { color: var(--bad); }
.plan-card { padding: 4px 16px; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.empty .empty-art { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 20px; background: var(--sunk); display: grid; place-items: center; color: var(--ink-3); }
.empty .empty-art svg { width: 30px; height: 30px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; font-size: 18px; }
.empty .btn { margin-top: 14px; }

/* ============ Sheet ============ */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 18, 14, .42); opacity: 0; transition: opacity .2s; }
.sheet {
  position: relative; width: 100%; max-height: 92dvh; background: var(--paper); border-radius: 24px 24px 0 0;
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .9, .3, 1);
  padding-bottom: var(--safe-b); box-shadow: 0 -10px 40px rgba(0,0,0,.18);
}
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line-2); margin: 9px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 6px 20px; flex: none; }
.sheet-head h3 { flex: 1; font-size: 20px; }
.sheet-body { overflow-y: auto; padding: 8px 20px 24px; overscroll-behavior: contain; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; padding: 24px; }
  .sheet { max-width: 540px; border-radius: 24px; transform: translateY(24px) scale(.98); opacity: 0; transition: transform .22s, opacity .18s; border: 1.5px solid var(--line); max-height: 88vh; }
  .sheet.wide { max-width: 760px; }
  .sheet-wrap.open .sheet { opacity: 1; }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 16px; }
}

/* ============ Toast ============ */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
@media (min-width: 900px) { #toast-root { bottom: 24px; left: 248px; } }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: 14px;
  font-weight: 650; font-size: 15px; box-shadow: 0 12px 30px rgba(0,0,0,.25); animation: toastIn .25s cubic-bezier(.2, 1.4, .4, 1); max-width: 100%;
}
.toast button { background: none; border: 0; color: var(--hl); font-weight: 800; padding: 0; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* ============ Burst ============ */
.burst-dot { position: fixed; z-index: 300; width: 9px; height: 9px; border-radius: 3px; pointer-events: none; animation: burst .75s cubic-bezier(.15, .7, .3, 1) forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; } }

/* ============ Item detail ============ */
.detail-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.detail-head h2 { font-size: 25px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--ink-2); font-size: 14.5px; margin-top: 6px; align-items: center; }
.detail-notes { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; white-space: pre-wrap; margin-bottom: 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { font-family: var(--font-d); font-weight: 700; font-size: 17px; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.thumb { aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1.5px solid var(--line); background: var(--sunk); padding: 0; position: relative; display: grid; place-items: center; color: var(--ink-3); font-size: 12px; font-weight: 700; text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.add { border-style: dashed; border-color: var(--line-2); background: transparent; display: flex; flex-direction: column; gap: 4px; }

/* ============ AI blocks ============ */
.ai-box { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-top: 10px; }
.ai-box .ai-head { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.ai-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.ai-actions .btn { justify-content: flex-start; }
.ai-locked { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--sunk); font-size: 14px; color: var(--ink-2); }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite both; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.md { font-size: 15.5px; line-height: 1.6; overflow-wrap: anywhere; }
.md > * + * { margin-top: .7em; }
.md h4, .md h5 { font-size: 17px; margin-top: 1em; }
.md ul, .md ol { padding-left: 1.3em; margin-bottom: 0; }
.md li + li { margin-top: .25em; }
.md code { font-family: ui-monospace, 'Cascadia Code', Menlo, monospace; font-size: .9em; background: var(--sunk); padding: .1em .35em; border-radius: 5px; }
.md pre { background: var(--sunk); padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--hl); color: var(--ink-2); }
.md table { border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1.5px solid var(--line); padding: 6px 10px; text-align: left; }
.md hr { border: 0; border-top: 1.5px dashed var(--line-2); }

/* ============ Quiz & flashcards ============ */
.quiz-progress { display: flex; gap: 4px; margin-bottom: 16px; }
.quiz-progress i { flex: 1; height: 6px; border-radius: 9px; background: var(--sunk); }
.quiz-progress i.right { background: var(--good); }
.quiz-progress i.wrong { background: var(--bad); }
.quiz-progress i.cur { background: var(--ink-3); }
.quiz-q { font-family: var(--font-d); font-size: 21px; font-weight: 700; margin-bottom: 16px; line-height: 1.3; }
.choices { display: grid; gap: 9px; }
.choice {
  text-align: left; display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: 14px; border: 1.5px solid var(--line-2);
  background: var(--card); font-weight: 600; font-size: 15.5px; line-height: 1.4;
}
.choice:hover { border-color: var(--ink); }
.choice .letter { width: 26px; height: 26px; border-radius: 8px; background: var(--sunk); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right .letter { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .letter { background: var(--bad); color: #fff; }
.choices.answered .choice { pointer-events: none; }
.explain { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--sunk); font-size: 15px; }
.score-big { font-family: var(--font-d); font-size: 64px; font-weight: 800; text-align: center; letter-spacing: -.04em; line-height: 1; margin: 10px 0 6px; }

.flash { perspective: 1200px; margin-bottom: 14px; }
.flash-inner { position: relative; min-height: 230px; transition: transform .45s cubic-bezier(.3, .9, .3, 1); transform-style: preserve-3d; cursor: pointer; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 20px; padding: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1.5px solid var(--edge); box-shadow: var(--btn-shadow);
  background: var(--card); font-size: 19px; font-weight: 650; line-height: 1.4; overflow-y: auto;
}
.flash-face small { position: absolute; top: 12px; left: 16px; font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.flash-face.back { transform: rotateY(180deg); background: var(--hl-soft); font-weight: 500; font-size: 17px; }
.flash-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ============ Notes ============ */
.notes-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search input { padding-left: 40px !important; }
.notes-grid { columns: 2 160px; column-gap: 12px; }
@media (min-width: 900px) { .notes-grid { columns: 3 200px; } }
.note-card {
  break-inside: avoid; margin-bottom: 12px; width: 100%; display: block; text-align: left; padding: 0; overflow: hidden;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); transition: transform .12s;
}
.note-card:hover { transform: translateY(-2px); }
.note-card img { width: 100%; max-height: 260px; object-fit: cover; border-bottom: 1.5px solid var(--line); background: var(--sunk); }
.note-card .nc-body { padding: 11px 13px 13px; }
.note-card .nc-title { font-weight: 750; font-size: 15px; line-height: 1.3; }
.note-card .nc-text { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.note-card .nc-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-3); margin-top: 8px; font-weight: 600; }
.note-card .nc-meta .ai-dot { margin-left: auto; display: inline-flex; gap: 3px; align-items: center; color: var(--accent-2); }
.drop {
  border: 2px dashed var(--line-2); border-radius: 18px; padding: 22px 16px; text-align: center; background: var(--card); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .drop-ico { width: 46px; height: 46px; border-radius: 14px; background: var(--sunk); display: grid; place-items: center; margin: 0 auto 8px; }
.drop b { display: block; }
.drop span { font-size: 13.5px; color: var(--ink-2); }
.preview-img { position: relative; border-radius: 16px; overflow: hidden; border: 1.5px solid var(--line); }
.preview-img img { width: 100%; max-height: 340px; object-fit: contain; background: var(--sunk); }
.preview-img .icon-btn { position: absolute; top: 8px; right: 8px; background: var(--card); box-shadow: var(--shadow); }
.note-img-full { border-radius: 16px; overflow: hidden; border: 1.5px solid var(--line); background: var(--sunk); cursor: zoom-in; margin-bottom: 14px; }
.note-img-full img { width: 100%; max-height: 420px; object-fit: contain; }
.lightbox { position: fixed; inset: 0; z-index: 400; background: rgba(10, 9, 7, .92); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-height: 100%; max-width: 100%; object-fit: contain; border-radius: 8px; }
.tabs-mini { display: flex; gap: 6px; margin: 16px 0 4px; flex-wrap: wrap; }

/* ============ Scanning ============ */
.scan-cta { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; margin-bottom: 16px; }
.scan-start { display: grid; gap: 10px; }
@media (min-width: 560px) { .scan-start { grid-template-columns: 1fr 1fr; } }
.scan-start .drop { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; font: inherit; color: inherit; }
.scan-start .drop svg { width: 30px; height: 30px; color: var(--accent); }
.scan-pages { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; }
.scan-page {
  position: relative; flex: none; width: 128px; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden;
  border: 1.5px solid var(--line); background: var(--sunk);
}
.scan-page img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.scan-page.add { border: 2px dashed var(--line-2); background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-weight: 700; font-size: 13px; color: var(--ink-2); padding: 0; }
.scan-page.add:hover { border-color: var(--accent); color: var(--accent-2); }
.pg-num { position: absolute; left: 6px; top: 6px; background: rgba(20, 18, 14, .75); color: #fff; font-size: 11.5px; font-weight: 800; padding: 2px 7px; border-radius: 7px; z-index: 1; }
.pg-tools { position: absolute; right: 5px; top: 5px; display: flex; gap: 4px; }
.pg-tools button { width: 26px; height: 26px; border-radius: 8px; border: 0; background: rgba(20, 18, 14, .75); color: #fff; display: grid; place-items: center; padding: 0; }
.pg-tools svg { stroke-width: 2.6; }
.note-img-full { position: relative; }
.note-img-full + .note-img-full { margin-top: -4px; }
.nc-img { position: relative; }
.page-count { position: absolute; right: 8px; bottom: 8px; background: rgba(20, 18, 14, .78); color: #fff; font-size: 11.5px; font-weight: 800; padding: 3px 8px; border-radius: 8px; }

/* ============ Import / found dates ============ */
.imp-list { display: flex; flex-direction: column; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); overflow: hidden; }
.imp-row { display: flex; gap: 12px; align-items: flex-start; padding: 11px 13px; border-bottom: 1.5px solid var(--line); cursor: pointer; }
.imp-row:last-child { border-bottom: 0; }
.imp-row input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--good); flex: none; }
.imp-main { flex: 1; min-width: 0; }
.imp-main .item-title { white-space: normal; font-size: 15px; }
.imp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 4px; }
.imp-meta select { font-size: 13.5px; padding: 4px 8px; border-radius: 9px; border: 1.5px solid var(--line-2); background: var(--card); max-width: 150px; }
.watch-badge { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--hl); color: #1F1D1A; vertical-align: -3px; margin-left: 4px; }
.watch-badge svg { width: 13px; height: 13px; stroke-width: 2.4; }
.heads-up.watch { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.heads-up.watch .hu-ico { background: var(--accent); color: #fff; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-actions .btn { flex-direction: column; gap: 6px; padding: 16px 10px; white-space: normal; text-align: center; }
.quick-actions .btn svg { width: 26px; height: 26px; color: var(--accent); }
.sync-line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); margin-top: 10px; flex-wrap: wrap; }
.src-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 800; padding: 3px 7px; border-radius: 6px; background: #E8F1FB; color: #2367B4; }
:root[data-theme="dark"] .src-tag { background: #16273A; color: #8CC0F5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .src-tag { background: #16273A; color: #8CC0F5; } }

/* ============ Week ============ */
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-nav .icon-btn { border: 1.5px solid var(--line); background: var(--card); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-family: var(--font-d); font-size: clamp(30px, 8vw, 44px); line-height: 1; letter-spacing: -.03em; }
.stat span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.stat small { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.stat.good b { color: var(--good); }
.stat.bad b { color: var(--bad); }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-grid .wd { gap: 5px; }
.week-grid .wd i { max-width: 52px; border-radius: 14px; }
.week-grid .wd em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--ink-2); text-align: center; line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-cols { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .week-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.week-cols .card { margin: 0; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1.5px solid var(--line); font-size: 15px; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .ml-when { margin-left: auto; font-size: 13px; color: var(--ink-3); font-weight: 700; white-space: nowrap; }
.mini-list .ok { color: var(--good); }
.mini-list .late { color: var(--bad); }
.subject-bars { display: grid; gap: 8px; }
.sbar { display: grid; grid-template-columns: 96px 1fr 22px; align-items: center; gap: 10px; font-size: 14px; font-weight: 650; }
.sbar .track { height: 10px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.sbar .track i { display: block; height: 100%; border-radius: 99px; background: var(--c); }
.sbar span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Buddy chat ============ */
.buddy { display: flex; flex-direction: column; min-height: calc(100dvh - 160px - var(--safe-b)); }
@media (min-width: 900px) { .buddy { min-height: calc(100dvh - 90px); } }
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 18px; padding-bottom: 16px; }
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--ink); color: var(--paper); border-radius: 20px 20px 6px 20px; padding: 11px 15px; max-width: 82%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble img { border-radius: 12px; max-height: 180px; margin-bottom: 8px; }
.msg.assistant .avatar { width: 32px; height: 32px; border-radius: 10px; background: var(--hl); color: #1F1D1A; display: grid; place-items: center; flex: none; }
.msg.assistant .avatar svg { width: 18px; height: 18px; }
.msg.assistant .content { flex: 1; min-width: 0; padding-top: 4px; }
.msg.error .content { color: var(--bad); font-weight: 600; }
.composer {
  position: sticky; bottom: calc(var(--tab-h) + var(--safe-b) + 10px); background: var(--card); border: 1.5px solid var(--edge);
  border-radius: 20px; padding: 8px; box-shadow: var(--btn-shadow);
}
@media (min-width: 900px) { .composer { bottom: 20px; } }
.composer textarea { width: 100%; border: 0; background: transparent; resize: none; outline: none; padding: 8px 8px 4px; font-size: 16px; max-height: 180px; line-height: 1.45; }
.composer-bar { display: flex; align-items: center; gap: 4px; }
.composer-bar .send { margin-left: auto; width: 42px; height: 42px; border-radius: 13px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; }
.composer-bar .send:disabled { background: var(--line-2); }
.attach-row { display: flex; gap: 8px; padding: 4px 6px 6px; flex-wrap: wrap; }
.attach-row .att { position: relative; width: 58px; height: 58px; border-radius: 11px; overflow: hidden; border: 1.5px solid var(--line); }
.attach-row .att img { width: 100%; height: 100%; object-fit: cover; }
.attach-row .att button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 6px; border: 0; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; padding: 0; }
.attach-row .att button svg { width: 12px; height: 12px; stroke-width: 3; }
.suggestions { display: grid; gap: 8px; margin-top: 14px; }
@media (min-width: 700px) { .suggestions { grid-template-columns: 1fr 1fr; } }
.suggest {
  text-align: left; padding: 13px 15px; border-radius: 16px; border: 1.5px solid var(--line-2); background: var(--card); font-weight: 650; font-size: 15px;
  display: flex; align-items: center; gap: 10px;
}
.suggest:hover { border-color: var(--ink); }
.suggest svg { color: var(--accent); }
.buddy-hero { text-align: center; padding: 24px 8px 8px; }
.buddy-hero .bh-ico { width: 64px; height: 64px; border-radius: 20px; background: var(--hl); color: #1F1D1A; display: grid; place-items: center; margin: 0 auto 14px; transform: rotate(-6deg); }
.buddy-hero .bh-ico svg { width: 32px; height: 32px; }
.setup-steps { counter-reset: s; list-style: none; padding: 0; margin: 16px 0; }
.setup-steps li { counter-increment: s; display: flex; gap: 12px; padding: 10px 0; font-size: 15px; }
.setup-steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 9px; background: var(--ink); color: var(--paper); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; }

/* ============ Settings ============ */
.settings-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .settings-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.settings-grid .card { margin: 0; }
.settings-grid .card h3 { margin-bottom: 4px; }
.settings-grid .card > p.muted { font-size: 14px; margin-bottom: 14px; }
.daypick { display: flex; gap: 6px; }
.daypick button { width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line-2); background: var(--card); font-weight: 800; font-size: 14px; color: var(--ink-2); }
.daypick button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 650; padding: 10px 12px; background: var(--sunk); border-radius: 12px; margin-bottom: 12px; }
.status-line .dot { --c: var(--ink-3); }
.status-line.on .dot { --c: var(--good); }
.status-line.off .dot { --c: var(--bad); }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; min-width: 0; }
.color-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.color-swatches button { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; background: var(--c); padding: 0; }
.color-swatches button.on { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--card); }

/* ============ Onboarding ============ */
.onboard { max-width: 520px; margin: 0 auto; padding: 24px 0 40px; }
.onboard .logo { margin-bottom: 28px; }
.onboard h1 { margin-bottom: 10px; }
.onboard .lead { color: var(--ink-2); font-size: 17px; margin-bottom: 26px; }
.onboard .card { margin-bottom: 14px; }
.promise { display: grid; gap: 10px; margin: 22px 0; }
.promise div { display: flex; gap: 12px; align-items: center; font-weight: 600; }
.promise i { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--card); border: 1.5px solid var(--line); flex: none; font-style: normal; }

/* ============ Milestone ============ */
.milestone { text-align: center; padding: 10px 0 6px; }
.milestone .flame { width: 90px; height: 90px; margin: 0 auto; animation: wiggle 1.2s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-4deg) scale(1); } 50% { transform: rotate(4deg) scale(1.06); } }
.milestone .big { font-family: var(--font-d); font-size: 72px; font-weight: 800; letter-spacing: -.04em; line-height: 1; margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
