:root {
  --bg: #0f1117;
  --surface: #171b26;
  --surface2: #1e2433;
  --border: #2a3144;
  --text: #e8ecf4;
  --muted: #9aa4b8;
  --accent: #5b8cff;
  --accent2: #3dd68c;
  --warn: #f5a524;
  --danger: #ff6b6b;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #141925, var(--bg));
}

.brand { display: flex; gap: 1rem; align-items: center; }
.brand h1 { margin: 0; font-size: 1.2rem; }
.subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
}

.status { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.badge {
  font-size: 0.75rem; padding: 0.35rem 0.65rem;
  border-radius: 999px; background: var(--surface2); border: 1px solid var(--border);
}
.badge.ok { color: var(--accent2); border-color: rgba(61, 214, 140, 0.35); }
.badge.warn { color: var(--warn); border-color: rgba(245, 165, 36, 0.35); }

.hero-banner {
  text-align: center;
  padding: 0.65rem 1.25rem;
  background: linear-gradient(90deg, rgba(91, 140, 255, 0.12), rgba(61, 214, 140, 0.1));
  border-bottom: 1px solid var(--border);
}

.hero-banner p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}

.hero-banner strong {
  color: var(--accent2);
}

.site-footer {
  margin-top: 2rem;
  padding: 2rem 1.5rem 1.5rem;
  border-top: 1px solid var(--border);
  background: #12151e;
  color: var(--muted);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  max-width: 1100px;
  margin: 0 auto 1.25rem;
}

.site-footer h2,
.site-footer h3 {
  color: var(--text);
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.site-footer h2 { font-size: 1.1rem; }

.site-footer p,
.site-footer li {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.55;
}

.site-footer ul,
.site-footer ol {
  margin: 0;
  padding-left: 1.15rem;
}

.footer-copy {
  text-align: center;
  font-size: 0.8rem;
  margin: 0;
  opacity: 0.85;
}

.app-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
}
.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: white;
}

.tab-panel.hidden { display: none; }
.tab-panel.active { display: block; }

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

.ocr-font-row {
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}
.ocr-font-row label {
  flex: 1;
  font-size: 0.75rem;
  color: var(--muted);
}
.font-size-input {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.ocr-font-row select {
  width: 100%;
  margin-top: 0.2rem;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: calc(100vh - 76px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  background: var(--surface);
}

.panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.hint { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.8rem; }

.file-drop {
  display: block;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.file-drop:hover, .file-drop.dragover {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.08);
  color: var(--text);
}

.checkbox { display: flex; gap: 0.5rem; align-items: center; font-size: 0.85rem; margin-bottom: 0.75rem; color: var(--muted); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.75rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); }
select, input[type="text"], textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
  margin-bottom: 0.5rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: white; font-weight: 600; }
.btn.success { background: #1f6f4a; border-color: #2f9d68; }
.btn.danger { color: #ffd0d0; border-color: rgba(255,107,107,0.4); }
.btn.subtle { background: transparent; }
.btn.icon { width: auto; padding: 0.4rem 0.75rem; margin: 0; }
.toolbar .btn.toolbar-btn { width: auto; margin: 0; padding: 0.4rem 0.65rem; font-size: 0.78rem; }

.block-list { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.4rem; }
.block-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--bg);
}
.block-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.block-item .meta { color: var(--muted); font-size: 0.7rem; margin-bottom: 0.25rem; }
.block-item textarea {
  width: 100%;
  min-height: 48px;
  resize: vertical;
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text);
}

.workspace { display: flex; flex-direction: column; min-width: 0; }
.toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.spacer { flex: 1; }

.canvas-wrap {
  flex: 1; overflow: auto; padding: 1.5rem;
  display: flex; justify-content: center; align-items: flex-start;
  background: radial-gradient(circle at top, #1a2030, var(--bg));
}

.empty-state {
  margin-top: 4rem; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 3rem 4rem; text-align: center;
}

.page-stage {
  position: relative;
  box-shadow: var(--shadow);
  background: white;
  line-height: 0;
  display: inline-block;
  max-width: 100%;
}
.page-stage.hidden, .hidden { display: none !important; }

#pageImage {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
}

.preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.92);
  color: #334155;
  font-size: 0.95rem;
  z-index: 5;
  line-height: normal;
}

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

.page-stage { position: relative; }

.preview-watermark {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: repeating-linear-gradient(
    -32deg,
    rgba(200, 50, 50, 0.07) 0,
    rgba(200, 50, 50, 0.07) 12px,
    transparent 12px,
    transparent 24px
  );
}

.preview-watermark::before {
  content: "PREVIEW — PAY TO DOWNLOAD";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 3vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(180, 40, 40, 0.45);
  transform: rotate(-24deg);
  text-align: center;
  white-space: nowrap;
}

.preview-watermark.hidden { display: none; }

.pay-success-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.pay-success-card {
  max-width: 420px;
  width: 100%;
  padding: 2rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
}

.pay-success-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.review-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 10, 16, 0.82);
}

.review-modal.hidden { display: none; }

body.review-open { overflow: hidden; }

.review-dialog {
  width: min(920px, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1.25rem 1.35rem 1.35rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.review-dialog h2 {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
}

.review-price {
  margin: 0.5rem 0 0;
  font-weight: 600;
  color: var(--accent2);
}

.review-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.85rem 0;
}

.review-image-wrap {
  background: #0a0c12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  min-height: 200px;
}

.review-image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 62vh;
  object-fit: contain;
  margin: 0 auto;
}

.review-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.btn.subtle.active {
  border-color: rgba(91, 140, 255, 0.5);
  color: var(--accent);
}

.indent-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.indent-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  pointer-events: none;
  transform: translateX(-0.5px);
}
.indent-guide.guide-start {
  background: rgba(91, 140, 255, 0.18);
}
.indent-guide.guide-end {
  background: rgba(245, 165, 36, 0.22);
}

.snap-guide-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
.snap-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  transform: translateX(-1px);
}
.snap-guide.near { width: 1px; }
.snap-guide.active { width: 2px; }
.snap-guide.start.near,
.snap-guide.orig-start.near {
  background: rgba(91, 140, 255, 0.9);
  box-shadow: 0 0 6px rgba(91, 140, 255, 0.4);
}
.snap-guide.start.active,
.snap-guide.orig-start.active {
  background: #5b8cff;
  box-shadow: 0 0 8px rgba(91, 140, 255, 0.55);
}
.snap-guide.end.near,
.snap-guide.orig-end.near {
  background: rgba(245, 165, 36, 0.95);
  box-shadow: 0 0 6px rgba(245, 165, 36, 0.4);
}
.snap-guide.end.active,
.snap-guide.orig-end.active {
  background: #f5a524;
  box-shadow: 0 0 8px rgba(245, 165, 36, 0.55);
}
.snap-guide-label {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  color: #fff;
}
.snap-guide.start .snap-guide-label,
.snap-guide.orig-start .snap-guide-label {
  background: rgba(91, 140, 255, 0.95);
}
.snap-guide.end .snap-guide-label,
.snap-guide.orig-end .snap-guide-label {
  background: rgba(245, 165, 36, 0.95);
  color: #1a1200;
}
.snap-guide.orig-hint {
  width: 1px;
  border-left: 1px dashed rgba(61, 214, 140, 0.85);
  background: transparent;
  opacity: 0.9;
}
.snap-guide.orig-hint .snap-guide-label {
  background: rgba(61, 214, 140, 0.9);
  color: #0f1117;
}

.text-box-wrap.dragging {
  z-index: 8;
  opacity: 0.92;
}

.text-box-wrap {
  position: absolute;
  pointer-events: auto;
  z-index: 1;
  box-sizing: border-box;
}
.text-box-wrap.selected { z-index: 3; }

.text-box {
  width: 100%;
  height: 100%;
  border: 1px dashed rgba(91, 140, 255, 0.45);
  background: transparent;
  cursor: text;
  overflow: hidden;
  line-height: 1.1;
  color: transparent;
  caret-color: transparent;
  padding: 0 2px;
  margin: 0;
  outline: none;
  white-space: nowrap;
  box-sizing: border-box;
}
.text-box-wrap:hover .text-box {
  border-color: rgba(91, 140, 255, 0.75);
}
.text-box-wrap.selected .text-box,
.text-box:focus {
  color: #111827;
  caret-color: #111827;
  background: rgba(255, 255, 255, 0.94);
  border-style: solid;
  white-space: pre-wrap;
  overflow: auto;
}

.move-handle {
  position: absolute;
  left: -14px;
  top: 0;
  width: 12px;
  height: 100%;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(91, 140, 255, 0.85);
  font-size: 10px;
  user-select: none;
  pointer-events: auto;
}
.move-handle:active { cursor: grabbing; }

.resize-handle {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border: 1px solid white;
  border-radius: 1px;
  cursor: nwse-resize;
  pointer-events: auto;
  z-index: 4;
  opacity: 0.7;
}
.text-box-wrap.selected .resize-handle { opacity: 1; }

.toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  background: var(--surface2); border: 1px solid var(--border);
  padding: 0.75rem 1rem; border-radius: 10px; box-shadow: var(--shadow);
  max-width: 360px; font-size: 0.9rem;
}
.toast.error { border-color: rgba(255,107,107,0.5); color: #ffc9c9; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}
