:root {
  --bg: #f2f5f7;
  --bg-deep: #e8eef3;
  --panel: #ffffff;
  --ink: #14212e;
  --ink-soft: #3d4d5e;
  --muted: #718195;
  --line: #e2e9ef;
  --line-strong: #cfdae4;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e6f4f2;
  --danger: #b3392f;
  --shadow-sm: 0 2px 8px rgba(16, 42, 67, 0.06);
  --shadow-md: 0 12px 34px rgba(16, 42, 67, 0.09);
  --shadow-lg: 0 26px 70px rgba(10, 30, 50, 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(20, 184, 166, 0.10), transparent 60%),
    radial-gradient(900px 420px at 95% 0%, rgba(59, 130, 246, 0.08), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

img {
  max-width: 100%;
}

.app-shell {
  width: min(1460px, 100%);
  margin: 0 auto;
  padding: 0 22px 26px;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 2px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #14b8a6, #0f766e 60%, #0b5f59);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
}

.brand-mark svg {
  width: 25px;
  height: 25px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 19px;
  letter-spacing: 0.02em;
}

.brand-text span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.19em;
}

.top-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
}

.pill.accent {
  border-color: rgba(15, 118, 110, 0.2);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

/* ------------------------------------------------------------------- main */
.main {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ----------------------------------------------------------------- upload */
.upload-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: min(58vh, 520px);
  padding: 48px 24px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.78));
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.dragover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.drop-zone.dragover {
  transform: translateY(-2px);
}

.drop-glow {
  position: absolute;
  inset: auto -10% -45% -10%;
  height: 60%;
  background: radial-gradient(closest-side, rgba(20, 184, 166, 0.18), transparent);
  pointer-events: none;
}

.drop-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 94px;
  height: 94px;
  margin-bottom: 20px;
  border-radius: 26px;
  color: var(--accent);
  background: linear-gradient(160deg, #f4fbfa, #e6f4f2);
  border: 1px solid rgba(15, 118, 110, 0.14);
  box-shadow: 0 18px 38px rgba(15, 118, 110, 0.12);
}

.drop-icon svg {
  width: 52px;
  height: 52px;
}

.drop-zone h2 {
  position: relative;
  margin: 0;
  font-size: clamp(20px, 2.4vw, 27px);
  letter-spacing: 0.01em;
}

.drop-sub {
  position: relative;
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.upload-actions {
  position: relative;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.fine {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.drop-zone > .fine {
  position: relative;
  margin-top: 18px;
}

.upload-busy {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(3px);
  color: var(--accent-strong);
  font-weight: 600;
  z-index: 2;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.feature {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "dot title" "dot text";
  column-gap: 10px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.feature-dot {
  grid-area: dot;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.1);
}

.feature strong {
  grid-area: title;
  font-size: 13px;
}

.feature span:last-child {
  grid-area: text;
  color: var(--muted);
  font-size: 11.5px;
}

/* ----------------------------------------------------------------- editor */
.editor-view {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.canvas-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-md);
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 9px 12px 9px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfcfd);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg);
  border-color: var(--line);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

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

.canvas-wrap {
  position: relative;
  height: clamp(380px, calc(100vh - 250px), 760px);
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(255, 255, 255, 0.06), transparent),
    #101a24;
  overflow: hidden;
  touch-action: none;
}

#editorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(8, 18, 28, 0.62);
  color: rgba(255, 255, 255, 0.78);
  font-size: 11.5px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(6px);
}

.canvas-busy {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(9, 20, 30, 0.62);
  color: #fff;
  font-weight: 600;
  backdrop-filter: blur(2px);
  z-index: 3;
}

/* -------------------------------------------------------------- side panel */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.preview-card,
.settings-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.preview-card {
  padding: 12px;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 1px 2px 9px;
  font-size: 12px;
  font-weight: 600;
}

.preview-head .muted {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.preview-body {
  position: relative;
  display: grid;
  place-items: center;
  height: 190px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(45deg, #f4f7f9 25%, transparent 25%),
    linear-gradient(-45deg, #f4f7f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f4f7f9 75%),
    linear-gradient(-45deg, transparent 75%, #f4f7f9 75%),
    #fbfcfd;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.preview-body img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}

.preview-empty {
  color: var(--muted);
  font-size: 12px;
}

.preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(1px);
}

.settings-card {
  padding: 4px 16px 16px;
}

.setting-group {
  padding: 12px 0 4px;
}

.setting-group + .setting-group {
  border-top: 1px solid var(--line);
}

.setting-group h3 {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 11px;
  min-width: 0;
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11.5px;
}

.field > span em {
  color: var(--accent-strong);
  font-style: normal;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

select,
input[type="number"] {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fbfcfd;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
  appearance: none;
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 15px) 16px,
    calc(100% - 10px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.segmented button {
  height: 31px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segmented button.active {
  background: #fff;
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: 0 1px 5px rgba(16, 42, 67, 0.12);
}

.range-field input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.switch-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 5px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  width: 36px;
  height: 21px;
  flex: none;
  border-radius: 999px;
  background: #d5dfe7;
  transition: background 0.18s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 42, 67, 0.22);
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(15px);
}

.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

.switch-label {
  display: flex;
  flex-direction: column;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.25;
}

.switch-label small {
  color: var(--muted);
  font-size: 10.5px;
}

.generate-bar {
  position: sticky;
  bottom: -16px;
  margin: 8px -16px -16px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
}

.generate-bar .fine {
  margin-top: 8px;
  text-align: center;
}

/* ------------------------------------------------------------------ pages */
.pages-view {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-sm);
}

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

.pages-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.pages-title h2 {
  margin: 0;
  font-size: 17px;
}

.pages-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pdf-hint {
  font-size: 11.5px;
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 12px;
}

.page-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(16, 42, 67, 0.05);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.page-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.page-thumb {
  display: grid;
  place-items: center;
  width: 100%;
  height: 168px;
  padding: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(45deg, #f2f5f7 25%, transparent 25%),
    linear-gradient(-45deg, #f2f5f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f5f7 75%),
    linear-gradient(-45deg, transparent 75%, #f2f5f7 75%),
    #fbfcfd;
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}

.page-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 2px 10px rgba(16, 42, 67, 0.14);
}

.page-info {
  padding: 9px 11px 2px;
}

.page-title {
  font-size: 12.5px;
  font-weight: 700;
}

.page-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.page-actions {
  display: flex;
  gap: 4px;
  padding: 7px 8px 9px;
}

.page-actions .btn {
  flex: 1;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease,
    transform 0.1s ease, opacity 0.15s ease;
}

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

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

.btn.primary {
  background: linear-gradient(180deg, #149084, var(--accent));
  color: #fff;
  box-shadow: 0 7px 16px rgba(15, 118, 110, 0.23);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #13a093, var(--accent-strong));
}

.btn.ghost {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink-soft);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.btn.tiny {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 7px;
}

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

.btn.danger:hover:not(:disabled) {
  border-color: rgba(179, 57, 47, 0.3);
  background: rgba(179, 57, 47, 0.07);
}

.btn.block {
  width: 100%;
  min-height: 44px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid rgba(15, 118, 110, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.canvas-busy .spinner,
.upload-busy .spinner {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
}

.upload-busy .spinner {
  border-color: rgba(15, 118, 110, 0.2);
  border-top-color: var(--accent);
}

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

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 60;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(18, 32, 45, 0.94);
  color: #fff;
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(10, 25, 40, 0.28);
  animation: toast-in 0.2s ease;
}

.toast.error {
  background: rgba(151, 43, 34, 0.96);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ------------------------------------------------------------------ modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 26px;
  background: rgba(7, 16, 25, 0.82);
  backdrop-filter: blur(6px);
}

.modal img {
  max-width: 92vw;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  background: #fff;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 25px;
  line-height: 1;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ----------------------------------------------------------------- footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 4px 0;
  color: var(--muted);
  font-size: 10.5px;
}

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

/* -------------------------------------------------------------- responsive */
@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 330px;
  }
  .feature-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 0 14px 20px;
  }
  .topbar {
    padding-top: 14px;
  }
  .top-badges .pill:first-child {
    display: none;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .canvas-wrap {
    height: clamp(300px, 46vh, 520px);
  }
  .side-panel {
    gap: 12px;
  }
  .settings-card {
    padding-bottom: 14px;
  }
  .generate-bar {
    bottom: 0;
  }
  .feature-row {
    display: none;
  }
  .drop-zone {
    min-height: 56vh;
    padding: 38px 18px;
  }
  .preview-body {
    height: 150px;
  }
  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .page-thumb {
    height: 138px;
  }
}

@media (max-width: 520px) {
  .brand-text span {
    display: none;
  }
  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }
  .brand-text strong {
    font-size: 17px;
  }
  .top-badges .pill {
    font-size: 10.5px;
    padding: 4px 9px;
  }
  .canvas-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
  }
  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .toolbar-right .btn {
    flex: 1;
    padding: 0 6px;
  }
  .canvas-hint {
    font-size: 10.5px;
  }
  .pages-view {
    padding: 13px;
  }
  .pages-head {
    align-items: flex-start;
  }
  .pages-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .pdf-hint {
    width: 100%;
    order: -1;
  }
  .modal {
    padding: 12px;
  }
  .footer {
    justify-content: center;
    text-align: center;
  }
}

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