/* ============================================================
   vibetool.app — styles
   Dark-only theme, Space Grotesk, glassy chrome, gradient brand
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --bg-0: #0A0A0F;
  --bg-1: #101018;
  --bg-2: #16161F;
  --bg-3: #1D1D29;
  --surface-glass: rgba(22, 22, 31, 0.72);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text-primary: #F2F2F7;
  --text-secondary: #A0A0B2;
  --text-tertiary: #8A8A97;
  --text-on-accent: #0A0A0F;
  --accent: #8B5CF6;
  --accent-bright: #A78BFA;
  --accent-cyan: #22D3EE;
  --gradient-brand: linear-gradient(120deg, #8B5CF6 0%, #6366F1 45%, #22D3EE 100%);
  --glow-accent: 0 0 24px rgba(139, 92, 246, 0.35);
  --success: #34D399;
  --warning: #FBBF24;
  --danger: #F87171;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 999px;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);

  --ease-default: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 180ms var(--ease-default);
  --t-spring: 420ms var(--ease-spring);

  --font-ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, Menlo, monospace;

  --header-h: 56px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules
   (e.g. #workspace is display:flex, which would otherwise override it). */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
input, textarea { font-family: inherit; color: var(--text-primary); }
a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h2 { font-size: 20px; font-weight: 700; margin: 0; }

.micro-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}

/* ---------- Page background ---------- */
.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.bg-glow-violet { background: radial-gradient(560px 380px at 70% -10%, rgba(139, 92, 246, 0.08), transparent); }
.bg-glow-cyan   { background: radial-gradient(480px 380px at 15% 110%, rgba(34, 211, 238, 0.045), transparent); }
.bg-dots {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, transparent 55vh);
  mask-image: linear-gradient(to bottom, #000 0, transparent 55vh);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}
.wordmark {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: filter var(--t-fast);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  user-select: none;
}
.wordmark-grad {
  background: var(--gradient-brand);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: grad-pan 6s linear 1 forwards;
}
.wordmark:hover { filter: brightness(1.15); opacity: 0.85; }
.wordmark-tld { color: var(--text-tertiary); font-weight: 500; }
@keyframes grad-pan {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 32px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-full);
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.status-pill:hover { border-color: var(--border-strong); background: var(--bg-3); }
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex: none;
}
.pill-dot.warn {
  background: var(--warning);
  animation: pill-pulse 1.2s ease-in-out 3;
}
@keyframes pill-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(251, 191, 36, 0); }
}
.pill-text {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Header account control (SIMPLE-UI) ---------- */
.header-account { position: relative; display: flex; align-items: center; }
.header-signedout { display: flex; align-items: center; }
/* GIS rendered button sits in a light-scheme box so Google's branding renders. */
.header-google-btn { min-height: 36px; display: flex; align-items: center; color-scheme: light; }
.header-google-btn:empty { display: none; }
/* Styled fallback button (GIS unavailable / not configured). */
.header-signin-fallback {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-full);
  background: #fff;
  color: #1f1f1f;
  border: 1px solid var(--border-default);
  font-size: 13px;
  font-weight: 600;
  transition: filter var(--t-fast);
}
.header-signin-fallback:hover { filter: brightness(0.96); }
.header-signin-fallback .g-mark { flex: none; }

.header-account-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-full);
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.header-account-chip:hover { border-color: var(--border-strong); background: var(--bg-3); }
.header-avatar {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--gradient-brand) center/cover no-repeat;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-on-accent);
  text-transform: uppercase;
}
.header-account-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--bg-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}
.header-menu-email {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-menu-signout {
  text-align: left;
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-3);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.header-menu-signout:hover { border-color: var(--border-strong); color: var(--text-primary); }
.header-menu-admin {
  text-align: left;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: var(--r-sm);
  color: var(--accent-bright);
  font-size: 13px;
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.header-menu-admin:hover { background: rgba(139, 92, 246, 0.2); border-color: var(--accent); }
.header-menu-admin:disabled { opacity: 0.5; cursor: progress; }

/* Very narrow screens: shrink the signed-out fallback + signed-in chip. */
@media (max-width: 420px) {
  .header-signin-fallback { padding: 0 var(--sp-2); }
  .header-account-name { display: none; }
  .header-account-chip { padding: 0; width: 36px; justify-content: center; }
}

/* ---------- Layout ---------- */
#main { position: relative; z-index: 1; }

/* ---------- Hero ---------- */
.hero {
  max-width: 720px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
  text-align: center;
}
.hero.leaving {
  animation: hero-out 200ms var(--ease-default) forwards;
}
@keyframes hero-out {
  to { opacity: 0; transform: translateY(-8px); }
}
.hero-title {
  font-size: clamp(32px, 5.5vw, 44px);
  line-height: 1.1;
  font-weight: 700;
  margin: 0 0 var(--sp-4);
  letter-spacing: -0.02em;
}
.grad-word {
  background: var(--gradient-brand);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: grad-pan 6s linear 1 forwards;
}
.hero-sub {
  color: var(--text-tertiary);
  margin: 0 auto var(--sp-7);
  max-width: 500px;
  font-size: 16px;
  line-height: 1.55;
}
.hero-hint {
  margin: calc(var(--sp-4) * -1) 0 var(--sp-6);
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 540px;
}

/* ---------- Prompt box ---------- */
.promptbox {
  position: relative;
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.promptbox:focus-within {
  border-color: rgba(139, 92, 246, 0.6);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.promptbox-hero {
  border-radius: var(--r-xl);
  min-height: 120px;
  padding: var(--sp-4) var(--sp-4) var(--sp-7);
}
.promptbox-compact {
  border-radius: var(--r-lg);
  min-height: 56px;
  padding: var(--sp-3) var(--sp-3) 44px;
}
.prompt-input {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  padding: 0;
  text-align: left;
}
.prompt-input::placeholder { color: var(--text-tertiary); }

.enter-hint {
  position: absolute;
  left: var(--sp-4);
  bottom: var(--sp-3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity var(--t-fast);
  pointer-events: none;
}
.enter-hint.show { opacity: 1; }
.promptbox-compact .enter-hint { left: var(--sp-3); bottom: 10px; }

.btn-generate {
  position: absolute;
  right: var(--sp-3);
  bottom: var(--sp-3);
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  border: none;
  border-radius: var(--r-md);
  background: var(--gradient-brand);
  color: var(--text-on-accent);
  font-size: 14px;
  font-weight: 700;
  transition: filter var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast);
}
.btn-generate:hover:not(:disabled) { filter: brightness(1.1); box-shadow: var(--glow-accent); }
.btn-generate:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-generate-sm { right: 10px; bottom: 8px; height: 32px; font-size: 13px; padding: 0 var(--sp-3); }

.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgba(10, 10, 15, 0.25);
  border-top-color: var(--text-on-accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Typewriter ghost placeholder */
.typewriter {
  position: absolute;
  top: var(--sp-4);
  left: var(--sp-4);
  right: var(--sp-4);
  color: var(--text-tertiary);
  pointer-events: none;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.typewriter[hidden] { display: none; }
.tw-caret {
  display: inline-block;
  width: 1px;
  height: 1.1em;
  margin-left: 2px;
  background: var(--text-secondary);
  vertical-align: text-bottom;
  animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* ---------- Example chips ---------- */
.chips-label {
  margin: var(--sp-5) 0 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  text-align: center;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
.chip {
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-4);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }

.chip-back {
  margin-top: var(--sp-4);
  color: var(--accent-bright);
}
.chip-back:hover { color: var(--accent-bright); }

/* ---------- Workspace (split view) ---------- */
.workspace {
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}
.workspace.entering {
  animation: split-in 300ms var(--ease-default) 100ms backwards;
}
@keyframes split-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Left rail */
.rail {
  width: 360px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-1);
  min-height: 0;
}
@media (max-width: 1100px) { .rail { width: 320px; } }

.rail-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}
.rail-head .rail-close { margin-left: auto; }

/* Cloud-sync indicator (rail head, signed-in only) */
.sync-ind {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.sync-ind.ok { color: var(--success); }
.sync-ind.err { color: var(--warning); }
.sync-spin {
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent-bright);
  animation: spin 0.8s linear infinite;
}
.history {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2);
  min-height: 0;
}
.history-empty {
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  padding: var(--sp-5);
}
.history-empty-title {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13px;
  margin-bottom: var(--sp-1);
}
.history-empty-hint {
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
}
.hist-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-3);
  color: var(--text-secondary);
  font-size: 13px;
  transition: background var(--t-fast), color var(--t-fast);
  overflow: hidden;
}
.hist-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--t-fast);
}
.hist-item:hover { background: var(--bg-3); color: var(--text-primary); }
.hist-item:hover::before { opacity: 1; }
.hist-item.active { background: var(--bg-3); color: var(--text-primary); }
.hist-item.active::before { opacity: 1; }
.hist-item.indent { margin-left: var(--sp-4); width: calc(100% - var(--sp-4)); }
.hist-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.hist-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-item.flash {
  animation: hist-flash 600ms ease-out;
}
@keyframes hist-flash {
  from { background: var(--bg-3); }
  to   { background: transparent; }
}
.hist-status { flex: none; display: inline-flex; align-items: center; }
.hist-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent-bright);
  animation: spin 0.8s linear infinite;
}
.hist-fail {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: var(--danger);
  font-size: 11px;
  font-weight: 500;
}
.hist-fail::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}
.hist-retry {
  color: var(--accent-bright);
  font-size: 11px;
  font-weight: 500;
}
.hist-item:hover .hist-retry { text-decoration: underline; }
.hist-del {
  flex: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1;
  padding: var(--sp-1);
  border-radius: var(--r-sm);
  opacity: 0.55;
  transition: opacity var(--t-fast), color var(--t-fast);
}
.hist-item:hover .hist-del { opacity: 1; }
.hist-del:hover { color: var(--danger); }
.hist-rename {
  flex: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  line-height: 0;
  padding: var(--sp-1);
  border-radius: var(--r-sm);
  opacity: 0.55;
  transition: opacity var(--t-fast), color var(--t-fast);
}
.hist-rename svg { display: block; width: 13px; height: 13px; }
.hist-item:hover .hist-rename { opacity: 1; }
.hist-rename:hover { color: var(--accent-bright); }
.hist-rename-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font: inherit;
  padding: 2px 6px;
  outline: none;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

/* Collapsed rail (desktop, fine pointer): history hidden, dock moves into the
   pane. Excludes touch-primary devices — they use the bottom-sheet rail. */
@media (min-width: 769px) and (pointer: fine) {
  .workspace.rail-collapsed .rail { display: none; }
  .workspace.rail-collapsed #btnHistory { display: inline-flex; }
}
.dock.in-pane {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
}

/* Dock (compact prompt) */
.dock {
  flex: none;
  border-top: 1px solid var(--border-subtle);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--bg-1);
}
.mode-toggle {
  display: inline-flex;
  gap: var(--sp-1);
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  padding: 3px;
  align-self: flex-start;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  transition: background var(--t-fast), color var(--t-fast);
}
.mode-btn.active { background: var(--bg-3); color: var(--text-primary); }
.mode-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Fast / Quality choice — compact segmented control (no model names).
   Mirrors .mode-toggle / .mode-btn; the active segment uses the brand accent. */
.gen-mode {
  display: inline-flex;
  gap: var(--sp-1);
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  padding: 3px;
  flex: none;
}
.gen-mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.gen-mode-btn:hover { color: var(--text-primary); }
.gen-mode-btn.active { background: var(--accent); color: var(--text-on-accent); }
/* Hero variant: the hero is a centered flex column, so alignment is inherited;
   just give it breathing room below the prompt box. */
.gen-mode-hero { margin-top: var(--sp-4); }

/* Right pane */
.pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp-4);
  gap: var(--sp-4);
  min-height: 0;
}
.tabbar {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.seg {
  position: relative;
  display: inline-flex;
  gap: var(--sp-1);
  background: var(--bg-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: 3px;
}
.seg-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--r-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
.seg-btn.active { background: var(--bg-3); color: var(--text-primary); }
.seg-underline {
  position: absolute;
  bottom: -1px;
  left: 0;
  height: 2px;
  width: 60px;
  background: var(--gradient-brand);
  border-radius: var(--r-full);
  transition: transform 200ms var(--ease-default), width 200ms var(--ease-default);
}
.tools { display: flex; align-items: center; gap: var(--sp-1); }

/* Current tool title, centered between tabs and tools */
.tab-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 16px;
}
.tab-title-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ver-pill {
  flex: none;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  color: var(--accent-bright);
  margin-left: 8px;
}
@media (max-width: 768px), (pointer: coarse) {
  .tab-title { display: none; }
}

/* Labeled history pill (desktop, collapsed rail) */
#btnHistory.pill-label {
  width: auto;
  padding: 0 var(--sp-3);
  border-radius: var(--r-full);
  border: 1px solid var(--border-default);
  background: var(--bg-2);
  font-size: 12px;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-primary); border-color: var(--border-subtle); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
#btnHistory { display: none; }

/* Incomplete notice */
.notice {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 13px;
}
.notice-warn {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--warning);
}
.notice-action {
  background: transparent;
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: var(--r-sm);
  color: var(--warning);
  font-size: 12px;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  transition: background var(--t-fast);
  white-space: nowrap;
}
.notice-action:hover { background: rgba(251, 191, 36, 0.12); }
.notice-info {
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: var(--accent-bright);
}
.notice-info .notice-action {
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--accent-bright);
}
.notice-info .notice-action:hover { background: rgba(139, 92, 246, 0.12); }

/* Views */
.viewwrap { flex: 1; position: relative; min-height: 0; }
.view {
  position: absolute;
  inset: 0;
  display: none;
}
.view.active { display: block; }

.iframe-shell {
  width: 100%;
  height: 100%;
  background: #fff;
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.iframe-shell iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
}
.iframe-shell.reveal iframe {
  animation: iframe-reveal var(--t-spring) backwards;
}
@keyframes iframe-reveal {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ============================================================
   Fullscreen preview mode — the CURRENT preview's iframe-shell is
   restyled to cover the whole viewport (same iframe, state preserved).
   Toggled by body.preview-fs (set in app.js).
   ============================================================ */
body.preview-fs .iframe-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 1000;
  border: none;
  border-radius: 0;
  background: #fff;
}
/* The preview pane must stay laid-out so the iframe keeps painting; force its
   view visible regardless of the active tab so fullscreen works from Code too. */
body.preview-fs #viewPreview { display: block; }
body.preview-fs { overflow: hidden; }
/* #main is z-index:1 with its own stacking context, and the header is z-index:40.
   A fixed descendant of #main can't beat the header from inside that context, so
   lift #main above the header while fullscreen — the fixed shell/bar then cover
   the whole viewport including the header (and its Google button). */
body.preview-fs #main { z-index: 100; }

/* Floating control bar over the fullscreen preview (top-right). */
.fs-bar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 1001;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 8px 6px 12px;
  border-radius: var(--r-full);
  background: rgba(16, 16, 24, 0.72);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 24px);
}
.fs-title {
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.fs-refine {
  flex: none;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r-full);
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.5);
  color: var(--accent-bright);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.fs-refine:hover { background: rgba(139, 92, 246, 0.28); border-color: var(--accent); }
.fs-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-default);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  transition: background var(--t-fast);
}
.fs-close:hover { background: rgba(255, 255, 255, 0.2); }

.view-code { display: none; }
.view-code.active { display: block; }
.code-pre {
  margin: 0;
  height: 100%;
  overflow: auto;
  background: var(--bg-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Streaming overlay — overlays the preview pane during generation/fetch.
   High z-index so it sits above the iframe; .viewwrap is position:relative. */
.stream-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  background: linear-gradient(180deg, rgba(16, 16, 24, 0.45) 0%, rgba(16, 16, 24, 0.85) 100%);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.stream-overlay[hidden] { display: none; }
.stream-status {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}
.shimmer {
  width: 240px;
  height: 4px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.shimmer-bar {
  width: 40%;
  height: 100%;
  border-radius: var(--r-full);
  background: var(--gradient-brand);
  animation: shimmer-slide 1.4s ease-in-out infinite;
}
@keyframes shimmer-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.stream-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  max-width: 260px;
  text-align: center;
}
.stream-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
}
.stream-elapsed { font-family: var(--font-mono); }
.btn-stop {
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-full);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-4);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.btn-stop:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- Settings drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 280ms ease-out;
}
.drawer-backdrop.open { opacity: 1; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  width: 400px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 280ms ease-out;
  visibility: hidden;
}
.drawer.open { transform: translateX(0); visibility: visible; }
.drawer-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
}
.key-banner {
  flex: none;
  margin: var(--sp-4) var(--sp-5) 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: var(--accent-bright);
  font-size: 13px;
  line-height: 1.45;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.provider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.provider-card {
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.provider-card:hover { border-color: var(--border-strong); }
.provider-card.active {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}
.provider-card .p-name { display: block; font-size: 14px; font-weight: 700; }
.provider-card .p-desc { display: block; font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.provider-card .p-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--success);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: var(--r-full);
}

.banner-tip {
  margin-top: var(--sp-2);
  font-size: 12px;
  color: var(--text-secondary);
}

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.label-hint { color: var(--text-tertiary); font-weight: 400; }
.field-row { display: flex; align-items: center; justify-content: space-between; }
.get-key { font-size: 12px; font-weight: 500; }
.field input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field input:focus {
  border-color: rgba(139, 92, 246, 0.6);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.key-row { position: relative; }
.key-row input { padding-right: 40px; }
.key-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}
.model-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.model-chip {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  padding: 2px var(--sp-3);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.model-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.model-chip.selected { border-color: var(--accent); color: var(--accent-bright); }

.test-row { display: flex; align-items: center; gap: var(--sp-3); min-height: 32px; }
.btn-test {
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-4);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.btn-test:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg-3); }
.btn-test:disabled { opacity: 0.5; cursor: wait; }
.test-result { font-size: 13px; min-width: 0; }
.test-result.ok { color: var(--success); }
.test-result.fail { color: var(--danger); }

.trust-line {
  flex: none;
  margin: 0;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
}

/* Account / Google sign-in (settings drawer) */
.account-box {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}
.account-signedout { display: flex; flex-direction: column; gap: var(--sp-2); }
.account-hint { margin: 0; font-size: 12px; color: var(--text-tertiary); }
#googleBtn { min-height: 40px; color-scheme: light; }
.account-signedin { display: flex; align-items: center; gap: var(--sp-2); }
.account-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--r-full);
  background: var(--gradient-brand) center/cover no-repeat;
  flex: none;
}
.account-email {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-signout {
  flex: none;
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.btn-signout:hover { border-color: var(--border-strong); color: var(--text-primary); }

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

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  /* Toasts must be the topmost surface so feedback is never painted behind the
     fullscreen preview shell (1000) or the library modal (90). */
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
  width: min(400px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-3) var(--sp-4);
  font-size: 13px;
  color: var(--text-primary);
  animation: toast-in 250ms var(--ease-spring) backwards;
}
.toast.leaving { animation: toast-out 200ms var(--ease-default) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}
.toast.success { border-left-color: var(--success); }
.toast.warn    { border-left-color: var(--warning); }
.toast.error   { border-left-color: var(--danger); }
.toast-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.toast-btn {
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  transition: border-color var(--t-fast);
}
.toast-btn:hover { border-color: var(--border-strong); }

/* Rail backdrop (mobile sheet) */
.rail-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, 0.5);
}

/* ============================================================
   Responsive ≤768px — also touch-primary (pointer:coarse) at any width,
   so touch laptops get the app-style layout and the bottom-sheet rail.
   ============================================================ */
@media (max-width: 768px), (pointer: coarse) {
  .pill-text { display: none; }
  .status-pill { padding: 0 var(--sp-3); }

  .chips {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    width: 100%;
    padding-bottom: var(--sp-1);
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
    mask-image: linear-gradient(to right, #000 88%, transparent);
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }

  /* Mobile is an app screen, not a scrolled page: lock the workspace to the
     viewport so the preview fills it and full-height tools don't get a scrollbar. */
  .workspace {
    flex-direction: column;
    height: calc(100dvh - var(--header-h));
    min-height: 0;
    overflow: hidden;
  }

  .pane {
    order: 1;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
    gap: 0;
    /* Room for the JS-relocated floating dock. --dock-h is set at runtime from the
       dock's measured height; 150px is the pre-JS fallback so nothing overlaps. */
    padding-bottom: calc(var(--dock-h, 150px) + env(safe-area-inset-bottom, 0px));
  }

  /* Slim native action bar directly under the header — no Preview/Code toggle. */
  .tabbar {
    order: 0;
    height: 48px;
    flex: none;
    padding: 0 var(--sp-2) 0 var(--sp-4);
    gap: var(--sp-1);
    border-bottom: 1px solid var(--border-subtle);
  }
  .seg { display: none; }
  .tab-title { display: flex; margin: 0; justify-content: flex-start; }
  .tab-title-text { font-size: 15px; color: var(--text-primary); }
  #btnHistory { display: inline-flex; }

  /* Preview fills all remaining space, edge-to-edge like a real app screen. */
  .viewwrap { order: 1; flex: 1; min-height: 0; height: auto; }
  .iframe-shell { border: none; border-radius: 0; }
  /* Match the square mobile shell so the generating overlay's rounded corners
     don't let the white shell bleed through during a build. */
  .stream-overlay, .fetch-overlay { border-radius: 0; }
  .notice { order: 0; flex: none; }

  /* History rail becomes a bottom sheet */
  .rail {
    order: 2;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    width: 100%;
    max-height: 60vh; /* fallback for browsers without dvh */
    max-height: 60dvh; /* exclude mobile browser chrome, like the rest of the app */
    border-right: none;
    border-top: 1px solid var(--border-default);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform 280ms ease-out;
    visibility: hidden;
  }
  .rail.open { transform: translateY(0); visibility: visible; }
  .rail::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: var(--r-full);
    background: var(--border-strong);
    margin: var(--sp-2) auto 0;
    flex: none;
  }
  .rail-close { display: inline-flex; }
  .rail-backdrop.open { display: block; }

  /* Dock gets relocated to <body> by JS and fixed to viewport bottom.
     Compacted on mobile so the preview gets as much height as possible:
     tighter padding/gaps, a slimmer secondary control row, and a shorter
     input — every px saved here is published into --dock-h and given back
     to the preview pane. */
  .dock.floating {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom, 0px));
  }
  /* Slim the secondary control row (mode toggle · quota · device pill). */
  .dock.floating .dock-toprow { gap: var(--sp-1); }
  .dock.floating .mode-toggle { padding: 2px; }
  .dock.floating .mode-btn { padding: 3px var(--sp-2); font-size: 11px; }
  .dock.floating .gen-mode { padding: 2px; }
  .dock.floating .gen-mode-btn { padding: 3px var(--sp-2); font-size: 11px; }
  .dock.floating .target-pill { height: 26px; }
  /* Shorter input box so the dock's resting height is minimal; it still grows. */
  .dock.floating .promptbox-compact { min-height: 48px; padding: var(--sp-2) var(--sp-3) 40px; }

  .drawer { width: 100%; border-left: none; }

  /* Share: keep the labeled button, drop the divider; popover is replaced
     by the bottom sheet on small screens. */
  .tools-divider { display: none; }
  .share-popover { display: none !important; }

  /* Fullscreen is the primary mobile escape hatch for clipped tools — make it
     prominent: an accent-tinted, larger tap target in the action bar. */
  .btn-fullscreen {
    width: 34px;
    height: 34px;
    color: var(--accent-bright);
    border-color: rgba(139, 92, 246, 0.45);
    background: rgba(139, 92, 246, 0.10);
  }
  .btn-fullscreen svg { width: 17px; height: 17px; }
}

/* ============================================================
   Share — toolbar button, popover (desktop), bottom sheet (mobile)
   ============================================================ */
.btn-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--bg-2);
  border: 1px solid rgba(139, 92, 246, 0.45);
  color: var(--accent-bright);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast);
}
.btn-share:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.10);
  box-shadow: var(--glow-accent);
}
.btn-share:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-share svg { flex: none; }
.btn-share .share-spin {
  display: none;
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgba(167, 139, 250, 0.3);
  border-top-color: var(--accent-bright);
  animation: spin 0.8s linear infinite;
}
.btn-share.busy svg,
.btn-share.busy .btn-share-label { display: none; }
.btn-share.busy .share-spin { display: inline-block; }
.tools-divider {
  width: 1px;
  height: 16px;
  flex: none;
  background: var(--border-default);
  margin: 0 var(--sp-2);
}

.share-popover {
  position: fixed;
  z-index: 70;
  width: 320px;
  background: var(--bg-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  transform-origin: top right;
}
.share-popover.in { animation: share-pop 180ms var(--ease-spring) backwards; }
@keyframes share-pop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
.share-title-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.share-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.share-title-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  padding: 0 var(--sp-3);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--t-fast);
}
.share-title-input:focus { border-color: rgba(139, 92, 246, 0.6); }
.share-title-row .ver-pill { margin-left: 0; }
.share-link-row { display: flex; gap: var(--sp-2); }
.share-link-row input {
  flex: 1;
  min-width: 0;
  height: 36px;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 0 var(--sp-3);
  color: var(--text-secondary);
  outline: none;
  transition: opacity var(--t-fast);
}
.share-link-row input:focus { border-color: rgba(139, 92, 246, 0.6); }
.share-link-row input.revoked { text-decoration: line-through; opacity: 0.4; }
.share-copy {
  flex: none;
  height: 36px;
  padding: 0 var(--sp-4);
  border: none;
  border-radius: var(--r-sm);
  background: var(--gradient-brand);
  color: var(--text-on-accent);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: filter var(--t-fast);
}
.share-copy:hover { filter: brightness(1.1); }
.share-copy.copied { background: var(--success); }
.share-qr-row { display: flex; align-items: center; gap: var(--sp-3); }
.share-qr-tile {
  width: 112px;
  height: 112px;
  flex: none;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-qr-tile canvas {
  width: 104px;
  height: 104px;
  display: block;
  image-rendering: pixelated;
}
.share-qr-caption {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.share-foot {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--sp-3);
  display: flex;
  align-items: flex-end;
  gap: var(--sp-3);
}
.share-foot-text {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.share-revoke {
  flex: none;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.share-revoke:hover { text-decoration: underline; }

.share-backdrop {
  position: fixed;
  inset: 0;
  z-index: 69;
  background: rgba(0, 0, 0, 0.5);
}
.share-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  background: var(--bg-1);
  border-top: 1px solid var(--border-default);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  transform: translateY(100%);
  transition: transform 280ms ease-out;
  visibility: hidden;
}
.share-sheet.open { transform: translateY(0); visibility: visible; }
.share-sheet::before {
  content: "";
  display: block;
  width: 40px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  margin: 0 auto var(--sp-1);
  flex: none;
}
.share-more {
  height: 44px;
  width: 100%;
  border-radius: var(--r-md);
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.share-more:hover { border-color: var(--border-strong); background: var(--bg-3); }

/* Drawer attention state for the share→sign-in path */
.account-box.attention {
  border: 1px solid rgba(139, 92, 246, 0.5);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  box-shadow: var(--glow-accent);
}
.account-line {
  margin: 0;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ============================================================
   Quota — dock meter, inline notices
   ============================================================ */
.dock-toprow {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.quota-meter {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  background: transparent;
  border: none;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  transition: color var(--t-fast), background var(--t-fast);
}
.quota-meter:hover { color: var(--text-secondary); background: var(--bg-2); }
.quota-meter.low { color: var(--warning); }
.quota-dots { display: inline-flex; align-items: center; gap: 3px; }
.quota-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gradient-brand);
}
.quota-dot.used {
  background: var(--bg-3);
  border: 1px solid var(--border-default);
}

.quota-notice { text-align: left; }
.quota-notice .q-lines {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.quota-notice .q-line1 { font-size: 13px; }
.notice-info .q-line1 { color: var(--accent-bright); }
.quota-notice .q-line2 { font-size: 11px; color: var(--text-tertiary); }
.quota-notice.q-in { animation: qn-in 250ms var(--ease-default) backwards; }
@keyframes qn-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.quota-notice.q-fade { opacity: 0; transition: opacity 200ms ease; }
.quota-notice.q-flash { animation: qn-flash 600ms ease; }
@keyframes qn-flash {
  0%, 100% { box-shadow: none; }
  30%      { box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.35); }
}
#heroQuotaNotice { width: 100%; margin-top: var(--sp-3); }
#dockQuotaNotice { padding: var(--sp-2) var(--sp-3); }

/* ============================================================
   Cloud sync — history skeletons, cloud glyph, anonymous nudge
   ============================================================ */
.hist-skel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--sp-3);
}
.skel-bar {
  height: 12px;
  border-radius: 4px;
  background: var(--bg-3);
  animation: skel-pulse 1.4s ease-in-out infinite;
}
.skel-bar.s1 { width: 65%; }
.skel-bar.s2 { width: 40%; height: 9px; }
@keyframes skel-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
.hist-cloud {
  display: inline-flex;
  align-items: center;
  color: var(--text-tertiary);
}
.fetch-overlay { z-index: 5; }

.sync-nudge {
  position: relative;
  flex: none;
  margin: var(--sp-2) var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}
.sync-nudge p {
  margin: 0 18px var(--sp-2) 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.sync-nudge .notice-action {
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--accent-bright);
}
.sync-nudge .notice-action:hover { background: rgba(139, 92, 246, 0.12); }
.sync-nudge-x {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 11px;
  line-height: 1;
  padding: 4px;
  border-radius: var(--r-sm);
  transition: color var(--t-fast);
}
.sync-nudge-x:hover { color: var(--text-primary); }

/* ============================================================
   Public tools — share visibility rows
   ============================================================ */
.share-vis { display: flex; flex-direction: column; gap: var(--sp-2); }
.vis-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  width: 100%;
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.vis-row:hover { border-color: var(--border-strong); }
.vis-row.active {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}
.vis-row.locked { opacity: 0.55; }
.vis-glyph {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  color: var(--accent-bright);
}
.vis-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vis-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.vis-sub { font-size: 11px; color: var(--text-tertiary); line-height: 1.45; }
.vis-check {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.vis-row.active .vis-check {
  border-color: var(--accent);
  background: radial-gradient(circle at center, var(--accent-bright) 0 4px, transparent 5px);
}
.vis-name { display: flex; flex-direction: column; gap: 4px; }
.vis-name input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  outline: none;
  transition: border-color var(--t-fast);
}
.vis-name input:focus { border-color: rgba(139, 92, 246, 0.6); }
.vis-name-help { margin: 0; font-size: 11px; color: var(--text-tertiary); }
.vis-anon {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}
.vis-anon input { accent-color: var(--accent); }
.vis-status { margin: 0; font-size: 11px; }
.vis-status.pending { color: var(--warning); }

/* ============================================================
   Public tools — reuse suggestion card
   ============================================================ */
.match-slot:empty { display: none; }
.match-card {
  position: relative;
  display: flex;
  gap: var(--sp-3);
  background: var(--bg-2);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  text-align: left;
}
#heroMatchSlot .match-card { margin-top: var(--sp-4); }
#dockMatchSlot .match-card { margin-bottom: var(--sp-2); }
.match-tile {
  flex: none;
  width: 96px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-3);
  border-radius: var(--r-md);
  color: var(--accent-bright);
}
.match-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.match-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.match-meta { font-size: 11px; color: var(--text-tertiary); }
.match-pitch { font-size: 12px; color: var(--accent-bright); line-height: 1.45; }
.match-actions { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-1); }
.match-open { position: static; }
.match-preview {
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 0 var(--sp-3);
  height: 32px;
  transition: border-color var(--t-fast), color var(--t-fast);
}
.match-preview:hover { border-color: var(--border-strong); color: var(--text-primary); }
.match-x {
  position: absolute;
  top: 6px;
  right: 6px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1;
  padding: 4px;
  border-radius: var(--r-sm);
  transition: color var(--t-fast);
}
.match-x:hover { color: var(--text-primary); }
@media (max-width: 768px) {
  .match-uses { display: none; }
}

/* Library-import history row + tab pill */
.hist-lib { display: inline-flex; align-items: center; color: var(--accent-bright); }
.ver-pill.lib-pill { color: var(--accent-bright); border-color: rgba(139, 92, 246, 0.45); }

/* One-time refine hint above the dock */
.lib-hint {
  flex: none;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.25);
  color: var(--accent-bright);
  font-size: 11px;
  line-height: 1.45;
}

/* Quota rescue (out-of-quota notice → library card) */
.q-rescue { width: 100%; margin-top: var(--sp-3); }
.q-rescue-line { font-size: 12px; color: var(--text-secondary); margin-bottom: var(--sp-2); }
/* The blocked notice is a flex row; let the rescue card span the full width below it. */
.quota-notice { flex-wrap: wrap; }

/* Display name field (account section) */
.name-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.name-row { display: flex; align-items: center; gap: var(--sp-2); }
.name-label { font-size: 12px; color: var(--text-tertiary); }
.name-value { flex: 1; min-width: 0; font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name-value.muted { color: var(--text-tertiary); font-style: italic; }
.name-edit, .name-save {
  flex: none;
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  transition: border-color var(--t-fast), color var(--t-fast);
}
.name-edit:hover, .name-save:hover { border-color: var(--border-strong); color: var(--text-primary); }
.name-edit-row { display: flex; gap: var(--sp-2); }
.name-edit-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  outline: none;
  transition: border-color var(--t-fast);
}
.name-edit-row input:focus { border-color: rgba(139, 92, 246, 0.6); }

/* ============================================================
   Public tools — library preview modal
   ============================================================ */
.lib-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 89;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 220ms ease-out;
}
.lib-modal-backdrop.open { opacity: 1; }
.lib-modal {
  position: fixed;
  z-index: 90;
  top: 50%;
  left: 50%;
  width: min(640px, calc(100vw - 32px));
  height: min(420px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  transition: transform 220ms var(--ease-spring), opacity 180ms ease-out;
}
.lib-modal.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.lib-modal-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}
.lib-modal-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-like {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--r-full);
  padding: 2px var(--sp-3);
  color: var(--text-secondary);
  font-size: 12px;
  transition: border-color var(--t-fast);
}
.lib-like:hover { border-color: var(--border-strong); }
.lib-like.nudge { border-color: var(--accent); }
.lib-like.nudge::after {
  content: "Sign in to like";
  position: absolute;
  top: 110%;
  right: 0;
  white-space: nowrap;
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-secondary);
}
.lib-heart { color: var(--text-tertiary); font-size: 14px; line-height: 1; transition: color var(--t-fast); }
.lib-heart.liked { color: var(--accent-bright); }
.lib-heart.pop { animation: heart-pop 300ms var(--ease-spring); }
@keyframes heart-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.lib-modal-meta { flex: none; padding: var(--sp-1) var(--sp-4) var(--sp-2); font-size: 11px; color: var(--text-tertiary); }
.lib-modal-frame { flex: 1; min-height: 0; background: #fff; }
.lib-modal-frame iframe { width: 100%; height: 100%; border: none; display: block; background: #fff; }
.lib-modal-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border-subtle);
}
.lib-use { position: static; }
.lib-secondary {
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-4);
  transition: border-color var(--t-fast);
}
.lib-secondary:hover { border-color: var(--border-strong); }
.lib-report {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 12px;
  text-decoration: underline;
}
.lib-report:hover { color: var(--text-secondary); }

/* Hero library chips */
.chip-instant { color: var(--accent-bright); font-weight: 600; }
.chip-library { border-color: rgba(139, 92, 246, 0.35); }
.chip-library:hover { border-color: var(--accent); }

/* ============================================================
   Target-device pill (dock toprow) + picker (popover / mobile sheet)
   ============================================================ */
/* The pill IS the indicator — it shows the resolved target, never the word
   "Auto". An active override that differs from the detected class tints it. */
.target-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  /* Right-align after the (often-hidden) quota meter. When the meter shows, it
     owns margin-left:auto and the pill simply follows it. */
  margin-left: auto;
  height: 24px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-full);
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color var(--t-fast), color var(--t-fast), filter var(--t-fast);
}
/* When the quota meter is visible it owns the auto margin; the pill follows it. */
.quota-meter:not([hidden]) + .target-pill { margin-left: 0; }
.target-pill:hover { border-color: var(--border-strong); filter: brightness(1.15); color: var(--text-primary); }
.target-pill.overridden { border-color: rgba(139, 92, 246, 0.4); }
.target-glyph { display: inline-flex; align-items: center; }
.target-glyph svg { display: block; }
.target-chev { display: inline-flex; align-items: center; color: var(--text-tertiary); }

/* Picker — desktop popover above the pill (origin bottom-right). */
.target-picker {
  position: fixed;
  z-index: 70;
  width: 200px;
  background: var(--bg-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-2);
  transform-origin: bottom right;
}
.target-picker.in { animation: target-pop 180ms var(--ease-spring) backwards; }
@keyframes target-pop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
.target-grab { display: none; }
.target-rows { display: flex; flex-direction: column; gap: 2px; }
.target-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  height: 32px;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  padding: 0 var(--sp-2);
  color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast);
}
.target-row:hover { background: var(--bg-2); color: var(--text-primary); }
.target-row-glyph { flex: none; display: inline-flex; align-items: center; color: var(--text-tertiary); }
.target-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.target-row-title { font-size: 13px; font-weight: 500; }
.target-row-sub { font-size: 10px; color: var(--text-tertiary); }
.target-row-check { flex: none; width: 14px; text-align: center; color: var(--accent-bright); opacity: 0; font-size: 12px; }
.target-row.selected { color: var(--accent-bright); }
.target-row.selected .target-row-title { color: var(--accent-bright); }
.target-row.selected .target-row-check { opacity: 1; }
.target-divider { height: 1px; background: var(--border-subtle); margin: var(--sp-1) 0; }
.target-helper {
  margin: var(--sp-2) var(--sp-1) 0;
  font-size: 11px;
  color: var(--text-secondary);
}
.target-foot {
  margin: var(--sp-2) var(--sp-1) 0;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.target-backdrop {
  position: fixed;
  inset: 0;
  z-index: 69;
  background: rgba(0, 0, 0, 0.5);
}

/* Faint manual-override tag on the history meta line. */
.hist-builtfor { color: var(--text-tertiary); font-size: 11px; }

/* Mobile picker becomes a bottom sheet; the pill collapses to glyph-only.
   Matches the JS mobileMQ (≤768px OR touch-primary). */
@media (max-width: 768px), (pointer: coarse) {
  .target-pill {
    width: 24px;
    height: 24px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
    gap: 0;
  }
  .target-label, .target-chev { display: none; }

  .target-picker.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    border: none;
    border-top: 1px solid var(--border-default);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: var(--sp-2) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 280ms ease-out;
  }
  .target-picker.sheet.in { animation: none; transform: translateY(0); }
  .target-picker.sheet .target-grab {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: var(--r-full);
    background: var(--border-strong);
    margin: var(--sp-1) auto var(--sp-2);
  }
  .target-picker.sheet .target-row { height: 48px; }
  .target-picker.sheet .target-row-title { font-size: 15px; }
  .target-picker.sheet .target-row-sub { font-size: 11px; }
}

/* ============================================================
   Touch-primary co-signal (pointer:coarse) — touch laptops included.
   Hover-only affordances get persistent/tappable equivalents regardless
   of width, so nothing is reachable by hover alone.
   ============================================================ */
@media (pointer: coarse) {
  /* The delete control is reveal-on-hover on the desktop rail — make it always
     visible and give it a comfortable tap target on touch-primary devices. */
  .hist-del, .hist-rename {
    opacity: 1;
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Larger tap targets on small interactive controls. */
  .icon-btn { min-width: 44px; min-height: 44px; }
  .mode-btn { padding: var(--sp-2) var(--sp-3); }
  .match-x, .sync-nudge-x { min-width: 32px; min-height: 32px; }
  /* Fullscreen is the primary mobile escape hatch from a clipped tool — its
     Close/Refine controls must meet the 44px touch standard the app enforces. */
  .fs-close { width: 44px; height: 44px; }
  .fs-refine { height: 44px; }
}

/* ============================================================
   Color scheme — INTENTIONALLY DARK-ONLY.
   We deliberately do NOT add a light theme or a (prefers-color-scheme: light)
   override; the app chrome is dark by design. (The user's actual light/dark
   preference is still detected in JS and passed to the generation prompt so the
   GENERATED tool can honor it — that is a separate concern from this UI.)
   ============================================================ */

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 150ms !important;
  }
  .wordmark-grad, .grad-word { animation: none; }
  .shimmer-bar { animation: none; transform: none; width: 100%; opacity: 0.6; }
  .tw-caret { animation: none; }
  .iframe-shell.reveal iframe { animation: none; }
  .share-popover.in { animation: none; }
  .quota-notice.q-in, .quota-notice.q-flash { animation: none; }
  .skel-bar { animation: none; opacity: 0.7; }
  .toast { animation: toast-fade 150ms ease both; }
  @keyframes toast-fade { from { opacity: 0; } to { opacity: 1; } }
  .lib-heart.pop { animation: none; }
  .lib-modal { transition: opacity 150ms ease; transform: translate(-50%, -50%); }
  .target-picker.in { animation: none; }
  .target-picker.sheet { transition: none; }
}

/* Narrow phones: the toolbar can't fit the tool title beside Share + the icon
   cluster (it truncated to "i.."). Hide it here — the tool is right below, and
   the name still shows in the tab on wider screens and in the share dialog.
   Also hide the icon actions that are useless on a phone — Open-in-new-tab,
   Copy HTML, and Download .html (no file/clipboard-into-editor workflow on
   mobile). Keep Share, History (🕐), Fullscreen and New tool (+). These stay
   on tablet/desktop where they're useful. Width-based, not pointer. */
@media (max-width: 520px) {
  .tab-title { display: none !important; }
  #btnOpenTab, #btnCopy, #btnDownload { display: none !important; }
}
