:root {
  color-scheme: light;
  --bg: #eef1ef;
  --panel: #fbfaf7;
  --ink: #1f2528;
  --muted: #6c7477;
  --line: #d7d8d2;
  --accent: #1f6f64;
  --primary: #1f6f64;
  --accent-2: #c6533b;
  --shadow: 0 18px 46px rgba(28, 32, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #aeb4ae;
}

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

button.active,
.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.danger-button {
  border-color: rgba(198, 83, 59, 0.38);
  color: #a83f2b;
}

.danger-button:hover {
  border-color: var(--accent-2);
}

.ghost-button {
  background: transparent;
}

.feature-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.feature-link:hover {
  border-color: #aeb4ae;
}

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 22px;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 72px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand,
.top-actions,
.section-head,
.stage-toolbar,
.form-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--ink);
  border-radius: 8px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 14px;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  gap: 8px;
}

.locale-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  color: var(--muted);
  font-size: 12px;
}

.locale-control select {
  height: 36px;
  max-width: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  min-height: 0;
  overflow: hidden;
}

.left-panel,
.right-panel {
  padding: 14px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.right-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.panel-context-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--line);
  margin-bottom: 2px;
}

.context-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.context-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  background: rgba(31, 111, 100, 0.12);
  color: var(--primary);
}

.context-title-group h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
  margin: 0;
}

.deselect-btn {
  padding: 3px 8px;
  min-height: 26px;
  font-size: 12px;
  border-radius: 6px;
  color: var(--muted);
}

.deselect-btn:hover {
  color: var(--fg);
  background: var(--bg);
}

.small-btn {
  padding: 4px 8px;
  font-size: 12px;
  min-height: 28px;
}

.inspector-section {
  transition: opacity 0.2s ease, transform 0.2s ease;
  animation: inspectorFadeIn 0.22s ease-out;
}

@keyframes inspectorFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

#fileInput {
  display: none;
}

.drop-zone {
  min-height: 84px;
  display: grid;
  place-items: center;
  border: 1px dashed #aeb4ae;
  border-radius: 8px;
  color: var(--muted);
  background: #f6f6f2;
  text-align: center;
}

.drop-zone.dragging {
  border-color: var(--accent);
  color: var(--accent);
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.asset-tile {
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  position: relative;
}

.asset-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.asset-tile.cover-locked {
  border-color: var(--accent-2);
}

.asset-tile.cover-locked::after,
.asset-tile.favorite-locked::before {
  position: absolute;
  left: 5px;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.asset-tile.cover-locked::after {
  content: "封面";
  bottom: 5px;
  background: rgba(198, 83, 59, 0.9);
}

.asset-tile.favorite-locked {
  border-color: var(--accent);
}

.asset-tile.favorite-locked::before {
  content: "最愛";
  top: 5px;
  background: rgba(31, 111, 100, 0.92);
}

.button-grid,
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.ratio-grid {
  grid-template-columns: repeat(3, 1fr);
}

.stage-wrap {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 86px;
  overflow: hidden;
}

.stage-toolbar {
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.safe-toggle {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.zoom-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.zoom-tools .icon-button {
  width: 32px;
  min-height: 30px;
  font-size: 18px;
}

#zoomSlider {
  width: 112px;
}

#zoomLabel {
  min-width: 44px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.canvas-scroll {
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: safe center;
  padding: 18px 24px;
  outline: 0 solid transparent;
  transition: outline-color 160ms ease, background-color 160ms ease;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.035) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.canvas-scroll.drop-active {
  outline: 3px solid rgba(31, 111, 100, 0.75);
  outline-offset: -8px;
  background-color: rgba(31, 111, 100, 0.08);
}

#editorCanvas {
  flex-shrink: 0;
  margin: auto;
  width: auto;
  max-width: none;
  height: calc(var(--canvas-zoom, 1) * min(54vh, 560px));
  background: #ffffff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.page-strip {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.page-thumb {
  width: 50px;
  flex: 0 0 auto;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #fff;
  padding: 3px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.page-thumb.active {
  border-color: var(--accent);
}

.page-thumb-add {
  display: grid;
  place-items: center;
  gap: 2px;
  color: var(--accent);
  border-style: dashed;
  min-height: 62px;
}

.page-thumb-add strong {
  font-size: 28px;
  line-height: 1;
}

.page-thumb-add span {
  position: static;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  padding: 0;
}

.page-thumb canvas {
  width: 100%;
  display: block;
  border-radius: 5px;
}

.page-thumb span {
  position: absolute;
  left: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.64);
  color: #fff;
  border-radius: 4px;
  font-size: 10px;
  padding: 1px 4px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
}

.field input[type="color"] {
  height: 42px;
  padding: 3px;
}

#fontFamilySelect {
  display: none;
}

.font-picker {
  position: relative;
}

.font-picker-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  text-align: left;
}

.font-picker-button::after {
  content: "⌄";
  color: var(--muted);
  font-size: 14px;
}

.font-picker-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: grid;
  gap: 4px;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.font-picker-menu[hidden] {
  display: none;
}

.font-picker-option {
  min-height: 40px;
  border: 0;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
}

.font-picker-option:hover,
.font-picker-option.active {
  background: #eef1ef;
  border-color: transparent;
}

.crop-ratio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.form-row {
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

dialog {
  width: min(92vw, 920px);
  border: 0;
  border-radius: 10px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(20, 24, 24, 0.45);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.dialog-head form {
  margin: 0;
  padding: 0;
  display: inline-flex;
}

.dialog-head .icon-button {
  cursor: pointer;
  z-index: 10;
  position: relative;
  pointer-events: auto;
}

.preview-slider {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 10px;
}

.preview-slider img {
  max-height: 70vh;
  max-width: 78vw;
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
  scroll-snap-align: center;
}

.ig-preview-dialog {
  max-width: 820px;
  width: 95vw;
  padding: 16px;
  border-radius: 16px;
  transition: max-width 0.25s ease;
}

.small-segmented {
  padding: 2px;
  gap: 2px;
}

.small-segmented button {
  min-height: 26px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 6px;
}

.ig-mockup-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
}

.ig-post-card {
  width: 100%;
  max-width: 720px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: max-width 0.25s ease;
}

.ig-post-card[data-view-cols="1"] {
  max-width: 420px;
}

.ig-post-card[data-view-cols="2"] {
  max-width: 720px;
}

.ig-post-card[data-view-cols="3"] {
  max-width: 920px;
}

.ig-post-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.ig-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ig-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(45deg, #f09433, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px #e1306c;
}

.ig-username {
  font-size: 13px;
  font-weight: 600;
  color: #262626;
}

.ig-page-badge {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  background: rgba(18, 18, 18, 0.72);
  padding: 3px 8px;
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.ig-carousel-viewport {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: #111;
}

.grid-preview.ig-carousel-track {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  overflow-x: auto !important;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: 2px;
  margin: 0;
  padding: 0;
  width: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.grid-preview.ig-carousel-track::-webkit-scrollbar {
  display: none;
}

.ig-post-card[data-view-cols="1"] .grid-preview.ig-carousel-track img {
  flex: 0 0 100% !important;
  width: 100% !important;
  aspect-ratio: var(--aspect-ratio, 4 / 5);
  object-fit: contain;
  scroll-snap-align: start;
  border-radius: 0;
  display: block;
}

.ig-post-card[data-view-cols="2"] .grid-preview.ig-carousel-track img {
  flex: 0 0 calc((100% - 2px) / 2) !important;
  width: calc((100% - 2px) / 2) !important;
  aspect-ratio: var(--aspect-ratio, 4 / 5);
  object-fit: contain;
  scroll-snap-align: start;
  border-radius: 0;
  display: block;
}

.ig-post-card[data-view-cols="3"] .grid-preview.ig-carousel-track img {
  flex: 0 0 calc((100% - 4px) / 3) !important;
  width: calc((100% - 4px) / 3) !important;
  aspect-ratio: var(--aspect-ratio, 4 / 5);
  object-fit: contain;
  scroll-snap-align: start;
  border-radius: 0;
  display: block;
}

.ig-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  color: #111;
  font-size: 20px;
  line-height: 1;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  transition: all 0.18s ease;
  user-select: none;
}

.ig-nav-btn:hover {
  background: #ffffff;
  transform: translateY(-50%) scale(1.08);
}

.ig-prev-btn {
  left: 10px;
}

.ig-next-btn {
  right: 10px;
}

.ig-nav-btn:disabled {
  opacity: 0;
  pointer-events: none;
}

.ig-carousel-footer {
  padding: 10px 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ffffff;
}

.ig-carousel-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  min-height: 12px;
}

.ig-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  cursor: pointer;
}

.ig-dot.active {
  background: #0095f6;
  transform: scale(1.35);
}

dialog:not([open]) {
  display: none !important;
}

.help-dialog-modal {
  max-width: 680px;
  width: min(92vw, 680px);
  max-height: min(85vh, 760px);
  padding: 0;
  border-radius: 16px;
  overflow: hidden;
}

.help-dialog-modal[open] {
  display: flex;
  flex-direction: column;
}

.help-dialog-modal .dialog-head {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.help-head-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.help-head-title h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.help-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.help-content-scroll {
  padding: 16px 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #fdfdfc;
}

.help-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.help-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.help-card-icon {
  font-size: 18px;
}

.help-card-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.help-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: start;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 580px) {
  .help-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.help-label {
  font-weight: 600;
  color: var(--ink);
}

.help-desc {
  color: var(--muted);
}

.help-desc strong {
  color: var(--ink);
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.shortcut-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1fr);
  gap: 10px 18px;
  color: var(--muted);
}

.shortcut-grid strong {
  color: var(--ink);
  font-weight: 700;
}

.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 160px;
  display: grid;
  gap: 4px;
  padding: 7px;
  background: rgba(251, 250, 247, 0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.context-menu[hidden] {
  display: none;
}

.context-menu button {
  justify-content: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
}

.context-menu button:hover {
  background: #eef1ef;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  transition: 180ms ease;
  pointer-events: none;
  z-index: 20;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.mobile-tools {
  display: none;
}

.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 13;
  background: rgba(15, 23, 20, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 220ms ease;
  pointer-events: none;
}

.mobile-panel-close {
  display: none;
}

@media (max-width: 920px) {
  /* 第一排：頂部導覽列 (Top bar) */
  .topbar {
    height: 52px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .brand {
    gap: 8px;
  }

  .brand p {
    display: none;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    font-size: 12px;
    border-radius: 8px;
  }

  h1 {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .top-actions {
    display: flex;
    align-items: center;
    gap: 5px;
  }

  .top-actions .feature-link,
  .top-actions #exportBtn {
    display: none;
  }

  .top-actions .icon-button {
    width: 32px;
    height: 32px;
    min-height: 32px;
    border-radius: 8px;
    font-size: 15px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .top-actions #previewBtn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    height: 32px;
    min-height: 32px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    background: rgba(31, 111, 100, 0.08);
    color: var(--primary);
    border: 1px solid rgba(31, 111, 100, 0.25);
  }

  .top-actions select[data-locale-select] {
    height: 32px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    max-width: 80px;
  }

  .top-actions .locale-control span {
    display: none;
  }

  /* 第二排：舞台操作快捷列 (Stage toolbar) */
  .stage-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(251, 250, 247, 0.95);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .stage-toolbar::-webkit-scrollbar {
    display: none;
  }

  .stage-toolbar .small-button {
    height: 32px;
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  .stage-toolbar .small-button:active {
    background: var(--bg);
    transform: scale(0.96);
  }

  .stage-toolbar #addPageBtn {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
  }

  .stage-toolbar .zoom-tools {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    height: 32px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    flex-shrink: 0;
  }

  .stage-toolbar #zoomSlider,
  .stage-toolbar #zoomLabel {
    display: none;
  }

  .stage-toolbar .zoom-tools .icon-button {
    width: 26px;
    height: 26px;
    min-height: 26px;
    border-radius: 6px;
    font-size: 14px;
    background: transparent;
    border: none;
  }

  .stage-toolbar .zoom-tools #fitViewBtn {
    height: 24px;
    min-height: 24px;
    padding: 0 6px;
    font-size: 11px;
    border-radius: 5px;
    background: var(--bg);
  }

  .stage-toolbar .safe-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    flex-shrink: 0;
    margin-left: 0;
  }

  .stage-toolbar .safe-toggle input {
    width: 14px;
    height: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
    height: calc(100dvh - 52px);
  }

  .mobile-backdrop.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* 現代化 Bottom Sheet 抽屜面板 */
  .left-panel,
  .right-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: block;
    max-height: min(72dvh, 580px);
    padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -12px 36px rgba(18, 26, 24, 0.18);
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
    transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1), opacity 200ms ease;
  }

  /* Bottom Sheet 頂部手勢抓手條 (Drag Handle) */
  .left-panel::before,
  .right-panel::before {
    content: "";
    position: sticky;
    top: -12px;
    display: block;
    width: 42px;
    height: 5px;
    margin: -10px auto 14px;
    background: rgba(0, 0, 0, 0.16);
    border-radius: 99px;
  }

  .left-panel.mobile-open,
  .right-panel.mobile-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .stage-wrap {
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr) 76px;
    padding-bottom: calc(62px + env(safe-area-inset-bottom));
  }

  .canvas-scroll {
    padding: 16px 12px;
    display: flex;
    align-items: center;
    justify-content: safe center;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  #editorCanvas {
    flex-shrink: 0;
    margin: auto;
    width: auto;
    height: calc(var(--canvas-zoom, 1) * min(48dvh, 460px));
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    border-radius: 6px;
    background: #ffffff;
  }

  .page-strip {
    min-height: 76px;
    max-height: 76px;
    padding: 8px 12px;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }

  .page-thumb {
    width: 48px;
    height: 60px;
    border-radius: 6px;
  }

  .add-page-thumb {
    width: 48px;
    height: 60px;
    border-radius: 6px;
  }

  /* 現代化 App 底部導航欄 */
  .mobile-tools {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
  }

  .mobile-tools button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    height: 50px;
    padding: 4px 2px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border: none;
    border-radius: 10px;
    transition: all 160ms ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tools button svg {
    display: block;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    transition: transform 160ms ease;
  }

  .mobile-tools button:active {
    transform: scale(0.92);
  }

  .mobile-tools button.active,
  .mobile-tools button.active-object {
    color: var(--accent);
    font-weight: 700;
    background: rgba(31, 111, 100, 0.12);
  }

  .mobile-tools button.active svg,
  .mobile-tools button.active-object svg {
    stroke: currentColor;
    transform: translateY(-1px);
  }

  .mobile-tools button.mobile-export-btn {
    color: var(--accent-2);
  }

  .mobile-tools button.mobile-export-btn.active {
    color: var(--accent-2);
    background: rgba(198, 83, 59, 0.12);
  }

  .mobile-tools button.mobile-export-btn.active svg {
    stroke: currentColor;
  }

  /* 表單與控制項手機適配優化 */
  .button-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .button-grid button {
    min-height: 44px;
    font-size: 14px;
  }

  .ratio-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .ratio-grid button {
    min-height: 42px;
    font-size: 13px;
  }

  .form-row {
    min-height: 44px;
    font-size: 14px;
  }

  .segmented {
    min-height: 38px;
  }

  .segmented button {
    min-height: 34px;
    font-size: 13px;
  }
}

.export-dialog-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
  margin: 0 auto;
}

.export-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.format-choice-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.choice-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.choice-card:hover {
  border-color: rgba(31, 111, 100, 0.45);
}

.choice-card:has(input:checked) {
  border-color: var(--primary);
  background: rgba(31, 111, 100, 0.08);
}

.choice-card input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--primary);
}

.choice-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.choice-body strong {
  font-size: 15px;
  color: var(--fg);
}

.choice-body small {
  font-size: 12px;
  color: var(--muted);
}

.form-row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.export-summary-box {
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.full-width {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}