/* ── tokens ──────────────────────────────────────────────────────── */
:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1b1e25;
  --line: #262a33;
  --line-strong: #333846;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #7cf7c4;
  --accent-ink: #06231a;
  --danger-bg: #2b1d21;
  --danger-line: #5d323c;
  --danger-text: #ffd7de;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --check-a: #1f232b;
  --check-b: #14161b;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

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

/* ── topbar ──────────────────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex: 0 0 auto;
}

.brand em {
  font-style: normal;
  color: var(--muted);
  font-weight: 400;
  margin-left: 1px;
}

/* ── botones ─────────────────────────────────────────────────────── */
.ghost,
.primary {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.ghost:hover { background: var(--panel-2); border-color: var(--muted); }

.primary {
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  font-weight: 600;
  margin-left: auto;
}

.primary:hover { background: #97ffd4; border-color: #97ffd4; }
.primary:active { transform: translateY(1px); }

/* ── layout ──────────────────────────────────────────────────────── */
main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  padding: 16px;
}

.view { display: flex; flex: 1 1 auto; min-height: 0; min-width: 0; }

/* ── estado subida ───────────────────────────────────────────────── */
#view-upload { align-items: center; justify-content: center; }

.dropzone {
  width: min(760px, 100%);
  min-height: min(430px, 62vh);
  padding: 36px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(124, 247, 196, 0.05), transparent 60%),
    var(--panel);
  border: 1.5px dashed var(--line-strong);
  border-radius: 22px;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.dropzone:hover,
.dropzone:focus-visible { border-color: var(--accent); }

.dropzone:focus-visible { outline-offset: 4px; }

body.is-dragging .dropzone {
  border-color: var(--accent);
  border-style: solid;
  background-color: rgba(124, 247, 196, 0.06);
}

.dz-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 8px;
}

.dz-title { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.dz-sub { color: var(--muted); font-size: 14px; }
.dz-hint { margin-top: 14px; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.dz-paste { margin-top: 2px; color: #6f7683; font-size: 12px; }

/* ── estado editor ───────────────────────────────────────────────── */
#view-editor { flex-direction: column; gap: 14px; }

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-height: 0;
}

.pane {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: clamp(260px, calc(100dvh - 320px), 640px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pane figcaption {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pane-label { color: var(--text); font-weight: 600; letter-spacing: 0.06em; }

.dims { font-family: var(--mono); font-size: 11px; letter-spacing: 0; text-transform: none; }

.frame {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow: hidden;
}

.checker {
  background-image:
    linear-gradient(45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check-a) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: var(--check-b);
}

#orig-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

#preview {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  border-radius: 2px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

/* ── controles ───────────────────────────────────────────────────── */
.controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.ctrl > label { flex: 0 0 auto; font-weight: 500; }

.ctrl output {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.ctrl-slider output { min-width: 15ch; }
.ctrl-slider input { width: 180px; }

input[type="range"] {
  accent-color: var(--accent);
  height: 22px;
  cursor: pointer;
}

select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
  min-height: 36px;
}

select:hover { border-color: var(--muted); }

.ctrl-check { gap: 8px; }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}

.ctrl-check label { cursor: pointer; }

.ctrl-check.is-disabled { opacity: 0.45; }
.ctrl-check.is-disabled label { cursor: default; }

/* ── toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(560px, 92vw);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-line);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

/* ── responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  main { padding: 12px; flex: 0 0 auto; }

  #view-editor { flex: 0 0 auto; width: 100%; }

  .panes {
    grid-template-columns: 1fr;
    gap: 12px;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  .pane { height: auto; }

  .frame { height: clamp(180px, 30vh, 320px); flex: 0 0 auto; }

  #view-editor { gap: 12px; }

  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .ctrl { justify-content: space-between; }

  .ctrl-slider { flex-wrap: wrap; }
  .ctrl-slider input { flex: 1 1 100%; width: 100%; order: 3; height: 32px; }
  .ctrl-slider output { min-width: 0; }

  .ctrl-check { justify-content: flex-start; }

  select { min-height: 44px; }

  .primary { width: 100%; min-height: 48px; margin-left: 0; }
}

@media (max-width: 420px) {
  .topbar { padding: 0 14px; }
  .dz-title { font-size: 17px; }
  .dz-hint { font-size: 11px; }
  .pane figcaption { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
