:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --surface: #fffdf9;
  --stage: #ebe6dc;
  --ink: #1c1915;
  --muted: #4f4a42;
  --line: #7d7568;
  --accent: #1b4332;
  --accent-hover: #143528;
  --on-accent: #f4faf6;
  --warn: #6b2e0e;
  --warn-bg: #f8ecdf;
  --shadow: 0 18px 40px rgba(48, 38, 22, 0.08);
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #11110f;
    --surface: #1c1b18;
    --stage: #26241f;
    --ink: #f6f2ea;
    --muted: #d5cec3;
    --line: #8a8274;
    --accent: #e4d3b4;
    --accent-hover: #f0e3cc;
    --on-accent: #1c1915;
    --warn: #f6d7bc;
    --warn-bg: #3d2e22;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: light) {
  :root { --line: #1c1915; }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root { --line: #f6f2ea; }
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}

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

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

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

.skip {
  position: absolute;
  left: 1rem;
  top: 0;
  transform: translateY(-140%);
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  z-index: 5;
  text-decoration: none;
  font-weight: 600;
}

.skip:focus {
  transform: none;
  top: 0.75rem;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

.wrap {
  width: min(1080px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  padding: 2.75rem 0 1.5rem;
}

.eyebrow,
.brand-name {
  margin: 0 0 0.8rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-name {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink);
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.mark {
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 5vw, 3.35rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.lede {
  max-width: 38rem;
  margin: 1rem 0 0;
  font-size: 1.0625rem;
  line-height: 1.55;
}

main {
  flex: 1;
  padding-bottom: 3.5rem;
}

.layout {
  display: grid;
  gap: 2.5rem;
  align-items: start;
}

form {
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
  min-width: 0;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-inline-size: 0;
}

legend {
  padding: 0;
  margin-bottom: 0.4rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.grid-2 {
  display: grid;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field > label,
.color-field legend {
  font-size: 0.9375rem;
  font-weight: 600;
}

.hint,
.meta,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.label-row label {
  font-size: 0.9375rem;
  font-weight: 600;
}

.label-row output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 7.25rem;
  resize: vertical;
  line-height: 1.45;
}

.payload-field {
  margin-top: 0.9rem;
}

#payload {
  min-height: 5.5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

input[type="range"] {
  width: 100%;
  height: 2.75rem;
  accent-color: var(--accent);
}

.segment {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.seg {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}

.seg input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.seg input:focus-visible {
  outline: none;
}

.seg:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.seg:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  font-weight: 600;
}

.check input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.color-grid {
  display: grid;
  gap: 1rem;
}

.color-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

input[type="color"] {
  width: 3rem;
  height: 2.75rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  flex: none;
}

.hex {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.warn {
  margin: 0;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.875rem;
  line-height: 1.45;
}

.banner {
  margin: 0 0 1.25rem;
}

.preview {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 1rem;
  border-radius: 12px;
  background: var(--stage);
}

canvas {
  display: block;
  width: min(100%, 320px);
  height: auto;
  background: #fff;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.empty {
  margin: 0;
  max-width: 16rem;
  text-align: center;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
}

button {
  appearance: none;
  min-height: 44px;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.to-preview {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.site-footer {
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.site-footer p {
  margin: 0.15rem 0;
}

.miss {
  padding-top: 1rem;
  max-width: 36rem;
}

.miss h1 {
  font-size: clamp(2rem, 4vw, 2.75rem);
}

@media (min-width: 640px) {
  .grid-2,
  .color-grid {
    grid-template-columns: 1fr 1fr;
  }

  .span-2 {
    grid-column: 1 / -1;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  #download-png {
    grid-column: 1 / -1;
  }
}

@media (min-width: 960px) {
  .wrap {
    width: min(1080px, calc(100% - 4.5rem));
  }

  .site-header {
    padding-top: 3.5rem;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 3.5rem;
  }

  form {
    grid-column: 1;
    grid-row: 1;
  }

  .preview {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 1.5rem;
  }

  .to-preview {
    display: none;
  }
}

@media (hover: hover) {
  button:hover:not(:disabled) {
    background: var(--accent-hover);
  }

  button.secondary:hover:not(:disabled) {
    background: var(--stage);
  }

  .seg:hover:not(:has(input:checked)) {
    background: var(--stage);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

#preview {
  scroll-margin-top: 1rem;
}
