/* ================================================================
   KDPEasy Margin Fixer — styles
   System fonts only. No @font-face, no remote assets.
   ================================================================ */

:root {
  --bg:            #f8fafc;   /* slate-50    */
  --surface:       #ffffff;
  --surface-2:     #f1f5f9;   /* slate-100   */
  --border:        #e2e8f0;   /* slate-200   */
  --border-strong: #cbd5e1;   /* slate-300   */
  --text:          #0f172a;   /* slate-900   */
  --text-muted:    #64748b;   /* slate-500   */
  --accent:        #ea580c;   /* orange-600  */
  --accent-hover:  #c2410c;   /* orange-700  */
  --accent-soft:   #fff7ed;   /* orange-50   */
  --ok:            #059669;   /* emerald-600 */
  --warn:          #d97706;   /* amber-600   */
  --danger:        #dc2626;   /* red-600     */
  --radius:        10px;
  --shadow:        0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}

* { box-sizing: border-box; }

/* Several elements below set an explicit `display`, which would otherwise beat
   the UA rule for [hidden]. Keep [hidden] authoritative. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------- header ---------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.wordmark { font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.wm-1 { color: var(--text); }
.wm-2 { color: var(--accent); }

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.privacy-pill svg { flex: none; color: var(--text-muted); }

.intro {
  margin: 0;
  padding: 12px 24px 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------------------------- layout ---------------------------- */

.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  padding: 16px 24px 32px;
  max-width: 1500px;
}

.sidebar {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.content { min-width: 0; }

/* ---------------------------- banners --------------------------- */

.banner-host:empty { display: none; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  font-size: 13px;
}
.banner p { margin: 0; }
.banner .banner-body { flex: 1 1 auto; min-width: 0; }
.banner .banner-x {
  flex: none;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}
.banner .banner-x:hover { color: var(--text); }

/* ---------------------------- steps ----------------------------- */

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  transition: opacity .25s ease;
}

.step.locked {
  opacity: .5;
  pointer-events: none;
}

.step-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.badge {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.step-label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.step-label label { cursor: pointer; }

.help-btn {
  flex: none;
  width: 18px; height: 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.help-btn:hover { border-color: var(--accent); color: var(--accent); }

.popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.12);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
}

.step-body { display: block; }

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

.field { margin-top: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

/* ---------------------------- controls -------------------------- */

.control {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.control:hover { border-color: var(--text-muted); }

select.control {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.custom-row .control { width: 120px; }
.custom-row .unit { font-size: 13px; color: var(--text-muted); }

.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  flex: 1 1 0;
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 10px;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-on {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}
.seg.seg-sm { padding: 2px; }
.seg.seg-sm .seg-btn { min-height: 30px; padding: 4px 14px; font-size: 12px; flex: none; }

.note-warn {
  margin: 8px 0 0;
  padding: 8px 10px;
  font-size: 12px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
}

.chip {
  display: inline-block;
  margin: 8px 0 0;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  border: 1px solid var(--border-strong);
  margin-left: 4px;
  vertical-align: -1px;
}

.info-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.info-panel summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius);
}
.info-panel summary:hover { color: var(--text); }
.info-panel p {
  margin: 0;
  padding: 0 12px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* file info line */
.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--accent-hover); }

/* ---------------------------- buttons --------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-secondary {
  width: 100%;
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--text-muted); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-swatch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px;
  margin-top: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-swatch:hover { border-color: var(--text-muted); }

.swatch-lg {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.solid-color-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.solid-color-row .link-btn { margin-top: 8px; }

/* Solid bar so cards scrolling underneath never show through the button. */
.sidebar-foot {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 12px 0 4px;
  background: var(--bg);
  box-shadow: 0 -10px 10px -6px var(--bg);
}

.spinner {
  width: 14px; height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------- toolbar --------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 2px 10px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 30px;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------------------------- stage ----------------------------- */

.stage {
  position: relative;
  height: min(70vh, 640px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stage.dragover .empty { border-color: var(--accent); background: var(--accent-soft); }

.empty {
  position: absolute;
  inset: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
}
.empty svg { color: var(--border-strong); margin-bottom: 8px; }
.empty-head { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.empty-sub { margin: 0; font-size: 13px; }
.empty-muted { margin: 6px 0 0; font-size: 12px; color: #94a3b8; }

.empty-privacy {
  margin: 10px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ------------------------ compare slider ------------------------ */

.compare { position: absolute; inset: 0; }

.layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.layer-before canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
}

.sheet {
  position: relative;
  display: block;
  background: #fff;
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 16px rgba(15,23,42,.14);
}
.sheet canvas { display: block; width: 100%; height: 100%; }
.sheet .overlay { position: absolute; inset: 0; pointer-events: none; }

.cmp-label {
  position: absolute;
  top: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text-muted);
  background: rgba(248,250,252,.8);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}
.cmp-left { left: 10px; }
.cmp-right { right: 10px; }

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  z-index: 5;
}

.handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: ew-resize;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(15,23,42,.18);
  user-select: none;
}

/* ---------------------------- toast ----------------------------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  font-size: 13px;
  color: #065f46;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-left: 4px solid var(--ok);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toast strong { font-weight: 600; }

/* ---------------------------- readout --------------------------- */

.readout {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.readout-main { margin: 0; font-size: 14px; font-weight: 600; }
.readout-sub { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }

.quality { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.q-title { margin: 0; font-size: 13px; font-weight: 600; }
.q-copy { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }
.q-ok    .q-title { color: var(--ok); }
.q-warn  .q-title { color: var(--warn); }
.q-bad   .q-title { color: var(--danger); }
.q-copy a { color: var(--accent); }

/* ---------------------------- footer ---------------------------- */

.app-footer {
  padding: 20px 24px 28px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}
.app-footer p { margin: 0 0 4px; font-size: 12px; color: var(--text-muted); }

/* ---------------------------- responsive ------------------------ */

@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px 16px 96px;
  }
  .sidebar { position: static; }
  .sidebar-foot {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: none;
  }
  .seg.seg-sm .seg-btn { min-height: 40px; }
  .app-header { padding: 12px 16px; }
  .intro { padding: 12px 16px 0; }
  .app-footer { padding-bottom: 88px; }
  .stage { height: min(60vh, 520px); }
}

@media (max-width: 420px) {
  .privacy-pill { font-size: 11px; }
  .layout { padding-left: 12px; padding-right: 12px; }
}

/* Desktop: keep the preview (toolbar + stage) pinned in view while the
   sidebar scrolls, so the whole image stays visible next to the controls
   (e.g. when picking a color from it). */
@media (min-width: 981px) {
  .layout { align-items: stretch; }
  .sidebar { align-self: start; }
  .preview-pin { position: sticky; top: 16px; z-index: 5; }
}


/* "Save as" (PNG / JPG) card above the Download button */
.format-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.format-row .field-label { margin: 0; }
#stepFormat .hint { margin: 8px 0 0; }
