:root {
  --navy: #0a1628;
  --navy-mid: #112240;
  --navy-light: #1a3a5c;
  --blue: #1e5f9b;
  --blue-bright: #2e7bc4;
  --gold: #c9a84c;
  --gold-light: #e8c97a;
  --white: #ffffff;
  --text: #d0dce8;
  --text-dim: #7a90a8;
  --danger: #d9534f;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  background: var(--navy);
  color: var(--text);
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

header.topbar {
  min-height: 56px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(10,22,40,0.97);
  border-bottom: 1px solid rgba(201,168,76,0.2);
}
.back-link { color: var(--text-dim); font-size: 0.85rem; white-space: nowrap; text-decoration: none; }
.back-link:hover { color: var(--gold); }
h1.tool-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--white);
}

main.tool-main {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 16px 90px;
}
.tool-intro { text-align: center; margin-bottom: 26px; }
.tool-intro h2 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: var(--white);
  margin-bottom: 8px;
}
.tool-intro p { color: var(--text-dim); font-size: 0.95rem; max-width: 520px; margin: 0 auto; }
.privacy-line {
  text-align: center; color: var(--text-dim); font-size: 0.8rem; margin-top: 14px;
}
.privacy-line strong { color: var(--gold-light); }

.dropzone {
  border: 2px dashed rgba(201,168,76,0.4);
  border-radius: 12px;
  padding: 44px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--gold); background: rgba(201,168,76,0.06); }
.dropzone p { color: var(--text-dim); font-size: 0.88rem; margin-bottom: 18px; }

.btn {
  border: 1px solid rgba(201,168,76,0.3);
  background: var(--navy-mid);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 5px;
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-gold { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: var(--navy); border: none; }
.btn-gold:hover { filter: brightness(1.05); }
.btn-danger { border-color: rgba(217,83,79,0.5); color: #f2a29e; }
.btn-block { width: 100%; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 0.82rem; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input[type="text"], .field input[type="number"], .field select {
  width: 100%; padding: 11px; border-radius: 5px; border: 1px solid rgba(201,168,76,0.3);
  background: var(--navy-mid); color: var(--text); font-size: 0.9rem;
}
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; }
.range-val { font-size: 0.85rem; color: var(--gold-light); min-width: 42px; text-align: right; }

.card {
  background: var(--navy-mid);
  border: 1px solid rgba(201,168,76,0.15);
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 18px;
}

.file-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--navy-mid); border: 1px solid rgba(201,168,76,0.2);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
}
.file-chip .name { flex: 1; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .size { font-size: 0.75rem; color: var(--text-dim); white-space: nowrap; }
.file-chip button { background: transparent; border: none; color: var(--text-dim); font-size: 1rem; padding: 4px 6px; }
.file-chip button:hover { color: var(--danger); }
.file-chip .drag-handle { cursor: grab; color: var(--text-dim); }

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.page-tile {
  position: relative;
  background: #0d1e35;
  border: 2px solid rgba(201,168,76,0.15);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}
.page-tile.selected { border-color: var(--gold); }
.page-tile canvas { display: block; width: 100%; height: auto; }
.page-tile .num {
  position: absolute; bottom: 3px; left: 5px; font-size: 0.62rem;
  background: rgba(0,0,0,0.55); padding: 1px 5px; border-radius: 3px; color: var(--text);
}
.page-tile .check {
  position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; border-radius: 4px;
  background: rgba(10,22,40,0.75); border: 1px solid rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: transparent;
}
.page-tile.selected .check { background: var(--gold); border-color: var(--gold); color: var(--navy); }

.toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar-row .grow { flex: 1; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--navy-mid); border: 1px solid rgba(201,168,76,0.3);
  color: var(--text); padding: 10px 18px; border-radius: 6px; font-size: 0.85rem;
  z-index: 300; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

#progressOverlay {
  position: fixed; inset: 0; background: rgba(5,10,20,0.85);
  display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px;
  z-index: 400; color: var(--text); padding: 20px; text-align: center;
}
#progressOverlay.show { display: flex; }
.spinner {
  width: 36px; height: 36px; border: 3px solid rgba(201,168,76,0.25); border-top-color: var(--gold);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-box {
  text-align: center; padding: 26px 16px;
}
.result-box .big-check {
  width: 54px; height: 54px; border-radius: 50%; background: rgba(46,139,87,0.15);
  border: 2px solid #2e8b57; color: #4fbf85; font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.stat-row { display: flex; justify-content: center; gap: 22px; margin: 14px 0 20px; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .n { font-size: 1.3rem; color: var(--gold-light); font-weight: 700; }
.stat .l { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

input[type="file"].hidden-input { display: none; }

.swatches { display: flex; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.selected { border-color: #fff; }

@media (max-width: 520px) {
  main.tool-main { padding: 20px 12px 90px; }
  .card { padding: 16px; }
  .dropzone { padding: 30px 14px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
}
