:root {
  --bg: #000000;
  --panel: #0d0d0f;
  --panel-2: #16161a;
  --line: #2a2a30;
  --text: #e8e8ea;
  --muted: #8a8a92;
  --accent: #ffffff;
  --accent-hover: #d4d4d8;
  --radius: 10px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

header {
  padding: 28px 32px 8px;
  font-family: "Tomorrow", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 1px;
  color: var(--text);
}
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

main { flex: 1; padding: 20px 32px; }

/* Dropzone */
.dropzone {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 60px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
  cursor: pointer;
  max-width: 720px;
  margin: 0 auto;
}
.dropzone.drag { border-color: var(--accent); background: var(--panel-2); }
.drop-icon { font-size: 22px; color: var(--muted); margin-bottom: 8px; }
.drop-inner p { margin: 4px 0; }
.hint { color: var(--muted); font-size: 12px; letter-spacing: 1px; }
.link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font: inherit; text-decoration: underline;
}
.drop-sample {
  display: flex;
  justify-content: center;
  margin: 18px auto 0;
}
.drop-sample img {
  display: block;
  width: min(100%, 320px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #000;
}

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 860px) { .workspace { grid-template-columns: 1fr; } }

.canvas-wrap {
  background:
    linear-gradient(45deg, #1a1d26 25%, transparent 25%) 0 0/20px 20px,
    linear-gradient(-45deg, #1a1d26 25%, transparent 25%) 0 0/20px 20px,
    var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  justify-content: center;
  overflow: auto;
}
#preview { max-width: 100%; height: auto; image-rendering: pixelated; }

.meta { color: var(--muted); font-size: 12px; margin: 10px 2px; }

.actions { display: flex; gap: 10px; margin-top: 8px; }

button, a.primary {
  font: inherit; cursor: pointer; border-radius: 8px;
  padding: 10px 16px; min-height: 44px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  transition: background .12s, border-color .12s;
}
button:hover { border-color: #3a414f; }
.primary {
  background: var(--accent); border-color: var(--accent);
  color: #0b0e12; text-decoration: none; display: inline-block; font-weight: 600;
}
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Progress */
.progress { margin-top: 16px; }
.bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
#bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width .1s; }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
#progress-label { font-size: 12px; color: var(--muted); }
#cancel { flex: none; }

/* Result */
.result { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#result-img { max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: #000; }

/* Controls */
.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ctrl { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.ctrl > span { color: var(--text); }
.ctrl em { color: var(--accent); font-style: normal; }
.note { color: var(--muted); font-size: 11px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="text"], select {
  font: inherit; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px; letter-spacing: 1px;
}
input[type="text"]:focus, select:focus { outline: none; border-color: var(--accent); }
fieldset.ctrl { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.radio, .checkbox { flex-direction: row; align-items: center; gap: 8px; display: flex; cursor: pointer; }
.row { display: flex; gap: 14px; margin-top: 10px; }
.swatch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
input[type="color"] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }

footer { padding: 12px 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 16px; }
.footer-nav { display: flex; gap: 14px; }
.footer-nav a { color: var(--muted); text-decoration: none; }
.footer-nav a:hover { color: var(--accent); }

.hidden { display: none !important; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  header { padding: 20px 16px 4px; }
  h1 { font-size: 23px; }
  main { padding: 14px 16px; }
  footer { padding: 12px 16px; }

  .workspace { gap: 16px; }
  .dropzone { padding: 44px 16px; }
  .controls { padding: 16px; gap: 16px; }

  /* Full-width, comfortably tappable primary actions */
  .actions { flex-direction: column; }
  .actions button { width: 100%; }
  .result .primary { width: 100%; text-align: center; }

  /* 16px prevents iOS Safari from auto-zooming on focus */
  input[type="text"] { font-size: 16px; padding: 12px; }

  /* Fatter slider track/thumb for touch */
  input[type="range"] { height: 30px; }

  /* Bigger tap area for radios, checkbox and color swatches */
  .radio, .checkbox { padding: 6px 0; }
  .radio input, .checkbox input { width: 20px; height: 20px; }
  input[type="color"] { width: 44px; height: 34px; }
  .row { gap: 18px; }
}
