:root {
  --bg: #f6f1e9;
  --paper: #fbf8f3;
  --ink: #2b2622;
  --muted: #8a7f76;
  --faint: #c9bfb4;
  --line: #e4dccf;
  --chip: #ece4d8;
  --accent: #7b6b61;
  --accent-ink: #fbf8f3;
  --danger: #b4523f;
  --rec: #c8432f;
  --type: "Courier Prime", "Noto Sans Tamil", "Courier New", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Tamil", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); }
body { min-height: 100vh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(var(--safe-top) + 18px) 22px 12px;
  background: var(--bg);
}
.nb-btn { font-size: 30px; font-weight: 600; letter-spacing: -0.3px; display: flex; align-items: baseline; gap: 6px; text-align: left; }
.nb-btn .caret { font-size: 14px; color: var(--muted); }
.sub { margin-top: 4px; font-size: 15px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status { font-size: 13px; color: var(--muted); padding: 2px 8px; border-radius: 99px; background: var(--chip); }
.status.warn { color: #8a4b2a; background: #f3dfcf; }
.status.ok { background: transparent; padding-left: 0; }
.top-actions { display: flex; gap: 6px; margin-top: 6px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon-btn:active { background: var(--chip); }
.icon-btn svg { width: 24px; height: 24px; }

.search-bar { padding: 0 22px 10px; }
.search-bar input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); font-size: 16px; outline: none; }

/* ---------- timeline ---------- */
.timeline { padding: 0 22px calc(var(--safe-bottom) + 120px); }
.day { display: flex; align-items: center; gap: 14px; margin: 22px 0 18px; color: var(--ink); font-size: 14px; letter-spacing: 2.5px; text-transform: uppercase; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.entry { display: grid; grid-template-columns: 62px 1fr; gap: 8px; margin-bottom: 30px; }
.when { color: var(--muted); font-size: 15px; padding-top: 2px; }
.when .chip { display: inline-block; margin-top: 8px; padding: 3px 9px; border-radius: 99px; background: var(--chip); font-size: 13px; }
.when .pending { display: block; margin-top: 8px; font-size: 11px; color: #a0643f; }
.body { min-width: 0; }
.nbtag { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.text { font-family: var(--type); font-size: 18px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.text.clamp { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.text + .strip, .strip + .text, .text + .audio, .strip + .audio { margin-top: 12px; }
.strip { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin-right: -22px; padding-right: 22px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.thumb { position: relative; flex: 0 0 auto; width: 150px; height: 200px; border-radius: 14px; overflow: hidden; background: var(--chip); scroll-snap-align: start; }
.thumb.single { width: min(100%, 260px); height: 260px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .vplay { position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; background: rgba(40,34,30,.55); display: grid; place-items: center; color: #fff; }
.thumb .vplay svg { width: 22px; height: 22px; margin-left: 3px; }
.thumb .x { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; background: rgba(40,34,30,.65); color: #fff; display: grid; place-items: center; }
.thumb .x svg { width: 14px; height: 14px; }
.thumb .busy { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; }

/* ---------- audio ---------- */
.audio { margin-top: 6px; }
.audio-row { display: flex; align-items: center; gap: 12px; }
.play { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.play svg { width: 18px; height: 18px; }
.play.loading { opacity: .6; }
.bars { display: flex; align-items: center; gap: 3px; height: 34px; flex: 1; min-width: 0; max-width: 180px; overflow: hidden; }
.bars i { flex: 0 0 5px; border-radius: 3px; background: var(--faint); opacity: .7; }
.bars i.on { background: var(--accent); opacity: 1; }
.dur { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 38px; }
.tbtn { margin-left: auto; width: 36px; height: 36px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; }
.tbtn.on { color: var(--ink); background: var(--chip); }
.tbtn svg { width: 22px; height: 22px; }
.transcript { margin: 8px 0 0 60px; font-family: var(--type); font-size: 16px; line-height: 1.45; color: #4a423c; white-space: pre-wrap; }

.empty-state { text-align: center; color: var(--muted); margin-top: 18vh; line-height: 1.6; font-size: 16px; }
.empty-state .big { font-family: var(--type); font-size: 22px; color: var(--ink); margin-bottom: 6px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 10px 0 20px; font-size: 15px; line-height: 1.5; }
.card .btn { margin-top: 10px; }
.more { display: block; margin: 0 auto 30px; color: var(--muted); font-size: 14px; padding: 10px; }

/* ---------- new note button ---------- */
.new-wrap { position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 22px calc(var(--safe-bottom) + 14px); background: linear-gradient(to top, var(--bg) 70%, rgba(246,241,233,0)); z-index: 4; }
.new-btn { width: 100%; height: 58px; border-radius: 30px; background: var(--accent); color: var(--accent-ink); font-size: 21px; letter-spacing: .3px; }
.new-btn:active { filter: brightness(.92); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 22px; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 17px; }
.btn:disabled { opacity: .5; }

/* ---------- sheets (composer, settings, notebooks) ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-top { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 10px) 14px 10px; border-bottom: 1px solid var(--line); }
.sheet-top .title { font-weight: 600; font-size: 17px; }
.sheet-top .link { padding: 8px 10px; font-size: 17px; color: var(--muted); }
.sheet-top .link.strong { color: var(--ink); font-weight: 600; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 22px 40px; -webkit-overflow-scrolling: touch; }

.meta-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.meta-row input, .meta-row select { background: var(--chip); border: 0; border-radius: 10px; padding: 8px 10px; font-size: 15px; color: var(--ink); max-width: 100%; }
.compose-text { width: 100%; min-height: 160px; border: 0; outline: none; resize: none; background: transparent; font-family: var(--type); font-size: 19px; line-height: 1.5; padding: 0; }
.compose-text::placeholder { color: var(--faint); }
.c-media { margin-top: 10px; }
.c-media .strip { margin-right: 0; padding-right: 0; flex-wrap: wrap; overflow: visible; }
.c-media .thumb { width: 96px; height: 120px; border-radius: 12px; }
.c-audio { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-top: 12px; }
.c-audio .audio-row .x { margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); }
.c-audio .audio-row .x svg { width: 16px; height: 16px; }
.c-audio textarea { width: 100%; min-height: 60px; margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px; font-family: var(--type); font-size: 16px; line-height: 1.4; resize: vertical; outline: none; }
.c-audio .t-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.danger-zone { margin-top: 40px; text-align: center; }

.toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px calc(var(--safe-bottom) + 10px); border-top: 1px solid var(--line); background: var(--bg); }
.tool { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px; border-radius: 23px; background: var(--chip); font-size: 16px; }
.tool svg { width: 22px; height: 22px; }
.rec-bar { display: flex; align-items: center; gap: 12px; flex: 1; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 18px; }
.stop-btn { margin-left: auto; height: 46px; padding: 0 20px; border-radius: 23px; background: var(--rec); color: #fff; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.stop-btn svg { width: 16px; height: 16px; }

/* settings + lists */
.group { margin-bottom: 26px; }
.group h3 { font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); font-weight: 500; margin: 0 0 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; font-size: 16px; }
.row .hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row select { background: var(--chip); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 15px; }
.row.tap { width: 100%; text-align: left; }
.row.active { border-color: var(--accent); }
.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 15px; background: var(--faint); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: 6px; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 30; background: #141210; display: flex; flex-direction: column; }
.viewer .v-top { display: flex; justify-content: space-between; align-items: center; padding: calc(var(--safe-top) + 8px) 12px 8px; color: #ddd; font-size: 15px; }
.viewer .v-top button { width: 40px; height: 40px; display: grid; place-items: center; color: #fff; }
.viewer .v-top svg { width: 20px; height: 20px; }
.viewer .slides { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.viewer .slides::-webkit-scrollbar { display: none; }
.viewer .slide { flex: 0 0 100%; scroll-snap-align: center; display: grid; place-items: center; padding-bottom: var(--safe-bottom); }
.viewer .slide img, .viewer .slide video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .slide .msg { color: #aaa; font-size: 14px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 92px); z-index: 50; background: #2b2622; color: #f6f1e9; padding: 11px 16px; border-radius: 14px; font-size: 15px; max-width: 88vw; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
