:root {
  color: #211d19;
  background: #f3eee6;
  font-family: Inter, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", sans-serif;
  font-synthesis: none;
  --ink: #211d19;
  --muted: #70675e;
  --paper: #fffdf9;
  --paper-warm: #faf6ef;
  --line: #d7cec2;
  --line-strong: #a99d8f;
  --accent: #c13b2b;
  --accent-dark: #b82f22;
  --accent-soft: #fff0e9;
  --green: #246c59;
  --focus: #0c6d9d;
  --shadow: 0 18px 48px rgba(48, 38, 29, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(37, 31, 26, 0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 31, 26, 0.024) 1px, transparent 1px),
    #f3eee6;
  background-size: 24px 24px;
}

button, input, select { font: inherit; }
button, select, input[type="radio"], input[type="checkbox"], input[type="range"] { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.site-header,
main,
footer {
  width: min(1380px, calc(100% - 48px));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 38px 0 26px;
  border-bottom: 3px solid var(--ink);
}

.eyebrow,
.step-label {
  margin: 0 0 7px;
  color: var(--accent-dark);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1 {
  margin: 0;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(2.1rem, 4vw, 3.65rem);
  line-height: 0.96;
  letter-spacing: -0.045em;
}

.lead { margin: 12px 0 0; color: var(--muted); font-size: 0.94rem; }

.privacy-badge {
  flex: none;
  margin: 0;
  padding: 9px 14px;
  border: 1px solid #9ab4a9;
  border-radius: 999px;
  background: #edf6f1;
  color: #245b4d;
  font-size: 0.8rem;
  font-weight: 700;
}
.privacy-badge span { color: #47a081; font-size: 0.65rem; }

main { padding: 30px 0 68px; }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}
.section-heading h2 { margin: 0; font-size: 1.34rem; line-height: 1.25; }
.section-heading > p { margin: 0; color: var(--muted); font-size: 0.78rem; }

.workspace { margin-bottom: 28px; }

.drop-zone {
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: 190px;
  padding: 26px;
  border: 2px dashed var(--line-strong);
  border-radius: 10px;
  background: rgba(255, 253, 249, 0.88);
  text-align: center;
  transition: border-color 150ms, background 150ms, transform 150ms, min-height 180ms;
}
.drop-zone:hover,
.drop-zone.is-dragging { border-color: var(--accent); background: #fff8f3; }
.drop-zone.is-dragging { transform: translateY(-2px); }
.drop-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--accent);
  font-size: 1.7rem;
  line-height: 1;
}
.drop-title { margin: 16px 0 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.2rem; font-weight: 700; }
.drop-help { margin: 6px 0 13px; color: var(--muted); font-size: 0.76rem; }
.input-meta { margin: 12px 0 0; color: var(--muted); font-size: 0.76rem; }

body.has-image .drop-zone {
  grid-template-columns: 1fr auto;
  justify-items: start;
  min-height: 84px;
  padding: 18px 22px;
  border-style: solid;
  text-align: left;
}
body.has-image .drop-icon,
body.has-image .drop-title,
body.has-image .drop-help { display: none; }
body.has-image .input-meta { display: block; grid-column: 1; grid-row: 1; margin: 0; color: var(--ink); font-weight: 700; }
body.has-image .drop-zone .button { grid-column: 2; grid-row: 1; }

.button {
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 9px 18px;
  font-weight: 800;
  transition: transform 100ms, box-shadow 100ms, background 100ms;
}
.button:hover:not(:disabled) { transform: translate(-2px, -2px); }
.button:active:not(:disabled) { transform: translate(0, 0); box-shadow: none; }
.button-secondary { background: var(--paper); box-shadow: 4px 4px 0 var(--ink); }
.button-primary { min-width: 200px; background: var(--accent); color: #fff; box-shadow: 5px 5px 0 var(--ink); }
.button-primary span { float: right; margin-left: 24px; font-size: 1.15rem; }
.button:disabled { cursor: not-allowed; border-color: #9e978f; background: #d8d3cc; color: #716c66; box-shadow: none; }

.text-button {
  border: 0;
  border-bottom: 1px solid currentColor;
  padding: 3px 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}
.text-button:hover { color: var(--accent-dark); }

.status { min-height: 22px; margin: 10px 0 0; color: var(--muted); font-size: 0.78rem; }
.status[data-kind="error"] { color: #a62821; font-weight: 700; }
.status[data-kind="success"] { color: var(--green); }

.studio-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  align-items: start;
  gap: 28px;
}

.controls-section {
  position: sticky;
  top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.controls-heading { margin: 0; padding: 22px 22px 18px; border-bottom: 1px solid var(--line); }

fieldset { min-width: 0; margin: 0; padding: 22px; border: 0; }
.controls-grid fieldset { border-top: 1px solid var(--line); }
legend { float: left; width: 100%; margin: 0 0 15px; padding: 0; font-size: 0.88rem; font-weight: 800; }
legend span { color: var(--muted); font-size: 0.68rem; font-weight: 500; }

.presets-fieldset { background: var(--paper-warm); }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; clear: both; }
.preset {
  min-height: 58px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 8px 9px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}
.preset strong, .preset span { display: block; }
.preset strong { font-size: 0.79rem; }
.preset span { margin-top: 3px; color: var(--muted); font-size: 0.62rem; }
.preset:hover { border-color: var(--accent); }
.preset.is-active { border-color: var(--ink); background: var(--ink); color: #fff; box-shadow: 3px 3px 0 var(--accent); }
.preset.is-active span { color: #ddd4cb; }

.select-row { display: flex; align-items: center; gap: 10px; clear: both; }
select,
.custom-size input {
  height: 41px;
  border: 1px solid #948a7f;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
select { flex: 1; min-width: 90px; padding: 0 32px 0 11px; }
.custom-size { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 0.7rem; }
.custom-size[hidden] { display: none; }
.custom-size input { width: 64px; padding: 0 7px; }
.field-help { clear: both; margin: 11px 0 0; color: var(--muted); font-size: 0.7rem; line-height: 1.55; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); clear: both; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid;
  place-items: center;
  height: 41px;
  border: 1px solid #948a7f;
  border-right: 0;
  background: #fff;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
}
.segmented label:first-child span { border-radius: 4px 0 0 4px; }
.segmented label:last-child span { border-right: 1px solid #948a7f; border-radius: 0 4px 4px 0; }
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 1; }

.toggle { display: flex; align-items: center; gap: 10px; clear: both; width: fit-content; font-weight: 700; }
.toggle input { position: absolute; opacity: 0; }
.toggle-track { position: relative; width: 48px; height: 26px; border: 2px solid var(--ink); border-radius: 30px; background: #c9c2b9; }
.toggle-track span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform 150ms; }
.toggle input:checked + .toggle-track { background: #f58a73; }
.toggle input:checked + .toggle-track span { transform: translateX(21px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--focus); outline-offset: 3px; }

.preview-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: rgba(255, 253, 249, 0.9);
  box-shadow: var(--shadow);
}
.preview-heading { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.output-meta { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.76rem; }

.preview-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 112px 112px auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-warm);
}
.toolbar-fieldset { padding: 0; }
.toolbar-fieldset legend,
.toolbar-select { margin: 0 0 6px; color: var(--muted); font-size: 0.65rem; font-weight: 700; }
.segmented-three { grid-template-columns: repeat(3, 1fr); }
.segmented-three span { height: 36px; font-family: inherit; font-size: 0.71rem; }
.segmented-four { grid-template-columns: repeat(4, 1fr); }
.segmented-four span { min-height: 36px; height: auto; font-family: inherit; font-size: 0.68rem; }
.toolbar-select { display: grid; gap: 6px; }
.toolbar-select select { width: 100%; height: 36px; padding-left: 9px; font-size: 0.72rem; }
.grid-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 9px;
  background: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.grid-toggle:has(input:disabled) { cursor: not-allowed; opacity: 0.52; }

.wipe-control {
  display: grid;
  grid-template-columns: auto 1fr 42px;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.wipe-control[hidden] { display: none; }
.wipe-control input { width: 100%; accent-color: var(--accent); }
.wipe-control output { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

.comparison {
  --wipe: 50%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-width: 0;
}
figure { min-width: 0; margin: 0; }
figcaption { display: flex; justify-content: space-between; align-items: center; min-height: 20px; margin-bottom: 8px; }
figcaption span { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.64rem; letter-spacing: 0.12em; }
figcaption strong { font-size: 0.78rem; }

.canvas-frame {
  display: grid;
  place-items: center;
  min-height: 430px;
  height: min(56vw, 620px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #a99f93;
  background-color: #faf7f1;
}
.checkerboard {
  background-image:
    linear-gradient(45deg, #e8e2da 25%, transparent 25%),
    linear-gradient(-45deg, #e8e2da 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e2da 75%),
    linear-gradient(-45deg, transparent 75%, #e8e2da 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.comparison[data-background="light"] .canvas-frame { background: #fff; }
.comparison[data-background="dark"] .canvas-frame { background: #141414; }

.canvas-frame img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
}
.canvas-surface {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 100%;
  height: 100%;
}
.canvas-surface canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
.canvas-surface[data-grid="true"]::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.34) 1px, rgba(0, 0, 0, 0.12) 1px, transparent 2px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.34) 1px, rgba(0, 0, 0, 0.12) 1px, transparent 2px);
  background-size: var(--pixel-step) var(--pixel-step);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.canvas-frame [hidden],
.canvas-surface[hidden] { display: none; }
.placeholder { max-width: 240px; margin: 0; padding: 14px; border: 1px solid #c8beb3; background: rgba(255, 253, 248, 0.92); color: var(--muted); text-align: center; font-size: 0.75rem; }

.comparison[data-mode="wipe"] { position: relative; grid-template-columns: 1fr; gap: 0; }
.comparison[data-mode="wipe"] figure { grid-area: 1 / 1; }
.comparison[data-mode="wipe"] figure:last-child {
  z-index: 2;
  clip-path: inset(0 calc(100% - var(--wipe)) 0 0);
  pointer-events: none;
}
.comparison[data-mode="wipe"] figure:last-child figcaption { visibility: hidden; }
.comparison[data-mode="wipe"]::after {
  position: absolute;
  z-index: 3;
  top: 28px;
  bottom: 0;
  left: var(--wipe);
  width: 2px;
  pointer-events: none;
  content: "";
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 0 16px rgba(0, 0, 0, 0.45);
}
.comparison[data-mode="result"] { grid-template-columns: minmax(0, 760px); justify-content: center; }
.comparison[data-mode="result"] figure:first-child { display: none; }

.result-footer { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.result-footer > div { min-width: 0; }
.palette-label { margin: 0 0 8px; color: var(--muted); font-size: 0.68rem; font-weight: 700; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; min-height: 23px; }
.swatch { width: 23px; height: 23px; border: 1px solid rgba(37, 31, 26, 0.5); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.palette-empty { color: var(--muted); font-size: 0.75rem; }

footer { padding: 22px 0 36px; border-top: 1px solid #c7bdb1; color: var(--muted); font-size: 0.74rem; text-align: center; }

@media (max-width: 1100px) {
  .studio-layout { grid-template-columns: 1fr; }
  .controls-section { position: static; }
  .controls-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
  .controls-grid fieldset { border-top: 1px solid var(--line); }
  .controls-grid fieldset + fieldset { border-left: 1px solid var(--line); }
  .preset-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; padding-top: 30px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .controls-heading { flex-direction: row; align-items: flex-end; }
  body.has-image .drop-zone { grid-template-columns: 1fr; gap: 14px; }
  body.has-image .drop-zone .button { grid-column: 1; grid-row: 2; width: 100%; }
  .controls-grid { grid-template-columns: 1fr; }
  .controls-grid fieldset + fieldset { border-left: 0; }
  .preview-toolbar { grid-template-columns: 1fr 1fr; }
  .mode-fieldset { grid-column: 1 / -1; }
  .grid-toggle { align-self: end; }
  .comparison[data-mode="side"] { grid-template-columns: 1fr; }
  .canvas-frame { min-height: 320px; height: min(96vw, 540px); }
}

@media (max-width: 520px) {
  .site-header, main, footer { width: min(100% - 24px, 1380px); }
  .workspace { margin-bottom: 18px; }
  .workspace .section-heading > p { display: none; }
  .drop-zone { min-height: 176px; padding: 24px 16px; }
  .preset-grid { grid-template-columns: 1fr 1fr; }
  .preview-section { padding: 16px; }
  .preview-toolbar { grid-template-columns: 1fr 1fr; padding: 9px; }
  .mode-fieldset, .grid-toggle { grid-column: 1 / -1; }
  .canvas-frame { min-height: 280px; }
  .result-footer { align-items: stretch; flex-direction: column; }
  .button-primary { width: 100%; }
}

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