:root {
  color-scheme: light dark;

  --paper: #faf6ef;
  --paper-raised: #ffffff;
  --ink: #2b2521;
  --ink-soft: #6b6058;
  --line: #e6ddd0;
  --line-strong: #d8cbb8;
  --accent: #c1592f;
  --accent-hover: #a84a24;
  --accent-soft: #f4e3d8;
  --focus: #c1592f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 37, 33, 0.04), 0 8px 24px rgba(43, 37, 33, 0.06);

  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1917;
    --paper-raised: #262220;
    --ink: #f1ece5;
    --ink-soft: #a89e93;
    --line: #3a332e;
    --line-strong: #4a4138;
    --accent: #e08150;
    --accent-hover: #ec9569;
    --accent-soft: #3a2a20;
    --focus: #e08150;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0);
  background-size: 28px 28px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

/* Header */

.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.eyebrow {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.hero h1 .arrow {
  color: var(--accent);
}

.subtitle {
  margin: 0 auto;
  max-width: 46ch;
  color: var(--ink-soft);
  line-height: 1.55;
}

.subtitle code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  font-size: 0.9em;
}

/* Layout */

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

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  animation: rise 0.35s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0 0 1.25rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

.footer {
  margin-top: 2.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Fields */

.field {
  margin-bottom: 1.1rem;
}

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

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.hint {
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

input[type="number"],
input[type="text"] {
  width: 100%;
  max-width: 220px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.grid-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.1rem;
}

.grid-controls .field {
  margin-bottom: 0;
}

.reference-controls {
  padding: 1rem 1rem 0.2rem;
  margin: -0.2rem 0 1.1rem;
  background: var(--paper);
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  flex-direction: column;
}

.reference-controls .grid-controls,
.reference-controls {
  display: flex;
  gap: 1.25rem;
}

.reference-controls .hint {
  width: 100%;
  margin-bottom: 0.9rem;
}

/* Checkbox */

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  appearance: none;
  width: 1.2rem;
  height: 1.2rem;
  flex-shrink: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper);
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.checkbox-field input[type="checkbox"]::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  transform: scale(0);
  transition: transform 0.1s ease;
  box-shadow: inset 1em 1em white;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.checkbox-field input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-field input[type="checkbox"]:checked::before {
  transform: scale(1);
}

.checkbox-field input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Dropzone / file input */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 2.25rem 1rem;
  border: 2px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--paper);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.dropzone-icon {
  font-size: 1.75rem;
}

.dropzone-text {
  font-weight: 600;
}

.dropzone-hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* Images / canvas */

img#original-preview {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  margin-bottom: 1.25rem;
  display: block;
  border: 1px solid var(--line);
}

.corrected-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.corrected-section h3 {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

canvas#corrected-canvas {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}

/* Buttons */

.btn {
  appearance: none;
  border: none;
  border-radius: 9px;
  padding: 0.7rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff8f2;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Format toggle */

.format-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.format-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.format-btn:hover {
  color: var(--ink);
}

.format-btn.active {
  background: var(--accent);
  color: #fff8f2;
}

.format-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Swatches */

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.swatch {
  text-align: center;
}

.swatch-color {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  margin-bottom: 0.4rem;
}

.swatch div:last-child {
  font-size: 0.68rem;
  line-height: 1.3;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: var(--ink-soft);
  overflow-wrap: break-word;
}

.hidden {
  display: none !important;
}

@media (max-width: 420px) {
  .page {
    padding: 2rem 1rem 3rem;
  }

  .card {
    padding: 1.25rem;
  }
}
