/* ═══════════════════════════════════════════════════════════════
   FOLIO PDF STUDIO — style.css
   ═══════════════════════════════════════════════════════════════ */

/* ── RESET ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ── CSS VARIABLES ───────────────────────────────────────────── */
:root {
  --accent:       #007AFF;
  --accent-hover: #0062cc;
  --accent-light: rgba(0,122,255,.12);
  --accent-glow:  rgba(0,122,255,.25);

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius:    16px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  --ease:     cubic-bezier(.4,0,.2,1);
  --spring:   cubic-bezier(.34,1.56,.64,1);
  --ease-out: cubic-bezier(0,0,.2,1);

  --shadow-sm: 0 1px 4px rgba(0,0,0,.08), 0 0 0 .5px rgba(0,0,0,.06);
  --shadow:    0 4px 20px rgba(0,0,0,.1), 0 1px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 36px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
  --shadow-xl: 0 24px 60px rgba(0,0,0,.22);

  --font-body:    'DM Sans', -apple-system, 'Helvetica Neue', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;

  /* Layout heights — overridden in media queries */
  --topbar-h:  58px;
  --toolbar-h: 60px;
  --search-h:  44px;
  --sidebar-w: 228px;
}

/* ── LIGHT THEME ─────────────────────────────────────────────── */
[data-theme="light"],
[data-resolved-theme="light"] {
  --bg:            #eeedf3;
  --bg-2:          #e4e3ea;
  --surface:       rgba(255,255,255,.82);
  --surface-solid: #ffffff;
  --border:        rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.13);
  --text:          #0d0d0e;
  --text-2:        #6b6b78;
  --text-3:        #9a9aa8;
  --glass:         rgba(255,255,255,.72);
  --glass-border:  rgba(255,255,255,.85);
  --pill-bg:       rgba(255,255,255,.82);
  --scrollbar:     rgba(0,0,0,.14);
  --page-shadow:   0 6px 28px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.08);
  --load-bg:       rgba(238,237,243,.85);
}

/* ── DARK THEME ──────────────────────────────────────────────── */
[data-theme="dark"],
[data-resolved-theme="dark"] {
  --bg:            #0e0e11;
  --bg-2:          #161619;
  --surface:       rgba(26,26,32,.88);
  --surface-solid: #1a1a20;
  --border:        rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --text:          #f0f0f5;
  --text-2:        #88889a;
  --text-3:        #55556a;
  --glass:         rgba(26,26,32,.78);
  --glass-border:  rgba(255,255,255,.10);
  --pill-bg:       rgba(26,26,32,.88);
  --scrollbar:     rgba(255,255,255,.14);
  --page-shadow:   0 8px 40px rgba(0,0,0,.6), 0 2px 12px rgba(0,0,0,.4);
  --load-bg:       rgba(14,14,17,.88);
}

/* ── BASE ────────────────────────────────────────────────────── */
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .35s var(--ease), color .35s var(--ease);
}

/* ── SCROLLBARS ──────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--scrollbar); border-radius: 99px; }

/* ── UTILITY ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

.app {
  width: 100vw;
  height: 100dvh;
  position: relative;
}

/* ══════════════════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  padding: 16px;
}

.empty-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.empty-bg__orb {
  position: absolute; border-radius: 50%;
  filter: blur(90px); opacity: .3;
  animation: orbFloat 8s ease-in-out infinite;
}
.empty-bg__orb--1 { width: 480px; height: 480px; background: var(--accent); top: -140px; left: -80px; }
.empty-bg__orb--2 { width: 380px; height: 380px; background: #BF5AF2; bottom: -80px; right: -60px; animation-delay: -3s; }
.empty-bg__orb--3 { width: 280px; height: 280px; background: #34C759; top: 50%; left: 50%;
  animation: orbFloat3 8s ease-in-out -6s infinite; }

@keyframes orbFloat {
  0%,100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-28px) scale(1.05); }
}
@keyframes orbFloat3 {
  0%,100% { transform: translate(-50%,-50%) scale(1); }
  50%      { transform: translate(-50%,-50%) scale(1.06) translateY(-18px); }
}

.empty-state__card {
  position: relative; z-index: 1;
  background: var(--glass);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 48px 52px;
  text-align: center;
  max-width: 510px; width: 100%;
  box-shadow: var(--shadow-xl);
  animation: cardIn .55s var(--spring) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(32px) scale(.95); }
  to   { opacity: 1; transform: none; }
}

.brand { display: flex; align-items: center; justify-content: center; gap: 11px; margin-bottom: 6px; }
.brand__icon     { width: 44px; height: 44px; flex-shrink: 0; }
.brand__icon--sm { width: 26px; height: 26px; }
.brand__name {
  font-family: var(--font-display);
  font-size: 2.2rem; font-weight: 300; font-style: italic;
  color: var(--text); letter-spacing: -.02em;
}
.brand__name--sm { font-size: 1.05rem; font-style: italic; }
.brand--small    { justify-content: flex-start; }

.empty-state__tagline { color: var(--text-2); font-size: .88rem; margin-bottom: 28px; }

.drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 36px 20px; margin-bottom: 20px;
  cursor: pointer; transition: all .28s var(--ease);
  background: var(--accent-light);
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent); background: rgba(0,122,255,.08); transform: scale(1.01);
}
.drop-zone__content { display: flex; flex-direction: column; align-items: center; gap: 9px; }
.drop-zone__icon {
  width: 54px; height: 54px; margin-bottom: 2px;
  animation: iconPulse 3s ease-in-out infinite;
}
@keyframes iconPulse {
  0%,100% { opacity: .65; transform: scale(1); }
  50%      { opacity: 1;  transform: scale(1.06); }
}
.drop-zone__label { font-size: .92rem; font-weight: 500; color: var(--text); }
.drop-zone__sep   { font-size: .75rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .09em; }

.feature-chips { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; }
.chip {
  padding: 4px 11px; border-radius: 99px;
  font-size: .72rem; font-weight: 500;
  color: var(--text-2); background: var(--border); letter-spacing: .02em;
}

/* ══════════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius);
  font-family: var(--font-body); font-size: .86rem; font-weight: 500;
  cursor: pointer; border: none; outline: none;
  transition: all .2s var(--ease);
  white-space: nowrap; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn--primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn--primary:hover  { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn--primary:active { transform: scale(.97); }
.btn--sm { padding: 7px 12px; font-size: .8rem; border-radius: var(--radius-sm); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: none; background: transparent; color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer; transition: all .16s var(--ease);
  outline: none; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg     { width: 17px; height: 17px; }
.icon-btn--sm     { width: 28px; height: 28px; }
.icon-btn--sm svg { width: 14px; height: 14px; }
.icon-btn:hover   { background: var(--border); color: var(--text); }
.icon-btn:active  { transform: scale(.88); }

/* ══════════════════════════════════════════════════════════════
   EDITOR LAYOUT
══════════════════════════════════════════════════════════════ */
.editor { display: flex; height: 100dvh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); height: 100dvh;
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: transform .32s var(--ease), width .32s var(--ease);
  z-index: 30; overflow: hidden;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); width: 0; }

.sidebar__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar__label {
  padding: 9px 14px 5px;
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-3); flex-shrink: 0;
}
.thumbnail-container {
  flex: 1; overflow-y: auto;
  padding: 6px 10px 16px;
  display: flex; flex-direction: column; gap: 7px;
}
.thumbnail-item {
  position: relative; cursor: pointer;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 2px solid transparent; transition: all .18s var(--ease);
  background: var(--surface-solid); box-shadow: var(--shadow-sm);
}
.thumbnail-item:hover  { border-color: var(--border-strong); transform: scale(1.01); }
.thumbnail-item.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.thumbnail-item canvas { width: 100%; display: block; }
.thumbnail-num {
  position: absolute; bottom: 4px; right: 5px;
  font-size: .62rem; font-weight: 600; color: var(--text-2);
  background: var(--surface); padding: 1px 5px; border-radius: 4px;
}
.thumb-loading {
  display: flex; align-items: center; justify-content: center;
  height: 110px; color: var(--text-3); font-size: .72rem;
}

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 35;
  backdrop-filter: blur(2px); animation: fadeIn .2s var(--ease);
}
@keyframes fadeIn { from { opacity:0; } }

/* ── Main area ───────────────────────────────────────────────── */
.main-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative; min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  flex-shrink: 0; z-index: 20;
}
.topbar__left   { display: flex; align-items: center; gap: 6px; flex: 1; }
.topbar__right  { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: flex-end; }
.topbar__center { display: flex; justify-content: center; flex-shrink: 0; }

.file-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: var(--border); border-radius: var(--radius-sm);
  min-width: 0; max-width: 200px;
}
.file-badge svg { width: 13px; height: 13px; flex-shrink: 0; }
.file-name {
  font-size: .78rem; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.glass-pill {
  display: flex; align-items: center; gap: 2px;
  background: var(--pill-bg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 99px;
  padding: 3px 5px; box-shadow: var(--shadow-sm);
}
.page-input-wrap { display: flex; align-items: center; gap: 3px; padding: 0 3px; }
.page-input {
  width: 36px; text-align: center;
  background: transparent; border: none; outline: none;
  font-family: var(--font-body); font-size: .8rem; font-weight: 600; color: var(--text);
}
.page-sep   { color: var(--text-3); font-size: .75rem; }
.page-total { font-size: .8rem; font-weight: 400; color: var(--text-2); }
.zoom-label {
  font-size: .78rem; font-weight: 600; color: var(--text);
  padding: 0 4px; min-width: 42px; text-align: center;
}

/* Theme menu */
.theme-menu-wrap { position: relative; }
.theme-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; min-width: 185px; box-shadow: var(--shadow-lg);
  z-index: 100; animation: menuIn .2s var(--spring) both;
}
@keyframes menuIn {
  from { opacity:0; transform: translateY(-8px) scale(.95); }
  to   { opacity:1; transform: none; }
}
.theme-menu__title {
  font-size: .66rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-3); padding: 3px 8px 5px;
}
.theme-menu__divider { height: 1px; background: var(--border); margin: 7px 0; }
.theme-option {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 6px 8px;
  border: none; background: transparent; color: var(--text);
  font-family: var(--font-body); font-size: .83rem;
  border-radius: var(--radius-sm); cursor: pointer; transition: background .14s;
  -webkit-tap-highlight-color: transparent;
}
.theme-option:hover  { background: var(--border); }
.theme-option.active { color: var(--accent); }
.theme-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--border-strong); flex-shrink: 0;
}
.theme-dot--light  { background: #f5f5f7; }
.theme-dot--dark   { background: #1c1c22; }
.theme-dot--system { background: linear-gradient(135deg, #f5f5f7 50%, #1c1c22 50%); }
.accent-swatches   { display: flex; gap: 6px; padding: 3px 8px 1px; flex-wrap: wrap; }
.swatch {
  width: 21px; height: 21px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: all .16s var(--spring); outline: none;
  -webkit-tap-highlight-color: transparent;
}
.swatch:hover  { transform: scale(1.22); }
.swatch.active { border-color: var(--text); }

/* ── Search bar ──────────────────────────────────────────────── */
.search-bar {
  height: var(--search-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 7px; padding: 0 14px;
  flex-shrink: 0; animation: slideDown .22s var(--ease-out);
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
.search-bar__icon { width: 14px; height: 14px; color: var(--text-3); flex-shrink: 0; }
.search-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: var(--font-body); font-size: .86rem; color: var(--text);
}
.search-input::placeholder { color: var(--text-3); }
.search-count { font-size: .75rem; color: var(--text-3); white-space: nowrap; padding: 0 4px; }

/* ── Viewport ────────────────────────────────────────────────── */
.viewport {
  flex: 1; overflow-y: auto; overflow-x: auto;
  background: var(--bg-2);
  display: flex; justify-content: center;
  padding: 24px;
  padding-bottom: calc(var(--toolbar-h) + 40px);
  transition: background .35s var(--ease);
  -webkit-overflow-scrolling: touch;
}
.pdf-pages {
  display: flex; flex-direction: column; gap: 18px;
  align-items: center; width: 100%;
}

/* ── Page wrapper ────────────────────────────────────────────── */
.page-wrapper {
  position: relative; border-radius: 4px; overflow: hidden;
  box-shadow: var(--page-shadow); background: #fff;
  transform-origin: top center;
  animation: pageIn .38s var(--ease-out) both;
  flex-shrink: 0;
  /* Prevent browser pan/zoom gestures from interfering with drawing */
  touch-action: none;
}
[data-resolved-theme="dark"] .page-wrapper { background: #1c1c24; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}
.pdf-canvas { display: block; pointer-events: none; user-select: none; }
.annotation-canvas {
  position: absolute; top: 0; left: 0;
  pointer-events: none; /* wrapper receives all pointer events */
  z-index: 2;
}
.page-number-badge {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; padding: 2px 9px;
  font-size: .66rem; font-weight: 600; color: var(--text-2);
  pointer-events: none; z-index: 5;
  opacity: 0; transition: opacity .18s;
}
.page-wrapper:hover .page-number-badge { opacity: 1; }

/* ── Search highlights ───────────────────────────────────────── */
/* CRITICAL: pointer-events:none so they never block drawing on the page */
.search-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 3;
}
.sh-rect {
  position: absolute;
  background: rgba(255,214,0,.42);
  border-radius: 2px;
  pointer-events: none;
}
.sh-rect.active { background: rgba(255,140,0,.55); }

/* ── Selection UI ────────────────────────────────────────────── */
.selection-box {
  position: absolute;
  border: 1.5px solid var(--accent); border-radius: 3px;
  pointer-events: none; z-index: 10;
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.annotation-delete-btn {
  position: absolute; width: 24px; height: 24px;
  background: #FF375F; border: none; border-radius: 50%;
  color: #fff; font-size: 15px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.28); z-index: 15;
  transition: transform .14s var(--spring);
  -webkit-tap-highlight-color: transparent;
}
.annotation-delete-btn:hover { transform: scale(1.18); }

/* ══════════════════════════════════════════════════════════════
   FLOATING TOOLBAR
══════════════════════════════════════════════════════════════ */
.floating-toolbar {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--glass);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border: 1px solid var(--glass-border); border-radius: 99px;
  padding: 5px 10px;
  display: flex; align-items: center; gap: 2px;
  box-shadow: var(--shadow-lg); z-index: 50;
  animation: toolbarIn .45s var(--spring) .05s both;
  max-width: calc(100% - 32px);
}
@keyframes toolbarIn {
  from { opacity:0; transform: translateX(-50%) translateY(18px) scale(.94); }
  to   { opacity:1; transform: translateX(-50%) translateY(0) scale(1); }
}

.toolbar__group { display: flex; align-items: center; gap: 2px; }
.toolbar__sep   { width: 1px; height: 20px; background: var(--border-strong); margin: 0 5px; flex-shrink: 0; }

.tool-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none;
  background: transparent; color: var(--text-2);
  border-radius: 99px; cursor: pointer;
  transition: all .16s var(--ease); outline: none;
  position: relative; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.tool-btn svg    { width: 17px; height: 17px; }
.tool-btn:hover  { background: var(--border); color: var(--text); transform: scale(1.08); }
.tool-btn:active { transform: scale(.9); }
.tool-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.tool-btn.active:hover { background: var(--accent-hover); transform: scale(1.06); }
.tool-btn[disabled]    { opacity: .3; pointer-events: none; }

/* ══════════════════════════════════════════════════════════════
   TOOL OPTIONS PANEL
══════════════════════════════════════════════════════════════ */
.tool-options {
  position: absolute;
  bottom: calc(var(--toolbar-h) + 16px);
  left: 50%; transform: translateX(-50%);
  background: var(--glass);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  padding: 11px 15px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg); z-index: 45;
  animation: optIn .2s var(--spring) both;
  flex-wrap: wrap; max-width: min(92vw, 560px); justify-content: center;
}
@keyframes optIn {
  from { opacity:0; transform: translateX(-50%) translateY(8px) scale(.96); }
  to   { opacity:1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* All groups hidden by default; .visible overrides */
.opt-group          { display: none; align-items: center; gap: 9px; flex-wrap: wrap; }
.opt-group.visible  { display: flex; }

.opt-label {
  font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-3); white-space: nowrap;
}
.opt-select {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font-body); font-size: .8rem;
  padding: 5px 7px; cursor: pointer; outline: none; max-width: 130px;
}
.opt-number {
  width: 50px; background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font-body); font-size: .8rem;
  padding: 5px 7px; text-align: center; outline: none;
}
.opt-color {
  width: 30px; height: 30px; border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; padding: 2px; background: transparent;
}
.opt-range { width: 80px; accent-color: var(--accent); cursor: pointer; }
.opt-check { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.highlight-swatches { display: flex; gap: 5px; }
.hl-swatch {
  width: 24px; height: 24px; border-radius: 5px;
  border: 2px solid transparent; cursor: pointer;
  transition: all .15s var(--spring); outline: none;
  -webkit-tap-highlight-color: transparent;
}
.hl-swatch:hover  { transform: scale(1.2); }
.hl-swatch.active { border-color: var(--text); transform: scale(1.12); }

/* ══════════════════════════════════════════════════════════════
   TEXT EDIT OVERLAY
══════════════════════════════════════════════════════════════ */
.text-edit-overlay {
  position: fixed; z-index: 200;
  border: 1.5px solid var(--accent); outline: none;
  font-family: 'DM Sans', sans-serif; font-size: 16px;
  resize: none; padding: 3px 5px; border-radius: 4px;
  min-width: 80px; min-height: 26px; overflow: hidden;
  box-shadow: 0 0 0 3px var(--accent-glow); line-height: 1.4;
  backdrop-filter: blur(4px);
}
[data-resolved-theme="light"] .text-edit-overlay { color: #0d0d0e; background: rgba(255,255,255,.75); }
[data-resolved-theme="dark"]  .text-edit-overlay { color: #f0f0f5; background: rgba(18,18,24,.75); }

/* ══════════════════════════════════════════════════════════════
   LOADING OVERLAY
══════════════════════════════════════════════════════════════ */
.loading-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--load-bg);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s var(--ease);
}
.loading-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 44px; box-shadow: var(--shadow-lg);
}
.spinner svg    { width: 38px; height: 38px; animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label  { font-size: .85rem; font-weight: 500; color: var(--text-2); }

/* ══════════════════════════════════════════════════════════════
   TOASTS
══════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed; bottom: 96px; right: 16px;
  display: flex; flex-direction: column; gap: 7px; z-index: 999;
}
.toast {
  background: var(--surface);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 16px; font-size: .82rem; font-weight: 500; color: var(--text);
  box-shadow: var(--shadow-lg); max-width: 260px;
  animation: toastIn .28s var(--spring) both;
}
.toast--success { border-left: 3px solid #30D158; }
.toast--error   { border-left: 3px solid #FF375F; }
.toast--info    { border-left: 3px solid var(--accent); }
@keyframes toastIn  { from { opacity:0; transform:translateX(16px) scale(.94); } }
.toast.removing     { animation: toastOut .22s var(--ease) both; }
@keyframes toastOut { to { opacity:0; transform:translateX(16px) scale(.9); } }

/* ══════════════════════════════════════════════════════════════
   TABLET  ≤ 900px
══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-w: 210px; }

  /* Off-canvas drawer.
     Use translateX(-100%) — not a px value — so the sidebar
     ALWAYS fully hides regardless of its own pixel width.
     The old bug: width=75vw but translated by -210px → partially visible. */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100dvh;
    width: var(--sidebar-w) !important;
    transform: translateX(-100%);
    pointer-events: none;
    z-index: 40;
    transition: transform .32s var(--ease);
  }
  .sidebar.open {
    transform: translateX(0);
    pointer-events: all;
  }
  /* On mobile the JS never adds .collapsed, but neutralise it anyway */
  .sidebar.collapsed {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .main-area { flex: 1; min-width: 0; }
  .topbar    { gap: 6px; padding: 0 10px; }
  .file-name { max-width: 120px; }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE  ≤ 640px
══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root {
    --topbar-h:  52px;
    /* Toolbar height: buttons(44) + padding-top(8) + padding-bottom(8) + safe-area handled separately */
    --toolbar-h: 60px;
  }

  /* ── Topbar: single-row compact layout ───────────────────── */
  .topbar {
    padding: 0 8px; gap: 4px;
    justify-content: space-between;
    /* Never wrap — keep single row */
    flex-wrap: nowrap;
  }
  .topbar__left   { flex: 0 0 auto; gap: 3px; min-width: 0; }
  .topbar__center { flex: 1; min-width: 0; justify-content: center; }
  .topbar__right  { flex: 0 0 auto; gap: 2px; }

  /* Hide filename text; icon-only badge */
  .file-name { display: none; }
  .file-badge { padding: 4px 6px; background: transparent; }
  .file-badge svg { width: 16px; height: 16px; }

  /* Compact page nav pill */
  .glass-pill { padding: 2px 3px; }
  .page-input { width: 24px; font-size: .74rem; }
  .page-total, .page-sep { font-size: .72rem; }

  /* Zoom label: hidden on mobile (saves ~50px) */
  .zoom-label { display: none; }

  /* Export button: icon only */
  .btn--sm { padding: 6px 8px; }
  .btn--sm .export-label { display: none; }

  /* Icon buttons compact */
  .icon-btn     { width: 34px; height: 34px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .icon-btn--sm { width: 26px; height: 26px; }

  /* ── Sidebar: wider off-canvas drawer ────────────────────── */
  /* Wider drawer on small phones — translateX(-100%) still works perfectly */
  .sidebar { width: 80vw !important; max-width: 300px; }

  /* ── Viewport: account for bottom toolbar ────────────────── */
  .viewport {
    padding: 12px 8px;
    padding-bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
  }

  /* ── Floating toolbar → full-width bottom strip ──────────── */
  .floating-toolbar {
    /* Override the centered floating pill */
    position: absolute;
    bottom: 0; left: 0; right: 0; top: auto;
    transform: none;
    max-width: none; width: 100%;
    /* Pill shape only on top corners */
    border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    /* Padding: top/sides fixed; bottom adds safe area */
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    /* Horizontal scroll if tools don't fit */
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-start;
    gap: 1px;
    /* Entry animation: slide up from bottom */
    animation: toolbarUp .35s var(--spring) both;
  }
  .floating-toolbar::-webkit-scrollbar { display: none; }

  @keyframes toolbarUp {
    from { opacity:0; transform: translateY(100%); }
    to   { opacity:1; transform: none; }
  }

  .toolbar__group { flex-shrink: 0; }
  .toolbar__sep   { height: 18px; margin: 0 3px; flex-shrink: 0; }

  /* Touch-friendly tool buttons — 44×44 minimum tap target */
  .tool-btn {
    width: 42px; height: 44px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
  }
  .tool-btn svg { width: 19px; height: 19px; }
  #undoBtn, #redoBtn { border-radius: var(--radius-sm); }

  /* ── Tool options: anchored above the toolbar ────────────── */
  .tool-options {
    /* Override centered absolute */
    left: 8px; right: 8px; bottom: auto;
    transform: none;
    /* Position above toolbar, factoring in safe area */
    bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px) + 10px);
    max-width: none; width: auto;
    border-radius: var(--radius-lg);
    padding: 10px 14px; gap: 8px;
    justify-content: flex-start;
    flex-wrap: wrap;
    overflow-x: auto; scrollbar-width: none;
  }
  .tool-options::-webkit-scrollbar { display: none; }

  /* Bigger touch targets inside options */
  .opt-color  { width: 34px; height: 34px; }
  .opt-range  { width: 100px; height: 28px; }
  .opt-number { width: 54px; padding: 6px 7px; }
  .hl-swatch  { width: 28px; height: 28px; border-radius: 7px; }

  /* ── Search bar ──────────────────────────────────────────── */
  .search-bar { padding: 0 10px; gap: 5px; }
  .search-count { display: none; }

  /* ── Toast position: clear toolbar ──────────────────────── */
  .toast-container {
    bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
    right: 8px; left: 8px;
  }
  .toast { max-width: none; }

  /* ── Theme menu: opens upward on mobile ──────────────────── */
  .theme-menu { top: auto; bottom: calc(100% + 8px); right: 0; }

  /* ── Empty state ─────────────────────────────────────────── */
  .empty-state__card { padding: 30px 22px; }
  .brand__name  { font-size: 1.9rem; }
  .drop-zone    { padding: 28px 14px; }
  .feature-chips { gap: 5px; }
  .chip { padding: 3px 9px; font-size: .68rem; }
}

/* ══════════════════════════════════════════════════════════════
   VERY SMALL  ≤ 390px
══════════════════════════════════════════════════════════════ */
@media (max-width: 390px) {
  .topbar       { padding: 0 5px; gap: 2px; }
  .tool-btn     { width: 38px; }
  /* Hide separators to pack more tools */
  .toolbar__sep { display: none; }
  .empty-state__card { padding: 24px 16px; }
  .brand__name { font-size: 1.6rem; }
}
