:root {
  --bg: #f2ede3;
  --panel: rgba(255, 251, 245, 0.88);
  --panel-strong: #fffdf8;
  --ink: #1e1c18;
  --muted: #716858;
  --line: rgba(54, 43, 25, 0.14);
  --accent: #a54620;
  --accent-dark: #7e2f13;
  --shadow: 0 20px 60px rgba(68, 45, 21, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(214, 128, 81, 0.18), transparent 28%),
    radial-gradient(circle at right 20%, rgba(165, 70, 32, 0.12), transparent 24%),
    linear-gradient(180deg, #f7f1e8 0%, var(--bg) 100%);
}

body.dragover-active {
  overflow: hidden;
}

.mobile-flow-nav {
  display: none;
}

.license-footer {
  padding: 0.75rem 1rem 1rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.license-footer a {
  color: var(--accent-dark);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 0.78rem 1rem;
  background: #efe4d4;
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: #e7d8c4;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(31, 111, 120, 0.62);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

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

button.primary {
  background: var(--accent);
  color: #fff7f1;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  background: #f7d9d4;
  color: #7f2619;
}

button.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.48rem;
}

button.icon-button::before {
  content: "";
  flex: 0 0 1.15rem;
  width: 1.15rem;
  height: 1.15rem;
  background: currentColor;
  -webkit-mask: var(--button-icon) center / contain no-repeat;
  mask: var(--button-icon) center / contain no-repeat;
}

button.icon-only {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 0;
}

button.icon-only::before,
.upload-card > span::before {
  content: "";
  width: 1.2rem;
  height: 1.2rem;
  background: currentColor;
  -webkit-mask: url("../icons/material/close.svg") center / contain no-repeat;
  mask: url("../icons/material/close.svg") center / contain no-repeat;
}

.upload-card > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.upload-card > span::before {
  -webkit-mask-image: url("../icons/material/upload_file.svg");
  mask-image: url("../icons/material/upload_file.svg");
}

#outputPreviewBtn { --button-icon: url("../icons/material/visibility.svg"); }
#exportBtn { --button-icon: url("../icons/material/picture_as_pdf.svg"); }
#pngExportBtn { --button-icon: url("../icons/material/image.svg"); }
#copyPageBtn,
#copyOutputPreviewBtn { --button-icon: url("../icons/material/content_copy.svg"); }
#cameraBtn { --button-icon: url("../icons/material/photo_camera.svg"); }
#exampleImageBtn,
#emptyExampleImageBtn { --button-icon: url("../icons/material/add_photo_alternate.svg"); }
#addPageBtn { --button-icon: url("../icons/material/add.svg"); }
#prevPageBtn { --button-icon: url("../icons/material/navigate_before.svg"); }
#nextPageBtn { --button-icon: url("../icons/material/navigate_next.svg"); }
#undoBtn { --button-icon: url("../icons/material/undo.svg"); }
#redoBtn { --button-icon: url("../icons/material/redo.svg"); }
#autoPageBtn { --button-icon: url("../icons/material/auto_fix_high.svg"); }
#detectDocumentBtn { --button-icon: url("../icons/material/document_scanner.svg"); }
#rotateLeftBtn { --button-icon: url("../icons/material/rotate_left.svg"); }
#rotateRightBtn { --button-icon: url("../icons/material/rotate_right.svg"); }
#resetCropBtn { --button-icon: url("../icons/material/restart_alt.svg"); }
#originalPreviewBtn { --button-icon: url("../icons/material/compare.svg"); }
#toggleCommentBtn { --button-icon: url("../icons/material/sticky_note_2.svg"); }
#removeBtn { --button-icon: url("../icons/material/delete.svg"); }

.shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(87, 49, 24, 0.24);
  backdrop-filter: blur(8px);
}

.drop-overlay.hidden {
  display: none;
}

.drop-overlay-card {
  width: min(100%, 560px);
  padding: 2rem;
  border-radius: 28px;
  border: 2px dashed rgba(165, 70, 32, 0.6);
  background: rgba(255, 251, 245, 0.96);
  text-align: center;
  box-shadow: var(--shadow);
}

.drop-overlay-card h2,
.drop-overlay-card p {
  margin-left: 0;
  margin-right: 0;
}

.sidebar,
.stage-panel,
.controls-panel {
  backdrop-filter: blur(16px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 248, 240, 0.84);
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.brand h1,
.panel-head h2,
.empty-state h3,
.tips h3 {
  font-family: Georgia, "Times New Roman", serif;
  margin: 0;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

.lede {
  color: var(--muted);
  line-height: 1.45;
}

.page-position {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.upload-card {
  display: grid;
  gap: 0.35rem;
  padding: 1rem;
  border-radius: 20px;
  border: 1px dashed rgba(165, 70, 32, 0.4);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
}

.example-image-btn {
  width: 100%;
  border: 1px solid rgba(165, 70, 32, 0.22);
  background: rgba(255, 255, 255, 0.68);
}

.empty-state > .example-image-btn {
  width: min(100%, 320px);
  margin: 0 auto;
}

.drop-zone,
.empty-drop-zone {
  display: grid;
  gap: 0.3rem;
  padding: 1rem;
  border-radius: 20px;
  border: 2px dashed rgba(31, 111, 120, 0.35);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(240, 248, 248, 0.55));
  color: var(--muted);
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.drop-zone {
  cursor: pointer;
}

.drop-zone strong,
.empty-drop-zone strong {
  color: var(--ink);
}

.drop-zone.drag-target,
.empty-drop-zone.drag-target {
  border-color: rgba(165, 70, 32, 0.7);
  background: linear-gradient(135deg, rgba(255, 247, 240, 0.95), rgba(255, 240, 230, 0.8));
  transform: translateY(-1px);
}

.stage-toolbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.38);
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.sidebar-actions button {
  min-width: 0;
  padding: 0.7rem 0.55rem;
  font-size: 0.86rem;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}

.sidebar-actions .primary {
  width: 100%;
}

.sidebar-actions-top {
  padding: 0.7rem;
  border: 1px solid rgba(165, 70, 32, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.52);
}

.sidebar-section {
  display: grid;
  gap: 0.7rem;
}

.compact-actions {
  display: flex;
  gap: 0.5rem;
}

.camera-btn {
  display: none;
  background: var(--accent);
  color: #fff7f1;
}

.toolbar-group {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  min-width: 0;
}

.toolbar-menu {
  position: relative;
}

.toolbar-menu-actions {
  margin-left: auto;
}

.toolbar-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.48rem;
  min-height: 40px;
  padding: 0.58rem 0.75rem;
  border-radius: 11px;
  background: #efe4d4;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.toolbar-menu > summary::-webkit-details-marker {
  display: none;
}

.toolbar-menu > summary::before {
  content: "";
  width: 1.15rem;
  height: 1.15rem;
  background: currentColor;
  -webkit-mask: var(--menu-icon) center / contain no-repeat;
  mask: var(--menu-icon) center / contain no-repeat;
}

.toolbar-menu > summary::after {
  content: "⌄";
  margin-left: 0.15rem;
  color: var(--muted);
  transition: transform 120ms ease;
}

.toolbar-menu[open] > summary {
  background: var(--accent);
  color: #fff7f1;
}

.toolbar-menu[open] > summary::after {
  color: inherit;
  transform: rotate(180deg);
}

.toolbar-menu-page { --menu-icon: url("../icons/material/navigate_next.svg"); }
.toolbar-menu-edit { --menu-icon: url("../icons/material/auto_fix_high.svg"); }
.toolbar-menu-actions { --menu-icon: url("../icons/material/sticky_note_2.svg"); }

.toolbar-menu[open] > .toolbar-group {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  z-index: 30;
  width: max-content;
  min-width: 240px;
  max-width: min(560px, 82vw);
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel-strong);
  box-shadow: 0 14px 38px rgba(68, 45, 21, 0.2);
}

.toolbar-menu-actions[open] > .toolbar-group {
  right: 0;
  left: auto;
}

.toolbar-group button {
  min-height: 40px;
  padding: 0.58rem 0.72rem;
  border-radius: 11px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.mobile-tools {
  display: none;
  margin-bottom: 0.8rem;
}

.mobile-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
}

.global-settings,
.controls-panel,
.stage-panel {
  background: var(--panel);
  box-shadow: var(--shadow);
}

.global-settings,
.controls-panel {
  border: 1px solid rgba(97, 75, 43, 0.1);
  border-radius: 24px;
  padding: 1rem;
}

.export-settings {
  padding: 0;
  overflow: hidden;
}

.export-settings summary {
  padding: 0.9rem 1rem;
  cursor: pointer;
  font-weight: 700;
  user-select: none;
}

.export-settings[open] summary {
  border-bottom: 1px solid var(--line);
}

.settings-body {
  padding: 1rem;
}

.settings-body h3 {
  margin: 0 0 0.75rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.98rem;
}

.settings-body h3:not(:first-child) {
  margin-top: 1.15rem;
}

.global-settings h2,
.section-head h2 {
  margin: 0 0 0.8rem;
  font-size: 1rem;
}

.global-settings label,
.controls-grid label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.8rem;
}

.global-settings strong,
.controls-grid strong {
  color: var(--muted);
  font-size: 0.9rem;
}

.page-list-wrap {
  min-height: 0;
  max-height: 38vh;
  display: flex;
  flex-direction: column;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page-list {
  display: grid;
  gap: 0.7rem;
  overflow: auto;
  padding-right: 0.2rem;
}

.add-page-btn {
  width: 100%;
  margin-bottom: 0.75rem;
  border: 1px dashed rgba(165, 70, 32, 0.45);
  background: rgba(255, 255, 255, 0.68);
}

.page-item {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  gap: 0.8rem;
  align-items: start;
  padding: 0.65rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
}

.page-item-content {
  min-width: 0;
}

.page-item-actions {
  display: none;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.page-item-delete {
  align-self: start;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: rgba(247, 217, 212, 0.95);
  color: #7f2619;
}

.page-sort-btn {
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  background: rgba(239, 228, 212, 0.95);
  font-size: 0.86rem;
}

.page-item.active {
  border-color: rgba(165, 70, 32, 0.4);
  background: rgba(255, 250, 245, 0.9);
}

.page-item.thumbnail-pending img,
.page-item.thumbnail-pending .page-thumb-placeholder {
  opacity: 0.55;
}

.page-item-thumbnail-status {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--accent-dark);
}

.page-item.dragging {
  opacity: 0.45;
  transform: scale(0.985);
}

.page-item.drop-before {
  box-shadow: inset 0 3px 0 rgba(165, 70, 32, 0.9);
}

.page-item.drop-after {
  box-shadow: inset 0 -3px 0 rgba(165, 70, 32, 0.9);
}

.page-item img {
  width: 68px;
  height: 88px;
  object-fit: cover;
  border-radius: 12px;
}

.page-thumb-placeholder {
  width: 68px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px dashed rgba(165, 70, 32, 0.45);
  background: rgba(255, 255, 255, 0.68);
  color: var(--accent);
  font-size: 2rem;
  line-height: 1;
}

.page-item strong,
.page-item small {
  display: block;
}

.page-item small {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 380px);
  gap: 1.2rem;
  padding: 1.2rem;
}

.mobile-export-dock {
  display: none;
}

.stage-panel {
  border-radius: 28px;
  border: 1px solid rgba(97, 75, 43, 0.1);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.controls-panel {
  align-self: start;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.status {
  color: var(--muted);
  max-width: 20rem;
  line-height: 1.4;
}

.empty-state {
  min-height: 420px;
  border-radius: 24px;
  border: 1px dashed var(--line);
  display: grid;
  place-content: center;
  gap: 1rem;
  text-align: center;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.6), rgba(255,255,255,0.2)),
    repeating-linear-gradient(135deg, rgba(165,70,32,0.04) 0 12px, transparent 12px 24px);
}

.empty-drop-zone {
  min-width: min(100%, 320px);
  margin: 0 auto;
}

.editor.hidden,
.hidden {
  display: none;
}

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 520px;
  aspect-ratio: 1 / 1.4142;
  max-width: min(100%, 760px);
  margin: 0 auto;
  border-radius: 0;
  overflow: visible;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.03) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.03) 75%),
    linear-gradient(45deg, rgba(0, 0, 0, 0.03) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.03) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.stage-wrap.preview-pending #previewCanvas,
.stage-wrap.preview-pending .handle-layer,
.stage-wrap.preview-pending .note-overlay {
  opacity: 0.72;
}

.preview-pending-overlay {
  position: absolute;
  right: 0.9rem;
  top: 0.9rem;
  z-index: 7;
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: rgba(165, 70, 32, 0.9);
  color: #fffaf3;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  font-size: 0.82rem;
  line-height: 1;
}

.preview-pending-overlay.hidden {
  display: none;
}

#previewCanvas,
.handle-layer {
  position: absolute;
  inset: 0;
}

#previewCanvas {
  width: 100%;
  height: 100%;
}

.handle-layer {
  touch-action: none;
}

.handle {
  position: absolute;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff6ec;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  cursor: grab;
  touch-action: none;
}

.handle.edge {
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  background: #1f6f78;
}

.handle.center {
  width: 32px;
  height: 32px;
  margin-left: -16px;
  margin-top: -16px;
  border-radius: 999px;
  background: rgba(30, 28, 24, 0.9);
  color: #fffaf3;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
}

.handle-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(14px, -10px);
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  font-size: 0.74rem;
  color: #fffaf3;
  background: rgba(30, 28, 24, 0.8);
  pointer-events: none;
}

.magnifier {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  width: 160px;
  height: 160px;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid rgba(165, 70, 32, 0.65);
  background: rgba(255, 251, 245, 0.94);
  box-shadow: 0 16px 28px rgba(32, 20, 8, 0.18);
  pointer-events: none;
}

.magnifier canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.readability-overlay {
  position: absolute;
  left: 0.9rem;
  top: 0.9rem;
  z-index: 6;
  max-width: min(82%, 320px);
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  background: rgba(30, 28, 24, 0.82);
  color: #fffaf3;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  line-height: 1.35;
  pointer-events: none;
}

.readability-overlay.hidden {
  display: none;
}

.readability-overlay strong,
.readability-overlay span {
  display: block;
}

.readability-overlay strong {
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

.readability-overlay span {
  font-size: 0.82rem;
  color: rgba(255, 250, 243, 0.88);
}

.stage-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: start center;
  gap: 0.45rem;
  text-align: center;
  color: var(--muted);
  padding: 1.5rem;
  padding-top: 3rem;
  background: linear-gradient(135deg, rgba(255,255,255,0.42), rgba(255,255,255,0.16));
  pointer-events: none;
}

.stage-placeholder.hidden {
  display: none;
}

.stage-placeholder strong {
  color: var(--ink);
}

.controls-grid {
  display: grid;
  gap: 0.8rem;
}

.controls-grid .conditional-control.hidden {
  display: none;
}

.filter-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.filter-presets button {
  min-width: 0;
  padding: 0.68rem 0.45rem;
  font-size: 0.82rem;
}

.filter-presets button.active,
#originalPreviewBtn.active {
  background: var(--accent);
  color: #fff7f1;
}

.active-preset-label,
.pdf-size-estimate {
  margin: -0.25rem 0 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.blue-ink-suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(36, 86, 179, 0.22);
  border-radius: 12px;
  background: rgba(36, 86, 179, 0.08);
  color: #244b91;
  font-size: 0.82rem;
  font-weight: 700;
}

.blue-ink-suggestion.hidden {
  display: none;
}

.blue-ink-suggestion button {
  flex: 0 0 auto;
  padding: 0.48rem 0.62rem;
  border-radius: 9px;
  background: #dce6fb;
  color: #244b91;
  font-size: 0.78rem;
}

.output-preview-dialog {
  width: min(94vw, 920px);
  max-height: 94vh;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.example-dialog {
  width: min(92vw, 760px);
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.output-preview-dialog::backdrop,
.example-dialog::backdrop {
  background: rgba(40, 30, 20, 0.62);
  backdrop-filter: blur(5px);
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.example-choice {
  display: grid;
  grid-template-rows: 180px auto;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.75rem;
  text-align: left;
  background: rgba(239, 228, 212, 0.62);
}

.example-choice img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 12px;
  background: #fff;
}

.example-choice span,
.example-choice strong,
.example-choice small {
  display: block;
  min-width: 0;
}

.example-choice small {
  margin-top: 0.25rem;
  color: var(--muted);
}

.output-preview-head,
.output-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.output-preview-head h2,
.output-preview-head p {
  margin: 0;
}

.output-preview-stage {
  display: grid;
  place-items: center;
  max-height: calc(94vh - 185px);
  margin: 1rem 0;
  padding: 1rem;
  overflow: auto;
  border-radius: 16px;
  background: #d9d3ca;
}

#outputPreviewCanvas {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(94vh - 220px);
  background: #fff;
  box-shadow: 0 8px 30px rgba(45, 34, 20, 0.2);
}

.output-preview-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.output-preview-status {
  min-height: 1.3em;
  margin: 0.65rem 0 0;
  color: var(--muted);
  text-align: right;
}

.pdf-size-estimate {
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(31, 111, 120, 0.08);
  color: #18565d;
  font-weight: 700;
}

input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
}

.auto-all-btn {
  width: 100%;
  background: #e3eeee;
  color: #18565d;
}

.setting-help {
  color: var(--muted);
  line-height: 1.35;
}

.advanced-settings {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.42);
  overflow: hidden;
}

.advanced-settings summary {
  padding: 0.85rem 1rem;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.advanced-settings[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-controls {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

.advanced-controls label:last-child {
  margin-bottom: 0;
}

.note-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.note-box {
  position: absolute;
  left: 58%;
  top: 9%;
  width: 30%;
  min-width: 130px;
  min-height: 130px;
  aspect-ratio: 1;
  padding: 0.5rem;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff4a8 0%, #ffe780 100%);
  box-shadow:
    0 12px 24px rgba(97, 75, 43, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(188, 149, 28, 0.28);
  transform: rotate(-0.7deg);
  resize: horizontal;
  overflow: hidden;
  pointer-events: auto;
}

.note-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: Georgia, "Times New Roman", serif;
  color: #5a4309;
  cursor: grab;
  user-select: none;
  padding: 0.15rem 0.25rem 0.4rem;
}

.note-close {
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  background: rgba(255, 250, 230, 0.72);
  color: #7a4d0f;
  line-height: 1;
}

.note-box textarea {
  width: 100%;
  height: calc(100% - 2rem);
  min-height: 0;
  border: 0;
  outline: none;
  background: rgba(255, 248, 200, 0.55);
  color: #4c3b0d;
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  line-height: 1.45;
  box-shadow: inset 0 0 0 1px rgba(128, 97, 8, 0.12);
  resize: none;
}

.note-box textarea::placeholder {
  color: rgba(90, 67, 9, 0.62);
}

.toggle-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.tips {
  margin-top: 1rem;
  color: var(--muted);
  line-height: 1.5;
}

input[type="range"] {
  width: 100%;
}

select {
  border-radius: 12px;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

input[type="text"] {
  border-radius: 12px;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 0.9rem;
    padding: 0.9rem;
  }

  .mobile-export-dock {
    display: grid;
    gap: 0.8rem;
  }

  .sidebar {
    gap: 0.9rem;
    padding: 1rem;
  }

  .stage-panel,
  .controls-panel,
  .global-settings {
    border-radius: 20px;
  }

  .stage-wrap {
    min-height: 360px;
    max-width: 100%;
  }

  .stage-toolbar {
    gap: 0.55rem;
  }

  .stage-toolbar button,
  .sidebar-actions button {
    flex: 1 1 140px;
    min-height: 46px;
  }

  .panel-head {
    gap: 0.7rem;
    margin-bottom: 0.8rem;
  }

  .status {
    font-size: 0.92rem;
    max-width: none;
  }

  .mobile-tools {
    display: block;
  }
}

@media (max-width: 700px) {
  html {
    scroll-behavior: smooth;
    scroll-padding-top: 0.75rem;
  }

  body {
    padding-bottom: 76px;
  }

  .sidebar {
    gap: 0.8rem;
    padding: 0.85rem;
  }

  .brand .lede {
    margin-bottom: 0;
  }

  .import-section {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .import-section .section-head {
    grid-column: 1 / -1;
  }

  .import-section .upload-card {
    min-height: 74px;
    padding: 0.8rem 0.9rem;
    border-radius: 16px;
  }

  .compact-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .compact-actions .example-image-btn {
    width: 100%;
    max-width: none;
    padding: 0.7rem 0.8rem;
    border-radius: 16px;
  }

  .compact-actions .camera-btn {
    display: block;
    min-height: 48px;
    border-radius: 16px;
  }

  .drop-zone {
    display: none;
  }

  .section-head h2,
  .global-settings h2 {
    margin-bottom: 0.45rem;
    font-size: 1rem;
  }

  .add-page-btn {
    margin-bottom: 0;
    padding: 0.7rem 0.85rem;
    border-radius: 14px;
  }

  .page-list-wrap {
    max-height: none;
  }

  .page-list {
    display: flex;
    gap: 0.65rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.1rem 0 0.5rem;
    scroll-snap-type: x proximity;
  }

  .page-item {
    flex: 0 0 min(82vw, 300px);
    scroll-snap-align: start;
  }

  .stage-panel {
    padding: 0.75rem;
  }

  .stage-wrap {
    width: 100%;
    min-height: min(68vh, 620px);
  }

  .stage-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .toolbar-menu,
  .toolbar-menu-actions {
    width: 100%;
    margin-left: 0;
  }

  .toolbar-menu > summary {
    width: 100%;
  }

  .toolbar-menu[open] > .toolbar-group,
  .toolbar-menu-actions[open] > .toolbar-group {
    position: static;
    width: 100%;
    max-width: none;
    margin-top: 0.45rem;
    box-shadow: none;
  }

  .toolbar-group button {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .export-settings {
    border-radius: 16px;
  }

  .export-settings summary {
    padding: 0.8rem 0.9rem;
  }

  .sidebar-actions {
    grid-template-columns: 1fr;
  }

  .sidebar-actions .primary {
    width: 100%;
    min-height: 48px;
    border-radius: 16px;
  }

  .filter-presets {
    grid-template-columns: 1fr;
  }

  .example-grid {
    grid-template-columns: 1fr;
  }

  .example-choice {
    grid-template-rows: 130px auto;
  }

  .example-choice img {
    height: 130px;
  }

  .filter-presets button {
    min-height: 44px;
  }

  .mobile-flow-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 0.45rem max(0.45rem, env(safe-area-inset-right)) calc(0.45rem + env(safe-area-inset-bottom)) max(0.45rem, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgba(255, 251, 245, 0.96);
    box-shadow: 0 -10px 30px rgba(68, 45, 21, 0.12);
    backdrop-filter: blur(16px);
  }

  .mobile-flow-nav a {
    padding: 0.65rem 0.2rem;
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
  }

  .mobile-flow-nav a:active,
  .mobile-flow-nav a:focus-visible,
  .mobile-flow-nav a.active {
    background: rgba(165, 70, 32, 0.12);
    color: var(--accent-dark);
    outline: none;
  }
}

@media (pointer: coarse) {
  .handle {
    width: 28px;
    height: 28px;
    margin-left: -14px;
    margin-top: -14px;
  }

  .handle.edge {
    width: 24px;
    height: 24px;
    margin-left: -12px;
    margin-top: -12px;
  }

  .handle.center {
    width: 40px;
    height: 40px;
    margin-left: -20px;
    margin-top: -20px;
    font-size: 1.1rem;
  }

  .handle-label {
    transform: translate(18px, -14px);
    font-size: 0.82rem;
  }

  .page-item-actions {
    display: flex;
  }

  .page-item {
    align-items: start;
  }

  .page-item img {
    width: 76px;
    height: 96px;
  }

  .page-thumb-placeholder {
    width: 76px;
    height: 96px;
  }

  .magnifier {
    width: 148px;
    height: 148px;
  }
}
