:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --fg: #1d1d21;
  --muted: #6f7380;
  --line: #e3e4e8;
  --accent: #3e63dd;
  --accent-fg: #ffffff;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --chip: #ececef;
  --shadow: 0 6px 24px rgba(20, 22, 30, 0.12);
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #1f2026;
    --fg: #e8e8eb;
    --muted: #8d919c;
    --line: #2d2f36;
    --accent: #7b96ff;
    --accent-fg: #0b0d14;
    --chip: #26272d;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ico { display: inline-flex; width: 24px; height: 24px; }
.ico svg { width: 100%; height: 100%; fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico svg [fill="none"] { fill: none; }

/* boot */
.boot { height: 100dvh; display: grid; place-items: center; }
.boot-logo, .logo {
  width: 64px; height: 64px; border-radius: 15px;
  background: url("/icons/icon-192.png") center / cover;
}

/* login */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--top) + 24px) 28px calc(var(--bottom) + 24px); text-align: center;
}
.login h1 { font-size: 26px; margin: 16px 0 6px; letter-spacing: -0.02em; }
.login .lead { margin: 0 0 2px; }
.login-form { width: 100%; max-width: 320px; margin-top: 22px; display: flex; flex-direction: column; gap: 12px; }
.code {
  text-align: center; font: 600 28px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em;
  padding: 14px 10px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); outline: none;
}
.code:focus { border-color: var(--accent); }
.primary {
  background: var(--accent); color: var(--accent-fg); font-weight: 600; padding: 14px 18px; border-radius: 14px;
}
.primary:disabled { opacity: 0.5; }
.primary.wide { width: 100%; margin-top: 14px; }
.err { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }
.hint { margin-top: 28px; font-size: 13px; color: var(--muted); max-width: 320px; }

/* shell */
.shell { height: 100dvh; display: flex; flex-direction: column; }
.top {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--top) + 6px) 8px 6px 4px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.icon-btn { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--fg); }
.icon-btn:active { background: var(--chip); }

/* tabs */
.tabs { flex: 1; display: flex; gap: 6px; overflow-x: auto; padding: 4px 4px 4px 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 17px;
  background: var(--chip); color: var(--muted); font-size: 15px; font-weight: 500; white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.on { background: var(--surface); color: var(--fg); box-shadow: inset 0 0 0 1.5px var(--c); }
.chip.add { padding: 0 9px; }
.chip.add .ico { width: 20px; height: 20px; }

.sync-dot { flex: none; width: 28px; height: 44px; display: grid; place-items: center; }
.sync-dot::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: 0.6; }
.sync-dot.ok::after { background: var(--ok); opacity: 1; }
.sync-dot.syncing::after { background: var(--warn); opacity: 1; animation: pulse 1s infinite alternate; }
.sync-dot.error::after { background: var(--danger); opacity: 1; }
@keyframes pulse { to { opacity: 0.35; } }

/* list */
.pages { list-style: none; margin: 0; padding: 6px 0; }
.page-row {
  width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px 18px;
}
.page-row:active { background: var(--chip); }
.pages li + li .page-row { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 600; font-size: 16.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-snip { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-time { flex: none; color: var(--muted); font-size: 13px; padding-top: 2px; }
.unsynced { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); margin-left: 6px; vertical-align: middle; }
.empty { padding: 60px 30px; text-align: center; color: var(--muted); }
.link { color: var(--accent); font-weight: 500; }
.archive-link { display: block; margin: 8px auto; padding: 12px 18px; }
.archive-head { display: flex; gap: 12px; align-items: center; padding: 12px 18px 4px; color: var(--muted); }
.bottom-space { height: calc(110px + var(--bottom)); }

.fabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px calc(var(--bottom) + 18px); pointer-events: none;
}
.fabbar > * { pointer-events: auto; }
.fab-new {
  display: inline-flex; align-items: center; gap: 6px; height: 50px; padding: 0 20px 0 16px; border-radius: 25px;
  background: var(--surface); box-shadow: var(--shadow); font-weight: 600;
}
.mic {
  width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 0.12s ease, background 0.12s ease;
}
.mic .ico { width: 30px; height: 30px; }
.mic.live { background: var(--danger); color: #fff; transform: scale(1.1); animation: ring 1.2s infinite; }
.mic.finishing { opacity: 0.6; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.45); } 100% { box-shadow: 0 0 0 18px rgba(229, 72, 77, 0); } }

/* editor */
.editor-view .top { padding-right: 4px; }
.title {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 17px; font-weight: 600;
  padding: 8px 4px;
}
.title::placeholder { color: var(--fg); opacity: 0.85; }
.title:focus::placeholder { opacity: 0.35; }
.note {
  min-height: 100%; padding: 16px 18px calc(120px + var(--bottom)); outline: none; font-size: 17px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; caret-color: var(--accent);
}
.note.is-empty::before { content: attr(data-placeholder); color: var(--muted); position: absolute; pointer-events: none; }
.note > div { min-height: 1.5em; }
.note .h1 { font-size: 1.55em; font-weight: 700; line-height: 1.25; margin: 0.5em 0 0.2em; }
.note .h2 { font-size: 1.25em; font-weight: 700; line-height: 1.3; margin: 0.4em 0 0.15em; }
.note b, .note strong { font-weight: 700; }
.pq-img {
  display: block; max-width: 100%; max-height: 70vh; margin: 8px 0; border-radius: 10px; border: 1px solid var(--line);
  background: var(--chip); min-height: 40px;
}
.pq-uploading {
  display: inline-block; padding: 8px 12px; margin: 6px 0; border-radius: 10px; background: var(--chip); color: var(--muted);
  font-size: 14px; animation: pulse 0.9s infinite alternate;
}
.partial { color: var(--muted); }

.toolbar {
  flex: none; display: flex; align-items: center; gap: 2px; padding: 6px 10px calc(var(--bottom) + 8px);
  background: var(--bg); border-top: 1px solid var(--line); will-change: transform;
}
body.kb-open .toolbar { padding-bottom: 6px; }
.toolbar .grow { flex: 1; }
.tb { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; color: var(--fg); }
.tb:active { background: var(--chip); }
.tb-h { font-weight: 700; }
.toolbar .mic { width: 52px; height: 52px; }
.toolbar .mic .ico { width: 26px; height: 26px; }

/* sheets */
.sheet-wrap {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0); display: flex; align-items: flex-end; z-index: 50;
  transition: background 0.2s ease;
}
.sheet-wrap.open { background: rgba(0, 0, 0, 0.35); }
.sheet {
  width: 100%; max-height: 85dvh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 6px 16px calc(var(--bottom) + 14px); transform: translateY(100%); transition: transform 0.2s ease;
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-title { font-weight: 600; text-align: center; margin: 0 8px 10px; color: var(--muted); font-size: 14px; }
.sheet-item { display: block; width: 100%; text-align: center; padding: 15px 10px; font-size: 17px; border-radius: 12px; }
.sheet-item + .sheet-item { border-top: 1px solid var(--line); border-radius: 0; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { font-weight: 600; margin-top: 6px; }
.sheet-item.rev { text-align: left; font-size: 15px; }
.field {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); outline: none;
  font-size: 17px;
}
.field:focus { border-color: var(--accent); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; justify-content: center; }
.swatch { width: 32px; height: 32px; border-radius: 50%; background: var(--c); }
.swatch.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.device { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.device-name { font-weight: 600; }
.small-btn { padding: 8px 12px; border-radius: 10px; background: var(--chip); font-size: 14px; }
.small-btn.danger { color: var(--danger); }
.rev-text {
  white-space: pre-wrap; word-wrap: break-word; font: 14px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg); padding: 12px; border-radius: 12px; max-height: 50dvh; overflow-y: auto; margin: 0;
}

.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.9); z-index: 60; display: grid; place-items: center;
  padding: calc(var(--top) + 10px) 10px calc(var(--bottom) + 10px);
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

.toast {
  position: fixed; left: 50%; top: calc(var(--top) + 64px); transform: translate(-50%, -20px); opacity: 0;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 70;
  max-width: calc(100% - 32px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 760px) {
  .shell { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .fabbar { max-width: 760px; margin: 0 auto; }
}
