/* PUB Rescue — visual language mirrors maconapps.com:
   dark #1c1c1c, orange accent #d2711f, Georgia display headings,
   uppercase letter-spaced buttons, white content surfaces. */
:root {
  --dark: #1c1c1c;
  --light: #fafafa;
  --white: #ffffff;
  --accent: #d2711f;
  --accent-dark: #b45f16;
  --accent-soft: #fbf1e8;
  --accent-line: #f0d7c0;
  --ink: #1c1c1c;
  --muted: #666666;
  --line: #e5e5e5;
  --panel: #f5f5f5;
  --danger: #b3372f;
  --font: 'Georgia', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --max-width: 1100px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--white);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---- top nav (matches maconapps.com header) ---- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--max-width); margin: 0 auto; padding: 0 2rem;
  height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--dark); text-decoration: none; }
.brand-icon { width: 40px; height: 40px; display: block; }
.brand h1 { margin: 0; white-space: nowrap; font-family: var(--font); font-size: 1.25rem; font-weight: bold; letter-spacing: .02em; line-height: 1.1; }
.brand .by { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.brand .by a { color: var(--muted); text-decoration: none; }
.brand .by a:hover { color: var(--accent); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.privacy-badge {
  font-size: .78rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent); border: 2px solid var(--accent);
  padding: .4rem 1rem; white-space: nowrap; text-decoration: none;
}
.nav-link { font-size: .875rem; color: var(--dark); text-decoration: none; }
.nav-link:hover { opacity: .6; }
.pb-short { display: none; }
@media (max-width: 640px) {
  .topbar-inner { padding: 0 1rem; height: 56px; }
  .brand-icon { width: 34px; height: 34px; }
  .brand h1 { font-size: 1.1rem; }
  .nav-link { display: none; }
  .privacy-badge { font-size: .68rem; padding: .3rem .6rem; }
  .pb-full { display: none; }
  .pb-short { display: inline; }
}

/* ---- hero + drop zone ---- */
.hero {
  background: var(--dark); color: var(--light);
  padding: 4rem 2rem 3.5rem;
}
.hero-inner { max-width: var(--max-width); margin: 0 auto; }
.hero-accent { width: 64px; height: 4px; background: var(--accent); margin-bottom: 1.25rem; }
.hero h2 {
  font-family: var(--font); font-weight: normal; line-height: 1.1;
  font-size: clamp(2rem, 5vw, 3.4rem); margin: 0 0 .75rem; max-width: 760px;
}
.hero p.lead { margin: 0 0 2rem; font-size: 1.1rem; color: #ccc; max-width: 700px; }

.drop-zone {
  border: 2px dashed #555;
  background: #242424;
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  outline: none;
}
.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.dragover {
  border-color: var(--accent);
  background: #2a2521;
}
.drop-icon { width: 56px; height: 56px; margin: 0 auto 6px; display: block; }
.drop-title { font-family: var(--font); font-size: 1.5rem; margin: 6px 0 4px; color: var(--white); }
.drop-title strong { color: var(--accent); font-weight: normal; }
.drop-sub { color: #bbb; margin: 0 0 18px; font-size: .95rem; }

.why { max-width: var(--max-width); margin: 0 auto; padding: 3rem 2rem 1rem; }
.why-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 2rem; }
.why h3 {
  font-size: .9rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; margin: 0 0 .5rem;
}
.why p { margin: 0; font-size: .95rem; color: #444; line-height: 1.7; }
.why .fineprint { margin-top: 2rem; font-size: .85rem; color: var(--muted); }
.why-icon { width: 32px; height: 32px; color: var(--accent); margin-bottom: .75rem; display: block; }

/* ---- workspace ---- */
main { max-width: var(--max-width); margin: 0 auto; padding: 24px 2rem 60px; }
@media (max-width: 640px) { main { padding: 16px 1rem 40px; } .hero { padding: 2.5rem 1rem 2rem; } .why { padding: 2rem 1rem 1rem; } }

#workspace { display: grid; grid-template-columns: 250px 1fr; gap: 20px; }
@media (max-width: 800px) { #workspace { grid-template-columns: 1fr; } }

.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-list-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  padding: 0 2px 4px;
}
.file-item {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  position: relative;
  border-left: 3px solid transparent;
}
.file-item:hover { border-color: #ccc; }
.file-item.active { border-left-color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); border-left-color: var(--accent); }
.file-item .fi-name { font-weight: 600; word-break: break-all; padding-right: 22px; }
.file-item .fi-meta { color: var(--muted); font-size: 12px; }
.file-item .fi-err { color: var(--danger); font-size: 12px; }
.file-item .fi-remove {
  position: absolute; top: 6px; right: 6px; border: none; background: none;
  color: #999; font-size: 16px; line-height: 1; cursor: pointer; padding: 2px 5px;
}
.file-item .fi-remove:hover { color: var(--danger); }

.viewer {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 18px 20px 24px;
  min-width: 0;
}
.viewer-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.viewer-head h2 { margin: 0; font-family: var(--font); font-weight: normal; font-size: 1.35rem; word-break: break-all; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 16px; overflow-x: auto; }
.tab {
  border: none; background: none; padding: 8px 14px; font-size: .8rem; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; font-family: var(--font-sans);
}
.tab:hover { color: var(--dark); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel-actions { margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.text-out {
  white-space: pre-wrap;
  font-size: 15px;
  font-family: var(--font);
  background: var(--light);
  border: 1px solid var(--line);
  padding: 20px 22px;
  max-height: 60vh;
  overflow: auto;
  line-height: 1.65;
}
.text-out .tb { margin-bottom: 16px; }
.text-out .empty, .gallery .empty { color: var(--muted); font-style: italic; font-family: var(--font-sans); }

.gallery { display: flex; flex-wrap: wrap; gap: 12px; }
.gallery figure {
  margin: 0; border: 1px solid var(--line); padding: 8px;
  background: var(--light); max-width: 220px;
}
.gallery img { max-width: 200px; max-height: 160px; display: block; }
.gallery figcaption { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.gallery .vector-chip {
  width: 200px; height: 80px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; background: #ececec; text-align: center;
}

.export-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.export-card {
  border: 1px solid var(--line); padding: 16px 18px; background: var(--light);
  display: flex; flex-direction: column;
}
.export-card h3 {
  margin: 0 0 6px; font-size: .85rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  display: flex; align-items: center; gap: 8px;
}
.export-card h3 svg { width: 20px; height: 20px; color: var(--accent); }
.export-card p { margin: 0 0 14px; font-size: 13px; color: #555; flex: 1; }

.batch-box {
  margin-top: 18px; border: 1px solid var(--accent-line); background: var(--accent-soft);
  padding: 16px 18px;
}
.batch-box h3 { margin: 0 0 4px; font-size: .85rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.batch-box p { margin: 0 0 12px; font-size: 13.5px; color: #444; }

.details-out { font-size: 13px; }
.details-out table { border-collapse: collapse; width: 100%; }
.details-out td, .details-out th {
  border-bottom: 1px solid var(--line); text-align: left; padding: 6px 8px; font-size: 12.5px;
}
.details-out th { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.details-out .warn { color: var(--danger); }
.details-wrap { overflow-x: auto; }

/* ---- buttons / toast ---- */
.btn {
  display: inline-block; font-family: var(--font-sans);
  font-size: .8rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  border: 2px solid var(--dark); background: transparent; color: var(--dark);
  padding: .55rem 1.2rem; cursor: pointer; text-decoration: none;
  transition: background .2s, color .2s, border-color .2s;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--white); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--white); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled, .btn-primary:disabled { opacity: .5; cursor: wait; }
.btn-light { border-color: var(--white); color: var(--white); }
.btn-light:hover { background: var(--white); border-color: var(--white); color: var(--dark); }
.btn-small { padding: .35rem .8rem; font-size: .72rem; }
.btn-ghost { border-color: transparent; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: #fff; padding: 10px 18px; border-left: 4px solid var(--accent);
  font-size: 13.5px; box-shadow: 0 4px 18px rgba(0,0,0,.25); z-index: 200; max-width: 90vw;
}

/* ---- Pro (web licensing) ---- */
.btn-pro { border-color: var(--accent); color: var(--accent); white-space: nowrap; }
.btn-pro.is-pro { background: var(--accent); color: var(--white); cursor: default; }
.pro-overlay {
  position: fixed; inset: 0; background: rgba(28,28,28,.55); z-index: 150;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.pro-card {
  background: var(--white); color: var(--ink); width: 100%; max-width: 460px;
  padding: 26px 28px 22px; box-shadow: 0 16px 48px rgba(0,0,0,.35); font-size: 14.5px; line-height: 1.55;
  max-height: 92vh; overflow: auto;
}
.pro-accent { width: 48px; height: 4px; background: var(--accent); margin-bottom: 12px; }
.pro-card h3 { font-family: var(--font); font-weight: normal; font-size: 1.5rem; margin: 0 0 6px; line-height: 1.15; }
.pro-sub { margin: 0 0 12px; color: #444; }
.pro-sub code { font-size: 12.5px; background: var(--panel); padding: 1px 4px; }
.pro-list { margin: 0 0 12px; padding-left: 18px; }
.pro-list li { margin: 3px 0; }
.pro-price { margin: 0 0 14px; font-size: 15px; }
.pro-price strong { color: var(--accent); font-size: 1.15em; }
.pro-note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.pro-alt { font-size: 12.5px; color: var(--muted); margin: 14px 0 0; }
.pro-alt a { color: var(--accent); }
.pro-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.pro-form { margin-top: 4px; }
.pro-input {
  width: 100%; font: inherit; font-size: 16px; letter-spacing: .04em; padding: 10px 12px;
  border: 2px solid var(--line); background: var(--light); color: var(--ink);
}
.pro-input:focus { outline: none; border-color: var(--accent); }
.pro-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.pro-ok { color: #1f6f3f; font-size: 14px; margin: 6px 0 0; }
.pro-key {
  font-family: Consolas, "Courier New", monospace; font-size: 20px; letter-spacing: .06em; text-align: center;
  background: var(--dark); color: var(--white); padding: 14px 10px; margin: 6px 0 4px; user-select: all; word-break: break-all;
}
@media (max-width: 640px) { .btn-pro { font-size: .66rem; padding: .3rem .5rem; } .pro-card { padding: 20px 18px; } }

/* ---- footer (matches maconapps.com) ---- */
footer {
  background: var(--dark); color: #888; border-top: 1px solid #333;
  padding: 2rem; text-align: center; font-size: .8rem; line-height: 1.8;
}
footer a { color: #bbb; text-decoration: none; }
footer a:hover { color: var(--accent); }
footer .foot-links { display: flex; gap: 1.5rem; justify-content: center; flex-wrap: wrap; margin-bottom: .5rem; }
footer .foot-logo { height: 64px; width: auto; display: block; margin: 0 auto 1rem; opacity: .9; }

@media print {
  .topbar, .hero, .why, .file-list, .tabs, .toolbar, .panel-actions, footer, .toast, #proBadge { display: none !important; }
  main { padding: 0; max-width: none; }
  #workspace { display: block; }
  .viewer { border: none; padding: 0; }
  .text-out { max-height: none; border: none; background: none; padding: 0; }
  .viewer-head h2 { font-size: 18pt; margin-bottom: 12pt; }
}

/* ---- Pages tab (libmspub layout rendering) ---- */
.pages-actions { align-items: center; justify-content: space-between; }
.zoom-label { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.zoom-select { font: inherit; font-size: .85rem; padding: 4px 8px; border: 2px solid var(--line); background: var(--white); color: var(--ink); }
.pages-status { font-size: 12.5px; color: var(--muted); }
/* ---- edit mode */
.edit-toggle { margin-left: auto; margin-right: 10px; }
.edit-toggle[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.pages-body { display: flex; gap: 12px; align-items: flex-start; }
.pages-body .pages-out { flex: 1 1 auto; min-width: 0; }
.editor-panel { display: none; flex: 0 0 270px; width: 270px; position: sticky; top: 8px; max-height: calc(100vh - 32px); overflow: auto; border: 2px solid var(--ink); background: var(--white); padding: 12px; font-size: .85rem; box-shadow: 4px 4px 0 var(--ink); }
body.editing .editor-panel { display: block; }
.editor-panel .ed-row { display: flex; flex-wrap: wrap; gap: 6px; }
.editor-panel .ed-tools { margin-bottom: 10px; }
.editor-panel .ed-kind { margin: 0 0 8px; font-weight: 700; }
.editor-panel .ed-section { display: none; margin-bottom: 12px; }
.editor-panel.is-text .ed-text-only, .editor-panel.is-picture .ed-picture-only, .editor-panel.has-selection .ed-sel-only, .editor-panel .ed-files { display: flex; flex-direction: column; gap: 6px; }
.editor-panel .ed-sel-only, .editor-panel .ed-files { flex-direction: row; }
.editor-panel .ed-label { font-weight: 700; }
.editor-panel .ed-label small { font-weight: 400; color: var(--muted); }
.editor-panel textarea { width: 100%; font: inherit; font-size: .85rem; padding: 6px; border: 2px solid var(--line); resize: vertical; box-sizing: border-box; }
.editor-panel .ed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; align-items: center; }
.editor-panel .ed-grid label { display: flex; flex-direction: column; gap: 2px; font-size: .75rem; color: var(--muted); }
.editor-panel .ed-grid label.ed-check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.editor-panel .ed-grid select, .editor-panel .ed-grid input[type=number] { font: inherit; font-size: .85rem; padding: 3px 6px; border: 2px solid var(--line); width: 100%; box-sizing: border-box; }
.editor-panel .ed-grid input[type=color] { width: 100%; height: 28px; padding: 0; border: 2px solid var(--line); background: var(--white); }
.editor-panel .ed-align { grid-column: 1 / -1; display: flex; gap: 4px; }
.editor-panel .ed-align button { flex: 1; font: inherit; font-weight: 700; padding: 4px 0; border: 2px solid var(--line); background: var(--white); cursor: pointer; }
.editor-panel .ed-align button.on { background: var(--ink); color: var(--white); border-color: var(--ink); }
.editor-panel .ed-file { cursor: pointer; display: inline-block; }
.editor-panel .ed-hint { margin: 8px 0; font-size: .72rem; color: var(--muted); line-height: 1.4; }
.editor-panel .ed-status { margin: 8px 0 0; font-size: .75rem; color: var(--muted); }
.btn-danger { color: #b3261e; border-color: #b3261e; }
.page-edit { position: relative; display: block; margin: 0 auto; }
.page-edit svg.page-svg { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.18); user-select: none; }
.page-edit svg.page-svg [data-eid] { transition: none; }
.sel-overlay { position: absolute; inset: 0; pointer-events: none; }
.hover-box { position: absolute; border: 1px dashed #d2711f; pointer-events: none; }
.sel-box { position: absolute; border: 2px solid #d2711f; pointer-events: none; }
.sel-label { position: absolute; left: -2px; top: -20px; background: #d2711f; color: #fff; font-size: 11px; padding: 1px 6px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.sel-handle { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid #d2711f; box-sizing: border-box; pointer-events: auto; }
.sel-handle.h-nw { left: -6px; top: -6px; cursor: nwse-resize; } .sel-handle.h-n { left: calc(50% - 5px); top: -6px; cursor: ns-resize; } .sel-handle.h-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.sel-handle.h-e { right: -6px; top: calc(50% - 5px); cursor: ew-resize; } .sel-handle.h-se { right: -6px; bottom: -6px; cursor: nwse-resize; } .sel-handle.h-s { left: calc(50% - 5px); bottom: -6px; cursor: ns-resize; }
.sel-handle.h-sw { left: -6px; bottom: -6px; cursor: nesw-resize; } .sel-handle.h-w { left: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.find-dialog { border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: 16px 18px; width: min(420px, 92vw); font-size: .9rem; }
.find-dialog::backdrop { background: rgba(0,0,0,.35); }
.find-dialog h3 { margin: 0 0 10px; font-size: 1.1rem; }
.find-dialog label { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-size: .8rem; color: var(--muted); }
.find-dialog label.ed-check { flex-direction: row; align-items: center; gap: 6px; }
.find-dialog input[type=text] { font: inherit; padding: 5px 8px; border: 2px solid var(--line); }
@media (max-width: 860px) { .pages-body { flex-direction: column; align-items: stretch; } .editor-panel { position: static; width: auto; flex: none; max-height: none; } }
@media print { .editor-panel, .sel-overlay { display: none !important; } }
.layout-options { position: relative; font-size: .75rem; }
.layout-options summary { cursor: pointer; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); list-style: none; padding: 4px 8px; border: 2px solid var(--line); background: var(--white); user-select: none; }
.layout-options summary::-webkit-details-marker { display: none; }
.layout-options summary::after { content: ' ▾'; }
.layout-options[open] summary { border-color: var(--ink); color: var(--ink); }
.layout-options-list { position: absolute; z-index: 5; top: 100%; left: 0; margin-top: 4px; min-width: 300px; max-width: 360px; padding: 10px 12px; background: var(--white); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); display: grid; gap: 8px; text-transform: none; letter-spacing: 0; }
.layout-options-list label { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: start; font-size: .85rem; font-weight: 600; color: var(--ink); cursor: pointer; }
.layout-options-list label input { margin-top: 3px; }
.layout-options-list label small { grid-column: 2; font-weight: 400; color: var(--muted); font-size: .75rem; line-height: 1.3; }
.pages-out {
  background: #e9e7e2; border: 1px solid var(--line); padding: 16px; max-height: 75vh; overflow: auto;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.pages-out .empty { color: var(--muted); font-style: italic; text-align: center; padding: 30px 10px; }
.pages-out figure.page { margin: 0; text-align: center; }
.pages-out figure.page img { display: block; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25); max-width: none; }
.pages-out figure.page figcaption { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media print { .pages-actions { display: none !important; } .pages-out { max-height: none; background: none; border: none; padding: 0; } .pages-out figure.page img { box-shadow: none; width: 100% !important; page-break-after: always; } }

/* editor edition */
.brand-edition { color: #d2711f; font-style: italic; }
/* The longer "PUB Rescue Editor" title needs the room on phones; the hero
   already says files never leave the device. */
@media (max-width: 430px) { .privacy-badge { display: none; } }
@media (max-width: 350px) { .topbar-inner { gap: 8px; padding: 0 .75rem; } .brand { gap: 8px; } .brand h1 { font-size: 1rem; } }
