/* PWA Autoprompt — clean low-fi prototype */
:root {
  --bg: #f3f0e7;
  --paper: #fbf9f2;
  --paper-2: #f6f3ea;
  --ink: #1a1a1a;
  --ink-2: #353332;
  --muted: #8a8a85;
  --line: #1a1a1a;
  --line-soft: #c8c4b6;
  --hi: #ffe45c;
  --hi-2: #fff1a0;
  --accent: #ff6b5b;
  --blue: #4a7eff;
  --green: #1f8a5b;
  --purple: #a259e6;
  --orange: #ff9d00;
  --teal: #0ea5b7;
  --danger: #d33a2c;
  --shadow: 0 2px 0 0 #1a1a1a;
  --shadow-sm: 0 1.5px 0 0 #1a1a1a;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --pad: 14px;
  --pad-sm: 10px;
  --gap: 12px;
  --gap-sm: 8px;
  --fs-body: 14px;
  --fs-mono: 13px;
  --fs-label: 12px;
  --fs-mini: 11px;
}
html.dark {
  --bg: #14130f;
  --paper: #1f1e1a;
  --paper-2: #26241f;
  --ink: #ede9dc;
  --ink-2: #c8c4b6;
  --muted: #7c7970;
  --line: #ede9dc;
  --line-soft: #4d4a42;
  --hi: #b89400;
  --hi-2: #6a5500;
  --shadow: 0 2px 0 0 #ede9dc;
  --shadow-sm: 0 1.5px 0 0 #ede9dc;
}
html[data-density="compact"] {
  --pad: 10px;
  --pad-sm: 7px;
  --gap: 9px;
  --gap-sm: 6px;
  --fs-body: 13px;
  --fs-mono: 12px;
  --fs-label: 11px;
  --fs-mini: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink); font-family: 'Inter', 'Sarabun', system-ui, sans-serif; font-size: var(--fs-body); line-height: 1.45; min-height: 100vh; }
button { font-family: inherit; }
ul { list-style: none; padding: 0; margin: 0; }
h1, h2, h3, h4, p { margin: 0; }

/* ── App shell ─────────────────────────────────────── */
.app {
  min-height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  padding-bottom: 72px;
  background: var(--bg);
  position: relative;
}
@media (min-width: 1100px) {
  .app { max-width: 1100px; padding-bottom: 0; padding-left: 220px; }
}

/* ── Top bar ────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1.5px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  box-shadow: var(--shadow);
}
.brand-name { font-family: 'Caveat', cursive; font-size: 24px; line-height: 1; font-weight: 700; }
.brand-tag { font-size: 11px; color: var(--muted); margin-left: 4px; }
@media (max-width: 480px) { .brand-tag { display: none; } }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.iconbtn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 8px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); cursor: pointer;
  font-size: var(--fs-mini); font-weight: 600;
}
.iconbtn:hover { background: var(--paper-2); }
.iconbtn .iconbtn-lbl { font-family: 'JetBrains Mono', monospace; font-size: 10px; }

/* ── Install banner ─────────────────────────────────── */
.install-banner {
  margin: 10px 16px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  background: var(--hi); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.install-icon { font-size: 22px; }
.install-text { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.install-text strong { font-size: 13px; }
.install-text span { font-size: 11px; color: var(--ink-2); }

/* ── Main ────────────────────────────────────────────── */
.main { padding: 14px 16px; }
@media (min-width: 700px) { .main { padding: 18px 24px; } }

/* ── Section ────────────────────────────────────────── */
.section { margin-bottom: var(--gap); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--gap-sm); }
.section-label {
  font-family: 'Caveat', cursive; font-size: 19px; line-height: 1;
  color: var(--ink); display: flex; gap: 8px; align-items: baseline;
  white-space: nowrap;
}
.section-label > * { white-space: nowrap; }
.section-label .muted { font-family: 'Inter', sans-serif; font-size: 11px; color: var(--muted); font-weight: 500; }
.section-right { font-size: var(--fs-mini); color: var(--muted); }
.btn-link { background: none; border: none; color: var(--muted); font-size: var(--fs-mini); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.btn-link:hover { color: var(--danger); }

/* ── Preview card (sticky) ───────────────────────────── */
.preview-card {
  position: sticky; top: 52px; z-index: 20;
  background: linear-gradient(180deg, color-mix(in srgb, var(--hi) 40%, var(--paper)) 0, var(--paper) 100%);
  border: 1.5px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--pad);
  margin-bottom: 18px;
  transition: box-shadow 0.2s;
}
.preview-card.enhancing { animation: pulseBorder 1s ease-in-out infinite; }
@keyframes pulseBorder { 0%,100% { box-shadow: var(--shadow); } 50% { box-shadow: 0 2px 0 var(--accent); } }
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.preview-title {
  font-family: 'Caveat', cursive; font-size: 22px; line-height: 1;
  display: flex; align-items: baseline; gap: 8px;
  white-space: nowrap; flex-shrink: 0;
}
.preview-arrow { color: var(--accent); }
.ai-badge { font-family: 'Inter', sans-serif; font-size: 10px; background: var(--ink); color: var(--paper); padding: 2px 6px; border-radius: 999px; font-weight: 600; }
.preview-thumb-row { display: flex; gap: 4px; align-items: center; }
.thumb-more { font-size: 10px; color: var(--muted); padding: 0 4px; border: 1.4px solid var(--line-soft); border-radius: 4px; height: 26px; display: flex; align-items: center; }

.preview-body {
  background: var(--paper); border: 1.5px dashed var(--line-soft);
  border-radius: var(--radius);
  padding: var(--pad-sm) var(--pad);
  min-height: 48px;
  margin-bottom: 10px;
}
.preview-text { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-mono); line-height: 1.55; color: var(--ink); }
.preview-text.mono { word-break: break-word; }
.preview-empty { color: var(--muted); font-style: italic; font-size: var(--fs-mono); }
.preview-seg { padding: 1px 3px; border-radius: 3px; }
.preview-sep { color: var(--muted); }

.preview-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); font-size: var(--fs-label); font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow-sm); transition: transform 0.06s, box-shadow 0.06s;
  flex-shrink: 0;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--hi); flex: 1; }
.btn.accent { background: var(--accent); color: #fff; flex: 1; }
.btn.success { background: var(--green); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.btn-sm { padding: 5px 8px; font-size: 11px; box-shadow: none; }
.btn:disabled, .btn.busy { opacity: 0.7; cursor: progress; }

/* ── Subject input ───────────────────────────────────── */
.subj-input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  font-family: 'Inter', sans-serif; font-size: 15px; line-height: 1.4;
  resize: vertical; box-shadow: var(--shadow-sm);
  min-height: 56px;
}
.subj-input:focus { outline: 2px solid var(--accent); outline-offset: -1.5px; }

/* ── Context input ───────────────────────────────────── */
.ctx-input {
  width: 100%; padding: 10px 12px;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  color: var(--ink);
  font-family: 'Inter', 'Sarabun', sans-serif; font-size: 14px; line-height: 1.5;
  resize: vertical;
  min-height: 64px;
}
.ctx-input:focus { outline: 2px solid var(--ink); outline-offset: -1.5px; border-style: solid; background: var(--paper); }
.ctx-input::placeholder { color: var(--muted); font-style: italic; }
.ctx-tip {
  margin-top: 6px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: var(--muted);
  line-height: 1.1;
}

/* ── Type tabs ───────────────────────────────────────── */
.type-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.type-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); font-size: var(--fs-label); font-weight: 600;
  cursor: pointer; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.type-tab:hover { background: var(--paper-2); }
.type-tab.active { background: var(--ink); color: var(--paper); }
.type-tab.active .ico { stroke: var(--paper); }

/* ── Stack ───────────────────────────────────────────── */
.empty-stack {
  padding: 20px; text-align: center;
  border: 1.5px dashed var(--line-soft); border-radius: var(--radius);
  color: var(--muted); font-size: var(--fs-label); font-style: italic;
  background: color-mix(in srgb, var(--paper) 50%, transparent);
}
.stack { display: flex; flex-direction: column; gap: 6px; }
.stack-block {
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--block-color) 18%, var(--paper));
  padding: 8px 10px;
  box-shadow: 2px 2px 0 0 color-mix(in srgb, var(--block-color) 70%, var(--ink));
  position: relative;
  overflow: hidden;
}
.stack-block::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--block-color);
}
.stack-block-head { display: flex; align-items: center; gap: 8px; padding-left: 4px; }
.stack-block-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.stack-block-cat { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-2); opacity: 0.7; font-weight: 700; }
.stack-block-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.stack-block-actions { display: flex; gap: 3px; }
.ico-mini {
  width: 24px; height: 24px; border: 1.5px solid var(--line); border-radius: 5px;
  background: var(--paper); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-family: inherit;
}
.ico-mini:hover { background: var(--paper-2); }
.ico-mini:disabled { opacity: 0.3; cursor: not-allowed; }
.ico-mini.danger { color: var(--danger); }
.ico-mini.danger:hover { background: var(--danger); color: #fff; }
.stack-block-desc {
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  font-family: 'Sarabun', 'Inter', sans-serif;
  margin-top: 2px;
}
.stack-block-phrase {
  margin-top: 4px; padding-left: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px;
  color: var(--ink-2); opacity: 0.8;
}

/* ── Library ────────────────────────────────────────── */
.library { display: flex; flex-direction: column; gap: var(--gap-sm); }
.lib-tabs { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 4px; }
.lib-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--ink); font-size: var(--fs-mini); font-weight: 600;
  cursor: pointer; flex-shrink: 0;
}
.lib-tab:hover { background: var(--paper-2); }
.lib-tab.active { background: var(--cat-color, var(--ink)); color: #fff; border-color: var(--line); box-shadow: var(--shadow-sm); }
.lib-tab.active .lib-tab-dot { background: #fff !important; }
.lib-tab-dot { width: 8px; height: 8px; border-radius: 50%; }
.lib-tab-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  padding: 1px 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--cat-color, var(--ink)) 30%, var(--paper));
  color: var(--ink);
}
.lib-tab.active .lib-tab-count { background: rgba(255,255,255,0.25); color: #fff; }

.lib-search {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); box-shadow: var(--shadow-sm);
  margin-bottom: 4px;
}
.lib-search input {
  flex: 1; border: none; outline: none; background: none;
  font-family: inherit; font-size: var(--fs-label); color: var(--ink);
}
.lib-search input::placeholder { color: var(--muted); }

.lib-empty {
  grid-column: 1 / -1;
  padding: 20px; text-align: center; color: var(--muted);
  font-style: italic; font-size: var(--fs-label);
}
.lib-more {
  align-self: center;
  margin-top: 6px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: var(--ink) !important;
}
.lib-more:hover { color: var(--accent) !important; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.lib-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); cursor: pointer; text-align: left;
  font-family: inherit; color: var(--ink);
  box-shadow: var(--shadow-sm); transition: transform 0.08s, box-shadow 0.08s;
  position: relative;
}
.lib-card:hover { background: color-mix(in srgb, var(--cat-color) 6%, var(--paper)); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line); }
.lib-card.on {
  background: color-mix(in srgb, var(--cat-color) 18%, var(--paper));
  outline: 2px solid var(--cat-color); outline-offset: -2px;
}
.lib-card.on::after { content: '✓'; position: absolute; top: 4px; right: 6px; width: 18px; height: 18px; background: var(--cat-color); color: #fff; border-radius: 50%; font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700; border: 1.5px solid var(--line); }
.lib-card-label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; }
.lib-card-desc {
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  padding: 0 8px;
  margin-top: 2px;
  font-family: 'Sarabun', 'Inter', sans-serif;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.lib-card.on .lib-card-desc {
  color: var(--ink);
  opacity: 0.7;
}
.lib-card-phrase {
  font-family: 'JetBrains Mono', monospace; font-size: 9.5px; line-height: 1.3;
  color: var(--muted); opacity: 0.9;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Tab bar ────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1.5px solid var(--line);
  padding: 6px 6px 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 0; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 10px; font-weight: 600;
  border-top: 2px solid transparent;
}
.tab.active { color: var(--ink); border-top-color: var(--accent); }
.tab.active .ico { stroke: var(--ink); }

@media (min-width: 1100px) {
  .tabbar {
    position: fixed; top: 0; left: 0; right: auto; bottom: 0;
    width: 200px; height: 100vh;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 24px 14px; border-top: none; border-right: 1.5px solid var(--line);
    background: var(--paper-2);
  }
  .tab {
    max-width: none; width: 100%; flex: 0;
    flex-direction: row; gap: 10px; align-items: center; justify-content: flex-start;
    padding: 10px 12px; border-radius: var(--radius-sm); border-top: none;
    font-size: 13px;
  }
  .tab.active { background: var(--hi); color: var(--ink); border-top: none; }
  .tabbar::before {
    content: '⚡ Autoprompt';
    display: block; font-family: 'Caveat', cursive; font-size: 26px;
    margin-bottom: 12px; padding-left: 8px;
  }
}

/* ── List screen ────────────────────────────────────── */
.list-screen, .settings { padding: 4px 0 20px; }
.screen-title { font-family: 'Caveat', cursive; font-size: 32px; margin-bottom: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow-sm);
}
.list-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.list-item-prompt {
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.list-item-meta { font-size: 10px; color: var(--muted); display: flex; gap: 6px; }
.list-item-actions { display: flex; gap: 4px; }
.list-empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--line-soft); border-radius: var(--radius);
  font-style: italic;
}

/* ── Settings screen ────────────────────────────────── */
.setting-grp {
  margin-bottom: 18px;
  padding: 12px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow-sm);
}
.setting-label { font-family: 'Caveat', cursive; font-size: 19px; margin-bottom: 8px; }
.setting-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 32px; height: 32px; border-radius: 8px; border: 1.5px solid var(--line); cursor: pointer; box-shadow: var(--shadow-sm); }
.setting-about { font-size: 12px; color: var(--ink-2); line-height: 1.5; }

/* ── Cache stats display ────────────────────────────── */
.cache-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 4px;
}
.cache-stats > div {
  padding: 10px;
  border: 1.5px dashed var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  text-align: center;
}
.cache-num {
  font-family: 'Caveat', cursive;
  font-size: 28px; line-height: 1;
  color: var(--accent); font-weight: 700;
}
.cache-lbl { font-size: 10px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── AI thumbnail (lazy, overlays VizThumb fallback) ──── */
.ai-thumb { position: relative; border-radius: 5px; overflow: hidden; flex-shrink: 0; border: 1.4px solid var(--line); background: var(--paper); }
.ai-thumb-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  animation: fadeInImg 0.4s ease;
}
@keyframes fadeInImg { from { opacity: 0; } to { opacity: 1; } }

/* ── Dice / Random button ──────────────────────────── */
.btn.dice {
  padding: 6px 10px; font-size: 16px; line-height: 1;
  background: linear-gradient(135deg, var(--hi) 0 50%, color-mix(in srgb, var(--accent) 40%, var(--paper)) 50% 100%);
}
.btn.dice:hover { transform: rotate(-5deg); }

/* ── Library category action row ────────────────────── */
.lib-cat-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px; margin-top: 2px;
}
.lib-cat-actions .btn-link {
  font-family: 'Caveat', cursive; font-size: 16px; color: var(--ink) !important;
  display: inline-flex; align-items: center; gap: 4px;
}
.lib-cat-actions .btn-link:hover { color: var(--accent) !important; }

/* ── Stack block actions — dice ─────────────────────── */
.stack-block-actions .ico-mini { font-size: 12px; }

/* ── icon overrides ─────────────────────────────────── */
.ico { stroke: var(--ink); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ico-fill { fill: var(--ink); }

/* ============================================================ */
/* SaaS layer: modals, auth, plan, locks                          */
/* ============================================================ */

/* ── Server loading ─────────────────────────────────── */
.server-loading {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 16px; padding: 10px 14px;
  background: var(--paper); border: 1.5px dashed var(--line-soft); border-radius: var(--radius);
  font-size: 12px; color: var(--muted);
  font-family: 'Caveat', cursive; font-size: 16px;
}
.server-loading-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid var(--line-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Plan badge in topbar ───────────────────────────── */
.plan-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 4px; border: 1.5px solid var(--line);
  border-radius: 999px; background: var(--paper); cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--ink);
  font-family: inherit;
}
.plan-badge:hover { background: var(--paper-2); }
.plan-badge.pro { background: linear-gradient(135deg, var(--hi), var(--accent)); border-color: var(--ink); color: var(--ink); }
.plan-badge .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.plan-badge.pro .avatar { background: var(--paper); color: var(--ink); }
.plan-badge .plan-name { padding: 0 2px; }
.plan-badge .plan-up {
  background: var(--accent); color: #fff;
  padding: 2px 7px; border-radius: 999px; font-size: 10px;
  margin-left: 2px;
}

/* ── Modal backdrop + shell ─────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: 0 8px 0 var(--line); padding: 24px;
  max-width: 420px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  position: relative;
  animation: modalIn 0.22s cubic-bezier(.2,.8,.2,1);
}
.modal-pricing { max-width: 780px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(0.96); } to { opacity: 1; transform: none; } }

.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--paper);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--paper-2); }

.modal-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.modal-brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--ink); color: var(--paper); display: flex; align-items: center; justify-content: center; font-weight: 700; box-shadow: var(--shadow-sm); }
.modal-brand-name { font-family: 'Caveat', cursive; font-size: 22px; }

.modal-title { font-family: 'Caveat', cursive; font-size: 32px; line-height: 1; margin: 8px 0 4px; }
.modal-sub { font-size: 12px; color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
.modal-reason {
  background: color-mix(in srgb, var(--accent) 12%, var(--paper));
  border-left: 3px solid var(--accent);
  padding: 8px 10px; border-radius: 4px;
  font-size: 12px; font-weight: 500; color: var(--ink);
  margin-bottom: 12px;
}
.modal-fine { font-size: 10px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

/* ── Auth buttons ───────────────────────────────────── */
.auth-buttons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.auth-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px;
  background: var(--paper); border: 1.5px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
  box-shadow: var(--shadow-sm); transition: transform 0.06s, box-shadow 0.06s;
}
.auth-btn:hover { background: var(--paper-2); }
.auth-btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--line); }
.auth-btn:disabled { opacity: 0.6; cursor: progress; }
.auth-ico {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.auth-ico.g { background: #fff; color: #4285f4; border: 1.5px solid var(--line); }
.auth-ico.f { background: #1877f2; color: #fff; }
.auth-ico.e { background: var(--ink); color: var(--paper); }

.auth-email-row { display: flex; gap: 6px; align-items: stretch; }
.auth-email-input {
  flex: 1; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); font-family: inherit; font-size: 13px;
  box-shadow: var(--shadow-sm);
}

/* ── Pricing modal ──────────────────────────────────── */
.billing-toggle {
  display: inline-flex; padding: 3px;
  background: var(--paper-2); border: 1.5px solid var(--line); border-radius: 999px;
  margin: 8px 0 16px;
}
.bill-tab {
  padding: 6px 14px; border-radius: 999px; border: none; background: transparent;
  cursor: pointer; font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted); display: inline-flex; align-items: center; gap: 6px;
}
.bill-tab.active { background: var(--ink); color: var(--paper); box-shadow: var(--shadow-sm); }
.bill-save { background: var(--green); color: #fff; padding: 1px 6px; border-radius: 999px; font-size: 9px; }
.bill-tab.active .bill-save { background: var(--hi); color: var(--ink); }

.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .plan-grid { grid-template-columns: 1fr; } }

.plan-card {
  position: relative;
  padding: 18px 16px 16px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 12px;
}
.plan-card.featured {
  background: linear-gradient(180deg, color-mix(in srgb, var(--hi) 30%, var(--paper)), var(--paper) 60%);
  border-width: 2px; box-shadow: 0 4px 0 var(--line); transform: translateY(-4px);
}
.plan-card.current { outline: 2px solid var(--green); outline-offset: 2px; }
.plan-ribbon {
  position: absolute; top: -10px; right: 12px;
  background: var(--accent); color: #fff; padding: 3px 10px;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  border: 1.5px solid var(--line); box-shadow: var(--shadow-sm);
}
.plan-name { font-family: 'Caveat', cursive; font-size: 28px; margin: 0; line-height: 1; }
.plan-price { display: flex; align-items: baseline; gap: 4px; }
.plan-amount { font-size: 32px; font-weight: 800; line-height: 1; }
.plan-period { font-size: 13px; color: var(--muted); }
.plan-features { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.plan-features li { display: flex; gap: 6px; align-items: flex-start; line-height: 1.4; }
.plan-features li.strike { color: var(--muted); text-decoration: line-through; }
.plan-features li.hi { font-weight: 600; }
.plan-cta { width: 100%; }

/* ── Account screen ─────────────────────────────────── */
.account-card {
  padding: 16px; margin-bottom: 18px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow-sm);
}
.account-card.pro {
  background: linear-gradient(135deg, color-mix(in srgb, var(--hi) 25%, var(--paper)), var(--paper) 70%);
  border-width: 2px;
}
.account-head { display: flex; align-items: center; gap: 12px; }
.account-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.account-avatar.guest-avatar { background: var(--paper-2); color: var(--muted); border: 1.5px dashed var(--line-soft); }
.account-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.account-name { font-size: 15px; font-weight: 700; }
.account-email { font-size: 11px; color: var(--muted); }
.plan-pill {
  padding: 4px 10px; border-radius: 999px;
  background: var(--paper-2); border: 1.5px solid var(--line);
  font-size: 11px; font-weight: 700;
}
.plan-pill.pro { background: var(--ink); color: var(--paper); }

.account-usage { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.usage-bar { display: flex; flex-direction: column; gap: 4px; }
.usage-bar-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; }
.usage-label { color: var(--ink-2); font-weight: 500; }
.usage-count { font-family: 'JetBrains Mono', monospace; color: var(--muted); }
.usage-count.maxed { color: var(--accent); font-weight: 700; }
.usage-bar-track { height: 6px; background: var(--paper-2); border: 1px solid var(--line-soft); border-radius: 999px; overflow: hidden; }
.usage-bar-fill { height: 100%; transition: width 0.3s; }

/* ── Locked categories / cards ──────────────────────── */
.lib-tab.locked {
  background: var(--paper-2); color: var(--muted);
  opacity: 0.7;
}
.lib-tab.locked .lib-tab-count { background: var(--line-soft); color: var(--paper); }
.lib-card.locked { opacity: 0.5; cursor: pointer; }
.lib-card.locked::before {
  content: '🔒'; position: absolute; top: 8px; right: 8px;
  font-size: 16px; z-index: 1;
}
.lib-locked-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 4px 0 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--paper)), var(--paper) 70%);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.lib-locked-text { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.lib-locked-text strong { font-size: 12px; font-weight: 700; }
.lib-locked-text span { font-size: 11px; color: var(--ink-2); }

/* ── Generic .locked button (e.g. Export) ───────────── */
.btn.locked { opacity: 0.55; }
.btn.locked:hover { background: color-mix(in srgb, var(--accent) 12%, var(--paper)); opacity: 0.85; }
