:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #1c2030;
  --muted: #6a7085;
  --line: #dfe2ea;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eceafd;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 6px 20px rgba(20, 24, 40, .08);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --surface: #1e212b;
    --surface-2: #262a36;
    --text: #e8eaf1;
    --muted: #9aa1b5;
    --line: #333848;
    --accent: #7c75f5;
    --accent-soft: #2c2b4d;
    --danger: #ef7a6d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

/* Barra superior */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--accent); }
.brand span { color: var(--text); }
.status { flex: 1; color: var(--muted); text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; }

/* Botones */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 13px; font-weight: 500; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Estructura */
.layout { flex: 1; display: grid; grid-template-columns: 330px 1fr; min-height: 0; }
.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 6px 18px 20px;
  overflow-y: auto;
}
main { padding: 20px; overflow-y: auto; min-width: 0; }

.panel section { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.panel h2 { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; }
.field small { color: var(--muted); font-size: 12px; }
.field.grow { flex: 1; min-width: 160px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
#sizeCustom { display: grid; gap: 10px; }

select, input[type="number"] {
  font: inherit;
  width: 100%;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; gap: 2px; }
.seg label { flex: 1; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 5px 6px; border-radius: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: 13px; }
.check input { margin-top: 2px; accent-color: var(--accent); }
.btn.reset { width: 100%; margin-top: 14px; }
.privacy { color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* Zona de carga */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 46px 20px;
  text-align: center;
  cursor: pointer;
  display: grid;
  gap: 6px;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--text); font-size: 17px; }
.dropzone:hover, body.dragging .dropzone { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.compact { padding: 14px 20px; }
.dropzone.compact strong { font-size: 14px; }

/* Tira de fotos */
.strip-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 16px 0 8px; color: var(--muted); font-size: 13px; }
.strip { display: flex; flex-wrap: wrap; gap: 10px; }
.card {
  width: 104px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px;
  display: grid;
  gap: 5px;
  position: relative;
  cursor: grab;
}
.card.dragging { opacity: .35; }
.card.drop-before { box-shadow: -3px 0 0 var(--accent); }
.card.drop-after { box-shadow: 3px 0 0 var(--accent); }
.card .thumb { all: unset; display: block; cursor: pointer; border-radius: 6px; overflow: hidden; background: var(--surface-2); height: 80px; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.card .del {
  position: absolute; top: 2px; right: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, .6); color: #fff;
  font-size: 13px; line-height: 1; cursor: pointer;
}
.card .del:hover { background: var(--danger); }

.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.stepper button { font: inherit; font-weight: 700; border: none; background: var(--surface-2); color: var(--text); width: 28px; height: 26px; cursor: pointer; }
.stepper button:hover { background: var(--accent-soft); }
.stepper b { flex: 1; min-width: 28px; text-align: center; font-size: 13px; }

/* Vista previa */
.warn { margin-top: 16px; padding: 10px 14px; border-radius: 8px; background: #fff3cd; color: #6b5200; border: 1px solid #f0d98a; }
.pages { display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; margin-top: 22px; }
.page-wrap { display: grid; gap: 6px; max-width: 100%; justify-items: center; }
.page-wrap figcaption, .page-label { color: var(--muted); font-size: 12px; }
svg.page { display: block; max-width: 100%; height: auto; background: #fff; box-shadow: var(--shadow); border-radius: 2px; }
svg.page .cell { cursor: pointer; }
svg.page .cell:hover .hit { stroke: #4f46e5; stroke-width: .8; }

/* Editor */
dialog#editor {
  border: none;
  border-radius: 14px;
  padding: 16px;
  width: min(640px, calc(100vw - 24px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog#editor::backdrop { background: rgba(10, 12, 20, .6); }
.ed-head { display: flex; align-items: center; gap: 10px; }
.ed-head span { flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-stage-wrap { display: flex; justify-content: center; margin: 12px 0 6px; background: var(--surface-2); border-radius: 10px; padding: 12px; }
#edStage { display: block; background: #fff; box-shadow: var(--shadow); cursor: grab; touch-action: none; user-select: none; }
#edStage:active { cursor: grabbing; }
.ed-hint { margin: 0 0 10px; text-align: center; color: var(--muted); font-size: 12px; }
.ed-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.btn-pair { display: flex; gap: 4px; }
.btn-pair .btn { font-size: 16px; line-height: 1.1; }
.ed-foot { display: flex; justify-content: space-between; margin-top: 16px; }

/* Capa de progreso y avisos */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 20, .6); display: grid; place-items: center; z-index: 50; }
.overlay-box { background: var(--surface); padding: 20px 26px; border-radius: 12px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); font-weight: 600; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #23263a; color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 60; max-width: calc(100vw - 32px);
}

@media (max-width: 860px) {
  body { display: block; }
  .layout { display: block; }
  .panel { border-right: none; border-bottom: 1px solid var(--line); overflow: visible; }
  main { overflow: visible; padding: 14px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .status { order: 3; flex-basis: 100%; text-align: left; }
  .actions { margin-left: auto; }
}
