:root {
  --bg: #f7f6fb; --surface: #ffffff; --surface2: #eeedf6; --text: #1b1b21; --muted: #6b6a75;
  --primary: #5b5bd6; --on-primary: #fff; --border: #d9d8e3; --danger: #c62828; --code-bg: #1e1e2e; --code-fg: #cdd6f4;
  --radius: 16px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121218; --surface: #1d1d26; --surface2: #282834; --text: #e6e4ef; --muted: #9a98a6;
  --primary: #a9a9ff; --on-primary: #16163a; --border: #33333f; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.no-scroll { overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button, select { background: var(--surface2); border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer; }
button:hover { filter: brightness(.97); }
button.primary, .btn { background: var(--primary); color: var(--on-primary); }
button.icon { background: transparent; padding: 6px 9px; font-size: 17px; }
button.danger, .danger-text { color: var(--danger); }
input, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--primary); }
.muted { color: var(--muted); } .small { font-size: 13px; } .big { font-size: 22px; font-weight: 700; }
.grow { flex: 1; min-width: 0; } .row { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .col { display: flex; flex-direction: column; }
.done { text-decoration: line-through; color: var(--muted); }
.clamp { max-height: 14em; overflow: hidden; } .clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 19px; }
#search { flex: 1; min-width: 180px; border-radius: 999px; }
.actions { display: flex; gap: 6px; }
.badge { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 12px; margin-left: 4px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 4px; }
.chip { white-space: nowrap; border: 1px solid var(--border); background: var(--surface); }
.chip.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ---------- note cards (masonry) ---------- */
.grid { columns: 230px; column-gap: 12px; padding: 12px 16px 110px; }
.card { break-inside: avoid; margin: 0 0 12px; background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow); cursor: pointer; overflow: hidden; }
.card:hover { outline: 2px solid var(--primary); }
.card h3 { margin: 4px 0 6px; font-size: 16px; }
.card-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.card .cover { display: block; width: calc(100% + 28px); margin: 6px -14px; max-height: 220px; object-fit: cover; background: var(--surface2); }
.card .link { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); column-span: all; }

/* ---------- new note ---------- */
.fab { position: fixed; right: 20px; bottom: 20px; z-index: 6; background: var(--primary); color: var(--on-primary);
  padding: 14px 22px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.newmenu { position: fixed; right: 20px; bottom: 80px; z-index: 7; display: none; grid-template-columns: repeat(2, 150px); gap: 8px;
  background: var(--surface); padding: 12px; border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.newmenu.open { display: grid; }
.newmenu button { border-radius: 12px; display: flex; flex-direction: column; align-items: flex-start; padding: 10px 12px; text-align: left; }
.newmenu small { color: var(--muted); }

/* ---------- editor ---------- */
.editor { position: fixed; inset: 0; z-index: 10; display: none; background: rgba(0,0,0,.35); }
.editor.open { display: flex; justify-content: center; align-items: flex-start; padding: 4vh 12px; overflow-y: auto; }
.ed-panel { width: 100%; max-width: 820px; background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.ed-bar { display: flex; align-items: center; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.ed-type { flex: 1; font-weight: 600; }
.ed-body { padding: 8px 18px 18px; }
.title { width: 100%; border: 0; background: transparent; font-size: 24px; font-weight: 600; padding: 8px 0; }
textarea.plain { width: 100%; border: 0; background: transparent; resize: vertical; padding: 8px 0; }
textarea.body { min-height: 260px; font-size: 16px; }
textarea.code { width: 100%; background: var(--code-bg); color: var(--code-fg); font: 13px/1.5 ui-monospace, Consolas, monospace;
  border-radius: 12px; padding: 12px; tab-size: 2; white-space: pre; overflow: auto; }
pre.code { background: var(--code-bg); color: var(--code-fg); border-radius: 8px; padding: 8px; overflow: hidden; margin: 4px 0; max-height: 10em; }
.notice { background: var(--surface2); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.box { background: var(--surface2); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; } .tbl td, .tbl th { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
.plainpre { white-space: pre-wrap; font: inherit; }

/* formatting bar + formatted text */
.fmt { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); position: sticky; top: 52px; background: inherit; }
.fmt button { padding: 5px 11px; border-radius: 8px; }
.fmt .dot { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid var(--border); }
.fmt .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.rt div { min-height: 1.2em; } .rt ul { margin: 0; padding-left: 22px; } .rt .rt-h { font-size: 1.4em; font-weight: 700; }
.rt mark { color: #1b1b21; border-radius: 3px; padding: 0 1px; }
.preview { background: var(--surface2); border-radius: 12px; padding: 10px 12px; }

/* links */
.linkcard { display: flex; gap: 12px; align-items: flex-start; background: var(--surface2); border-radius: 14px; padding: 10px; margin: 8px 0; }
.linkcard img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; background: var(--surface); }
.linkcard img.fav { width: 40px; height: 40px; padding: 6px; }
.linkcard .site { font-size: 11px; color: var(--primary); font-weight: 600; letter-spacing: .3px; }
.linkcard a { color: inherit; font-weight: 600; text-decoration: none; word-break: break-word; }

/* media */
.btn { display: inline-block; border-radius: 999px; padding: 8px 16px; cursor: pointer; margin: 6px 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 8px 0; }
.gallery img, .gallery video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; cursor: zoom-in; background: var(--surface2); }
.files .mitem { background: var(--surface2); border-radius: 12px; padding: 8px 10px; margin: 8px 0; }
.files video { width: 100%; max-height: 420px; border-radius: 10px; background: #000; }
.files audio { width: 100%; }
.mrow { display: flex; align-items: center; gap: 4px; }
.fileicon { font-size: 30px; }
img.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.missing { opacity: .3; }

/* photo viewer */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: none; align-items: center; justify-content: center; }
.viewer.open { display: flex; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer button { position: absolute; background: rgba(255,255,255,.15); color: #fff; font-size: 26px; padding: 6px 16px; }
.vclose { top: 14px; right: 14px; } .vprev { left: 10px; } .vnext { right: 10px; }
.vcount { position: absolute; bottom: 16px; color: #fff; }

/* dialogs, clip result, toast */
.dialog { position: fixed; inset: 0; z-index: 30; display: none; background: rgba(0,0,0,.4); align-items: center; justify-content: center; padding: 16px; }
.dialog.open { display: flex; }
.dialog-box { background: var(--surface); border-radius: var(--radius); padding: 18px 20px; max-width: 460px; width: 100%; max-height: 90vh; overflow: auto; }
.dialog-box.wide { max-width: 640px; }
.dialog-box h3 { margin: 10px 0 6px; }
.bm { display: inline-block; background: var(--primary); color: var(--on-primary); padding: 10px 18px; border-radius: 999px; text-decoration: none; font-weight: 600; }
.clipdone { position: fixed; inset: 0; z-index: 40; display: none; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 20px; }
.clipdone.open { display: flex; }
.clip-ok { font-size: 22px; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .25s; z-index: 50;
  background: #333; color: #fff; padding: 10px 16px; border-radius: 10px; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 640px) {
  .top { padding: 8px 10px; } .actions button { padding: 7px 10px; }
  .grid { columns: 2 150px; padding: 10px 10px 110px; }
  .editor.open { padding: 0; } .ed-panel { min-height: 100%; border-radius: 0; }
  .newmenu { grid-template-columns: repeat(2, 1fr); left: 12px; right: 12px; }
}

/* ---------- finance / expenses / reminder / cooking ---------- */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 8px 0; }
.field input, .field select, .field textarea { color: var(--text); font-size: 15px; width: 100%; box-sizing: border-box; }
.field select { border-radius: 12px; padding: 9px 12px; }
.sumcard { background: var(--primary); color: var(--on-primary); border-radius: 18px; padding: 14px 16px; margin: 8px 0; }
.sumcard select { background: rgba(255,255,255,.2); color: inherit; }
.sumcard select option { color: #000; }
.sumcard .icon { background: rgba(255,255,255,.18); color: inherit; }
.sumcard.dim { opacity: .75; }
.big2 { font-size: 20px; font-weight: 700; margin: 4px 0; }
.huge { font-size: 44px; font-weight: 700; line-height: 1.1; }
.bar { height: 8px; background: rgba(127,127,127,.25); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.bar span { display: block; height: 100%; background: currentColor; border-radius: 99px; }
.box .bar span, .catrow .bar span, .cook-panel .bar span { background: var(--primary); }
.bar.over span { background: var(--danger) !important; }
.bar.thin { height: 5px; margin: 4px 0; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; font-size: 12px; color: var(--muted); }
.facts b { display: block; color: var(--text); font-size: 14px; }
.hist { border-top: 1px solid var(--border); margin-top: 6px; }
.wide { width: 100%; padding: 12px; margin: 8px 0; }
.catchips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.catrow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; font-size: 14px; }
.catrow .bar { flex-basis: 100%; color: inherit; }
.catrow .bar span { background: currentColor; }
.sumcard .muted { color: inherit; opacity: .75; }
.center { text-align: center; }
.dayhead { margin-top: 14px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.exp { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-radius: 10px; cursor: pointer; }
.exp:hover { background: var(--surface2); }
.exp .ico { font-size: 20px; }
.accent { color: var(--primary); }
.ing { display: flex; gap: 6px; align-items: center; margin: 6px 0; position: relative; }
.ing [data-amt] { width: 90px; }
.ingphoto { width: 44px; height: 44px; flex: none; border-radius: 10px; background: var(--surface2); display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; }
.ingphoto img { width: 100%; height: 100%; object-fit: cover; }
.ing [data-rmphoto] { position: absolute; left: 30px; top: -6px; padding: 0 5px; font-size: 10px; }
.step { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.step .num { width: 26px; height: 26px; flex: none; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; margin-top: 6px; }
.step textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.stepmedia { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.stepmedia .sm { position: relative; }
.stepmedia img, .stepmedia video { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; }
.stepmedia button { position: absolute; top: 2px; right: 2px; padding: 0 6px; }
label.icon { cursor: pointer; padding: 6px 10px; }
.big-btn { font-size: 17px; font-weight: 600; }
h4 { margin: 14px 0 4px; }
.cook { position: fixed; inset: 0; z-index: 25; display: none; background: var(--bg); }
.cook.open { display: block; }
.cook-panel { max-width: 720px; height: 100%; margin: 0 auto; display: flex; flex-direction: column; padding: 10px 16px; box-sizing: border-box; }
.cook-title { font-size: 18px; }
.cook-body { flex: 1; overflow: auto; padding: 8px 0; }
.cook-panel footer { padding: 8px 0 14px; }
.huge-btn { font-size: 18px; padding: 14px 22px; font-weight: 600; }
.okbtn { background: #2e7d32; color: #fff; }
.ok-text { color: #2e7d32; }
.stepnum { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.stepnum.ok { background: #2e7d32; color: #fff; }
.steptext { font-size: 26px; font-weight: 600; line-height: 1.3; margin: 12px 0; }
.needs { display: flex; gap: 8px; overflow-x: auto; margin: 6px 0 12px; }
.need { flex: none; width: 110px; background: var(--surface2); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.need img { width: 100%; height: 80px; object-fit: cover; border-radius: 8px; }
.stepbig { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 14px; margin: 6px 0; background: var(--surface2); }
.nextbox { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-top: 14px; color: var(--muted); }
.cookling { display: flex; gap: 10px; align-items: center; padding: 10px; background: var(--surface); border-radius: 12px; margin: 6px 0; font-size: 17px; }
.cookling input { width: 22px; height: 22px; }
.ingthumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.ovstep { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; cursor: pointer; }
.ovstep.cur { background: var(--surface2); }
.finish .emoji { font-size: 72px; margin-top: 40px; }
.cook-timer { display: flex; gap: 10px; align-items: center; background: var(--surface2); border-radius: 12px; padding: 10px 14px; font-size: 22px; margin: 6px 0; }
.cook-timer[hidden] { display: none; }
.cook-timer.ring { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .7; } }

/* ---------- ⋮ menus ---------- */
.popmenu { position: fixed; z-index: 60; background: var(--surface); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  padding: 6px; display: flex; flex-direction: column; min-width: 190px; border: 1px solid var(--border); }
.popmenu button { background: none; border-radius: 8px; text-align: left; padding: 9px 12px; color: var(--text); }
.popmenu button:hover { background: var(--surface2); }
.popmenu button.danger { color: var(--danger); }
.mname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery .mitem { position: relative; }
.gallery .mrow { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; background: linear-gradient(transparent, rgba(0,0,0,.55)); border-radius: 0 0 12px 12px; color: #fff; }
.gallery .mrow .icon { color: #fff; background: rgba(0,0,0,.3); }
.gallery .mrow .mname { visibility: hidden; }

/* ---------- audio playlist ---------- */
.rec { color: var(--danger); font-weight: 600; }
.playcard { background: var(--primary); color: var(--on-primary); border-radius: 18px; padding: 12px 14px; margin: 10px 0; }
.playcard .icon { background: rgba(255,255,255,.18); color: inherit; font-size: 17px; }
.playcard .icon.off { opacity: .45; }
.playcard .wide { background: rgba(255,255,255,.95); color: #2b2b80; font-weight: 700; }
.nowtitle { font-weight: 600; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playcard input[type=range] { width: 100%; accent-color: #fff; margin: 6px 0 0; padding: 0; border: 0; background: none; }
.playcard .controls { margin: 0; }
.playbtn { width: 52px; height: 52px; border-radius: 50%; font-size: 22px; background: #fff; color: #2b2b80; padding: 0; }
.track { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 10px; border-radius: 12px; margin: 4px 0; background: var(--surface2); cursor: pointer; }
.track:hover { outline: 1px solid var(--border); }
.track.cur { background: color-mix(in srgb, var(--primary) 18%, var(--surface)); }
.track.cur .ttitle { color: var(--primary); font-weight: 600; }
.track .grow { display: flex; flex-direction: column; min-width: 0; }
.ttitle { overflow: hidden; text-overflow: ellipsis; }
.tnum { width: 26px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- mini player (stays while you browse) ---------- */
.miniplayer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; background: var(--surface); box-shadow: 0 -4px 20px rgba(0,0,0,.15); }
.miniplayer[hidden] { display: none; }
.mp-progress { height: 3px; background: var(--surface2); }
.mp-progress span { display: block; height: 100%; background: var(--primary); }
.mp-row { display: flex; align-items: center; gap: 4px; padding: 6px 10px; max-width: 900px; margin: 0 auto; }
.mp-info { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; background: none; text-align: left; padding: 4px; border-radius: 10px; }
.mp-info span { display: flex; flex-direction: column; min-width: 0; }
.mp-info b, .mp-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-info small { color: var(--muted); }
body.has-mini { padding-bottom: 64px; }
body.has-mini .fab { bottom: 80px; }

/* ---------- code editor (colors match the app) ---------- */
.code-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.code-wrap { --code-size: 13px; display: flex; background: #1e1e2e; border-radius: 12px; overflow: hidden; height: 60vh; min-height: 260px; }
.code-wrap.full { position: fixed; inset: 0; z-index: 40; height: auto; border-radius: 0; }
.code-gutter { background: #181825; color: #6c7086; text-align: right; padding: 12px 8px; min-width: 2.2em; white-space: pre;
  font: var(--code-size)/1.5 ui-monospace, Consolas, "Cascadia Code", monospace; overflow: hidden; user-select: none; }
.code-area { position: relative; flex: 1; min-width: 0; }
.code-hl, .code-input { position: absolute; inset: 0; margin: 0; padding: 12px; border: 0; border-radius: 0; box-sizing: border-box;
  font: var(--code-size)/1.5 ui-monospace, Consolas, "Cascadia Code", monospace; tab-size: 2; white-space: pre; overflow: auto;
  overflow-wrap: normal; word-break: normal; }
.code-hl { color: #cdd6f4; pointer-events: none; overflow: hidden; }
.code-input { background: transparent; color: transparent; caret-color: #cdd6f4; resize: none; outline: none; }
.code-input::selection { background: rgba(137,180,250,.35); color: transparent; }
.code-input::placeholder { color: #7f849c; }
.code-wrap.wrap .code-hl, .code-wrap.wrap .code-input { white-space: pre-wrap; overflow-wrap: anywhere; }
.hl-kw { color: #cba6f7; } .hl-str { color: #a6e3a1; } .hl-com { color: #7f849c; }
.hl-num { color: #fab387; } .hl-attr { color: #89b4fa; } .hl-fn { color: #f9e2af; }
.code-status { margin-top: 4px; }
.code-hl, .code-input { scrollbar-gutter: stable; }
.code-exit { display: none; position: absolute; top: 8px; right: 14px; z-index: 2; background: #313244; color: #cdd6f4; }
.code-wrap { position: relative; }
.code-wrap.full { position: fixed; }
.code-wrap.full .code-exit { display: block; }
.ok-line { color: #2e7d32; font-weight: 600; }
.howlist { padding-left: 20px; } .howlist li { margin: 6px 0; }
#clipperInstall[hidden], #clipperHow[hidden] { display: none; }
