:root {
  --bg: #0e0e10;
  --panel: #17171a;
  --line: #2a2a2f;
  --line-hover: #4a4a52;
  --dash: #3a3a42;
  --field: #0f0f12;
  --seg-on: #2a2a31;
  --check-a: #141417;
  --check-b: #101013;
  --text: #ececf1;
  --muted: #8d8d97;
  --accent: #f5c542;
  --radius: 12px;
  color-scheme: dark;
}
/* Claro: forzado por el usuario, o automático si el sistema lo prefiere */
:root[data-theme="light"] {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --line: #dcdce2;
  --line-hover: #b4b4bd;
  --dash: #c4c4cc;
  --field: #f6f6f8;
  --seg-on: #e4e4ea;
  --check-a: #ececf0;
  --check-b: #e4e4e9;
  --text: #18181c;
  --muted: #62626d;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f4f6; --panel: #ffffff; --line: #dcdce2; --line-hover: #b4b4bd;
    --dash: #c4c4cc; --field: #f6f6f8; --seg-on: #e4e4ea;
    --check-a: #ececf0; --check-b: #e4e4e9; --text: #18181c; --muted: #62626d;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.top { padding: 20px 24px 8px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top-text { min-width: 0; }
button.theme { flex: none; padding: 8px 12px; font-size: 13px; }
button.danger:hover:not(:disabled) { border-color: #e5484d; color: #e5484d; }
.top-text h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.top-text p { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  padding: 16px 24px 32px;
  align-items: start;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
}

.stage {
  align-self: stretch; /* misma altura que el panel de la derecha */
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-height: 60dvh; justify-content: center;
  background:
    repeating-conic-gradient(var(--check-a) 0% 25%, var(--check-b) 0% 50%) 50% / 24px 24px;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
}
.drop {
  flex: 1; width: 100%; min-height: 50dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border: 1.5px dashed var(--dash); border-radius: var(--radius); text-align: center; padding: 24px;
  transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--accent); background: #f5c5420a; }
.drop-title { font-size: 18px; font-weight: 600; }
.drop-sub { color: var(--muted); font-size: 13px; }

.preview-wrap { display: flex; justify-content: center; width: 100%; }
#preview {
  cursor: grab; touch-action: none; user-select: none;
  display: block; max-width: 100%; max-height: 72dvh; width: auto; height: auto;
  border-radius: 6px; box-shadow: 0 0 0 1px #ffffff14, 0 20px 50px #0008;
}
.meta { margin: 0; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.panel { display: flex; flex-direction: column; gap: 14px; }
fieldset {
  margin: 0; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
legend { padding: 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }

select, input[type=number] {
  width: 100%; background: var(--field); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font: inherit;
}
.row { display: flex; gap: 8px; align-items: end; }
.row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.x { padding-bottom: 10px; color: var(--muted); }

button {
  font: inherit; border-radius: 8px; padding: 10px 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--field); color: var(--text);
}
button.ghost { flex: 1; }
button.ghost:hover { border-color: var(--line-hover); }
button.primary { background: var(--accent); color: #111; border-color: transparent; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }

.seg { display: flex; background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg label { flex: 1; text-align: center; padding: 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--seg-on); }

input[type=color] {
  width: 44px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer;
}
.swatches { display: flex; gap: 6px; align-items: center; flex: 1; }
.swatches button {
  width: 28px; height: 28px; padding: 0; border-radius: 50%;
  background: var(--c); border: 2px solid var(--line-hover);
}
.swatches button.on { outline: 2px solid var(--accent); outline-offset: 2px; }
#solidRow[aria-disabled=true] { opacity: .35; pointer-events: none; }

.slider { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; font-size: 13px; }
.slider output { color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--accent); }
.photo-opts { display: flex; flex-direction: column; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }

/* ---------- Táctil ---------- */
.only-coarse { display: none; }
@media (pointer: coarse) {
  .only-fine { display: none; }
  .only-coarse { display: block; }
  .swatches button { width: 34px; height: 34px; }
  .slider input { height: 28px; }        /* área de toque más cómoda */
  button { min-height: 44px; }
}

/* ---------- Móvil ---------- */
@media (max-width: 820px) {
  .top { padding: 14px 16px 0; }
  .top-text h1 { font-size: 20px; }
  .top-text p { font-size: 13px; }

  /* iOS amplía la página al enfocar campos con letra < 16px */
  select, input[type=number] { font-size: 16px; }

  .stage { min-height: 0; padding: 12px; }
  .drop { min-height: 42dvh; }

  /* Con foto cargada, la vista previa se queda fija arriba mientras ajustas */
  .stage:has(.preview-wrap:not([hidden])) {
    position: sticky;
    top: env(safe-area-inset-top);
    z-index: 10;
    margin: 0 -16px;
    border-radius: 0 0 var(--radius) var(--radius);
    border-width: 0 0 1px;
    padding: 10px 16px 8px;
    box-shadow: 0 10px 24px #000a;
  }
  #preview { max-height: 40dvh; }
  .panel { gap: 12px; }
}

/* Pantallas muy bajas (móvil en horizontal): preview más pequeña */
@media (max-width: 820px) and (max-height: 500px) {
  #preview { max-height: 34dvh; }
}

#preview.dragging { cursor: grabbing; }

/* ---------- Idioma y privacidad ---------- */
.top-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.top-actions select { width: auto; padding: 8px 10px; font-size: 13px; }
.top-text .privacy-short { font-size: 13px; }
.privacy-short a { color: var(--text); text-decoration: underline; }
.privacy {
  margin: 0 24px 32px; padding: 16px 18px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); color: var(--muted); font-size: 13px;
}
.privacy h2 { margin: 0 0 8px; font-size: 14px; color: var(--text); }
.privacy ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
@media (max-width: 820px) {
  .privacy { margin: 0 16px 24px; }
  .top { flex-wrap: wrap; }
}

/* ---------- Vista previa fija al hacer scroll (escritorio) ---------- */
.sticky { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
@media (min-width: 821px) {
  .stage:has(.preview-wrap:not([hidden])) { justify-content: flex-start; }
  .sticky { position: sticky; top: 16px; }
  #preview { max-height: calc(100dvh - 120px); }
}
