/* MORPH — styles.css
   Retro-arcade / CRT-era, modern-polished. Dark only.
   Pixel type (Press Start 2P) lives in the header, panel HUD labels and key
   actions; the working controls stay clean and utilitarian. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --control-line: #5e5e80; /* >=3:1 against --surface for form-field boundaries */
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
  --checker: repeating-conic-gradient(#1c1c2c 0% 25%, #14141f 0% 50%);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(69, 240, 255, 0.3); }

[hidden] { display: none !important; }

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

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

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

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

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

main {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px var(--space-gutter) 72px;
}

/* ---------- drop zone ---------- */

.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: clamp(40px, 8vw, 90px) 20px;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 29, 0.3));
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s var(--ease-out);
}
.drop-zone:hover, .drop-zone.is-over {
  border-color: var(--cyan);
  box-shadow: 0 0 28px rgba(69, 240, 255, 0.12), inset 0 0 48px rgba(69, 240, 255, 0.04);
}
.drop-zone.is-over { transform: scale(1.01); }

.drop-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 28px;
  color: var(--dim);
  font-size: 14px;
}

.shape { width: 22px; height: 22px; display: inline-block; }
.shape-square { background: var(--gold); }
.shape-diamond { background: var(--magenta); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.shape-circle { background: var(--cyan); border-radius: 50%; }

.drop-zone:hover .shape { animation: bob 1.2s ease-in-out infinite; }
.drop-zone:hover .shape-diamond { animation-delay: 0.15s; }
.drop-zone:hover .shape-circle { animation-delay: 0.3s; }
@keyframes bob { 50% { transform: translateY(-6px); } }

.drop-title {
  margin: 0 0 14px;
  font-family: var(--pixel);
  font-size: clamp(11px, 2.6vw, 15px);
  color: var(--text);
  letter-spacing: 1px;
}

.drop-sub { margin: 0 0 18px; color: var(--dim); font-size: 14px; }

.drop-formats {
  margin: 22px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}

.privacy-note {
  margin: 18px auto 0;
  max-width: 520px;
  text-align: center;
  font-size: 12.5px;
  color: var(--dim);
}

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

.src-info {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  word-break: break-all;
}

.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.editor-preview { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.preview-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  min-height: 280px;
}

.editor-controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(69, 240, 255, 0.4);
}

.hint { margin: 0; font-size: 12px; color: var(--dim); }
.note { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.5; }
.note-gold { color: var(--gold); }
.note-green { color: var(--green); }

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

.crop-stage {
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  background: var(--checker) 0 0 / 16px 16px;
  border-radius: 4px;
}

.crop-stage canvas { display: block; }
.crop-stage canvas.pixelated { image-rendering: pixelated; }

.crop-box {
  position: absolute;
  cursor: move;
  /* punch-out dim + inset border so the edge stays visible at the full-frame crop */
  box-shadow: 0 0 0 9999px rgba(6, 6, 14, 0.62), inset 0 0 0 1px var(--cyan);
}
.crop-box:focus-visible {
  outline: none;
  box-shadow: 0 0 0 9999px rgba(6, 6, 14, 0.62), inset 0 0 0 2px var(--cyan);
}

.handle {
  position: absolute;
  width: 12px; height: 12px;
  background: var(--bg);
  border: 2px solid var(--cyan);
}
/* generous invisible hit area for touch */
.handle::after { content: ""; position: absolute; inset: -10px; }

/* handles sit fully inside the box so the stage's overflow clip never cuts them */
.handle[data-handle="nw"] { top: 0; left: 0; cursor: nwse-resize; }
.handle[data-handle="n"]  { top: 0; left: calc(50% - 6px); cursor: ns-resize; }
.handle[data-handle="ne"] { top: 0; right: 0; cursor: nesw-resize; }
.handle[data-handle="e"]  { top: calc(50% - 6px); right: 0; cursor: ew-resize; }
.handle[data-handle="se"] { bottom: 0; right: 0; cursor: nwse-resize; }
.handle[data-handle="s"]  { bottom: 0; left: calc(50% - 6px); cursor: ns-resize; }
.handle[data-handle="sw"] { bottom: 0; left: 0; cursor: nesw-resize; }
.handle[data-handle="w"]  { top: calc(50% - 6px); left: 0; cursor: ew-resize; }

.thirds {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.is-dragging .thirds { opacity: 1; }
.thirds i { position: absolute; background: rgba(69, 240, 255, 0.35); }
.thirds i:nth-child(1) { left: 33.333%; top: 0; bottom: 0; width: 1px; }
.thirds i:nth-child(2) { left: 66.666%; top: 0; bottom: 0; width: 1px; }
.thirds i:nth-child(3) { top: 33.333%; left: 0; right: 0; height: 1px; }
.thirds i:nth-child(4) { top: 66.666%; left: 0; right: 0; height: 1px; }

/* ---------- buttons & chips ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  min-height: 40px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(69, 240, 255, 0.22);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 11px; padding: 14px 20px; }

.transform-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 6px 10px;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.chip:hover:not(:disabled) { border-color: var(--cyan); color: var(--text); }
.chip.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(69, 240, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.35);
}
.chip:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- fields ---------- */

input[type="number"], input[type="text"] {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--control-line);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  transition: border-color 0.12s;
}
input[type="number"]:hover, input[type="text"]:hover { border-color: #74749a; }

.field-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.field-grid label, .size-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}

.size-row { display: flex; align-items: flex-end; gap: 8px; }
.size-row label { flex: 1; }

.lock-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.lock-btn[aria-pressed="true"] {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: inset 0 0 8px rgba(69, 240, 255, 0.15);
}

.field-row { display: flex; align-items: center; gap: 10px; }
.field-row > label, .field-row > .field-label {
  flex: 0 0 92px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}
.field-row input[type="text"] { flex: 1; }

input[type="range"] { flex: 1; accent-color: var(--cyan); min-width: 0; }

#qualityVal {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--gold);
  min-width: 28px;
  text-align: right;
}

input[type="color"] {
  width: 46px; height: 32px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.ico-sizes { display: flex; flex-wrap: wrap; gap: 10px; }
.ico-sizes label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.ico-sizes input { accent-color: var(--cyan); }

/* ---------- metadata, batch, target, adjust ---------- */

.metadata-panel, .batch-panel {
  margin: 0 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.metadata-panel summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--cyan);
}
.metadata-list {
  margin: 8px 0 10px;
  display: grid;
  grid-template-columns: minmax(90px, 150px) minmax(0, 1fr);
  gap: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
}
.metadata-list dt { color: var(--dim); }
.metadata-list dd { margin: 0; color: var(--text); word-break: break-word; }

.batch-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.batch-actions, .batch-item-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.batch-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.batch-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.batch-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--checker) 0 0 / 10px 10px; }
.batch-top { display: flex; justify-content: space-between; gap: 10px; font-family: var(--mono); font-size: 12px; }
.batch-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-size, .batch-status { color: var(--dim); }
.batch-status { margin: 4px 0 0; font-size: 12px; }
.batch-progress { width: 100%; height: 8px; accent-color: var(--cyan); }
.batch-item.is-done { border-color: rgba(65, 255, 139, 0.45); }
.batch-item.is-error { border-color: rgba(255, 85, 96, 0.6); }

.target-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}
.toggle-line, .adjust-toggles label {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}
.toggle-line input, .adjust-toggles input { accent-color: var(--cyan); }
.target-status { color: var(--gold); }

.panel-toggle {
  min-height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--cyan);
  font-family: var(--pixel);
  font-size: 10px;
  padding: 0;
  cursor: pointer;
}
.panel-toggle:disabled { cursor: not-allowed; color: var(--dim); }
.adjust-body { display: flex; flex-direction: column; gap: 12px; }
.adjust-toggles { display: flex; flex-wrap: wrap; gap: 10px; }
.field-row output {
  font-family: var(--mono);
  color: var(--gold);
  min-width: 32px;
  text-align: right;
}

/* ---------- convert bar ---------- */

.convert-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
}

.estimate {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}
.estimate output {
  display: inline-block;
  margin-left: 6px;
  font-size: 13.5px;
  color: var(--gold);
}

/* ---------- result ---------- */

#stageResult { max-width: 600px; margin: 0 auto; text-align: center; }

.result-heading {
  margin: 8px 0 22px;
  font-family: var(--pixel);
  font-size: clamp(12px, 2.6vw, 16px);
  color: var(--green);
  text-shadow: 0 0 12px rgba(65, 255, 139, 0.5);
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.thumb-frame {
  max-width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--checker) 0 0 / 14px 14px;
}

#resultThumb { display: block; max-width: 100%; max-height: 280px; }

.result-sizes { margin: 0; font-family: var(--mono); font-size: 15px; }
.result-sizes.is-smaller { color: var(--green); }
.result-sizes.is-larger { color: var(--gold); }

.result-dims { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--dim); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
}

/* ---------- dialog ---------- */

.dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: min(440px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(5, 5, 12, 0.72); }

.dialog-title { margin: 0 0 12px; font-family: var(--pixel); font-size: 12px; color: var(--gold); }
.dialog p { margin: 0 0 18px; color: var(--dim); line-height: 1.55; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; }

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

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

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

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
}

/* larger touch targets on coarse pointers */
@media (pointer: coarse) {
  .chip { min-height: 40px; padding: 10px 14px; }
  .lock-btn { width: 40px; height: 40px; }
  .ico-sizes label { padding: 8px 4px; }
  .handle::after { inset: -14px; }
}

@media (max-width: 480px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .convert-bar { flex-direction: column; align-items: stretch; text-align: center; }
  .field-row { flex-wrap: wrap; }
  .field-row > label, .field-row > .field-label { flex-basis: 100%; }
  .wordmark { letter-spacing: 1px; }
}

/* ---------- reduced motion: kill all looping/auto animation ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
}
