/* ============ Scriptly — stationery / ink & paper ============ */
:root {
  --paper-bg: #f3efe4;
  --panel: #fdfbf3;
  --panel-2: #f7f3e7;
  --ink: #1d2433;
  --navy: #22326e;
  --muted: #6f6a58;
  --line: #ddd5bf;
  --line-strong: #c9c0a5;
  --red: #c2492f;
  --red-soft: #f6e3de;
  --green: #3d7a4e;
  --paper: #fdfbf3;
  --paper-line: #e5ddc6;
  --radius: 10px;

  /* Layered elevation (Material-style soft shadows, tinted toward ink) */
  --elev-1: 0 1px 2px rgba(29,36,51,.06), 0 1px 3px rgba(29,36,51,.08);
  --elev-2: 0 1px 2px rgba(29,36,51,.06), 0 4px 10px rgba(29,36,51,.10);
  --elev-3: 0 2px 4px rgba(29,36,51,.08), 0 10px 26px rgba(29,36,51,.14);
  --elev-4: 0 4px 8px rgba(29,36,51,.10), 0 20px 44px rgba(29,36,51,.18);

  /* Spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { overflow-x: hidden; max-width: 100%; }
body {
  font-family: "Inter", system-ui, sans-serif;
  background:
    radial-gradient(rgba(29,36,51,.028) 1px, transparent 1px);
  background-size: 22px 22px;
  background-color: var(--paper-bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(34,50,110,.18); }

/* Consistent keyboard focus ring across all interactive elements */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: 4px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px !important;
  cursor: pointer;
}

h2, h3, .plan-price, .stat-val { font-family: "Fraunces", Georgia, serif; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1.5px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  padding: 112px 16px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 28px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  border-radius: 8px;
  transition: opacity .15s;
}
.brand:hover { opacity: .8; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--navy);
  color: var(--paper);
  font-family: "Caveat", cursive;
  font-size: 1.6rem;
  display: grid;
  place-items: center;
}
.brand-name {
  font-family: "Caveat", cursive;
  font-size: 1.9rem;
  color: var(--navy);
}
/* Sidebar wordmark, drawn once (no animation) in the user's own captured
   handwriting — same fallback blend as the home hero's brand canvas. */
.brand-name-canvas { height: 30px; width: auto; display: block; }

.side-nav { display: flex; flex-direction: column; gap: 1px; }
.side-nav .tab-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  border-left: 2.5px solid transparent;
  border-radius: 0 8px 8px 0;
  transition: color .12s, background .12s, border-color .12s;
}
.side-nav .tab-btn:hover { color: var(--ink); background: rgba(34,50,110,.05); }
.side-nav .tab-btn.active {
  color: var(--navy);
  font-weight: 600;
  background: rgba(34,50,110,.07);
  border-left-color: var(--red);
}
.nav-ic { width: 19px; text-align: center; opacity: .75; }
.nav-ic-text { font-size: 0.68em; font-weight: 700; letter-spacing: -0.02em; }

/* Always-on account indicator — a floating pill fixed to the top-left corner
   of the viewport, above the sidebar/content, so who you're signed in as
   stays visible no matter which tab or scroll position you're at. */
.account-chip {
  position: fixed;
  top: 64px;
  left: 14px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--elev-3);
  transition: box-shadow .14s, transform .14s, border-color .14s;
}
.account-chip:hover { border-color: var(--navy); box-shadow: var(--elev-4); transform: translateY(-1px); }
.account-chip.expanded { border-color: var(--navy); }
/* .ripple-host (added on click by the global press-feedback handler) sets
   position:relative — pin this back to fixed so the chip doesn't get pulled
   into the flex flow and stretched to the page's full height. */
.account-chip.ripple-host { position: fixed; }
.account-avatar {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: transform .3s cubic-bezier(.22,.85,.32,1.2);
}
.account-chip.expanded .account-avatar { transform: rotate(-8deg) scale(1.06); }
.account-chip-label {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 76px;
  opacity: 1;
  transform: translateX(0);
  transition: max-width .38s cubic-bezier(.22,.85,.32,1.15), opacity .28s ease .04s, transform .32s cubic-bezier(.22,.85,.32,1.15);
}
.account-chip.expanded .account-chip-label { max-width: 260px; }

.wallet-card {
  margin-top: auto;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.wallet-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.wallet-row-right { display: flex; align-items: center; gap: 8px; }
.settings-gear {
  background: transparent;
  border: 1.5px solid var(--line-strong);
  color: var(--muted);
  width: 26px; height: 26px;
  border-radius: 7px;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.settings-gear:hover { color: var(--navy); border-color: var(--navy); }
.wallet-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; }
#plan-pill {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--navy);
  background: rgba(34,50,110,.09);
  border: 1px solid rgba(34,50,110,.25);
  padding: 2px 9px;
  border-radius: 999px;
}
#token-pill {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
}
.wallet-upgrade {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 9px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--paper);
  background: var(--navy);
  cursor: pointer;
}
.wallet-upgrade:hover { background: #2c3f88; }

/* ---------- Content ---------- */
.content { flex: 1; padding: 34px 40px 70px; max-width: 1150px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* Admin takes the whole screen — everything else in the app shell is hidden
   while it's open, since it's a one-operator tool, not part of the product. */
#tab-admin { position: relative; }
#admin-iframe { display: none; width: 100%; border: none; }
#admin-exit-btn { display: none; }
body.admin-fullscreen .sidebar,
body.admin-fullscreen .account-chip { display: none; }
body.admin-fullscreen .content { padding: 0; max-width: none; margin: 0; }
body.admin-fullscreen #admin-exit-btn {
  display: block;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 400;
  background: #000;
  color: #39ff6b;
  border: 1.5px solid #1f6b34;
  border-radius: 4px;
  padding: 8px 14px;
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: 0.82rem;
  cursor: pointer;
}
body.admin-fullscreen #admin-iframe { display: block; height: 100vh; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
#api-settings { display: none; }
.tut-btn-row { text-align: center; margin: 24px 0 4px; }

/* ---------- Tutorial spotlight overlay ---------- */
#tut-overlay { position: fixed; inset: 0; z-index: 3000; display: none; }
#tut-overlay.active { display: block; }
#tut-ring {
  position: fixed; border: 3px solid var(--red); border-radius: 12px;
  box-shadow: 0 0 0 4000px rgba(20,22,30,.6);
  transition: left .35s ease, top .35s ease, width .35s ease, height .35s ease;
  pointer-events: none; display: none;
}
#tut-tooltip {
  position: fixed; max-width: 320px; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 12px; padding: 18px; box-shadow: 0 12px 34px rgba(0,0,0,.3); z-index: 3001;
}
#tut-tooltip .tut-progress { font-size: 0.68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
#tut-tooltip h4 { margin: 0 0 6px; font-size: 1.05rem; }
#tut-tooltip p { margin: 0 0 14px; font-size: 0.86rem; color: var(--muted); line-height: 1.5; }
#tut-tooltip .tut-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.page-head.center { justify-content: center; text-align: center; }
.page-head h2 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; }
.page-head .hint { margin: 7px 0 0; max-width: 660px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--elev-1);
}

.hint { color: var(--muted); font-size: 0.87rem; line-height: 1.6; }
.sim-note { color: #9a927c; font-size: 0.85em; }

/* ---------- Buttons & controls ---------- */
button { font: inherit; cursor: pointer; }
.btn-primary, .file-btn.btn-primary {
  background: var(--navy);
  color: var(--paper);
  border: 1.5px solid var(--navy);
  padding: 9px 17px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-block;
  position: relative;
  overflow: hidden;
  transition: background .12s, transform .1s, box-shadow .12s;
}
.btn-primary:hover { background: #2c3f88; box-shadow: var(--elev-1); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { background: #b9b3a0; border-color: #b9b3a0; cursor: not-allowed; }
.btn-lg { padding: 13px 26px; font-size: 0.98rem; }

/* Ripple feedback (Material-style press ripple, CSS-driven from app.js) */
.ripple-host { position: relative; overflow: hidden; }
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  transform: scale(0);
  animation: ripple-anim .55s ease-out forwards;
  pointer-events: none;
}
.ripple.dark-ripple { background: rgba(29,36,51,.16); }
@keyframes ripple-anim {
  to { transform: scale(2.6); opacity: 0; }
}

.btn-ghost, .file-btn.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  display: inline-block;
}
.btn-ghost:hover { border-color: var(--navy); color: var(--navy); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1.5px solid rgba(194,73,47,.4);
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
}
.btn-danger:hover { background: var(--red-soft); }

.chip {
  background: rgba(34,50,110,.08);
  border: 1px solid rgba(34,50,110,.22);
  color: var(--navy);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 999px;
}
.cost-chip {
  background: var(--red-soft);
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.max-chip {
  background: var(--red);
  color: var(--paper);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: .07em;
  padding: 2px 7px;
  border-radius: 999px;
}
.ink-toggle.locked { opacity: .45; }

/* Custom switch look for toggle checkboxes (ink options, dark mode) */
.ink-toggle input, .theme-toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 36px; height: 20px;
  background: var(--line-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
  vertical-align: middle;
}
.ink-toggle input::before, .theme-toggle input::before {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(29,36,51,.35);
  transition: transform .15s;
}
.ink-toggle input:checked, .theme-toggle input:checked { background: var(--red); }
.ink-toggle input:checked::before, .theme-toggle input:checked::before { transform: translateX(16px); }
.ink-toggle input:disabled { opacity: .5; cursor: not-allowed; }

.style-picker select {
  background: var(--panel);
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  border-radius: 7px;
  padding: 7px 10px;
  font: inherit;
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 11px;
  align-items: center;
  margin-bottom: 15px;
}
.toolbar .spacer { flex: 1; }
.toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--muted);
}
input[type="range"] { accent-color: var(--navy); width: 110px; }
input[type="color"] {
  width: 36px; height: 27px;
  border: 1.5px solid var(--line-strong);
  border-radius: 7px;
  padding: 1px;
  background: var(--panel);
  cursor: pointer;
}
#page-label { font-size: 0.84rem; color: var(--muted); font-weight: 600; padding: 0 4px; }
.text-counter { font-size: 0.76rem; color: var(--muted); margin: -10px 0 15px; text-align: right; }
.streak-badge {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid var(--red);
  border-radius: 999px;
  padding: 4px 12px;
}

textarea {
  width: 100%;
  padding: 13px 15px;
  border: 1.5px solid var(--line-strong);
  border-radius: 9px;
  font: inherit;
  font-size: 0.95rem;
  margin-bottom: 15px;
  resize: vertical;
  background: var(--panel);
  color: var(--ink);
}
textarea::placeholder { color: #a49c85; }
textarea:focus { outline: none; border-color: var(--navy); }

/* ---------- Chart sub-tabs (My Handwriting) ---------- */
.chart-sub { display: none; }
.chart-sub.active { display: block; animation: fade .16s ease; }
.chart-sub-tab {
  background: transparent;
  border: none;
  padding: 9px 20px;
  font: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--muted);
}
.chart-sub-tab + .chart-sub-tab { border-left: 1.5px solid var(--line-strong); }
.chart-sub-tab.active { background: var(--navy); color: var(--paper); }

/* Same card family as .next-step-card (icon + body + button) so the two
   boxes read as a consistent pair, not two different card styles. */
.intro-explainer { cursor: default; }
.intro-explainer:hover { border-color: var(--line-strong); transform: none; box-shadow: var(--elev-1); }
.intro-explainer-icon { background: rgba(34,50,110,.09); color: var(--navy); font-size: 1.1rem; }
.intro-explainer .btn-ghost { flex-shrink: 0; }

#tab-home { position: relative; }
.home-tutorial-btn {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 14px 5px 5px;
  font-size: 0.82rem; font-weight: 600; color: var(--ink);
  box-shadow: var(--elev-3);
  transition: box-shadow .14s, transform .14s, border-color .14s;
}
.home-tutorial-btn:hover { border-color: var(--navy); box-shadow: var(--elev-4); transform: translateY(-1px); }
.home-tutorial-btn::before {
  content: "?";
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--paper);
  font-size: 0.78rem; font-weight: 700;
  display: grid; place-items: center;
}
@media (max-width: 880px) {
  /* Sits below the sticky top bar, mirroring the account chip on the left,
     so it never covers the token balance. */
  .home-tutorial-btn { top: 64px; right: 14px; font-size: 0.78rem; padding: 4px 12px 4px 4px; }
  .home-tutorial-btn::before { width: 22px; height: 22px; font-size: 0.7rem; }
}

/* ---------- Full-screen "how it works" demo ---------- */
#intro-demo-overlay {
  position: fixed; inset: 0; z-index: 2500;
  background: var(--paper-bg, var(--panel));
  /* align-items:center + overflow:auto famously traps scroll on tall content
     (the top becomes unreachable) — flex-start plus top padding keeps it
     looking centered on normal screens while staying fully scrollable. */
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 60px 24px 40px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transition: opacity .45s ease;
}
#intro-demo-overlay.show { opacity: 1; }
#intro-demo-overlay #intro-demo-inner {
  transform: translateY(22px);
  transition: transform .5s cubic-bezier(.2,.8,.3,1);
}
#intro-demo-overlay.show #intro-demo-inner { transform: none; }
#intro-demo-skip {
  position: fixed; top: 18px; right: 18px; z-index: 2501;
  background: var(--panel); color: var(--ink);
  border: 1.5px solid var(--line-strong); border-radius: 999px;
  padding: 9px 18px; font: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; box-shadow: var(--elev-2, 0 2px 10px rgba(0,0,0,.08));
}
#intro-demo-skip:hover { border-color: var(--navy); color: var(--navy); }
#intro-demo-inner { max-width: 720px; width: 100%; text-align: center; margin: 0 auto; }
#intro-demo-title { font-size: 1.5rem; margin: 10px 0 22px; }
#intro-demo-canvas {
  display: block; width: 100%; max-width: 680px; aspect-ratio: 640 / 360;
  height: auto; margin: 0 auto; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 12px;
}
#intro-demo-caption {
  margin: 16px 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .01em;
}
#intro-demo-detail { max-width: 480px; margin: 0 auto; font-size: 0.95rem; }
@media (max-width: 640px) {
  #intro-demo-title { font-size: 1.2rem; margin-bottom: 14px; }
  #intro-demo-caption { font-size: 0.98rem; }
  #intro-demo-skip { top: 10px; right: 10px; padding: 7px 14px; font-size: 0.8rem; }
}

/* ---------- Home next-step card ---------- */
.next-step-card {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  cursor: pointer;
  transition: border-color .14s, transform .14s, box-shadow .14s;
}
.next-step-card:hover { border-color: var(--navy); transform: translateY(-1px); box-shadow: var(--elev-2); }
.next-step-icon {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--red);
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--red-soft);
  border-radius: 50%;
}
.next-step-body { flex: 1; min-width: 0; }
.next-step-body h3 { font-size: 1.08rem; font-weight: 600; margin-bottom: 4px; }
.next-step-body p { color: var(--muted); font-size: 0.87rem; margin-bottom: 10px; }
.next-step-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; max-width: 320px; }
.next-step-bar-fill { height: 100%; background: var(--navy); border-radius: 999px; transition: width .3s ease; }
.next-step-card .btn-primary { flex-shrink: 0; }

/* ---------- Home hero ---------- */
.hero-microcopy { margin-top: 14px; font-size: 0.78rem; color: var(--muted); }

#tab-home { position: relative; }

/* Compact info card — deliberately not another hero; a quiet summary you land on
   after scrolling well past the brand moment above. */
.info-panel {
  max-width: 640px;
  margin: 14vh auto 0;
  padding: 26px 30px;
  text-align: left;
  animation: hero-rise .5s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes hero-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.info-panel-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.info-panel h2 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
}
.info-panel p { color: var(--muted); line-height: 1.6; font-size: 0.92rem; margin: 0 0 16px; max-width: 540px; }
.info-panel-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

/* Simple "chat with Scriptly" walk-through — replaces the old marketing hero
   + feature-card grid with a plain, friendly numbered explanation. */
.intro-chat {
  max-width: 520px;
  margin: 14vh auto 0;
  padding: 26px 28px;
  text-align: left;
  animation: hero-rise .5s cubic-bezier(.2,.8,.3,1) both;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.chat-msg { display: flex; align-items: flex-start; gap: 12px; }
.chat-avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 700;
}
.chat-bubble {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px 14px 14px 14px;
  padding: 12px 16px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
}
.chat-bubble b { color: var(--navy); }

.home-plans-head { margin: 48px auto 4px; max-width: 640px; padding: 0 4px; }
.home-plans-preview { max-width: 780px; margin: 0 auto; }
.home-plans-more { text-align: center; margin: 16px 0 0; }

.hero-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-chip {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--navy);
  background: var(--panel-2);
  border: 1px solid rgba(34,50,110,.16);
  padding: 5px 11px;
  border-radius: 999px;
}

.hero-badge {
  display: inline-block;
  color: var(--red);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.hero-accent {
  font-style: italic;
  color: var(--navy);
  position: relative;
  white-space: nowrap;
}
.hero-accent::after {
  content: "";
  position: absolute;
  left: 2%; right: 4%;
  bottom: 0.04em;
  height: 0.08em;
  background: var(--red);
  border-radius: 999px;
  transform: rotate(-0.8deg);
}

/* ---------- Site notices (admin announcements + disabled-feature warnings) ---------- */
#home-banners { position: relative; z-index: 2; display: flex; flex-direction: column; gap: 8px; padding: 14px 14px 0; max-width: 780px; margin: 0 auto; }
.site-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  border: 1.5px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--ink);
}
.site-banner.error { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.site-banner.update { background: rgba(61,122,78,.1); border-color: var(--green); color: var(--green); }
.site-banner.notice { background: rgba(34,50,110,.08); border-color: var(--navy); color: var(--navy); }
.site-banner-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
  opacity: 0.7;
}
.site-banner-close:hover { opacity: 1; }

/* ---------- Brand hero — writes "Scriptly" in your own handwriting ---------- */
.brand-hero {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  animation: hero-rise .7s cubic-bezier(.2,.8,.3,1) both;
}
#brand-canvas { display: block; width: min(88vw, 640px); height: auto; }
.brand-caption {
  color: var(--muted);
  font-size: 0.86rem;
  max-width: 380px;
  line-height: 1.55;
}
.scroll-cue {
  margin-top: 14px;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  animation: cue-bob 2.2s ease-in-out infinite;
}
.scroll-cue:hover { color: var(--navy); }
.scribble-arrow path {
  fill: none;
  stroke: var(--red);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 150;
  stroke-dashoffset: 150;
  animation: scribble-draw 2.6s ease-in-out infinite;
}
@keyframes scribble-draw {
  0% { stroke-dashoffset: 150; opacity: 1; }
  55% { stroke-dashoffset: 0; opacity: 1; }
  85% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}
@keyframes cue-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(7px); }
}
@media (max-width: 880px) {
  .brand-hero {
    min-height: 100vh;
    justify-content: flex-start;
    padding-top: 22vh;
    gap: 14px;
  }
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 4px 0 26px;
}
.stat {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 15px 18px;
}
.stat-val { font-size: 1.6rem; font-weight: 600; color: var(--navy); }
.stat-label { font-size: 0.74rem; color: var(--muted); font-weight: 600; margin-top: 1px; letter-spacing: .02em; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}
.home-card {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-5);
  cursor: pointer;
  box-shadow: var(--elev-1);
  transition: border-color .14s, transform .14s, box-shadow .14s;
}
.home-card:hover {
  border-color: var(--navy);
  transform: translateY(-2px);
  box-shadow: var(--elev-3);
}
.step-num {
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 10px;
}
.home-card h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 7px; }
.home-card p { color: var(--muted); font-size: 0.87rem; line-height: 1.6; }
.hc-progress { margin-top: 12px; font-size: 0.8rem; color: var(--green); font-weight: 700; }

/* ---------- Chart grid ---------- */
#chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 11px;
}
.glyph-cell { text-align: center; }
.glyph-cell .label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.glyph-cell .label b { font-family: "Fraunces", Georgia, serif; font-size: 1rem; color: var(--navy); }
.glyph-cell .redo { background: none; border: none; color: #b0a88e; padding: 0 4px; font-size: 0.9rem; }
.glyph-cell .redo:hover { color: var(--red); }
.glyph-cell canvas {
  width: 100%;
  aspect-ratio: 1;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  touch-action: none;
  cursor: crosshair;
  transition: border-color .13s;
}
.glyph-cell canvas:hover { border-color: var(--navy); }
.glyph-cell.done canvas { border: 1.5px solid #9dbfa7; }
.glyph-cell .zoom { background: none; border: none; color: #b0a88e; padding: 0 4px; font-size: 0.9rem; }
.glyph-cell .zoom:hover { color: var(--navy); }

/* ---------- Zoomed-in single-character editor ---------- */
#glyph-zoom-overlay {
  position: fixed; inset: 0; z-index: 2600;
  background: var(--paper-bg);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 64px 20px 40px;
  overflow-y: auto;
}
#glyph-zoom-close {
  position: fixed; top: 18px; right: 18px; z-index: 2601;
  background: var(--panel); color: var(--ink);
  border: 1.5px solid var(--line-strong); border-radius: 999px;
  padding: 8px 16px; font-size: 0.85rem; font-weight: 600;
  box-shadow: var(--elev-2);
}
#glyph-zoom-close:hover { border-color: var(--navy); }
#glyph-zoom-inner { width: 100%; max-width: 460px; text-align: center; }
#glyph-zoom-label {
  font-family: "Fraunces", Georgia, serif;
  font-size: 2.4rem; font-weight: 700; color: var(--navy);
  line-height: 1; margin-bottom: 6px;
}
#glyph-zoom-inner > .hint { margin-bottom: 18px; }
#glyph-zoom-row { display: flex; align-items: center; gap: 12px; }
#glyph-zoom-row .icon-btn { flex-shrink: 0; font-size: 1.5rem; padding: 14px 16px; line-height: 1; }
#glyph-zoom-canvas {
  flex: 1; min-width: 0;
  aspect-ratio: 1;
  width: 100%; height: auto;
  border: 1.5px dashed var(--line-strong); border-radius: 12px;
  background: var(--paper);
  touch-action: none; cursor: crosshair;
}
#glyph-zoom-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 16px;
}
#glyph-zoom-actions .hint { margin: 0; }
@media (max-width: 600px) {
  #glyph-zoom-row { gap: 6px; }
  #glyph-zoom-row .icon-btn { padding: 12px 10px; font-size: 1.3rem; }
  #glyph-zoom-label { font-size: 2rem; }
}

/* ---------- Preview ---------- */
#preview-canvas {
  width: 100%;
  background: repeating-linear-gradient(var(--paper), var(--paper) 39px, var(--paper-line) 40px);
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
}

/* ---------- Documents toolbar (compact) ---------- */
.toolbar-main { margin-bottom: 18px; }
.icon-btn {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
}
.icon-btn:hover { border-color: var(--navy); color: var(--navy); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.popover-wrap { position: relative; }
.split-btn { position: relative; display: flex; }
.split-btn #analyze-btn { border-radius: 8px 0 0 8px; }
.split-btn-caret { border-radius: 0 8px 8px 0 !important; border-left: 1px solid rgba(255,255,255,.25) !important; padding: 8px 10px !important; }
.popover {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--elev-3);
  padding: 14px;
  z-index: 40;
  min-width: 210px;
}
.popover.open { display: block; animation: modal-in .14s cubic-bezier(.2,.9,.3,1.2); }
.popover label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}
.popover .swatches { justify-content: flex-start; margin-bottom: 10px; }
.popover .ink-toggle { margin-bottom: 10px; }
.popover .ink-toggle:last-child { margin-bottom: 0; }
.popover-list { padding: 6px; min-width: 190px; }
.popover-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--ink);
}
.popover-list button:hover { background: var(--panel-2); }
.popover-list button:disabled { opacity: .4; cursor: not-allowed; }
.popover-list button:hover:disabled { background: transparent; }
.popover-list hr { border: none; border-top: 1px solid var(--line); margin: 6px 4px; }
.popover-list .file-btn { border-radius: 7px; margin: 0; }
.popover-list .file-btn:hover { background: var(--panel-2); }
.popover-list .danger-item { color: var(--red); }
.popover-list .danger-item:hover { background: var(--red-soft); }
.kbd { float: right; font-size: 0.72rem; color: var(--muted); font-weight: 500; }

/* ---------- Documents ---------- */
.mode-tabs {
  display: inline-flex;
  border: 1.5px solid var(--line-strong);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 10px;
}
.mode-tab {
  background: transparent;
  border: none;
  padding: 9px 20px;
  font: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--muted);
}
.mode-tab + .mode-tab { border-left: 1.5px solid var(--line-strong); }
.mode-tab.active { background: var(--navy); color: var(--paper); }
#mode-hint { margin-bottom: 14px; }

/* Documents panel reading order: pick a mode, then the drop zone (the one
   thing a new user actually needs to do first), then the document itself,
   and finally every action button in a single group at the bottom. Ordering
   is done with flex `order` so the DOM stays as-is for the JS that drives it. */
#doc-panel { display: flex; flex-direction: column; }
#doc-panel > .mode-tabs        { order: 1; }
#doc-panel > #mode-hint        { order: 2; }
#doc-panel > #drop-zone        { order: 3; }
#doc-panel > #batch-list       { order: 4; }
#doc-panel > #doc-status       { order: 5; }
#doc-panel > #confidence-legend{ order: 6; }
#doc-panel > #doc-stage-wrap   { order: 7; }
#doc-panel > .toolbar-main     { order: 8; margin-top: 18px; margin-bottom: 0; }
#doc-panel > #history-sec      { order: 9; }
#doc-panel > #api-settings     { order: 10; }
/* .mode-tabs is inline-flex by default, which would stretch oddly as a
   flex-column child — keep it hugging its content. */
#doc-panel > .mode-tabs { align-self: flex-start; }
.cost-callout { color: var(--red); font-weight: 800; }

details { margin-top: 18px; border-top: 1.5px solid var(--line); padding-top: 15px; }
details summary { cursor: pointer; font-weight: 600; font-size: 0.84rem; color: var(--muted); margin-bottom: 9px; }
details label { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
details input {
  flex: 1;
  padding: 9px 13px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  background: var(--panel);
  color: var(--ink);
}

#drop-zone {
  border: 2px dashed var(--line-strong);
  border-radius: 12px;
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--paper);
}
#drop-zone:hover { border-color: var(--navy); background: #fffef9; }
.panel.dragging-over #drop-zone, .panel.dragging-over { border-color: var(--navy); }
.panel.dragging-over { background: #fbf8ec; }
.dz-title { font-family: "Fraunces", Georgia, serif; font-size: 1.3rem; font-weight: 600; margin-bottom: 6px; }
.dz-sub { color: var(--muted); font-size: 0.88rem; margin-bottom: 22px; }
.dz-steps { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.dz-steps span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy);
  background: rgba(34,50,110,.07);
  border: 1px solid rgba(34,50,110,.18);
  padding: 5px 13px;
  border-radius: 999px;
}

#doc-stage-wrap { overflow: auto; border-radius: 8px; }
#doc-stage { position: relative; display: inline-block; max-width: 100%; }
#doc-stage img { display: block; max-width: 100%; border-radius: 8px; border: 1.5px solid var(--line-strong); }

.answer-box {
  position: absolute;
  cursor: grab;
  border: 1px dashed transparent;
  border-radius: 5px;
}
.answer-box:hover { border-color: rgba(34,50,110,.6); background: rgba(34,50,110,.05); }
.answer-box.dragging { cursor: grabbing; border-color: var(--navy); }
.answer-box canvas { display: block; pointer-events: none; }
.answer-box .del {
  position: absolute;
  top: -10px; right: -10px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--red);
  color: var(--paper);
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  padding: 0;
  border: none;
  display: none;
}
.answer-box:hover .del { display: block; }

#doc-status { min-height: 1.3em; font-weight: 600; margin-bottom: 11px; }
#doc-status.error { color: var(--red); }
#doc-status.ok { color: var(--green); }

/* ---------- Plans ---------- */
.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
  gap: 14px;
  align-items: start;
}
.plan-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 26px 20px;
  text-align: center;
  box-shadow: var(--elev-1);
  transition: transform .14s, box-shadow .14s;
}
.plan-card:hover { transform: translateY(-2px); box-shadow: var(--elev-3); }
.plan-card.popular {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--paper);
}
.plan-card.popular .plan-price, .plan-card.popular h3 { color: var(--paper); }
.plan-card.popular li { color: #c3cae6; }
.plan-card.popular li b { color: #fff; }
.plan-card.popular li::before { color: #8fd3a5; }
.plan-card.popular .plan-tokens { color: #f0c987; }
.plan-card.popular .plan-btn { background: var(--paper); color: var(--navy); }
.plan-card.active-plan { border-color: var(--green); }
.ribbon {
  position: absolute;
  top: -12px; left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: var(--paper);
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.plan-card h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.plan-price { font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
.plan-price span { font-family: "Inter", sans-serif; font-size: 0.82rem; color: inherit; opacity: .6; font-weight: 500; }
.plan-tokens { color: var(--red); font-weight: 700; margin: 8px 0 14px; font-size: 0.9rem; }
.plan-card ul { list-style: none; text-align: left; margin: 0 0 18px; }
.plan-card li { font-size: 0.83rem; color: var(--muted); padding: 4px 0 4px 22px; position: relative; line-height: 1.45; }
.plan-card li b { color: var(--ink); }
.plan-card li::before { content: "✓"; position: absolute; left: 2px; color: var(--green); font-weight: 800; }

.pack-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.pack-btn {
  width: 100%;
  background: var(--panel-2);
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px;
  font-size: 0.83rem;
  font-weight: 600;
  transition: border-color .12s;
}
.pack-btn:hover { border-color: var(--navy); color: var(--navy); }

.plan-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--paper);
  background: var(--navy);
}
.plan-btn:hover { filter: brightness(1.12); }
.plan-card.active-plan .plan-btn { background: var(--green); color: var(--paper); }

.file-btn { cursor: pointer; }

/* ---------- Swatches, selection, history ---------- */
.head-actions { display: flex; gap: 10px; }
.swatches { display: inline-flex; gap: 5px; align-items: center; }
.swatch {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  outline: 1.5px solid var(--line-strong);
  padding: 0;
  cursor: pointer;
}
.swatch:hover { outline-color: var(--navy); }

.locked-feature { opacity: .55; }
.locked-panel { text-align: center; padding: 44px 24px; }
.locked-panel-icon { font-size: 2.2rem; margin-bottom: 10px; opacity: .6; filter: grayscale(1); }
.locked-panel h3 { margin-bottom: 6px; }
.locked-panel .hint { max-width: 380px; margin: 0 auto 18px; }
#fonts-content.tab-locked { opacity: .4; filter: grayscale(.7); pointer-events: none; user-select: none; }
#select-all-btn.group-on { background: var(--navy); color: var(--paper); border-color: var(--navy); }

.answer-box.selected {
  border-color: var(--navy) !important;
  background: rgba(34,50,110,.07);
}

.history-title { font-size: 1.05rem; font-weight: 600; margin: 22px 0 4px; }
#history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.history-row {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1.5px solid var(--line); }
.history-row {
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
}
.history-row img {
  width: 52px; height: 66px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: #fff;
}
.history-meta { flex: 1; min-width: 0; }
.history-meta b { display: block; font-size: 0.88rem; }
.history-meta span { font-size: 0.78rem; color: var(--muted); }

/* ---------- Toast & modal ---------- */
#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--paper);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--elev-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: min(90vw, 480px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(29,36,51,.45);
  display: grid;
  place-items: center;
  z-index: 300;
  animation: fade .15s ease;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 22px;
  width: min(92vw, 400px);
  box-shadow: var(--elev-4);
  animation: modal-in .16s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
.modal h4 { font-family: "Fraunces", Georgia, serif; font-size: 1.02rem; font-weight: 600; margin-bottom: 14px; }
.modal input {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  margin-bottom: 16px;
}
.modal input:focus { outline: none; border-color: var(--navy); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Responsive: mobile app shell ---------- */
@media (max-width: 880px) {
  .app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 90;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-right: none;
    border-bottom: 1.5px solid var(--line-strong);
  }
  .brand { padding: 0; }
  .account-chip {
    padding: 5px;
    transition: padding .38s cubic-bezier(.22,.85,.32,1.15), box-shadow .14s, transform .14s, border-color .14s;
  }
  .account-chip-label { max-width: 0; opacity: 0; transform: translateX(-4px); }
  .account-chip.expanded { padding: 5px 12px 5px 5px; }
  .account-chip.expanded .account-chip-label { max-width: 200px; opacity: 1; transform: translateX(0); }
  .brand-mark { width: 30px; height: 30px; font-size: 1.3rem; }
  .brand-name { font-size: 1.5rem; }

  .side-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    background: var(--panel);
    border-top: 1.5px solid var(--line-strong);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 10px rgba(29,36,51,.06);
  }
  .side-nav .tab-btn {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    white-space: nowrap;
    border: none !important;
    border-radius: 10px;
    padding: 6px 2px;
    font-size: 0.64rem;
    font-weight: 600;
    max-width: 96px;
    margin: 0 auto;
  }
  .side-nav .nav-ic { font-size: 1.25rem; width: auto; opacity: 1; }
  .side-nav .tab-btn.active { background: rgba(34,50,110,.09); }

  .sidebar-bottom { margin-top: 0; }
  .wallet-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    padding: 0;
  }
  #token-pill {
    order: 1;
    margin-bottom: 0;
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
  }
  .wallet-row {
    order: 2;
    gap: 8px;
    margin-bottom: 0;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 4px 3px 10px;
  }
  .wallet-label { display: none; }
  .wallet-row-right { gap: 6px; }
  #plan-pill { border: none; background: transparent; padding: 0; }
  .settings-gear {
    background: transparent;
    border: none;
    width: 24px; height: 24px;
  }
  .settings-gear:hover { background: rgba(29,36,51,.06); border-radius: 6px; }
  .wallet-upgrade { display: none; }

  .content { padding: 108px 14px calc(78px + env(safe-area-inset-bottom, 0px)); overflow-x: hidden; margin: 0; max-width: 100%; width: 100%; }
  .page-head { flex-wrap: wrap; }
  .page-head h2 { font-size: 1.4rem; }
  .head-actions { flex-wrap: wrap; width: 100%; }
  .head-actions button { flex: 1 1 auto; }
  .info-panel { margin-top: 8vh; padding: 20px 18px; }
  .info-panel h2 { font-size: 1.22rem; }
  .info-panel-row { flex-direction: column; align-items: stretch; }
  .info-panel-row .btn-primary { width: 100%; text-align: center; }
  .intro-chat { margin-top: 8vh; padding: 20px 16px; }
  .home-plans-head { margin-top: 34px; }
  .home-plans-head h2 { font-size: 1.4rem; }
  .home-plans-preview { grid-template-columns: 1fr; }
  .next-step-card { flex-direction: column; align-items: flex-start; text-align: left; }
  .next-step-card > button { width: 100%; margin-top: 4px; }

  /* Prevent iOS auto-zoom on focus: inputs need >=16px font */
  input, select, textarea { font-size: 16px !important; }

  /* The Documents mode-tabs / My Handwriting sub-tabs row holds more tabs
     than fit a phone's width. A horizontal scroller hides the later tabs
     with no affordance that they exist, so wrap them into a visible grid
     instead — every tab stays on screen and reachable. */
  .mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    max-width: 100%;
  }
  /* full-width grid on phones, so undo the desktop hug-content rule */
  #doc-panel > .mode-tabs { align-self: stretch; }
  .mode-tab, .chart-sub-tab {
    min-width: 0;
    white-space: normal;
    padding: 10px 8px;
    font-size: 0.82rem;
    line-height: 1.25;
    border-left: none !important;
  }
  /* Grid cells need their own dividers now that the flex-sibling
     border-left rule no longer lines up with the visual columns. */
  .mode-tabs > *:nth-child(2n) { border-left: 1.5px solid var(--line-strong) !important; }
  .mode-tabs > *:nth-child(n + 3) { border-top: 1.5px solid var(--line-strong); }
}

/* ---------- Sidebar bottom / dark mode toggle ---------- */
.sidebar-bottom { margin-top: auto; }
.theme-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 8px 12px;
}
.wallet-card { margin-top: 0; }

/* ---------- Boot gate (shown until we know sign-in status) ---------- */
.boot-loading {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: var(--paper-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.boot-loading .brand-mark {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--navy);
  color: var(--paper);
  font-family: "Caveat", cursive;
  font-size: 2rem;
  display: grid;
  place-items: center;
  animation: boot-pulse 1.1s ease-in-out infinite;
}
@keyframes boot-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .6; transform: scale(.94); } }

/* ---------- Full-page sign in / create account ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--paper-bg);
  background-image: radial-gradient(rgba(29,36,51,.028) 1px, transparent 1px);
  background-size: 22px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.auth-close {
  position: absolute;
  top: 18px; right: 22px;
  background: transparent;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
}
.auth-close:hover { color: var(--ink); }
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--elev-4);
  padding: 36px 32px;
  margin: 20px 0;
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 28px; }
.auth-brand .brand-mark { width: 36px; height: 36px; font-size: 1.6rem; }
.auth-brand .brand-name { font-size: 1.9rem; color: var(--navy); }
.auth-view h2 { font-size: 1.4rem; font-weight: 600; text-align: center; margin-bottom: 6px; }
.auth-view > .hint { text-align: center; margin-bottom: 20px; }
.banned-card .banned-icon { font-size: 2.6rem; text-align: center; margin-bottom: 10px; }
.banned-card .hint { margin-bottom: 0; }
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  font-weight: 600;
  text-decoration: none;
}
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 0.82rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-mode-tabs { display: flex; width: 100%; margin-bottom: 18px; }
.auth-mode-tab { flex: 1; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: 9px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--panel-2);
  color: var(--ink);
}
.auth-form .btn-lg { width: 100%; }
.auth-error { color: var(--red); text-align: center; min-height: 1.2em; margin-top: 12px; }
.auth-switch { text-align: center; margin-top: 18px; }
.tos-check {
  display: flex; align-items: flex-start; gap: 8px; font-size: 0.8rem; color: var(--muted);
  line-height: 1.4; margin: 4px 0 14px; cursor: pointer;
}
.tos-check input { margin-top: 2px; flex-shrink: 0; }
.tos-check a { color: var(--navy); }
.link-btn { background: none; border: none; color: var(--navy); font-weight: 700; cursor: pointer; text-decoration: underline; font-size: inherit; padding: 0; }

/* ---------- Account ---------- */
.account-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.account-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.account-form h4 { font-size: 0.92rem; font-weight: 700; margin-bottom: 2px; }
.account-form input {
  padding: 9px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--panel);
  color: var(--ink);
}
#account-error { color: var(--red); margin-top: 10px; min-height: 1.2em; }
.account-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.account-row b { display: block; font-size: 0.98rem; }
.account-row .hint { margin: 2px 0 0; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) { .account-forms { grid-template-columns: 1fr; } }

/* ---------- Section titles ---------- */
.section-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 8px; }

/* ---------- Signature ---------- */
#sig-canvas {
  width: 100%;
  max-width: 700px;
  height: 160px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--paper);
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Language pack grid (shares chart-grid look) ---------- */
#lang-pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 11px;
  margin-top: 12px;
}

/* ---------- Mood toggle ---------- */
.mood-toggle { display: inline-flex; border: 1.5px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.mood-btn { background: transparent; border: none; padding: 7px 14px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.mood-btn + .mood-btn { border-left: 1.5px solid var(--line-strong); }
.mood-btn.active { background: var(--navy); color: var(--paper); }

/* ---------- Confidence dots ---------- */
.conf-dot {
  position: absolute;
  top: -5px; left: -5px;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--paper);
}
.conf-dot.conf-high, #confidence-legend .conf-high { background: var(--green); }
.conf-dot.conf-medium, #confidence-legend .conf-medium { background: #d9a441; }
.conf-dot.conf-low, #confidence-legend .conf-low { background: var(--red); }
#confidence-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
#confidence-legend .conf-dot { position: static; display: inline-block; border: none; margin-left: 8px; }

/* ---------- Batch upload list ---------- */
#batch-list:not(:empty) { margin-bottom: 16px; }
.batch-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.batch-head span { font-weight: 600; font-size: 0.88rem; color: var(--muted); }
.batch-items { display: flex; flex-direction: column; gap: 6px; }
.batch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  background: var(--panel);
}
.batch-item:hover { border-color: var(--navy); }
.batch-item.active { border-color: var(--navy); background: var(--panel-2); }
.batch-status { width: 9px; height: 9px; border-radius: 50%; background: #c9c0a5; flex-shrink: 0; }
.batch-status.batch-done { background: var(--green); }
.batch-status.batch-error { background: var(--red); }
.batch-name { flex: 1; font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-pages { font-size: 0.78rem; color: var(--muted); }

/* ---------- Usage dashboard ---------- */
#usage-chart { display: flex; align-items: flex-end; gap: 14px; height: 130px; padding-top: 10px; }
.usage-bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; }
.usage-bar { width: 100%; max-width: 34px; background: var(--navy); border-radius: 5px 5px 0 0; }
.usage-bar-col span { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.usage-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 0.83rem;
  color: var(--muted);
}
.usage-row span:last-child { color: var(--ink); font-weight: 600; text-align: right; }

/* ---------- Referral ---------- */
.referral-panel { margin-top: 20px; }
.referral-input {
  flex: 1;
  min-width: 180px;
  padding: 9px 13px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  background: var(--panel-2);
  color: var(--ink);
}

/* ---------- Dark mode ---------- */
body.dark {
  --paper-bg: #14151c;
  --panel: #1b1d26;
  --panel-2: #21232e;
  --ink: #e9e8e2;
  --navy: #7c8fe0;
  --muted: #9a9689;
  --line: #33353f;
  --line-strong: #43454f;
  --red: #e0755a;
  --red-soft: #3a2620;
  --green: #5cb679;
}
body.dark { background-image: radial-gradient(rgba(255,255,255,.03) 1px, transparent 1px); }
body.dark .plan-card.popular { background: #10142e; border-color: var(--navy); }
body.dark .plan-card.popular .plan-btn { background: var(--paper-bg); color: var(--navy); }

/* ---------- Mobile touch targets & bottom-sheet popovers ---------- */
@media (max-width: 600px) {
  .answer-box .del { width: 30px; height: 30px; font-size: 16px; line-height: 30px; top: -15px; right: -15px; }
  .answer-box { padding: 6px; }
  .icon-btn, .btn-primary, .btn-ghost, .file-btn, .plan-btn, .pack-btn, .mode-tab, .chart-sub-tab, .mood-btn { padding: 12px 16px; font-size: 0.92rem; }
  input[type="range"] { width: 100%; height: 26px; }
  .toolbar { row-gap: 12px; }
  .toolbar label { font-size: 0.88rem; width: 100%; justify-content: space-between; }
  .swatch { width: 30px; height: 30px; }

  .toolbar-main { flex-wrap: wrap; }
  .toolbar-main > .file-btn, .toolbar-main > #analyze-btn, .toolbar-main > #export-btn {
    flex: 1 1 auto;
    text-align: center;
    min-width: 120px;
  }

  /* Keep Upload + Analyze front and center; everything else (Write all
     pages, Style, Tools, Export) drops to its own row below so the primary
     "upload a file" action isn't buried in a wall of buttons. */
  .toolbar-main > .file-btn { order: 1; flex: 1 1 100%; }
  .toolbar-main > .split-btn { order: 2; flex: 1 1 auto; }
  .toolbar-main > #analyze-cost-chip { order: 3; align-self: center; }
  .toolbar-main > .spacer { display: none; }
  .toolbar-main > #write-all-btn,
  .toolbar-main > .popover-wrap,
  .toolbar-main > #export-btn {
    order: 4;
    flex: 1 1 auto;
    min-width: 90px;
  }
  .toolbar-main > #page-nav { order: 4; }

  .popover-wrap { position: static; }
  .popover {
    position: fixed;
    left: 0; right: 0; top: auto;
    bottom: 0;
    width: auto;
    min-width: 0;
    max-height: 75vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
    z-index: 160;
    box-shadow: 0 -10px 40px rgba(29,36,51,.25);
    animation: sheet-up .2s cubic-bezier(.2,.9,.3,1.1);
  }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
  body.popover-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(20,21,28,.4);
    z-index: 150;
  }
  .popover::after {
    content: "";
    display: block;
    position: sticky;
    top: -18px;
    margin: -18px auto 10px;
    width: 40px; height: 4px;
    border-radius: 999px;
    background: var(--line-strong);
  }

  #chart-grid, #lang-pack-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
  }

  .modal { position: fixed; left: 12px; right: 12px; bottom: 12px; width: auto; }
}
