/* ------------------------------------------------------------------
   Paperglass — on-device document scanner
   ------------------------------------------------------------------ */

:root {
  --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --font-mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  --topbar-h: 66px;
  --sidebar-w: 274px;
  --inspector-w: 306px;
  --radius-sm: 9px;
  --radius-md: 13px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --ease: cubic-bezier(0.2, 0.75, 0.25, 1);

  /* Light — warm paper + deep teal ink */
  --bg: #f1efe9;
  --bg-soft: #eae7df;
  --bg-elevated: #f8f6f1;
  --surface: #fffefb;
  --surface-2: #f5f2eb;
  --surface-3: #ece8df;
  --border: #e2ddd2;
  --border-strong: #d2cbbb;
  --text: #1c2320;
  --text-soft: #434c47;
  --muted: #767c76;
  --faint: #a4a8a1;
  --accent: #0f7a6c;
  --accent-hover: #0b675b;
  --accent-soft: #dcefe9;
  --accent-soft-2: #eef7f4;
  --accent-ink: #0a5a50;
  --accent-contrast: #ffffff;
  --danger: #b3413b;
  --danger-soft: #f8e7e5;
  --shadow-xs: 0 1px 2px rgba(28, 35, 32, 0.05);
  --shadow-sm: 0 2px 5px rgba(28, 35, 32, 0.06), 0 1px 1px rgba(28, 35, 32, 0.04);
  --shadow-md: 0 10px 28px -10px rgba(28, 35, 32, 0.22), 0 2px 6px rgba(28, 35, 32, 0.05);
  --shadow-lg: 0 30px 70px -22px rgba(24, 31, 28, 0.34), 0 4px 14px rgba(24, 31, 28, 0.06);
  --stage-glow: rgba(15, 122, 108, 0.08);
  --dot: rgba(28, 35, 32, 0.14);
  --overlay: rgba(18, 24, 21, 0.48);
  --scrub: #d7d2c7;
  --glass: rgba(248, 246, 241, 0.82);
  --logo-shadow: 0 4px 10px rgba(15, 122, 108, 0.25);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1211;
  --bg-soft: #111716;
  --bg-elevated: #121816;
  --surface: #171e1c;
  --surface-2: #1b2421;
  --surface-3: #243029;
  --border: #27312d;
  --border-strong: #37453f;
  --text: #e9efec;
  --text-soft: #c0cac5;
  --muted: #8d9a94;
  --faint: #66736d;
  --accent: #42c9ae;
  --accent-hover: #63d8c1;
  --accent-soft: rgba(66, 201, 174, 0.14);
  --accent-soft-2: rgba(66, 201, 174, 0.075);
  --accent-ink: #89e7d5;
  --accent-contrast: #052b25;
  --danger: #f08a83;
  --danger-soft: rgba(240, 138, 131, 0.12);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 14px 34px -14px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 34px 80px -26px rgba(0, 0, 0, 0.8), 0 4px 18px rgba(0, 0, 0, 0.35);
  --stage-glow: rgba(66, 201, 174, 0.055);
  --dot: rgba(233, 239, 236, 0.11);
  --overlay: rgba(4, 8, 7, 0.66);
  --scrub: #34413c;
  --glass: rgba(13, 18, 17, 0.78);
  --logo-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.35s var(--ease), color 0.35s var(--ease);
}

body.is-dragging-over {
  cursor: copy;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img,
canvas,
video {
  display: block;
  max-width: 100%;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

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

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

/* ------------------------------------------------------------------ */
/* App shell                                                           */
/* ------------------------------------------------------------------ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.topbar {
  position: relative;
  z-index: 30;
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex: none;
  border-radius: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--logo-shadow);
  transition: transform 0.25s var(--ease);
}

.brand:hover .brand-mark {
  transform: translateY(-1px) rotate(-2deg);
}

.brand-mark svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 21px;
  letter-spacing: -0.02em;
  font-weight: 600;
  line-height: 1;
  padding-bottom: 2px;
}

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease),
    color 0.18s var(--ease), transform 0.12s var(--ease), box-shadow 0.18s var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 1px 2px rgba(10, 40, 35, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-soft);
  box-shadow: var(--shadow-xs);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-2);
}

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-soft);
}

.btn-soft:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 1px 2px rgba(100, 20, 16, 0.2);
}

[data-theme="dark"] .btn-danger {
  color: #2a0906;
}

.btn-small {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-full {
  width: 100%;
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease),
    border-color 0.16s var(--ease), transform 0.12s var(--ease);
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.icon-btn.small {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.icon-btn.small .icon {
  width: 16px;
  height: 16px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.16s var(--ease);
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tool-btn.is-active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent-ink);
}

.tool-btn .icon {
  width: 16px;
  height: 16px;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: color 0.16s var(--ease), background-color 0.16s var(--ease);
}

.text-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.text-btn .icon {
  width: 14px;
  height: 14px;
}

.text-danger {
  color: var(--danger);
}

.text-danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ------------------------------------------------------------------ */
/* Workspace                                                           */
/* ------------------------------------------------------------------ */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--inspector-w);
}

.workspace.is-empty {
  grid-template-columns: minmax(0, 1fr);
}

.workspace.is-empty .sidebar,
.workspace.is-empty .inspector {
  display: none;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */

.sidebar,
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-elevated);
}

.sidebar {
  border-right: 1px solid var(--border);
}

.inspector {
  border-left: 1px solid var(--border);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 18px 14px;
  flex: none;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.page-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrub) transparent;
}

.page-list::-webkit-scrollbar {
  width: 8px;
}

.page-list::-webkit-scrollbar-thumb {
  background: var(--scrub);
  border-radius: 99px;
  border: 2px solid var(--bg-elevated);
}

.page-list::-webkit-scrollbar-track {
  background: transparent;
}

.page-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 7px 7px 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: grab;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease),
    box-shadow 0.16s var(--ease), opacity 0.16s var(--ease);
  animation: cardIn 0.35s var(--ease) both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.page-card:hover {
  background: var(--surface-2);
}

.page-card.is-active {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.page-card.is-active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.page-card.is-dragging {
  opacity: 0.35;
  cursor: grabbing;
}

.page-card.is-drop-target {
  box-shadow: inset 0 2px 0 var(--accent);
}

.thumb-wrap {
  position: relative;
  flex: none;
  width: 42px;
  height: 54px;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(20, 30, 25, 0.08), 0 1px 3px rgba(20, 30, 25, 0.1);
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(100deg, #fff 0%, #f4f4f1 45%, #fff 80%);
  background-size: 220% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -120% 0;
  }
}

.page-index {
  position: absolute;
  left: -5px;
  bottom: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--text);
  color: var(--bg-elevated);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.page-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-name {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-soft);
}

.page-card.is-active .page-name {
  color: var(--text);
}

.page-meta {
  margin: 0;
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-more {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: none;
  opacity: 0;
}

.page-card:hover .page-more,
.page-card.is-active .page-more,
.page-more[aria-expanded="true"] {
  opacity: 1;
}

.page-more .icon {
  width: 15px;
  height: 15px;
}

.card-menu {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  min-width: 158px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: menuIn 0.16s var(--ease) both;
}

@keyframes menuIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.card-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-soft);
  font-size: 12.5px;
  text-align: left;
}

.card-menu button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.card-menu button:disabled {
  opacity: 0.35;
  cursor: default;
}

.card-menu button.danger {
  color: var(--danger);
}

.card-menu button.danger:hover {
  background: var(--danger-soft);
}

.card-menu .icon {
  width: 15px;
  height: 15px;
}

.menu-sep {
  height: 1px;
  margin: 4px 5px;
  background: var(--border);
}

.sidebar-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
}

.save-state .icon {
  width: 13px;
  height: 13px;
  flex: none;
}

.save-state.is-saving .icon {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.sidebar-foot .text-btn {
  font-size: 11px;
  flex: none;
}

/* ------------------------------------------------------------------ */
/* Stage + empty state                                                 */
/* ------------------------------------------------------------------ */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(900px 560px at 50% -10%, var(--stage-glow), transparent 70%),
    var(--bg);
  transition: background-color 0.35s var(--ease);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0);
  background-size: 24px 24px;
  opacity: 0.42;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 45%, #000 20%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 80% at 50% 45%, #000 20%, transparent 100%);
}

.empty {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 38px 28px 46px;
  scrollbar-width: thin;
}

.hero {
  max-width: 620px;
  text-align: center;
  animation: rise 0.6s var(--ease) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 8px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-xs);
}

.eyebrow-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.hero h1 {
  margin: 18px 0 12px;
  font-family: var(--font-display);
  font-size: clamp(38px, 5.1vw, 60px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: var(--text);
}

.hero h1 em {
  font-style: italic;
  color: var(--accent);
}

.hero-sub {
  margin: 0 auto;
  max-width: 510px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.65;
  text-wrap: pretty;
}

.dropzone {
  position: relative;
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 22px 24px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  box-shadow: var(--shadow-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), box-shadow 0.25s var(--ease),
    transform 0.25s var(--ease), background-color 0.25s var(--ease);
  animation: rise 0.6s 0.08s var(--ease) both;
}

.dropzone::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(360px 140px at 18% 50%, var(--accent-soft-2), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  pointer-events: none;
}

.dropzone:hover,
.dropzone.is-hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.dropzone:hover::after,
.dropzone.is-hover::after {
  opacity: 1;
}

.dropzone > * {
  position: relative;
  z-index: 1;
}

.drop-graphic {
  position: relative;
  width: 84px;
  height: 84px;
  flex: none;
}

.mini-sheet {
  position: absolute;
  width: 58px;
  height: 74px;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(25, 35, 30, 0.14), 0 0 0 1px rgba(25, 35, 30, 0.05);
}

[data-theme="dark"] .mini-sheet {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sheet-back {
  left: 4px;
  top: 8px;
  transform: rotate(-9deg);
  opacity: 0.55;
}

.sheet-mid {
  left: 14px;
  top: 5px;
  transform: rotate(5deg);
  opacity: 0.8;
}

.sheet-front {
  left: 13px;
  top: 4px;
  overflow: hidden;
  padding: 13px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-line {
  display: block;
  height: 3px;
  border-radius: 3px;
  background: #cfd8d4;
}

.sheet-line.w-70 { width: 70%; }
.sheet-line.w-90 { width: 90%; }
.sheet-line.w-55 { width: 55%; }
.sheet-line.w-80 { width: 80%; }

.sheet-front .sheet-line:first-child {
  height: 5px;
  background: var(--accent);
  width: 42%;
  margin-bottom: 2px;
}

.scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 22px;
  background: linear-gradient(to bottom, transparent, rgba(15, 122, 108, 0.2) 65%, rgba(15, 122, 108, 0.65));
  border-bottom: 1px solid rgba(15, 122, 108, 0.9);
  animation: beam 2.6s var(--ease) infinite;
}

@keyframes beam {
  0%, 12% {
    transform: translateY(-24px);
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  92%, 100% {
    transform: translateY(76px);
    opacity: 0;
  }
}

.drop-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.drop-copy strong {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.drop-copy span {
  color: var(--muted);
  font-size: 12.5px;
}

.drop-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
}

.drop-actions .btn {
  width: 100%;
  justify-content: flex-start;
}

.feature-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 700px;
  animation: rise 0.6s 0.16s var(--ease) both;
}

.feature-row li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.feature-row .icon {
  width: 13px;
  height: 13px;
  color: var(--accent);
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: -4px 0 0;
  color: var(--faint);
  font-size: 11px;
  animation: rise 0.6s 0.22s var(--ease) both;
}

.privacy-note .icon {
  width: 12px;
  height: 12px;
}

/* ------------------------------------------------------------------ */
/* Editor                                                              */
/* ------------------------------------------------------------------ */

.editor {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 55%, transparent);
  min-height: 54px;
}

.editor-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-index {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  box-shadow: var(--shadow-xs);
  flex: none;
}

.file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.file-meta strong {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(36vw, 320px);
}

.file-meta span {
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.editor-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.editor-tools .icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.tool-sep {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: var(--border);
  flex: none;
}

.canvas-area {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  padding: 24px;
  position: relative;
}

.canvas-slot {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.paper-holder {
  position: relative;
  flex: none;
  line-height: 0;
  border-radius: 2px;
  background: #fff;
  box-shadow:
    0 0 0 1px rgba(20, 30, 26, 0.1),
    0 2px 5px rgba(20, 30, 26, 0.09),
    0 26px 60px -18px rgba(20, 30, 26, 0.4);
  transition: box-shadow 0.3s var(--ease);
}

[data-theme="dark"] .paper-holder {
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    0 3px 8px rgba(0, 0, 0, 0.4),
    0 30px 70px -16px rgba(0, 0, 0, 0.75);
}

#previewCanvas {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: #fff;
}

.editor.is-cropping .paper-holder {
  box-shadow:
    0 0 0 1px var(--accent),
    0 0 0 5px color-mix(in srgb, var(--accent) 18%, transparent),
    0 26px 60px -18px rgba(20, 30, 26, 0.4);
}

.crop-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  overflow: visible;
}

.editor.is-cropping .crop-svg {
  opacity: 1;
}

.crop-handles {
  position: absolute;
  inset: 0;
  display: none;
}

.editor.is-cropping .crop-handles {
  display: block;
}

.crop-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  padding: 0;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.16);
  touch-action: none;
  cursor: grab;
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.crop-handle:hover {
  transform: scale(1.15);
}

.crop-handle.is-dragging {
  cursor: grabbing;
  transform: scale(1.2);
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 26%, transparent), 0 3px 8px rgba(0, 0, 0, 0.3);
}

.crop-handle::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.9;
}

.render-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, #fff 32%, transparent);
  backdrop-filter: blur(1.5px);
  opacity: 0.9;
  transition: opacity 0.2s var(--ease);
}

.editor-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px 12px;
  min-height: 46px;
}

.stage-hint {
  color: var(--muted);
  font-size: 11.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.crop-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  animation: menuIn 0.18s var(--ease) both;
}

.crop-actions .text-btn {
  padding: 6px 8px;
}

.crop-actions .btn {
  margin-left: 4px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
  flex: none;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 2.5px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------ */
/* Inspector                                                           */
/* ------------------------------------------------------------------ */

.inspector-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrub) transparent;
}

.inspector-scroll::-webkit-scrollbar {
  width: 8px;
}

.inspector-scroll::-webkit-scrollbar-thumb {
  background: var(--scrub);
  border-radius: 99px;
  border: 2px solid var(--bg-elevated);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.group-label {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.value-pill {
  min-width: 34px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.field-hint {
  margin: 0;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.5;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  overflow: hidden;
  text-align: left;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease),
    transform 0.12s var(--ease);
}

.preset:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.preset:active {
  transform: scale(0.985);
}

.preset.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm);
}

.preset-swatch {
  display: block;
  height: 42px;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.swatch-clean {
  background: #ffffff;
}

.swatch-clean::before,
.swatch-ink::before,
.swatch-color::before,
.swatch-original::before {
  content: "";
  position: absolute;
  inset: 9px 10px;
  background:
    linear-gradient(#2a2a2a 0 0) 0 0 / 55% 2.5px no-repeat,
    linear-gradient(#b9b9b4 0 0) 0 8px / 88% 2px no-repeat,
    linear-gradient(#b9b9b4 0 0) 0 14px / 78% 2px no-repeat,
    linear-gradient(#b9b9b4 0 0) 0 20px / 84% 2px no-repeat;
}

.swatch-ink {
  background: #ffffff;
}

.swatch-ink::before {
  background:
    linear-gradient(#000 0 0) 0 0 / 55% 3px no-repeat,
    linear-gradient(#000 0 0) 0 8px / 88% 2.5px no-repeat,
    linear-gradient(#000 0 0) 0 14px / 78% 2.5px no-repeat,
    linear-gradient(#000 0 0) 0 20px / 84% 2.5px no-repeat;
}

.swatch-color {
  background: #fffdf7;
}

.swatch-color::before {
  background:
    linear-gradient(#1b4d3d 0 0) 0 0 / 45% 4px no-repeat,
    linear-gradient(#5b8f7d 0 0) 0 8px / 88% 2px no-repeat,
    linear-gradient(#d7a13a 0 0) 0 14px / 30% 2.5px no-repeat,
    linear-gradient(#5b8f7d 0 0) 0 20px / 84% 2px no-repeat;
}

.swatch-original {
  background: linear-gradient(135deg, #dcd3c2, #b9ad97 55%, #e7dfd0);
}

.swatch-original::before {
  inset: 6px 8px;
  border-radius: 2px;
  background:
    linear-gradient(#fff 0 0) 0 0 / 100% 100% no-repeat,
    linear-gradient(#6b6152 0 0) 5px 6px / 50% 2.5px no-repeat,
    linear-gradient(#a89d8b 0 0) 5px 12px / 70% 2px no-repeat,
    linear-gradient(#a89d8b 0 0) 5px 17px / 60% 2px no-repeat,
    linear-gradient(#a89d8b 0 0) 5px 22px / 66% 2px no-repeat;
}

.preset-name {
  padding: 7px 9px 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-soft);
  letter-spacing: -0.005em;
}

.preset.is-active .preset-name {
  color: var(--accent-ink);
}

.preset-note {
  padding: 0 9px 8px;
  color: var(--faint);
  font-size: 9.5px;
  line-height: 1.4;
}

.preset-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 15px !important;
  height: 15px !important;
  padding: 2px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.16s var(--ease), transform 0.2s var(--ease);
}

.preset.is-active .preset-check {
  opacity: 1;
  transform: scale(1);
}

/* Range slider */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--scrub) var(--fill, 0%));
}

.range::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: var(--scrub);
}

.range::-moz-range-progress {
  height: 4px;
  border-radius: 99px;
  background: var(--accent);
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(15, 40, 34, 0.3), 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.range::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(15, 40, 34, 0.3);
}

.range:hover::-webkit-slider-thumb {
  transform: scale(1.12);
}

.range:active::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 18%, transparent);
}

.range:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.inspector.is-disabled .range,
.inspector.is-disabled .value-pill {
  opacity: 0.35;
}

.info-card {
  display: flex;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}

.info-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.info-icon .icon {
  width: 15px;
  height: 15px;
}

.info-card p {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.55;
}

.info-card strong {
  color: var(--text-soft);
  font-weight: 650;
}

.inspector-foot {
  flex: none;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 36px;
  gap: 6px;
}

.action-row .btn {
  padding: 0 8px;
  gap: 6px;
  font-size: 11.5px;
}

.action-row .btn .icon {
  width: 14px;
  height: 14px;
}

.page-action-danger {
  width: 36px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
}

.page-action-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.inspector-foot .btn {
  height: 36px;
  font-size: 12.5px;
}

/* ------------------------------------------------------------------ */
/* Drop overlay                                                        */
/* ------------------------------------------------------------------ */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 28px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(7px);
  animation: fadeIn 0.16s var(--ease) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

.drop-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(460px, 100%);
  padding: 46px 28px;
  border: 2px dashed var(--accent);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
  pointer-events: none;
}

.drop-overlay-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 4px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.drop-overlay-icon .icon {
  width: 26px;
  height: 26px;
}

.drop-overlay-card strong {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.drop-overlay-card > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

/* ------------------------------------------------------------------ */
/* Modals                                                              */
/* ------------------------------------------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fadeIn 0.2s var(--ease) both;
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(90vh, 760px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.28s var(--ease) both;
  overflow: hidden;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
}

.modal-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 16px;
}

.modal-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.16s var(--ease);
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.is-active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.segmented button .icon {
  width: 16px;
  height: 16px;
}

.segmented-small {
  border-radius: 9px;
}

.segmented-small button {
  height: 32px;
  font-size: 12px;
  border-radius: 7px;
}

.export-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.2s var(--ease) both;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  padding: 0 32px 0 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  cursor: pointer;
}

.select-wrap .icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

.input-affix {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  padding-right: 11px;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.input-affix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft-2);
}

.input-affix input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 4px 0 11px;
  border: 0;
  background: transparent;
  font-size: 13px;
  outline: none;
}

.input-affix > span {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.export-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-soft);
}

.export-summary > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.export-summary .icon {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

.summary-note {
  color: var(--faint);
  font-size: 10.5px;
  white-space: nowrap;
}

.confirm-card {
  width: min(410px, 100%);
}

.confirm-card .modal-head {
  padding-bottom: 10px;
}

.confirm-card .modal-head h3 {
  font-size: 21px;
}

.confirm-card .modal-foot {
  border-top: 0;
  padding-top: 12px;
}

/* Camera */
.camera-card {
  width: min(660px, 100%);
}

.camera-stage {
  position: relative;
  margin: 0 24px;
  border-radius: 14px;
  overflow: hidden;
  background: #0a0f0d;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0a0f0d;
}

.camera-guide {
  position: absolute;
  inset: 9%;
  border: 1.5px solid rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  box-shadow: 0 0 0 999px rgba(4, 8, 7, 0.18);
  pointer-events: none;
}

.camera-guide::before,
.camera-guide::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--accent);
}

.camera-guide::before {
  left: -2px;
  top: -2px;
  border-right: 0;
  border-bottom: 0;
  border-radius: 4px 0 0 0;
}

.camera-guide::after {
  right: -2px;
  bottom: -2px;
  border-left: 0;
  border-top: 0;
  border-radius: 0 0 4px 0;
}

.camera-error {
  position: absolute;
  left: 24px;
  right: 24px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.camera-foot {
  justify-content: space-between;
  border-top: 0;
  padding-top: 16px;
}

.shutter-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  margin-right: 1px;
}

/* ------------------------------------------------------------------ */
/* Busy + toasts                                                       */
/* ------------------------------------------------------------------ */

.busy {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 58%, transparent);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.18s var(--ease) both;
}

.busy-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(380px, 100%);
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
}

.busy-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.busy-copy strong {
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.busy-copy span {
  color: var(--muted);
  font-size: 11.5px;
}

.progress {
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--scrub);
  overflow: hidden;
  margin-top: 2px;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.25s var(--ease);
}

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(460px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn 0.32s var(--ease) both;
}

.toast.is-leaving {
  animation: toastOut 0.22s var(--ease) both;
}

.toast .toast-icon {
  display: grid;
  place-items: center;
  color: var(--accent);
  flex: none;
}

.toast.is-error .toast-icon {
  color: var(--danger);
}

.toast .icon {
  width: 16px;
  height: 16px;
}

.toast span {
  min-width: 0;
}

.toast button {
  margin-left: 4px;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11.5px;
  font-weight: 700;
  flex: none;
}

.toast button:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

/* ------------------------------------------------------------------ */
/* Utility + responsive                                                */
/* ------------------------------------------------------------------ */

.only-mobile {
  display: none;
}

.inspector-scrim {
  display: none;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .only-mobile {
    display: inline-flex;
  }

  .inspector {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    z-index: 60;
    width: min(340px, 92vw);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(102%);
    transition: transform 0.3s var(--ease);
    visibility: hidden;
  }

  .inspector.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .inspector-scrim {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 55;
    display: block;
    background: var(--overlay);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s var(--ease) both;
  }

  .canvas-area {
    padding: 20px;
  }
}

@media (max-width: 900px) {
  :root {
    --topbar-h: 60px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  /* Stage first, page strip at the bottom of the screen. */
  .stage {
    grid-row: 1;
  }

  .sidebar {
    grid-row: 2;
    border-right: 0;
    border-top: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--bg-elevated);
    overflow: hidden;
    height: calc(96px + env(safe-area-inset-bottom));
    flex: none;
  }

  .sidebar .panel-head,
  .sidebar-foot {
    display: none;
  }

  .page-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px;
    gap: 8px;
    height: 100%;
    align-items: center;
  }

  .page-card {
    flex: none;
    width: auto;
    padding: 4px;
    border-radius: 9px;
    gap: 0;
    cursor: pointer;
  }

  .page-card.is-active::before {
    display: none;
  }

  .page-info,
  .page-more {
    display: none;
  }

  .thumb-wrap {
    width: 44px;
    height: 60px;
    border-radius: 4px;
  }

  .thumb-wrap img {
    border-radius: 4px;
  }

  .page-index {
    font-size: 8px;
    min-width: 15px;
    height: 15px;
  }

  .topbar-center {
    display: none;
  }

  .topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .brand-name {
    font-size: 19px;
  }

  .editor-bar {
    padding: 8px 12px;
    min-height: 50px;
  }

  .canvas-area {
    padding: 14px;
  }

  .editor-foot {
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .stage-hint {
    display: none;
  }

  .crop-label {
    display: none;
  }

  #cropBtn {
    padding: 0 9px;
  }

  .dropzone {
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding: 20px;
  }

  .drop-actions {
    grid-column: 1 / -1;
    flex-direction: row;
  }

  .drop-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .feature-row li:nth-child(4) {
    display: none;
  }

  .modal {
    padding: 14px;
    align-items: end;
  }

  .modal-card {
    max-height: 92vh;
    border-radius: 22px;
  }

  .camera-stage {
    margin: 0 16px;
  }

  .toast-stack {
    /* Keep toasts clear of the bottom page strip. */
    bottom: calc(110px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 640px) {
  .topbar-actions .hide-mobile {
    display: none;
  }

  .topbar .btn-primary {
    height: 36px;
    padding: 0 12px;
  }

  .hero h1 {
    font-size: 40px;
  }

  .hero-sub {
    font-size: 13.5px;
  }

  .empty {
    gap: 18px;
    padding: 26px 16px 32px;
    justify-content: flex-start;
    padding-top: 34px;
  }

  .eyebrow {
    font-size: 10px;
  }

  .dropzone {
    padding: 18px;
    border-radius: 20px;
  }

  .drop-graphic {
    width: 64px;
    height: 64px;
    transform: scale(0.8);
    transform-origin: left center;
  }

  .drop-copy strong {
    font-size: 17px;
  }

  .drop-copy span {
    font-size: 11px;
  }

  .drop-actions {
    flex-direction: column;
  }

  .feature-row li:nth-child(n + 3) {
    display: none;
  }

  .privacy-note {
    font-size: 10px;
    text-align: center;
  }

  .file-meta strong {
    max-width: 42vw;
  }

  .file-index {
    display: none;
  }

  .tool-sep {
    margin: 0 3px;
  }

  .editor-tools .icon-btn {
    width: 32px;
    height: 32px;
  }

  .nav-actions .btn span {
    display: none;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-head {
    padding: 18px 18px 12px;
  }

  .modal-head h3 {
    font-size: 21px;
  }

  .modal-body {
    padding: 0 18px 16px;
  }

  .modal-foot {
    padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
  }

  .export-summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .summary-note {
    padding-left: 22px;
  }

  .sidebar {
    height: calc(86px + env(safe-area-inset-bottom));
  }

  .thumb-wrap {
    width: 40px;
    height: 56px;
  }
}

@media (max-height: 720px) and (min-width: 641px) {
  .empty {
    gap: 16px;
    padding-top: 26px;
    padding-bottom: 28px;
    justify-content: flex-start;
  }

  .hero h1 {
    font-size: 44px;
    margin: 12px 0 8px;
  }

  .hero-sub {
    font-size: 13px;
  }

  .dropzone {
    padding: 16px 20px;
  }

  .drop-graphic {
    width: 70px;
    height: 70px;
    transform: scale(0.88);
    transform-origin: left center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------ */
/* Language switcher                                                   */
/* ------------------------------------------------------------------ */

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease),
    color 0.16s var(--ease);
}

.lang-btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.lang-btn:active {
  transform: translateY(1px);
}

.lang-btn .icon {
  width: 15px;
  height: 15px;
  color: var(--accent);
  flex: none;
}

/* ------------------------------------------------------------------ */
/* Arabic typography                                                   */
/* ------------------------------------------------------------------ */

[lang="ar"] {
  --font-sans: "Noto Naskh Arabic", "Dubai", "Segoe UI", Tahoma, Arial, sans-serif;
  --font-display: "Noto Naskh Arabic", "Traditional Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
}

[lang="ar"] body {
  letter-spacing: 0;
}

[lang="ar"] .brand-name {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  letter-spacing: -0.02em;
}

[lang="ar"] .hero h1,
[lang="ar"] .panel-head h2,
[lang="ar"] .modal-head h3,
[lang="ar"] .drop-copy strong {
  letter-spacing: 0;
}

[lang="ar"] .hero h1 {
  line-height: 1.24;
}

[lang="ar"] .hero h1 em {
  font-style: normal;
}

[lang="ar"] .drop-copy strong {
  line-height: 1.4;
}

[lang="ar"] .eyebrow,
[lang="ar"] .group-label {
  letter-spacing: 0;
}

/* ------------------------------------------------------------------ */
/* Right-to-left layout                                                */
/* ------------------------------------------------------------------ */

[dir="rtl"] .sidebar {
  border-right: 0;
  border-left: 1px solid var(--border);
}

[dir="rtl"] .inspector {
  border-left: 0;
  border-right: 1px solid var(--border);
}

[dir="rtl"] .page-card {
  padding: 7px 8px 7px 7px;
}

[dir="rtl"] .page-card.is-active::before {
  left: auto;
  right: -1px;
  border-radius: 3px 0 0 3px;
}

[dir="rtl"] .page-index {
  left: auto;
  right: -5px;
}

[dir="rtl"] .card-menu button {
  text-align: right;
}

[dir="rtl"] .eyebrow {
  padding: 5px 8px 5px 11px;
}

[dir="rtl"] .dropzone {
  text-align: right;
  background: linear-gradient(225deg, var(--surface) 0%, var(--surface-2) 100%);
}

[dir="rtl"] .dropzone::after {
  background: radial-gradient(360px 140px at 82% 50%, var(--accent-soft-2), transparent 70%);
}

[dir="rtl"] .preset {
  text-align: right;
}

[dir="rtl"] .preset-check {
  right: auto;
  left: 6px;
}

[dir="rtl"] .crop-actions {
  margin-left: 0;
  margin-right: auto;
}

[dir="rtl"] .crop-actions .btn {
  margin-left: 0;
  margin-right: 4px;
}

[dir="rtl"] #exportBtn .icon {
  transform: scaleX(-1);
}

[dir="rtl"] .select-wrap select {
  padding: 0 11px 0 32px;
}

[dir="rtl"] .select-wrap .icon {
  right: auto;
  left: 10px;
}

[dir="rtl"] .input-affix {
  padding-right: 0;
  padding-left: 11px;
}

[dir="rtl"] .input-affix input {
  padding: 0 11px 0 4px;
}

[dir="rtl"] .range::-webkit-slider-runnable-track {
  background: linear-gradient(to left, var(--accent) var(--fill, 0%), var(--scrub) var(--fill, 0%));
}

[dir="rtl"] .camera-guide::before {
  left: auto;
  right: -2px;
  border-left: 0;
  border-right: 2.5px solid var(--accent);
  border-radius: 0 4px 0 0;
}

[dir="rtl"] .camera-guide::after {
  right: auto;
  left: -2px;
  border-right: 0;
  border-left: 2.5px solid var(--accent);
  border-radius: 0 0 0 4px;
}

[dir="rtl"] .shutter-dot {
  margin-right: 0;
  margin-left: 1px;
}

[dir="rtl"] .toast button {
  margin-left: 0;
  margin-right: 4px;
}

[dir="rtl"] .drop-graphic {
  transform-origin: right center;
}

[dir="rtl"] .lang-btn {
  padding: 0 9px 0 11px;
}

@media (max-width: 1180px) {
  [dir="rtl"] .inspector {
    right: auto;
    left: 0;
    border-right: 1px solid var(--border);
    border-left: 0;
    transform: translateX(-102%);
  }

  [dir="rtl"] .inspector.is-open {
    transform: translateX(0);
  }
}

@media (max-width: 900px) {
  [dir="rtl"] .sidebar {
    border-left: 0;
  }
}

@media (max-width: 640px) {
  [dir="rtl"] .summary-note {
    padding-left: 0;
    padding-right: 22px;
  }
}

@media (max-width: 560px) {
  #langLabel {
    display: none;
  }

  .lang-btn {
    padding: 0 9px;
  }

  [dir="rtl"] .lang-btn {
    padding: 0 9px;
  }
}
