/* ── Reset & variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f0f2fc;
  --card:        #ffffff;
  --border:      #e2e6f0;
  --accent:      #6d28d9;
  --accent-h:    #5b21b6;
  --accent-faint:#f5f0ff;
  --green:       #059669;
  --green-h:     #047857;
  --red:         #e11d48;
  --red-h:       #be123c;
  --text:        #1e293b;
  --muted:       #64748b;
  --radius:      18px;
  --shadow:      0 4px 28px rgba(0,0,0,0.08);
  --trans:       0.18s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ────────────────────────────────────────────── */
header {
  background: var(--accent);
  color: #fff;
  padding: 28px 0 0;
  position: relative;
  overflow: hidden;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px 28px;
  position: relative;
  z-index: 1;
}

.logo {
  display: flex;
  align-items: center;
}

/* Wordmark used in the purple app header */
.wm-stave { font-size: 20px; font-weight: 400; color: #fff; letter-spacing: -0.02em; }
.wm-cut   { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -0.02em; }

.tagline {
  margin-top: 5px;
  font-size: 0.88rem;
  opacity: 0.8;
  font-weight: 400;
}

.staff-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 0 2px;
  opacity: 0.18;
}

.staff-lines span {
  display: block;
  height: 1.5px;
  background: #fff;
  width: 100%;
}

/* ── Main layout ───────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 72px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Card ──────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

/* ── Drop zone ─────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--trans), background var(--trans);
  user-select: none;
  outline: none;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-faint);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-faint);
  transform: scale(1.005);
}

.drop-zone.has-file {
  border-color: var(--green);
  background: #f0fdf8;
}

.drop-icon  { font-size: 2.8rem; margin-bottom: 12px; display: block; }
.drop-title { font-size: 1.05rem; font-weight: 700; }
.drop-sub   { margin-top: 6px; color: var(--muted); font-size: 0.9rem; }
.drop-hint  { margin-top: 8px; font-size: 0.78rem; color: var(--muted); }

.link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}

/* Drop-zone loading spinner */
.dz-spinner {
  display: block;
  width: 38px;
  height: 38px;
  border: 3.5px solid rgba(109,40,217,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 14px;
}

/* ── Upload error message ──────────────────────────────── */
.upload-error-msg {
  margin-top: 12px;
  padding: 11px 16px;
  background: #fef2f2;
  border: 1.5px solid #fca5a5;
  border-radius: 10px;
  color: #dc2626;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.55;
}

.upload-error-msg[hidden] { display: none; }

/* ── Option toggles ────────────────────────────────────── */
.options-row {
  display: flex;
  gap: 14px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.opt-card {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 210px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: #f8fafc;
  cursor: pointer;
  transition: border-color var(--trans), background var(--trans);
}

.opt-card:hover { border-color: var(--accent); background: var(--accent-faint); }

.opt-card input[type="checkbox"] { display: none; }

.toggle-track {
  width: 46px;
  height: 26px;
  border-radius: 13px;
  background: #cbd5e1;
  position: relative;
  flex-shrink: 0;
  transition: background var(--trans);
}

.toggle-thumb {
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.22);
  transition: transform var(--trans);
}

.opt-card input:checked + .toggle-track            { background: var(--accent); }
.opt-card input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }

.opt-text strong { display: block; font-size: 0.88rem; }
.opt-text small  { display: block; color: var(--muted); font-size: 0.75rem; margin-top: 2px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans), transform 0.1s, opacity var(--trans);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

/* Compact accent (toolbar) */
.btn-accent {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
}
.btn-accent:hover:not(:disabled) { background: var(--accent-h); }
.btn-accent:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-green {
  background: var(--green);
  color: #fff;
  padding: 10px 20px;
}
.btn-green:hover { background: var(--green-h); }

.btn-outline {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  padding: 9px 16px;
}
.btn-outline:hover         { border-color: var(--accent); color: var(--accent); background: var(--accent-faint); }
.btn-outline:disabled      { opacity: 0.35; cursor: not-allowed; }
.btn-outline:disabled:hover { border-color: var(--border); color: var(--muted); background: transparent; }

/* "Add cut line" — red accent outline */
.btn-add {
  border-color: var(--red);
  color: var(--red);
}
.btn-add:hover { border-color: var(--red-h); color: var(--red-h); background: #fff1f2; }

/* ── Spinner (inside buttons) ──────────────────────────── */
.spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

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

/* ── Editor layout ─────────────────────────────────────── */
.editor-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.editor-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
}

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

.editor-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 14px;
  line-height: 1.6;
}

/* ── Page navigation ───────────────────────────────────── */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 10px 20px;
  background: var(--accent-faint);
  border: 1.5px solid #ddd6fe;
  border-radius: 11px;
}

.page-nav[hidden] { display: none; }

.page-nav-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 120px;
  text-align: center;
}

.btn-page-nav {
  padding: 7px 16px;
  font-size: 0.88rem;
  min-width: 44px;
}

/* ── Image wrap & cut lines ────────────────────────────── */
#image-wrap {
  position: relative;
  display: block;
  line-height: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#page-img {
  width: 100%;
  display: block;
}

/* Loading overlay shown while navigating to a new page */
.img-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.80);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 20;
}

.img-overlay[hidden] { display: none; }

.img-overlay-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(109,40,217,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.img-overlay-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
}

/* Cut lines — zero-height divs positioned at top: Y% */
.cut-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  z-index: 10;
  pointer-events: none;
}

.cut-line-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  top: -1px;
  background: var(--red);
  pointer-events: none;
}

/* Invisible drag-handle centred on the line */
.cut-line-handle {
  position: absolute;
  left: 0;
  right: 62px;
  height: 24px;
  top: -12px;
  cursor: ns-resize;
  pointer-events: all;
}

/* Number badge + × button at the right edge */
.cut-line-badge {
  position: absolute;
  right: 4px;
  top: -12px;
  height: 24px;
  display: flex;
  align-items: center;
  background: var(--red);
  color: #fff;
  border-radius: 7px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0 2px 0 9px;
  pointer-events: all;
  cursor: ns-resize;
  white-space: nowrap;
  gap: 0;
}

.cut-line-del {
  width: 20px;
  height: 20px;
  background: rgba(0,0,0,0.22);
  border: none;
  color: #fff;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 6px;
  flex-shrink: 0;
  transition: background 0.1s;
}
.cut-line-del:hover { background: rgba(0,0,0,0.45); }

/* ── Results ───────────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
  flex-wrap: wrap;
}

.results-meta h2 { font-size: 1.15rem; font-weight: 700; }
.muted { color: var(--muted); font-size: 0.83rem; margin-top: 3px; }

.results-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Preview grid ──────────────────────────────────────── */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.preview-item {
  border: 1.5px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
  background: #fafbff;
  transition: box-shadow var(--trans), transform var(--trans), border-color var(--trans);
}

.preview-item:hover {
  box-shadow: 0 6px 20px rgba(109,40,217,0.14);
  transform: translateY(-3px);
  border-color: #c4b5fd;
}

.preview-img-wrap {
  position: relative;
  background: #fff;
  cursor: zoom-in;
  border-bottom: 1px solid var(--border);
}

.preview-img-wrap img {
  width: 100%;
  display: block;
  max-height: 160px;
  object-fit: contain;
  padding: 8px;
}

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 7px 12px;
  background: #f8fafc;
}

.preview-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.btn-dl-single {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background var(--trans);
  line-height: 1;
  color: var(--muted);
}

.btn-dl-single:hover { background: #e0e7ff; color: var(--accent); }

/* ── Lightbox ──────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox[hidden] { display: none; }

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 28, 0.78);
  backdrop-filter: blur(5px);
  cursor: pointer;
}

.lb-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  max-width: min(92vw, 1000px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.45);
}

.lb-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 1;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--trans);
}

.lb-close:hover { background: rgba(0,0,0,0.75); }

.lb-box img {
  display: block;
  max-width: 100%;
  max-height: calc(90vh - 40px);
  object-fit: contain;
}

.lb-label {
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  background: #f8fafc;
  border-top: 1px solid var(--border);
}

/* ── Account bar ───────────────────────────────────────── */
.account-bar {
  background: #0f172a;
  color: #94a3b8;
  padding: 0 24px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.acct-email { color: #e2e8f0; font-weight: 500; }

.acct-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.acct-badge.free { background: #334155; color: #94a3b8; }
.acct-badge.pro  { background: var(--green); color: #fff; }

.acct-count { color: #64748b; }

.acct-upgrade {
  color: #fff;
  background: var(--green);
  text-decoration: none;
  padding: 3px 10px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.78rem;
  transition: background var(--trans);
}
.acct-upgrade:hover { background: var(--green-h); }

.acct-link {
  color: #94a3b8;
  text-decoration: none;
  font-weight: 500;
  transition: color var(--trans);
}
.acct-link:hover { color: #e2e8f0; }

.acct-signup {
  background: #1e293b;
  padding: 3px 10px;
  border-radius: 5px;
  color: #e2e8f0 !important;
}

.acct-sep { color: #334155; }

/* ── Upgrade modal ─────────────────────────────────────── */
.upgrade-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.upgrade-modal[hidden] { display: none; }

.upgrade-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,8,28,0.72);
  backdrop-filter: blur(4px);
  cursor: pointer;
}

.upgrade-modal-box {
  position: relative;
  background: #fff;
  border-radius: 18px;
  padding: 44px 40px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
}

.upgrade-modal-icon { font-size: 2.8rem; margin-bottom: 14px; }

.upgrade-modal-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 10px;
}

.upgrade-modal-msg {
  font-size: 0.95rem;
  color: #64748b;
  line-height: 1.65;
  margin-bottom: 28px;
}

.upgrade-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  .card                  { padding: 20px; }
  .options-row           { flex-direction: column; }
  .editor-toolbar        { flex-direction: column; align-items: stretch; }
  .editor-actions        { flex-wrap: wrap; }
  .page-nav              { flex-wrap: wrap; }
  .results-header        { flex-direction: column; align-items: flex-start; }
  .results-actions       { flex-wrap: wrap; }
  .logo                  { font-size: 1.25rem; }
}
