/* ============================================================
   Inkwell — Apple-style component styles.
   All design values come from tokens.css (the single source of
   truth). This file maps tokens onto the app's components.
   ============================================================ */
@import url("tokens.css");

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; overscroll-behavior: none; }

body {
  font-family: var(--font-sans);
  font-size: calc(var(--text-body) * var(--text-scale, 1));
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-body);
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

/* Keyboard focus: visible ring on interactive elements (a11y §1).
   Pointer interactions stay clean via :focus-visible. */
:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
.list-row:focus-visible, .nb-cover:focus-visible, .entry-card:focus-visible { outline-offset: -2.5px; }

/* Respect reduced-motion: keep meaning, drop movement (a11y §7) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

#app { display: flex; flex-direction: column; height: 100%; }

/* ---------- Navigation bar (translucent material) ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(var(--nav-h) + var(--safe-top));
  padding: var(--safe-top) 10px 0;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
#viewTitle {
  font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Nav buttons */
.icon-btn {
  border: none; background: transparent; color: var(--accent);
  width: var(--tap-min); height: var(--tap-min); border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; flex: none; padding: 0;
}
.icon-btn svg { width: 24px; height: 24px; display: block; }
.icon-btn:active { background: var(--fill); }
#backBtn { color: var(--accent); font-weight: 500; gap: 2px; }

/* Stat chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--fill); padding: 5px 10px; border-radius: 999px;
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em; color: var(--label);
}
.chip-icon { font-size: 13px; }
.chip.pulse { animation: pop 0.45s cubic-bezier(.34,1.56,.64,1); }

/* ---------- Buttons ---------- */
.btn {
  border: none; background: var(--fill); color: var(--accent);
  padding: 9px 16px; border-radius: 999px; font-size: 16px; font-weight: 600;
  letter-spacing: -0.01em; cursor: pointer; transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); }
.danger, .destructive { color: var(--red); }

/* ---------- Main / views ---------- */
#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { display: none; padding: 18px 16px calc(40px + var(--safe-bottom)); max-width: 760px; margin: 0 auto; }
.view.active { display: block; }

/* Large title (iOS) shown at top of scrolling content */
.large-title { font-size: calc(var(--text-large) * var(--text-scale, 1)); font-weight: 700; letter-spacing: var(--tracking-tight); margin: 4px 2px 14px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

/* Search field (iOS rounded fill) */
.search-wrap { flex: 1; min-width: 200px; position: relative; }
.search-wrap::before {
  content: ''; position: absolute; left: 12px; top: 50%; width: 16px; height: 16px;
  transform: translateY(-50%);
  background: var(--label-2);
  -webkit-mask: var(--icon-search) center/contain no-repeat;
  mask: var(--icon-search) center/contain no-repeat;
}
#globalSearch {
  width: 100%; padding: 10px 14px 10px 36px; border-radius: var(--radius-md);
  border: none; background: var(--fill); font-size: 17px; color: var(--label);
  font-family: inherit; letter-spacing: -0.01em;
}
#globalSearch::placeholder { color: var(--label-2); }
#globalSearch:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }

input, textarea, select, button { font-family: inherit; color: var(--label); }

/* ---------- Library: notebook covers (Ink & Paper) ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.nb-cover {
  position: relative; aspect-ratio: 3 / 4; min-height: 150px; overflow: hidden;
  background: var(--cloth, var(--oxblood)); border: 1px solid rgba(0,0,0,0.06);
  border-radius: 3px 10px 10px 3px;
  padding: 16px 14px 14px 26px; cursor: pointer; display: flex; flex-direction: column;
  box-shadow: var(--shadow-card); transition: transform .12s ease;
}
.nb-cover::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 11px; background: rgba(0,0,0,0.10); }
.nb-cover::after  { content: ''; position: absolute; left: 18px; top: 0; bottom: 0; width: 1px; background: rgba(0,0,0,0.07); }
.nb-cover:active, .nb-cover.lp-armed { transform: scale(0.97); }
.nbc-title { margin: 0; font-family: var(--font-serif); font-size: 19px; font-weight: 600;
  line-height: 1.18; letter-spacing: -0.005em; color: var(--cover-ink); }
.nbc-count { margin-top: auto; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(58,53,46,0.58); }
.nb-del {
  position: absolute; top: 8px; right: 8px; border: none; background: rgba(40,33,26,0.16);
  color: var(--cover-ink); width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; opacity: 0; transition: opacity .15s ease; z-index: 2;
}
.nb-del svg { width: 14px; height: 14px; }
.nb-cover:hover .nb-del { opacity: 1; }
.nb-del:active { background: rgba(40,33,26,0.30); }

/* ---------- Inset grouped list (pages / search) ---------- */
.list-group {
  background: var(--bg-card); border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-card);
}
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px 11px 14px;
  position: relative; cursor: pointer; background: transparent;
  transition: background .12s ease;
}
.list-row:active { background: var(--fill); }
.list-row.lp-armed, .notebook-card.lp-armed { transform: scale(0.97); transition: transform .2s ease; }
.list-row:not(:last-child)::after {
  content: ''; position: absolute; left: 60px; right: 0; bottom: 0; height: 0.5px; background: var(--separator);
}
.lr-avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--fill); font-size: 19px;
}
.lr-body { flex: 1; min-width: 0; }
.lr-title { font-size: 17px; font-weight: 500; letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-sub { color: var(--label-2); font-size: 14px; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.tag-pill {
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
  font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; letter-spacing: -0.01em;
}
.lr-chevron { flex: none; color: var(--label-3); display: grid; place-items: center; }
.lr-chevron svg { width: 16px; height: 16px; }

/* group heading */
.group-head { font-size: 13px; font-weight: 500; color: var(--label-2);
  text-transform: uppercase; letter-spacing: 0.02em; margin: 4px 6px 8px; }

/* ---------- Ink & Paper shell: Library + Notebook only ---------- */
body:has(#libraryView.active),
body:has(#notebookView.active) { background: var(--paper-bg); }
body:has(#libraryView.active) #main,
body:has(#notebookView.active) #main { background: var(--paper-bg); }
body:has(#libraryView.active) #topbar,
body:has(#notebookView.active) #topbar {
  background: var(--paper-nav); border-bottom-color: var(--paper-edge);
}
body:has(#libraryView.active) .icon-btn,
body:has(#notebookView.active) .icon-btn { color: var(--ink); }
#libraryView .large-title, #notebookTitle {
  font-family: var(--font-serif); font-style: italic; font-weight: 600; letter-spacing: 0;
  color: var(--ink);
}
#libraryView .btn-primary, #notebookView .btn-primary { background: var(--ink); color: var(--paper-bg); }
#libraryView .btn-primary:active, #notebookView .btn-primary:active { background: var(--ink-soft); }
#notebookPageCount { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--smallcaps); }

/* Page entries — dated timeline (marginalia) */
.entries { position: relative; padding-left: 74px; }
.entries::before { content: ''; position: absolute; left: 62px; top: 6px; bottom: 6px; width: 1px; background: var(--paper-edge); }
.entry { position: relative; margin-bottom: 14px; }
.entry-date { position: absolute; left: -74px; width: 52px; text-align: right; }
.ed-day { display: block; font-family: var(--font-serif); font-size: 22px; line-height: 1; color: var(--ink); }
.ed-mon { display: block; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--smallcaps); margin-top: 3px; }
.entry-node { position: absolute; left: -16px; top: 10px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--paper-edge); box-shadow: 0 0 0 3px var(--paper-bg); }
.entry-node.today { background: var(--oxblood); }
.entry-card { background: var(--paper-card); border: 1px solid var(--paper-edge); border-radius: 10px;
  padding: 14px 16px; cursor: pointer; transition: transform .12s ease; }
.entry-card:active, .entry-card.lp-armed { transform: scale(0.985); }
.entry-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.entry-title { font-family: var(--font-serif); font-size: 18px; color: var(--ink); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-snippet { font-size: 13px; color: var(--ink-soft); line-height: 1.5; margin-top: 5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-snippet.ink { font-style: italic; color: var(--ink-muted); }
.entry-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.entry-tag { font-size: 11px; color: var(--oxblood); border: 1px solid color-mix(in srgb, var(--oxblood) 32%, transparent);
  border-radius: 999px; padding: 2px 9px; }
.entry-mood { font-size: 16px; flex: none; }
.hw-badge { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-muted);
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; flex: none; }
.hw-badge svg { width: 13px; height: 13px; }

/* New-notebook sheet (replaces the native prompt) */
.paper-sheet { background: var(--paper-card); }
.paper-sheet h2 { font-family: var(--font-serif); font-style: italic; color: var(--ink); }
.nn-label { display: block; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--smallcaps); margin: 16px 0 7px; }
.nn-input { width: 100%; background: var(--paper-bg); border: 1px solid var(--paper-edge); border-radius: 8px;
  padding: 11px 13px; font-family: var(--font-serif); font-size: 18px; color: var(--ink); outline: none; }
.nn-input:focus { border-color: var(--ink); }
.nn-covers { display: flex; gap: 11px; flex-wrap: wrap; }
.nn-swatch { width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--sw); transition: transform .1s ease; }
.nn-swatch.selected { box-shadow: 0 0 0 2px var(--paper-card), 0 0 0 4px var(--ink); }
.nn-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.nn-create { background: var(--ink); color: var(--paper-bg); }
.nn-create:active { background: #000; }

/* ---------- Editor ---------- */
#pageView.active { display: flex; flex-direction: column; height: 100%; padding: 0; max-width: none; }
.editor-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; flex-wrap: wrap; }
.page-title-input {
  flex: 1; min-width: 160px; font-size: 24px; font-weight: 700; letter-spacing: -0.03em;
  border: none; background: transparent; padding: 4px 0; outline: none;
}
.page-title-input::placeholder { color: var(--label-3); }
.editor-controls { display: flex; align-items: center; gap: 8px; }

/* Segmented control */
.mode-toggle { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; position: relative; }
.mode-btn {
  border: none; background: transparent; color: var(--label); padding: 6px 14px;
  border-radius: 7px; font-size: 14px; font-weight: 500; letter-spacing: -0.01em; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; transition: color .15s ease;
}
.mode-btn svg { width: 15px; height: 15px; }
.mode-btn.active { background: var(--bg-elevated); color: var(--label); font-weight: 600; box-shadow: var(--shadow-seg); }

.editor-subbar {
  display: flex; align-items: center; gap: 14px; padding: 4px 16px 12px;
  border-bottom: 0.5px solid var(--separator); flex-wrap: wrap;
}
.mood-picker { display: inline-flex; gap: 2px; }
.mood {
  border: none; background: transparent; font-size: 22px; cursor: pointer;
  opacity: 0.35; padding: 4px; border-radius: 9px; filter: grayscale(0.5);
  transition: transform .12s ease, opacity .12s ease;
}
.mood.selected { opacity: 1; filter: none; background: var(--fill); transform: scale(1.1); }
.tag-input {
  flex: 1; min-width: 140px; border: none; background: var(--fill);
  border-radius: var(--radius-sm); padding: 7px 11px; font-size: 15px; letter-spacing: -0.01em;
}
.tag-input::placeholder { color: var(--label-2); }
.wordcount { display: flex; align-items: center; gap: 7px; color: var(--label-2); font-size: 13px; white-space: nowrap; }
.goal-input { width: 52px; border: none; background: var(--fill); border-radius: 7px; padding: 4px 7px; font-size: 13px; }
.goal-sep { opacity: 0.5; }
.goal-bar { width: 64px; height: 6px; background: var(--fill-strong); border-radius: 999px; overflow: hidden; }
.goal-fill { height: 100%; width: 0%; background: var(--green); border-radius: 999px; transition: width .35s cubic-bezier(.4,0,.2,1); }

.editor-pane { display: none; flex: 1; min-height: 0; }
.editor-pane.active { display: flex; flex-direction: column; }
/* Rich-text formatting toolbar */
.rt-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 6px 14px; border-bottom: 0.5px solid var(--separator);
  position: sticky; top: 0; z-index: 6; background: var(--bg);
}
.rt-dd { position: relative; display: inline-flex; }
.rt-btn {
  border: none; background: transparent; color: var(--label); font-family: inherit;
  min-width: 38px; height: 38px; padding: 0 8px; border-radius: 8px; cursor: pointer;
  display: inline-grid; place-items: center; font-size: 16px; line-height: 1;
}
.rt-btn svg { width: 19px; height: 19px; }
.rt-btn:hover { background: var(--fill); }
.rt-btn.active { background: var(--accent-tint); color: var(--accent); }
.rt-text { font-size: 14px; font-weight: 500; gap: 2px; }
.rt-caret { font-size: 10px; color: var(--label-2); margin-left: 1px; }
.rt-aa { font-weight: 700; } .rt-aa span { font-size: 0.78em; font-weight: 600; }
.rt-sep { width: 1px; height: 20px; background: var(--separator); margin: 0 5px; flex: none; }
.rt-hl { font-weight: 700; border-bottom: 3px solid #e7c84a; padding: 0 1px; line-height: 1; }
.rt-fg { font-weight: 700; border-bottom: 3px solid var(--accent); padding: 0 1px; line-height: 1; }

.rt-pop {
  position: absolute; top: calc(100% + 5px); left: 0; z-index: 20;
  background: var(--bg-elevated); border-radius: var(--radius-md); box-shadow: var(--shadow-pop);
  padding: 6px; min-width: 168px; animation: popIn .14s cubic-bezier(.34,1.4,.64,1);
}
.rt-pop button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 9px 12px; border-radius: 7px; font-size: 15px; color: var(--label); cursor: pointer; font-family: inherit;
}
.rt-pop button:hover { background: var(--fill); }
.rt-opt-title { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.rt-opt-heading { font-size: 18px; font-weight: 700; }
.rt-opt-subheading { font-size: 16px; font-weight: 600; }
.rt-swatches { display: flex; flex-wrap: wrap; gap: 9px; width: 190px; padding: 11px; }
.rt-swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 1.5px solid var(--separator); display: grid; place-items: center; }
.rt-swatch.rt-none { background: var(--bg-card); color: var(--label-2); }
.rt-swatch.rt-none svg { width: 15px; height: 15px; }

/* Rich-text editing surface */
.rt-editor {
  flex: 1; min-height: 0; overflow-y: auto; outline: none; -webkit-overflow-scrolling: touch;
  padding: 22px 20px; font-size: calc(18px * var(--text-scale, 1)); line-height: var(--leading-body);
  letter-spacing: var(--tracking-body); color: var(--label);
}
.rt-editor:empty::before { content: attr(data-placeholder); color: var(--label-3); pointer-events: none; }
.rt-editor:focus { outline: none; }
.rt-editor h1 { font-size: 1.6em; font-weight: 700; letter-spacing: -0.02em; margin: .6em 0 .3em; }
.rt-editor h2 { font-size: 1.3em; font-weight: 700; margin: .6em 0 .3em; }
.rt-editor h3 { font-size: 1.1em; font-weight: 600; margin: .5em 0 .25em; }
.rt-editor p { margin: 0 0 .7em; }
.rt-editor ul, .rt-editor ol { margin: 0 0 .7em; padding-left: 1.5em; }
.rt-editor li { margin: .2em 0; }
.rt-editor blockquote { border-left: 3px solid var(--accent); margin: .4em 0; padding-left: 14px; color: var(--label-2); }
.rt-editor a { color: var(--accent); }
.rt-editor code { background: var(--fill); padding: 2px 6px; border-radius: 6px; font-size: .88em; font-family: var(--font-mono); }
.rt-editor pre { background: var(--fill); padding: 14px; border-radius: var(--radius-md); overflow-x: auto; }
.rt-editor mark { background: #e7c84a; color: #2a2620; padding: 0 2px; border-radius: 3px; }
.rt-editor hr { border: none; border-top: 1px solid var(--separator); margin: 1em 0; }
.rt-editor [style*="background"] { color: #2a2620; }   /* keep highlighted text legible in both themes */
.rt-fs-s { font-size: .85em; } .rt-fs-m { font-size: 1em; } .rt-fs-l { font-size: 1.3em; } .rt-fs-xl { font-size: 1.6em; }
.rt-ff-serif { font-family: var(--font-serif); } .rt-ff-sans { font-family: var(--font-sans); } .rt-ff-mono { font-family: var(--font-mono); }
.rt-todo { list-style: none; padding-left: 2px; }
.rt-todo li { display: flex; align-items: flex-start; gap: 10px; }
.rt-check { flex: none; width: 22px; height: 22px; margin-top: 2px; border-radius: 6px;
  border: 2px solid var(--label-3); cursor: pointer; display: inline-grid; place-items: center; }
.rt-todo li.done .rt-check { background: var(--green); border-color: var(--green); }
.rt-todo li.done .rt-check::after { content: ''; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translateY(-1px); }
.rt-todo li.done { color: var(--label-2); text-decoration: line-through; }

/* Draw */
#drawPane.active { display: flex; flex-direction: column; }
.draw-toolbar {
  display: flex; align-items: center; gap: 12px; padding: 9px 16px;
  border-bottom: 0.5px solid var(--separator); flex-wrap: wrap;
}
.pen-colors { display: flex; gap: 8px; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bg-card);
  box-shadow: 0 0 0 1px var(--separator); cursor: pointer; transition: transform .1s ease; }
.color-swatch.active { box-shadow: 0 0 0 2.5px var(--accent); transform: scale(1.12); }
.pen-sizes { display: flex; gap: 4px; }
.size-btn, .tool-btn {
  border: none; background: var(--fill); color: var(--label);
  min-width: 38px; height: 38px; border-radius: var(--radius-sm); cursor: pointer; font-size: 15px;
  display: grid; place-items: center; padding: 0 9px;
}
.tool-btn svg { width: 19px; height: 19px; }
.size-btn.active, .tool-btn.active { background: var(--accent); color: #fff; }
.canvas-wrap { flex: 1; min-height: 0; position: relative; overflow: hidden;
  background: var(--paper);
  background-image: linear-gradient(rgba(60,64,90,0.07) 1px, transparent 1px);
  background-size: 100% 32px; }
#drawCanvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- Search results ---------- */
.search-results { margin-bottom: 16px; }
.sr-head { color: var(--label-2); font-size: 14px; margin: 0 6px 10px; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 64px 24px; color: var(--label-2); }
.empty-emoji {
  width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 22px;
  display: grid; place-items: center; background: var(--fill); font-size: 38px;
}
.empty-emoji svg { width: 38px; height: 38px; color: var(--label-3); }
.empty-state h2 { color: var(--label); margin: 6px 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.empty-state p { max-width: 340px; margin: 0 auto 20px; line-height: 1.5; font-size: 16px; }

/* ---------- AI summaries ---------- */
#summarizeNotebookBtn { display: inline-flex; align-items: center; gap: 5px; }
#summarizeNotebookBtn svg { width: 15px; height: 15px; }
.ai-input {
  width: 100%; border: none; background: var(--fill); color: var(--label);
  border-radius: var(--radius-sm); padding: 11px 12px; font-size: 16px;
  font-family: inherit; margin-bottom: 8px; -webkit-appearance: none; appearance: none;
}
.ai-input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
select.ai-input { background-image: var(--icon-chevron, none); }
.ai-badge {
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--label-2); background: var(--fill); padding: 2px 7px; border-radius: 999px; margin-left: 6px;
}
.ai-disclaimer { margin: 8px 2px 0; line-height: 1.45; }
.ai-status { color: var(--label-2); font-size: 15px; padding: 10px 2px; }
.ai-status.error { color: var(--red); }
.ai-result {
  white-space: pre-wrap; line-height: 1.6; font-size: 16px; color: var(--label);
  margin-top: 6px; max-height: 52vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}

/* ---------- Popover / menu ---------- */
.popover {
  position: fixed; background: var(--bg-elevated);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: var(--radius-md); box-shadow: var(--shadow-pop); z-index: 50;
  overflow: hidden; min-width: 240px; padding: 6px;
  animation: popIn .16s cubic-bezier(.34,1.4,.64,1); transform-origin: top right;
}
.popover button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; border: none; background: transparent;
  padding: 11px 12px; font-size: 16px; cursor: pointer; color: var(--label); border-radius: 8px;
}
.popover button:active { background: var(--fill); }
.popover button svg { width: 19px; height: 19px; color: var(--label-2); }
.popover button.danger svg { color: var(--red); }

/* ---------- Modal (iOS sheet feel) ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: grid; place-items: center; z-index: 60; padding: 16px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: fadeIn .2s ease; }
.modal-card {
  background: var(--bg-card); border-radius: var(--radius-xl); padding: 28px; max-width: 520px;
  width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-pop); position: relative;
  animation: sheetIn .3s cubic-bezier(.34,1.2,.64,1);
}
.modal-card h2 { margin-top: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.modal-card h3 { font-size: 18px; font-weight: 600; }
.modal-close { position: absolute; top: 16px; right: 16px; border: none; background: var(--fill);
  width: 30px; height: 30px; border-radius: 50%; font-size: 18px; cursor: pointer; color: var(--label-2);
  display: grid; place-items: center; line-height: 1; }
.help-list { line-height: 1.55; padding-left: 20px; font-size: 16px; }
.help-list li { margin-bottom: 9px; }
.help-actions { margin-top: 18px; }
.ach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; margin-top: 12px; }
.ach { border: none; border-radius: var(--radius-md); padding: 12px 10px; text-align: center;
  background: var(--fill); opacity: 0.6; transition: opacity .2s ease; }
.ach.unlocked { opacity: 1; background: color-mix(in srgb, var(--green) 12%, var(--bg-card)); }
.ach .ach-icon { font-size: 26px; filter: grayscale(1); }
.ach.unlocked .ach-icon { filter: none; }
.ach .ach-name { font-size: 13px; font-weight: 600; margin-top: 5px; }
.ach .ach-desc { font-size: 11.5px; color: var(--label-2); margin-top: 2px; }

/* ---------- iOS install hint ---------- */
.install-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom));
  display: flex; align-items: center; gap: 12px; z-index: 70;
  background: var(--bg-elevated); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 0.5px solid var(--separator); border-radius: var(--radius-lg);
  padding: 13px 14px; box-shadow: var(--shadow-pop); max-width: 520px; margin: 0 auto;
  animation: sheetIn .3s ease;
}
.install-hint .ih-icon { font-size: 24px; flex: none; }
.install-hint .ih-text { flex: 1; font-size: 14px; line-height: 1.4; color: var(--label); }
.install-hint .ih-share { color: var(--accent); font-weight: 700; }
.install-hint .ih-close { border: none; background: var(--fill); color: var(--label-2);
  width: 28px; height: 28px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: none;
  display: grid; place-items: center; line-height: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-bottom)); transform: translateX(-50%);
  background: rgba(28,28,30,0.92); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em; z-index: 80; box-shadow: var(--shadow-pop);
  animation: toastIn 0.28s cubic-bezier(.34,1.3,.64,1); max-width: 90vw; text-align: center;
}
.toast.achievement { background: linear-gradient(120deg, var(--accent), #9b59ff); }

@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px) scale(.96); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes popIn { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.22); } 100% { transform: scale(1); } }

.muted { color: var(--label-2); }
[hidden] { display: none !important; }

/* Screen-reader-only (visible to AT, hidden visually) */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Brand lockup / logo ---------- */
.brand-lockup { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--on-accent); background: linear-gradient(135deg, var(--accent), #8a78ff); box-shadow: var(--shadow-seg); }
.brand-mark svg { width: 22px; height: 22px; }
.brand-mark-lg { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 18px; }
.brand-mark-lg svg { width: 44px; height: 44px; }

.modal-close svg { width: 17px; height: 17px; }

/* ---------- Settings ---------- */
.settings-group { margin-top: 18px; }
.settings-label { font-size: var(--text-footnote); font-weight: 500; color: var(--label-2);
  text-transform: uppercase; letter-spacing: 0.03em; margin: 0 4px 8px; }
.seg-control { display: flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; }
.seg { flex: 1; border: none; background: transparent; color: var(--label); padding: 8px 10px;
  border-radius: 8px; font-size: var(--text-subhead); font-weight: 500; cursor: pointer;
  min-height: 36px; transition: background var(--dur-fast) var(--ease-standard); }
.seg.active { background: var(--bg-elevated); font-weight: 600; box-shadow: var(--shadow-seg); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--bg-card); border-radius: var(--radius-md); padding: 12px 14px; }
.settings-row-title { font-size: var(--text-callout); font-weight: 500; }
.settings-row-sub { font-size: var(--text-footnote); margin-top: 1px; }
.settings-action {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--bg-card); border: none; color: var(--label); border-radius: var(--radius-md);
  padding: 13px 14px; font-size: var(--text-callout); cursor: pointer; margin-bottom: 8px;
  min-height: var(--tap-min);
}
.settings-action:active { background: var(--fill); }
.settings-action .chev { color: var(--label-3); font-size: 22px; line-height: 1; }
.settings-foot { font-size: var(--text-footnote); text-align: center; margin-top: 22px; }

/* iOS-style switch */
.switch { position: relative; width: 51px; height: 31px; border-radius: 999px; border: none;
  background: var(--fill-strong); cursor: pointer; padding: 0; flex: none; transition: background var(--dur) var(--ease-standard); }
.switch[aria-checked="true"] { background: var(--green); }
.switch-knob { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.25); transition: transform var(--dur) var(--ease-spring); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); }

/* ---------- Onboarding ---------- */
.onboarding {
  position: fixed; inset: 0; z-index: 90; background: var(--bg);
  display: grid; place-items: center; padding: 24px;
  padding-top: calc(24px + var(--safe-top)); padding-bottom: calc(24px + var(--safe-bottom));
  animation: fadeIn var(--dur-slow) var(--ease-out);
}
.onboard-card { max-width: 380px; width: 100%; text-align: center; animation: sheetIn 0.45s var(--ease-out); }
.onboard-title { font-size: var(--text-large); font-weight: 700; letter-spacing: var(--tracking-tight); margin: 0 0 8px; }
.onboard-tagline { color: var(--label-2); font-size: var(--text-callout); line-height: var(--leading-body);
  margin: 0 auto 28px; max-width: 300px; }
.onboard-features { list-style: none; padding: 0; margin: 0 0 28px; text-align: left; display: flex; flex-direction: column; gap: 18px; }
.onboard-features li { display: flex; align-items: center; gap: 14px; }
.of-icon { width: 44px; height: 44px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: var(--accent-tint); color: var(--accent); }
.of-icon svg { width: 23px; height: 23px; }
.onboard-features b { display: block; font-size: var(--text-callout); font-weight: 600; }
.onboard-features .muted { display: block; font-size: var(--text-subhead); margin-top: 1px; }
.btn-block { width: 100%; padding: 15px; font-size: var(--text-body); border-radius: 14px; }

/* Inline icon mask sources */
:root {
  --icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
}
