/* ── Reset & tokens ──────────────────────────────────────────── */
:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #9ca3af;
  --brand: #0f766e;
  --brand-light: rgba(15, 118, 110, 0.07);
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  padding: 24px 24px 16px;
  text-align: center;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 8px;
}

header p {
  display: block;
  max-width: 62ch;
  margin: 0 auto 10px;
  color: var(--muted);
  font-size: 13px;
}

.nav-links {
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-links a {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
  transition: color 0.1s;
}

.nav-links a:hover {
  color: var(--text);
}

/* ── Shell ───────────────────────────────────────────────────── */
.shell {
  width: min(1200px, calc(100vw - 24px));
  margin: 0 auto;
  padding-bottom: 48px;
}

/* ── Top tabs (2D / 1D) ──────────────────────────────────────── */
.tabs {
  display: flex;
  width: fit-content;
  margin: 0 auto 14px;
  border-bottom: 1px solid var(--border);
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  padding: 8px 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--muted);
  user-select: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition:
    color 0.12s,
    border-color 0.12s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

/* ── 2D type picker ──────────────────────────────────────────── */
.type-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 12px 12px;
  width: min(1200px, calc(100vw - 24px));
  margin: 0 auto;
}

.type-btn {
  appearance: none;
  padding: 4px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition:
    color 0.1s,
    border-color 0.1s,
    background 0.1s;
}

.type-btn:hover {
  color: var(--text);
  border-color: #9ca3af;
}

.type-btn.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

/* ── Main layout ─────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) 360px;
  gap: 16px;
  align-items: start;
}

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

/* ── Panel / card ────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.controls {
  padding: 20px;
}

/* ── Settings blocks ─────────────────────────────────────────── */
.settings-grid {
  display: grid;
  gap: 0;
}

.settings-block {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.settings-block:first-child {
  padding-top: 0;
}

.settings-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-block h3 {
  margin-bottom: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Form fields ─────────────────────────────────────────────── */
.field {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field label .val {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-weight: 500;
  color: var(--brand);
  font-size: 11px;
}

.field .desc {
  font-size: 11px;
  color: var(--muted);
}

.quick-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.quick-examples span {
  align-self: center;
  color: var(--muted);
  font-size: 11px;
}

.quick-example {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}

.quick-example:hover {
  border-color: var(--brand);
  color: var(--brand);
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  transition:
    border-color 0.12s,
    box-shadow 0.12s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-light);
}

textarea {
  resize: vertical;
  min-height: 66px;
}

/* ── Segmented controls ──────────────────────────────────────── */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.seg button {
  background: transparent;
  border: none;
  padding: 6px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.12s,
    color 0.12s;
}

.seg button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ── Sliders ─────────────────────────────────────────────────── */
input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  padding: 0;
  border: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  border: 2px solid #fff;
}

/* ── Color swatches ──────────────────────────────────────────── */
.swatch-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch-row > .field {
  flex: 1;
  min-width: 110px;
}

.swatch-input {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

.swatch-input input[type="color"] {
  width: 30px;
  height: 24px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.swatch-input input[type="text"] {
  border: none;
  padding: 3px 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: transparent;
}

.swatch-input input[type="text"]:focus {
  box-shadow: none;
  border: none;
}

/* ── Row grids ───────────────────────────────────────────────── */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

@media (max-width: 420px) {
  .row-2,
  .row-3 {
    grid-template-columns: 1fr;
  }
}

/* ── Checkbox ────────────────────────────────────────────────── */
.check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.check-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ── Preview column ──────────────────────────────────────────── */
.preview-col {
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.preview {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}

.preview .frame {
  background: #fff;
  padding: 8px;
  border-radius: 6px;
  max-width: 100%;
  overflow: auto;
}

.preview canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  text-align: center;
}

/* ── Action buttons ──────────────────────────────────────────── */
.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  font-family: inherit;
  transition:
    border-color 0.1s,
    background 0.1s;
}

.btn:hover {
  border-color: #9ca3af;
  background: var(--panel-2);
}

.btn.primary {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.btn.primary:hover {
  background: #1f2937;
  border-color: #1f2937;
  color: #fff;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.action-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 11px;
}

/* ── Payload section ─────────────────────────────────────────── */
.payload-section {
  display: grid;
  gap: 5px;
}

.payload-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.payload-box {
  width: 100%;
  min-height: 90px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  font:
    11px/1.5 "SF Mono",
    Menlo,
    Consolas,
    monospace;
  color: var(--muted);
  resize: vertical;
}

/* ── Error & utilities ───────────────────────────────────────── */
.error {
  padding: 8px 12px;
  border: 1px solid #fecaca;
  border-radius: 7px;
  background: #fef2f2;
  color: var(--danger);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

/* ── Section label (hidden — type buttons provide context) ───── */
.section-label {
  display: none;
}

/* ── Controls heading ────────────────────────────────────────── */
.controls h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.controls .hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

input[type="file"] {
  width: 100%;
  font-size: 12px;
  color: var(--muted);
}

/* ── Sticky preview ─────────────────────────────────────────── */
@media (min-width: 861px) {
  .preview-col {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
}

/* ── Dark mode ───────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --panel: #1f2937;
    --panel-2: #111827;
    --border: #374151;
    --text: #f9fafb;
    --muted: #6b7280;
    --brand: #2dd4bf;
    --brand-light: rgba(45, 212, 191, 0.1);
    --danger: #f87171;
  }

  input[type="text"],
  input[type="email"],
  input[type="url"],
  input[type="number"],
  input[type="datetime-local"],
  textarea,
  select {
    background: var(--panel);
    color: var(--text);
    border-color: var(--border);
  }

  .seg {
    background: var(--panel-2);
  }
  .seg button.active {
    background: var(--panel);
    color: var(--text);
  }

  .tabs {
    border-bottom-color: var(--border);
  }
  .tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
  }

  .type-btn {
    color: var(--muted);
    border-color: var(--border);
  }
  .type-btn:hover {
    color: var(--text);
    border-color: #4b5563;
  }
  .type-btn.active {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
  }

  .swatch-input {
    background: var(--panel);
    border-color: var(--border);
  }
  .swatch-input input[type="color"] {
    background: var(--panel);
  }
  .swatch-input input[type="text"] {
    color: var(--text);
  }

  .btn {
    background: var(--panel);
    color: var(--text);
    border-color: var(--border);
  }
  .btn:hover {
    background: #263044;
    border-color: #4b5563;
  }
  .btn.primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
  }
  .btn.primary:hover {
    background: #e5e7eb;
    color: #111827;
    border-color: #e5e7eb;
  }

  .preview {
    background: var(--panel-2);
    border-color: var(--border);
  }
  .preview .frame {
    background: var(--panel);
  }

  .payload-box {
    background: var(--panel-2);
    color: var(--muted);
    border-color: var(--border);
  }

  .error {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.3);
  }

  input[type="range"]::-webkit-slider-thumb {
    background: var(--text);
  }
  input[type="range"]::-moz-range-thumb {
    background: var(--text);
  }
}

/* ── Footer ──────────────────────────────────────────────────── */
footer {
  text-align: center;
  margin-top: 20px;
  padding: 0 24px 24px;
  color: var(--muted);
  font-size: 12px;
}

footer a {
  color: var(--brand);
}

footer a:hover {
  text-decoration: underline;
}

/* Readable controls and a preview that remains visible on wide screens. */
:root {
  --muted: #64748b;
}
header {
  padding-top: 32px;
}
header h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}
header .privacy-note {
  color: var(--brand);
  font-weight: 600;
  font-size: 12px;
}
.btn,
.tab,
.type-btn {
  min-height: 40px;
}
:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 3px;
}
.skip-link {
  position: fixed;
  top: -80px;
  left: 16px;
  z-index: 20;
  padding: 12px;
  background: white;
}
.skip-link:focus {
  top: 12px;
}
.scan-warning {
  color: #854d0e;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
}
@media (min-width: 901px) {
  .preview-col {
    position: sticky;
    top: 20px;
  }
}
@media (max-width: 600px) {
  input,
  textarea,
  select {
    font-size: 16px !important;
  }
  .actions .btn {
    flex: 1 1 40%;
    min-height: 44px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
@media print {
  body,
  .shell,
  .panel,
  .preview,
  .preview .frame {
    background: white;
    border: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
  }
  header,
  footer,
  .tabs,
  .type-picker,
  .controls,
  .actions,
  .action-status,
  .payload-section,
  .scan-warning,
  .skip-link {
    display: none !important;
  }
  .layout {
    display: block;
  }
  .layout > :not(.preview-col) {
    display: none;
  }
  .preview-col {
    position: static;
    display: block;
  }
  .preview {
    min-height: 0;
    break-inside: avoid;
  }
  .preview canvas {
    max-width: 100%;
  }
  .meta {
    color: black;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --muted: #a5b4c5;
  }
  .skip-link {
    background: var(--panel);
  }
}
