/* ==========================================================================
   Letter Studio — editor design layer
   Loaded after style.css. Re-themes the studio chrome to the brand system
   (ink, paper, volt) and adds the rail/pill layout. The A4 sheet and its
   --doc-* tokens are intentionally untouched so screen matches print/PDF.
   ========================================================================== */

:root {
  --studio-volt: #d4ff3a;
  --studio-volt-hover: #e4ff75;
  --studio-ink: #0a0a0a;
  --studio-display: 'Anton', Impact, 'Arial Narrow', sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --ui-font-sm: 12px;
  --ui-font-md: 13px;
  --header-height: 60px;
  --panel-width: 360px;
  --rail-width: 76px;

  /* Light: warm paper, ink accent, volt only as highlight */
  --ui-bg: #e9e8e1;
  --ui-surface: #ffffff;
  --ui-surface-raised: #ffffff;
  --ui-surface-2: #f7f7f2;
  --ui-surface-3: #efeee7;
  --ui-surface-4: #e3e2da;
  --ui-control-bg: #ffffff;
  --ui-control-bg-hover: #f5f5ef;
  --ui-input-bg: #ffffff;
  --ui-border: #e4e3da;
  --ui-border-dark: #d8d7cd;
  --ui-border-strong: #c9c8bd;
  --ui-border-stronger: #9f9e93;
  --ui-text-main: #0a0a0a;
  --ui-text-sub: #3d3d38;
  --ui-text-muted: #6b6b63;
  --ui-accent: #0a0a0a;
  --ui-accent-hover: #262626;
  --ui-accent-strong: #0a0a0a;
  --ui-accent-soft: rgba(10, 10, 10, 0.06);
  --ui-accent-soft-hover: rgba(10, 10, 10, 0.1);
  --ui-accent-soft-border: rgba(10, 10, 10, 0.16);
  --ui-accent-soft-border-hover: rgba(10, 10, 10, 0.3);
  --ui-on-accent: #f5f5f0;
  --ui-input-focus: rgba(10, 10, 10, 0.12);
  --ui-highlight: #d4ff3a;
  --ui-scroll-thumb: #cfcec4;
  --ui-scroll-thumb-hover: #a8a79d;
  --ui-shadow-sm: 0 1px 2px rgba(10, 10, 10, 0.06);
  --ui-shadow-md: 0 8px 24px -10px rgba(10, 10, 10, 0.25);
  --ui-shadow-paper: 0 2px 6px rgba(10, 10, 10, 0.08), 0 24px 60px -24px rgba(10, 10, 10, 0.35);
  --ui-sheet-border: rgba(10, 10, 10, 0.06);
  --ui-sheet-shadow: 0 2px 6px rgba(10, 10, 10, 0.06), 0 30px 70px -30px rgba(10, 10, 10, 0.4);
  --ui-stage-glow: radial-gradient(1200px 600px at 50% -10%, rgba(212, 255, 58, 0.18), transparent 60%);
}

:root[data-theme="dark"] {
  --ui-bg: #0a0a0a;
  --ui-surface: #111111;
  --ui-surface-raised: #171717;
  --ui-surface-2: #161616;
  --ui-surface-3: #1f1f1f;
  --ui-surface-4: #2a2a2a;
  --ui-control-bg: #1a1a1a;
  --ui-control-bg-hover: #242424;
  --ui-input-bg: #0d0d0d;
  --ui-border: rgba(255, 255, 255, 0.08);
  --ui-border-dark: rgba(255, 255, 255, 0.12);
  --ui-border-strong: rgba(255, 255, 255, 0.18);
  --ui-border-stronger: rgba(255, 255, 255, 0.32);
  --ui-text-main: #f5f5f0;
  --ui-text-sub: #c9c9c2;
  --ui-text-muted: #8c8c86;
  --ui-accent: #d4ff3a;
  --ui-accent-hover: #e4ff75;
  --ui-accent-strong: #d4ff3a;
  --ui-accent-soft: rgba(212, 255, 58, 0.1);
  --ui-accent-soft-hover: rgba(212, 255, 58, 0.16);
  --ui-accent-soft-border: rgba(212, 255, 58, 0.3);
  --ui-accent-soft-border-hover: rgba(212, 255, 58, 0.5);
  --ui-on-accent: #0a0a0a;
  --ui-input-focus: rgba(212, 255, 58, 0.22);
  --ui-highlight: #d4ff3a;
  --ui-scroll-thumb: #2e2e2e;
  --ui-scroll-thumb-hover: #474747;
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
  --ui-shadow-md: 0 12px 32px -12px rgba(0, 0, 0, 0.8);
  --ui-shadow-paper: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 40px 90px -30px rgba(0, 0, 0, 0.95);
  --ui-sheet-border: rgba(255, 255, 255, 0.08);
  --ui-sheet-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 40px 90px -30px rgba(0, 0, 0, 0.95);
  --ui-stage-glow: radial-gradient(1100px 560px at 50% -12%, rgba(212, 255, 58, 0.09), transparent 62%);
}

/* ---------- Base & height chain ---------- */
.studio-root { display: contents; }
body {
  height: 100vh;
  height: 100dvh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--ui-bg);
}
.app-workspace { min-height: 0; position: relative; }
.control-panel { min-height: 0; }
.preview-area { min-width: 0; min-height: 0; }
::selection { background: rgba(212, 255, 58, 0.45); color: #0a0a0a; }
:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.app-header {
  padding: 0 var(--space-4) 0 var(--space-3);
  gap: var(--space-3);
  background-color: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
}
.header-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--studio-volt);
  color: var(--studio-ink);
}
.header-logo-icon svg { width: 18px; height: 18px; }
.header-title {
  font-family: var(--studio-display);
  font-weight: 400;
  text-transform: uppercase;
  font-size: 20px;
  letter-spacing: 0.01em;
  line-height: 0.95;
}
.header-separator { height: 24px; }
.quick-theme-pill { display: none !important; }
.btn-icon-subtle { width: 36px; height: 36px; border-radius: var(--radius-md); }
.autosave-status { border-radius: 999px; padding: 4px 10px; font-weight: 600; }
.page-fit-gauge { border-radius: 999px; padding: 5px 10px; }
.btn-showcase {
  height: 38px;
  padding: 0 var(--space-4);
  border-radius: 999px;
  font-size: var(--ui-font-md);
  font-weight: 700;
  background: var(--ui-surface-2);
  border-color: var(--ui-border);
}
.btn-showcase:hover { border-color: var(--ui-border-strong); color: var(--ui-text-main); background: var(--ui-surface-3); }
.header-search-btn {
  height: 38px;
  min-width: 240px;
  padding: 0 var(--space-4);
  border-radius: 999px;
  font-size: var(--ui-font-md);
  justify-content: flex-start;
}
.header-search-btn .search-kbd { margin-left: auto; border-radius: 6px; }
.header-search-btn:hover { border-color: var(--ui-border-strong); }
.theme-mode-toggle { width: 38px; height: 38px; border-radius: 999px; }
#moreActionsDropdown > .btn { height: 38px; border-radius: 999px; padding: 0 14px; }
.dropdown-menu { padding: 6px; border-radius: var(--radius-lg); box-shadow: var(--ui-shadow-md); }
.dropdown-item { padding: 10px 12px; font-size: var(--ui-font-md); border-radius: var(--radius-sm); }

/* The one primary action */
#printBtn {
  height: 40px;
  padding: 0 20px;
  border-radius: 999px;
  background: var(--studio-volt);
  border-color: var(--studio-volt);
  color: var(--studio-ink);
  font-weight: 800;
  font-size: 14px;
}
#printBtn:hover { background: var(--studio-volt-hover); border-color: var(--studio-volt-hover); }

/* ---------- Buttons & inputs ---------- */
.btn { border-radius: var(--radius-md); font-size: var(--ui-font-md); padding: 9px 16px; font-weight: 700; }
.btn-sm { padding: 7px 12px; font-size: var(--ui-font-sm); }
.btn-primary { box-shadow: none; }
.btn-secondary { background: var(--ui-surface-2); }
.btn-icon { width: 30px; height: 30px; border-radius: 999px; }
.btn-toolbar { padding: 6px 10px; border-radius: 999px; }
.form-group { margin-bottom: var(--space-3); }
.group-label,
.form-group label { font-size: var(--ui-font-sm); font-weight: 600; color: var(--ui-text-sub); margin-bottom: 6px; }
.form-row { gap: var(--space-2); }
.form-input,
.form-select,
.form-textarea {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: var(--ui-font-md);
  border-color: var(--ui-border-dark);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.form-textarea { min-height: 0; }
.form-input:hover,
.form-select:hover,
.form-textarea:hover { border-color: var(--ui-border-strong); }
.form-input:focus,
.form-select:focus,
.form-textarea:focus { border-color: var(--ui-accent); box-shadow: 0 0 0 4px var(--ui-input-focus); }
.segmented-control { border-radius: var(--radius-md); }
.segment-btn { border-radius: 8px; font-weight: 600; }
.layout-card-btn,
.theme-card-btn,
.logo-dropzone,
.sig-pill-btn,
.stamp-pill-btn,
.stamp-swatch-btn,
.logo-preset-pill { border-radius: var(--radius-md); }
.quick-fill-chip,
.token-chip,
.quick-chip,
.preset-chip,
.btn-micro-chip { border-radius: 999px; }
.toggle-track { background-color: var(--ui-border-strong); }
.form-range { accent-color: var(--ui-accent); }

/* ---------- Icon rail ---------- */
.studio-rail {
  flex: 0 0 var(--rail-width);
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-3) 8px;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-border);
  z-index: 40;
  overflow-y: auto;
  scrollbar-width: none;
}
.studio-rail-btn {
  position: relative;
  width: 60px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ui-text-muted);
  font: 600 11px/1 'Inter', sans-serif;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.studio-rail-btn svg { width: 20px; height: 20px; }
.studio-rail-btn:hover { background: var(--ui-surface-3); color: var(--ui-text-main); }
.studio-rail-btn.is-active { color: var(--ui-text-main); background: var(--ui-accent-soft); }
.studio-rail-btn.is-active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--studio-volt);
}
.studio-rail-btn.is-active svg { color: var(--ui-accent-strong); }
:root:not([data-theme="dark"]) .studio-rail-btn.is-active { background: var(--studio-volt); color: var(--studio-ink); }
:root:not([data-theme="dark"]) .studio-rail-btn.is-active svg { color: var(--studio-ink); }
.studio-panel-collapsed .studio-rail-btn.is-active { background: transparent; color: var(--ui-text-muted); }
.studio-panel-collapsed .studio-rail-btn.is-active::before { opacity: 0; }
.studio-rail-sep { width: 32px; height: 1px; background: var(--ui-border); margin: 6px 0; }

/* ---------- Settings panel ---------- */
.control-panel { width: var(--panel-width); background: var(--ui-surface); }
.panel-header {
  padding: var(--space-4) var(--space-5) var(--space-3);
  border-bottom: none;
  align-items: flex-start;
}
.panel-heading { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.panel-heading::after {
  content: attr(data-sub);
  display: block;
  margin-top: 4px;
  font-size: var(--ui-font-sm);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ui-text-muted);
}
.panel-header .btn-micro-text { text-decoration: none; font-weight: 600; font-size: 12px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--ui-border); }
.panel-header .btn-micro-text:hover { border-color: var(--ui-danger-border-strong); }

.tab-content {
  min-height: 0;
  overscroll-behavior: contain;
  padding: var(--space-2) var(--space-4) var(--space-6);
}

@media screen and (min-width: 841px) {
  .control-tabs { display: none; }
  .panel-collapse-btn { display: none !important; }
}

/* Collapsible sections */
.panel-section {
  background-color: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.panel-section:hover { border-color: var(--ui-border-dark); }
.panel-section[open] { box-shadow: var(--ui-shadow-sm); }
.panel-section-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: 0 var(--space-4);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--ui-text-main);
  border-radius: var(--radius-lg);
}
.panel-section-summary::-webkit-details-marker { display: none; }
.panel-section-summary::after {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 2px solid var(--ui-text-muted);
  border-bottom: 2px solid var(--ui-text-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s ease;
}
.panel-section[open] > .panel-section-summary::after { transform: rotate(-135deg) translateY(-1px); }
.panel-section-summary:hover { background-color: var(--ui-surface-2); }
.panel-section[open] > .panel-section-summary { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.panel-section-title { flex: 0 0 auto; white-space: nowrap; }
.panel-section-hint {
  flex: 1;
  min-width: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--ui-font-sm);
  font-weight: 500;
  color: var(--ui-text-muted);
}
.panel-section-hint.is-off { color: var(--ui-text-muted); opacity: 0.7; }
.panel-section-body { padding: var(--space-1) var(--space-4) var(--space-4); }
.panel-section-body > :last-child,
.panel-section-body > .form-card > :last-child { margin-bottom: 0; }
.panel-section-body .form-card,
.panel-section-body .form-card.sub-card { background: transparent; border: none; padding: 0; margin: 0; }
.panel-section-body .card-top-row .card-title { display: none; }
.panel-section-body .card-top-row:not(:has(.card-sub-hint))::before {
  content: "Show on letter";
  font-size: var(--ui-font-sm);
  font-weight: 600;
  color: var(--ui-text-sub);
}
.panel-section-body .card-top-row:not(:has(.switch-toggle)):not(:has(.card-sub-hint)) { display: none; }
.panel-section-body .card-top-row {
  margin-bottom: var(--space-3);
  gap: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--ui-surface-2);
}
.panel-inline-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }

.tab-content > .form-card { background: transparent; border: none; padding: 0; margin: 0; }
.tab-content > .form-card > .card-top-row {
  background-color: var(--ui-surface-2);
  border: 1px solid var(--ui-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: 10px;
}

/* ---------- Canvas ---------- */
.preview-area { background: var(--ui-stage-glow), var(--ui-bg); }
.paper-viewport { background: transparent; padding-bottom: 120px; }

@media screen and (min-width: 841px) {
  .preview-toolbar {
    background: transparent;
    border-bottom: none;
    padding: var(--space-3) var(--space-4) var(--space-1);
  }
  .toolbar-nav-wrap {
    background-color: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: 999px;
    padding: 5px 12px;
    box-shadow: var(--ui-shadow-md);
  }
  .toolbar-nav-wrap .doc-formatting-toolbar { scrollbar-width: none; padding-bottom: 0; }
  .toolbar-nav-wrap .doc-formatting-toolbar::-webkit-scrollbar { display: none; }
  .paper-viewport { padding-top: var(--space-5); }
}

.toolbar-tool-btn,
.toolbar-chip-btn,
.toolbar-font-family-btn { border-radius: 8px; }
.toolbar-tool-btn.active { background: var(--ui-accent-soft); color: var(--ui-accent-strong); }
.toolbar-dropdown-menu { border-radius: var(--radius-lg); padding: 8px; }
.page-sheet-strip { border-radius: 999px; padding-left: 12px; padding-right: 8px; }
.strip-page-pill { border-radius: 999px; }

/* Floating canvas pills (page count + zoom) */
.studio-canvas-pills {
  position: absolute;
  left: var(--space-5);
  right: var(--space-5);
  bottom: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  pointer-events: none;
  z-index: 20;
}
.studio-canvas-pills > * { pointer-events: auto; }
.studio-canvas-pills .doc-page-manager-bar {
  padding: 6px 6px 6px 14px;
  gap: var(--space-3);
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  box-shadow: var(--ui-shadow-md);
}
.studio-canvas-pills .doc-page-manager-left { gap: 8px; }
.studio-canvas-pills .doc-page-manager-right { display: flex; gap: 6px; }
.studio-canvas-pills .page-manager-note { display: none; }
.studio-canvas-pills .page-badge-counter { background: transparent; border: none; padding: 0; color: var(--ui-text-sub); font-size: 12px; }
.studio-canvas-pills .btn-page-action { border-radius: 999px; padding: 7px 12px; font-size: 12px; }
.studio-canvas-pills .zoom-controls {
  gap: 2px;
  padding: 5px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  box-shadow: var(--ui-shadow-md);
}
.studio-canvas-pills .zoom-controls .btn-icon,
.studio-canvas-pills .zoom-controls .btn-toolbar { border-color: transparent; background: transparent; color: var(--ui-text-sub); }
.studio-canvas-pills .zoom-controls .btn-icon:hover,
.studio-canvas-pills .zoom-controls .btn-toolbar:hover { background: var(--ui-surface-3); color: var(--ui-text-main); }
.studio-canvas-pills .zoom-text { min-width: 44px; }

/* ---------- Modals ---------- */
.modal-backdrop,
#startScreenModal { background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(10px) saturate(120%); -webkit-backdrop-filter: blur(10px) saturate(120%); }
.modal-dialog {
  border-radius: 20px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.7);
}
.modal-header h3 { font-family: var(--studio-display); font-weight: 400; text-transform: uppercase; font-size: 30px; letter-spacing: 0.01em; }
.gallery-filter-tab { border-radius: 999px; font-weight: 600; }
.gallery-filter-tab.active { background: var(--ui-accent) !important; color: var(--ui-on-accent) !important; border-color: var(--ui-accent) !important; }

/* Template gallery with real letters */
.gallery-card {
  border-radius: 16px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s, box-shadow 0.25s;
}
.gallery-card:hover { transform: translateY(-4px); border-color: var(--ui-border-strong); box-shadow: var(--ui-shadow-md); }
.gallery-card.active { border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft-border); }
.gallery-card-preview.has-image {
  height: auto;
  aspect-ratio: 4 / 3;
  padding: 16px 16px 0;
  background: var(--ui-surface-3);
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
:root[data-theme="dark"] .gallery-card-preview.has-image { background: var(--ui-surface-3); }
.gallery-card-preview.has-image img {
  width: 100%;
  height: auto;
  border-radius: 6px 6px 0 0;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.45);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.gallery-card:hover .gallery-card-preview.has-image img { transform: translateY(-6px); }
.gallery-card-title { font-weight: 800; }
.gallery-card .btn { border-radius: 999px; }
.gallery-card:hover .btn { background: var(--ui-accent); color: var(--ui-on-accent); border-color: var(--ui-accent); }

/* Start screen */
#startScreenModal { padding: 20px; }
.start-screen-card {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.7fr);
  gap: 40px;
  align-items: center;
  width: min(1040px, 100%);
  max-width: none;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 48px;
  text-align: left;
  border-radius: 24px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
}
.start-screen-eyebrow {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--ui-accent-strong);
  font-weight: 800;
  letter-spacing: 0.18em;
}
:root:not([data-theme="dark"]) .start-screen-eyebrow { background: var(--studio-volt); color: var(--studio-ink); padding: 4px 8px; border-radius: 4px; }
.start-screen-title {
  font-family: var(--studio-display);
  font-weight: 400;
  text-transform: uppercase;
  font-size: clamp(40px, 5.2vw, 64px);
  line-height: 0.95;
  letter-spacing: 0;
  margin-bottom: 14px;
}
.start-screen-subtitle { font-size: 15px; margin-bottom: 26px; max-width: 520px; }
.start-picks { display: grid; gap: 14px; margin-bottom: 26px; }
.start-pick-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ui-text-muted); margin-bottom: 8px; }
.start-pick-row { display: flex; flex-wrap: wrap; gap: 8px; }
.start-pick {
  font: 600 13px/1 'Inter', sans-serif;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--ui-border-dark);
  background: var(--ui-surface-2);
  color: var(--ui-text-main);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.start-pick:hover { background: var(--studio-volt); border-color: var(--studio-volt); color: var(--studio-ink); transform: translateY(-1px); }
.start-screen-choices { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.start-choice-btn {
  flex-direction: row;
  justify-content: flex-start;
  text-align: left;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--ui-border-dark);
  background: var(--ui-surface-2);
}
.start-choice-btn:hover { border-color: var(--ui-border-stronger); background: var(--ui-surface-3); box-shadow: none; }
#openGalleryFromStartBtn { background: var(--studio-volt); border-color: var(--studio-volt); color: var(--studio-ink); }
#openGalleryFromStartBtn:hover { background: var(--studio-volt-hover); }
#openGalleryFromStartBtn .start-choice-desc { color: rgba(10, 10, 10, 0.7); }
#openGalleryFromStartBtn .start-choice-icon { background: rgba(10, 10, 10, 0.1); color: var(--studio-ink); }
.start-choice-icon { width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; }
.start-choice-title { font-weight: 800; font-size: 15px; }
.start-screen-hint { text-align: left; margin: 0; }
.start-screen-thumbs { position: relative; height: 440px; }
.start-thumb {
  position: absolute;
  width: 66%;
  padding: 0;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s;
}
.start-thumb img { display: block; width: 100%; height: auto; }
.start-thumb:nth-child(1) { left: 0; top: 40px; transform: rotate(-8deg); z-index: 1; }
.start-thumb:nth-child(2) { left: 30%; top: 70px; transform: rotate(7deg); z-index: 2; }
.start-thumb:nth-child(3) { left: 14%; top: 0; transform: rotate(-1deg); z-index: 3; }
.start-thumb:hover { z-index: 4; transform: rotate(0deg) translateY(-10px) scale(1.03); box-shadow: 0 0 0 3px var(--studio-volt), 0 40px 70px -20px rgba(0, 0, 0, 0.7); }

/* ---------- Motion (alive, but calm) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .tab-content.active { animation: studio-panel-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .panel-section[open] > .panel-section-body { animation: studio-section-in 0.24s ease; }
  .panel-section.is-flash { animation: studio-flash 1.3s ease; }
  .btn:active, .studio-rail-btn:active, .start-pick:active, #printBtn:active { transform: scale(0.97); }
  #autoSaveBadge.is-pulse .status-dot { animation: studio-pulse 0.9s ease; }
  .modal-dialog, .start-screen-card { animation: studio-modal-in 0.34s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .studio-canvas-pills > * { animation: studio-rise 0.5s 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
}
@keyframes studio-panel-in { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes studio-section-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes studio-flash {
  0%, 100% { box-shadow: var(--ui-shadow-sm); border-color: var(--ui-border); }
  20% { box-shadow: 0 0 0 3px rgba(212, 255, 58, 0.55); border-color: #d4ff3a; }
}
@keyframes studio-pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); } 100% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); } }
@keyframes studio-modal-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes studio-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Tablet ---------- */
@media screen and (min-width: 841px) and (max-width: 1180px) {
  :root { --panel-width: 320px; }
  .control-panel:not(.collapsed) { width: var(--panel-width) !important; }
  .header-search-btn { min-width: 0; width: 38px; padding: 0; justify-content: center; }
  .header-search-btn .search-btn-text,
  .header-search-btn .search-kbd { display: none; }
  .page-fit-gauge { display: none; }
  .sidebar-resizer { display: none; }
  .studio-canvas-pills .btn-page-action span { display: none; }
  .studio-canvas-pills .page-manager-note,
  .studio-canvas-pills .page-badge-counter span { display: none; }
}

/* Narrow tablets: the panel floats over the canvas instead of squeezing it */
@media screen and (min-width: 841px) and (max-width: 960px) {
  .control-panel:not(.collapsed) {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--rail-width);
    box-shadow: 30px 0 60px -30px rgba(0, 0, 0, 0.6);
    z-index: 35;
  }
}

/* ---------- Phones ---------- */
@media screen and (max-width: 840px) {
  .studio-rail,
  .studio-canvas-pills { display: none !important; }
  .header-title { font-size: 17px; }
  .control-tabs {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
    overflow-x: auto;
  }
  .tab-btn {
    flex: 1 0 auto;
    flex-direction: column;
    gap: 4px;
    min-height: 56px;
    padding: 8px 12px;
    border: 1px solid var(--ui-border) !important;
    border-radius: 12px !important;
    font-size: 12px;
    font-weight: 700;
  }
  .tab-btn svg { width: 18px; height: 18px; }
  .tab-btn.active { background: var(--ui-accent) !important; color: var(--ui-on-accent) !important; border-color: var(--ui-accent) !important; }
  .panel-header { padding: 14px 16px 6px; }
  .tab-content { padding: 8px 12px 96px; }
  .form-input,
  .form-select,
  .form-textarea { font-size: 16px; min-height: 44px; }
  .panel-section-summary { min-height: 56px; }
  .mobile-bottom-dock {
    background: color-mix(in srgb, var(--ui-surface) 88%, transparent) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--ui-border) !important;
  }
  .mobile-dock-btn.active { color: var(--ui-text-main) !important; }
  .mobile-dock-btn .dock-icon { width: 52px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 999px; transition: background-color 0.2s; }
  .mobile-dock-btn.active .dock-icon { background: var(--studio-volt) !important; }
  .mobile-dock-btn.active .dock-icon svg { stroke: var(--studio-ink) !important; }
  .header-search-btn { min-width: 0; width: 38px; padding: 0; justify-content: center; }
  .header-search-btn .search-btn-text,
  .header-search-btn .search-kbd { display: none; }
  .start-screen-card { grid-template-columns: 1fr; padding: 28px 22px; gap: 0; }
  .start-screen-thumbs { display: none; }
  .start-screen-choices { grid-template-columns: 1fr; }
  .modal-dialog { border-radius: 18px; }
}

@media (max-width: 420px) {
  .start-screen-title { font-size: 38px; }
  .start-pick { padding: 10px 12px; font-size: 13px; }
}

/* ---------- Priority ribbon: quick inserts appear as the toolbar gains room ----------
   Breakpoints = measured toolbar width for each tier + wrapper padding + 16px buffer. */
.toolbar-nav-wrap { container-type: inline-size; container-name: ribbon; }
.tb-quick-divider,
.tb-quick-group,
.tb-quick-btn,
.tb-quick-label { display: none; }
.tb-quick-group { align-items: center; gap: 2px; }
.tb-quick-btn { align-items: center; gap: 6px; width: auto !important; padding: 0 8px !important; font: 600 12px/1 'Inter', sans-serif; white-space: nowrap; }
.tb-quick-btn[aria-pressed="true"] { background: var(--ui-accent-soft); color: var(--ui-accent-strong); }

@container ribbon (min-width: 1230px) {
  .tb-quick-divider { display: block; }
  .tb-quick-group { display: inline-flex; }
  .tb-quick-btn[data-priority="1"],
  .tb-quick-btn[data-priority="2"] { display: inline-flex; }
}
@container ribbon (min-width: 1300px) {
  .tb-quick-btn[data-priority="3"],
  .tb-quick-btn[data-priority="4"] { display: inline-flex; }
}
@container ribbon (min-width: 1370px) {
  .tb-quick-btn[data-priority="5"],
  .tb-quick-btn[data-priority="6"] { display: inline-flex; }
}
@container ribbon (min-width: 1670px) {
  .tb-quick-label { display: inline; }
}

/* ---------- Print: none of the studio layer may reach paper ---------- */
@media print {
  .studio-rail,
  .studio-canvas-pills,
  .tb-quick-group,
  .tb-quick-divider {
    display: none !important;
  }
}

/* ---------- Segmented controls never overflow the panel ---------- */
.control-panel,
.tab-content { overflow-x: hidden; }
.panel-section-body .segmented-control { flex-wrap: wrap; }
.panel-section-body .segmented-control .segment-btn { flex: 1 1 auto; min-width: 0; white-space: nowrap; }
/* Four long margin labels: lay out as a 2x2 grid instead of one squeezed row */
#pageMarginGroup { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
#pageMarginGroup .segment-btn { width: 100%; }

/* Consistent native-select arrows with room for long labels. */
.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23777777' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.label-with-action { min-height: 32px; gap: 8px; }
.form-group .label-with-action label { margin-bottom: 0; }
#setTodayBtn { min-height: 32px; margin: 0; }

/* Keep browser autofill legible and consistent in either editor theme. */
.form-input:autofill {
  background-color: var(--ui-input-bg);
  color: var(--ui-text-main);
  box-shadow: inset 0 0 0 1000px var(--ui-input-bg);
}
.form-input:-webkit-autofill,
.form-input:-webkit-autofill:hover,
.form-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ui-text-main);
  -webkit-box-shadow: inset 0 0 0 1000px var(--ui-input-bg);
  caret-color: var(--ui-text-main);
}
.form-input:-webkit-autofill:focus {
  box-shadow: inset 0 0 0 1000px var(--ui-input-bg), 0 0 0 4px var(--ui-input-focus);
}

.saved-letterheads-body { display: flex; flex-direction: column; gap: 12px; }
.saved-letterheads-body > label { font-size: var(--ui-font-sm); margin: 0; }
.saved-letterheads-body .form-row { flex-wrap: wrap; gap: 8px; }
.saved-letterheads-body .form-row .btn { flex: 1 1 120px; min-height: 44px; }
.saved-letterheads-body .canvas-hint { margin: 0; }
#brandProfileStatus:empty { display: none; }

.feature-search-backdrop { padding-left: 12px; padding-right: 12px; }
.feature-search-header { padding: 16px; }
.feature-search-input-wrap { padding: 8px; border-radius: 8px; border: 1px solid var(--ui-border); }
.feature-search-input-wrap:focus-within { border-color: var(--ui-accent); box-shadow: 0 0 0 3px var(--ui-input-focus); }
.feature-search-input { min-width: 0; border-radius: 6px; padding: 4px; }
.feature-search-input:focus { outline: none; box-shadow: none; }
.feature-search-body { padding: 12px; }

/* Empty workspace uses the editor's existing surface, type and accent tokens. */
.workspace-empty-state { width: min(100%, 520px); margin: auto; padding: 40px 24px; text-align: center; color: var(--ui-text-main); }
.workspace-empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 24px; border-radius: var(--radius-md); background: var(--studio-volt); color: var(--studio-ink); }
.workspace-empty-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--ui-text-muted); margin-bottom: 12px; }
.workspace-empty-state h2 { font-size: clamp(24px, 4vw, 32px); letter-spacing: -.04em; margin: 0 0 12px; }
.workspace-empty-state > p:not(.workspace-empty-eyebrow) { font-size: 14px; line-height: 1.6; color: var(--ui-text-sub); }
.workspace-empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.workspace-empty-actions .btn { min-height: 44px; }
.workspace-empty .document-canvas-wrapper,
.workspace-empty #docFormattingToolbar,
.workspace-empty .control-panel,
.workspace-empty .studio-rail,
.workspace-empty .zoom-controls,
.workspace-empty .doc-page-manager-bar,
.workspace-empty #mobileCanvasHint,
.workspace-empty #mobileFloatingPreviewBtn { display: none !important; }
.workspace-empty .paper-viewport { display: flex !important; min-height: 360px; }
.workspace-empty .preview-area { display: flex !important; }
.workspace-empty #sidebarResizer { display: none !important; }
.workspace-empty #emptyWorkspace { display: block; }
.workspace-empty #printBtn,
.workspace-empty #dockPrintBtn { visibility: hidden; }
.workspace-empty button:disabled { opacity: .4; cursor: default; }
.gallery-apply-mode { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.gallery-apply-mode label { color: var(--ui-text-sub); font-size: 12px; white-space: nowrap; }
.gallery-apply-mode .form-select { max-width: 240px; }
.page-body-only #pageContainer-1 #previewMetaRow,
.page-body-only #pageContainer-1 #previewRecipientBlock,
.page-body-only #pageContainer-1 #previewSubjectWrap,
.page-body-only #pageContainer-1 #previewSalutation,
.page-body-only #pageContainer-1 #previewDetailsBlock,
.page-body-only #pageContainer-1 #previewClosingCourtesy,
.page-body-only #pageContainer-1 #previewSignoffRow,
.page-body-only #pageContainer-1 .section-spacer-widget { display: none !important; }
@media (max-width: 840px) {
  .workspace-empty-state { padding: 32px 20px; }
  .workspace-empty-actions { flex-direction: column; }
}
