:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --accent: #0071e3;
  --danger: #d70015;
  --ok: #1a7f37;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header {
  padding: 20px 24px 8px;
}
header h1 { margin: 0; font-size: 22px; }
header .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

main {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 20px;
  padding: 16px 24px 32px;
  align-items: start;
}
@media (max-width: 820px) { main { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.field span code { color: var(--ink); background: #f0f0f2; padding: 0 3px; border-radius: 3px; }
.field input, .field select, textarea {
  font: inherit;
  font-size: 16px; /* >=16px so Mobile Safari doesn't zoom on focus */
  color: var(--ink);
  width: 100%; /* fill the field so flex rows can shrink to fit narrow screens */
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px; }
.field.checkbox { flex-direction: row; align-items: center; gap: 6px; }
.field.checkbox input { width: auto; }

.row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.row .field { flex: 1; }
.controls .field:first-child { margin-bottom: 4px; }

.readout {
  margin: 14px 0 4px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ok);
}
.readout.warn { color: var(--danger); font-weight: 600; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button {
  font: inherit;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.secondary { background: #fff; color: var(--accent); border-color: var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.preview-stage { display: flex; align-items: center; gap: 10px; justify-content: center; }
.preview-frame {
  flex: 0 1 auto;
  min-width: 0; /* allow the frame to shrink so the stage never overflows */
  display: grid;
  place-items: center;
  padding: 16px;
  background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 / 20px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#preview-img { display: block; image-rendering: auto; width: 320px; height: auto; max-width: 100%; }
.nav {
  flex: 0 0 auto; /* keep a full-size touch target; let the frame absorb shrink */
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  width: 36px; height: 36px; border-radius: 50%; font-size: 20px; line-height: 1; padding: 0;
}
.caption { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; min-height: 18px; }

@media (max-width: 820px) {
  .nav { width: 44px; height: 44px; } /* comfortable touch target on phones */
}

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.thumbs img {
  width: 64px; height: 64px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 6px; padding: 3px; background: #fff; cursor: pointer;
}
.thumbs img.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,113,227,0.25); }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(245,245,247,0.9); color: var(--muted); font-size: 14px;
  transition: opacity 0.2s; z-index: 10;
}
.loading.hidden { opacity: 0; pointer-events: none; }
