:root {
  color-scheme: light;
  --paper: #fffdf7;
  --paper-deep: #f2efe5;
  --ink: #14213d;
  --navy: #102d6a;
  --navy-dark: #091d47;
  --coral: #ff5f56;
  --yellow: #ffd166;
  --blue-soft: #dbe8ff;
  --line: #c9d2e3;
  --line-dark: #8da0c2;
  --muted: #63708a;
  --white: #ffffff;
  --shadow: 5px 5px 0 rgba(16, 45, 106, 0.14);
  --focus: #ff5f56;
  font-family:
    ui-rounded,
    "Hiragino Maru Gothic ProN",
    "Hiragino Sans",
    "Yu Gothic UI",
    system-ui,
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

button:not(:disabled),
select,
input[type="radio"],
input[type="range"] {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.6rem 0.9rem;
  color: var(--white);
  background: var(--navy);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: relative;
  z-index: 20;
  display: flex;
  width: 100%;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem max(1rem, calc((100vw - 1440px) / 2));
  color: var(--white);
  background: var(--navy);
  border-bottom: 5px solid var(--coral);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand > span:last-child {
  display: grid;
  line-height: 1.15;
}

.brand strong {
  font-size: 1.05rem;
  letter-spacing: 0.015em;
}

.brand small {
  margin-top: 0.2rem;
  color: #bfd0f3;
  font-size: 0.68rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 4px;
  border: 2px solid var(--white);
  box-shadow: 3px 3px 0 var(--coral);
}

.brand-mark span {
  background: var(--yellow);
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
  background: var(--coral);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: #dbe8ff;
  font-size: 0.78rem;
  font-weight: 700;
}

.local-badge span {
  color: #65d6a6;
  font-size: 0.65rem;
}

.home-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.8rem;
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.55);
}

.home-link:hover {
  color: var(--navy);
  background: var(--white);
}

main {
  width: min(calc(100% - 2rem), 1440px);
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 6rem) 0 5rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.65fr);
  gap: clamp(2rem, 8vw, 8rem);
  align-items: end;
  margin: 0 auto clamp(2.5rem, 5vw, 4.5rem);
}

.eyebrow,
.section-kicker,
.palette-label,
.ad-label {
  margin: 0 0 0.65rem;
  color: var(--coral);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(3.2rem, 7vw, 7.6rem);
  font-weight: 900;
  letter-spacing: -0.075em;
  line-height: 0.95;
}

.hero h1 em {
  position: relative;
  color: var(--coral);
  font-style: normal;
  white-space: nowrap;
}

.hero h1 em::after {
  position: absolute;
  right: 0.02em;
  bottom: -0.12em;
  left: 0.08em;
  height: 0.08em;
  background: var(--yellow);
  content: "";
}

.hero-copy {
  padding-bottom: 0.45rem;
}

.hero-copy > p {
  margin: 0;
  font-size: clamp(1rem, 1.4vw, 1.18rem);
  font-weight: 650;
  line-height: 1.9;
}

.hero-copy ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.hero-copy li {
  padding: 0.35rem 0.65rem;
  color: var(--navy);
  background: var(--blue-soft);
  border: 1px solid var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(360px, 0.72fr);
  gap: 1.25rem;
  align-items: start;
}

.preview-panel,
.controls-panel {
  min-width: 0;
  background: var(--white);
  border: 2px solid var(--navy);
  box-shadow: var(--shadow);
}

.preview-panel {
  position: sticky;
  top: 1rem;
}

.pixel-canvas-stack {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  place-items: center;
}

.pixel-canvas-stack canvas {
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 0;
}

.pixel-canvas-stack #pixel-canvas {
  cursor: crosshair;
  touch-action: manipulation;
}

.region-selection-canvas {
  z-index: 2;
  pointer-events: none;
  image-rendering: pixelated;
}

.mobile-live-preview {
  display: none;
}

.panel-heading {
  display: flex;
  min-height: 88px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 2px solid var(--navy);
}

.panel-heading > div:first-child {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.panel-heading h2 {
  margin: 0;
  color: var(--navy);
  font-size: 1.15rem;
  line-height: 1.2;
}

.section-kicker {
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.step-number {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--white);
  background: var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 900;
  box-shadow: 3px 3px 0 var(--yellow);
}

.step-number.coral {
  background: var(--coral);
  box-shadow: 3px 3px 0 var(--navy);
}

.view-switcher {
  display: inline-flex;
  padding: 3px;
  background: var(--paper-deep);
  border: 1px solid var(--line-dark);
}

.view-switcher button {
  min-height: 38px;
  padding: 0 0.75rem;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 800;
}

.view-switcher button[aria-pressed="true"] {
  color: var(--white);
  background: var(--navy);
}

.display-case {
  position: relative;
  min-height: 485px;
  padding: 1.15rem;
  overflow: hidden;
  color: var(--white);
  background: var(--navy-dark);
  border-bottom: 2px solid var(--navy);
}

.display-case::before,
.display-case::after {
  position: absolute;
  z-index: 0;
  width: 12px;
  height: 12px;
  background: var(--line-dark);
  border: 3px solid var(--paper-deep);
  border-radius: 50%;
  content: "";
}

.display-case::before {
  top: 0.8rem;
  left: 0.8rem;
}

.display-case::after {
  right: 0.8rem;
  bottom: 0.8rem;
}

.display-label {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  margin: 0.1rem 1.35rem 0.8rem;
  color: #8094bb;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.display-case.dragging {
  outline: 4px solid var(--yellow);
  outline-offset: -8px;
}

.empty-state {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 410px;
  place-content: center;
  justify-items: center;
  padding: 2rem;
  text-align: center;
  border: 1px dashed #7086b1;
}

.empty-state p {
  margin: 0;
  color: #aebee0;
  font-size: 0.85rem;
}

.empty-state p strong {
  display: block;
  margin: 1rem 0 0.2rem;
  color: var(--white);
  font-size: 1.15rem;
}

.empty-icon {
  display: grid;
  width: 72px;
  height: 72px;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  transform: rotate(-3deg);
}

.empty-icon span {
  background: #48628f;
}

.empty-icon span:nth-child(1),
.empty-icon span:nth-child(5),
.empty-icon span:nth-child(9) {
  background: var(--yellow);
}

.empty-icon span:nth-child(3),
.empty-icon span:nth-child(7) {
  background: var(--coral);
}

.secondary-button {
  min-height: 46px;
  margin-top: 1.25rem;
  padding: 0 1rem;
  color: var(--navy);
  background: var(--white);
  border: 2px solid var(--white);
  font-weight: 900;
  box-shadow: 4px 4px 0 var(--coral);
}

.secondary-button:hover {
  color: var(--white);
  background: var(--coral);
}

.preview-grid {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 410px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

body[data-view="original"] .preview-grid,
body[data-view="pixel"] .preview-grid {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="original"] [data-preview-pane="pixel"],
body[data-view="pixel"] [data-preview-pane="original"] {
  display: none;
}

.preview-figure {
  display: flex;
  min-width: 0;
  margin: 0;
  flex-direction: column;
}

.preview-figure figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.55rem;
  color: #c5d2ed;
  background: #18396f;
  border: 1px solid #5d77a7;
  border-bottom: 0;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-figure figcaption output {
  color: var(--yellow);
  letter-spacing: 0;
}

.canvas-frame {
  display: grid;
  min-height: 300px;
  flex: 1;
  place-items: center;
  padding: 0.8rem;
  overflow: hidden;
  background: var(--paper-deep);
  border: 1px solid #5d77a7;
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 355px;
  object-fit: contain;
}

.original-figure canvas {
  image-rendering: auto;
}

.pixel-figure canvas {
  image-rendering: pixelated;
}

.pixel-canvas-frame {
  position: relative;
  background: var(--white);
}

.pixel-canvas-frame::after {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  width: 9px;
  height: 9px;
  background: var(--coral);
  border: 2px solid var(--navy);
  content: "";
}

.render-overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.8rem;
  color: var(--white);
  background: rgba(9, 29, 71, 0.86);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.render-indicator {
  display: block;
  width: 38px;
  height: 38px;
  background: var(--yellow);
  border: 8px solid var(--coral);
  animation: render-pulse 0.8s steps(2, end) infinite;
}

@keyframes render-pulse {
  50% {
    transform: rotate(90deg) scale(0.75);
  }
}

.preview-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.25rem;
  align-items: center;
  padding: 1rem 1.25rem;
}

.render-stats {
  display: flex;
  gap: clamp(1rem, 4vw, 2.5rem);
}

.render-stats span {
  display: grid;
}

.render-stats small,
.palette-label {
  margin: 0;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.57rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.render-stats strong {
  color: var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
}

.palette {
  display: flex;
  min-width: 120px;
  max-width: 210px;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 0.3rem;
}

.palette span {
  display: block;
  width: 15px;
  height: 15px;
  border: 1px solid rgba(16, 45, 106, 0.4);
}

.text-button {
  min-height: 44px;
  padding: 0.35rem 0;
  color: var(--navy);
  background: transparent;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.control-section {
  min-width: 0;
  margin: 0;
  padding: 1.2rem;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.control-section legend {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0;
  font-weight: 900;
}

.control-section legend span {
  color: var(--navy);
  font-size: 0.92rem;
}

.control-section legend small {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
}

.file-button {
  display: grid;
  width: 100%;
  min-height: 74px;
  grid-template-columns: auto 1fr auto;
  gap: 0.8rem;
  align-items: center;
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem;
  text-align: left;
  background: var(--blue-soft);
  border: 2px solid var(--navy);
  box-shadow: 3px 3px 0 var(--navy);
}

.file-button:hover {
  background: #eef4ff;
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--navy);
}

.file-button > span:nth-child(2) {
  display: grid;
}

.file-button strong {
  color: var(--navy);
  font-size: 0.9rem;
}

.file-button small {
  color: var(--muted);
  font-size: 0.63rem;
}

.file-button-icon {
  display: grid;
  width: 35px;
  height: 35px;
  place-items: center;
  color: var(--white);
  background: var(--coral);
  font-size: 1.25rem;
  font-weight: 500;
}

.file-meta {
  min-height: 1.5em;
  margin: 0.7rem 0 0;
  overflow: hidden;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta.error {
  color: #a51d25;
  font-family: inherit;
  font-weight: 800;
  white-space: normal;
}

.choice-grid {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.size-grid,
.color-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.choice-grid label {
  min-width: 0;
}

.choice-grid input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.choice-grid label > span {
  display: grid;
  min-height: 58px;
  place-content: center;
  padding: 0.4rem 0.25rem;
  text-align: center;
  background: var(--white);
  border: 1px solid var(--line-dark);
}

.choice-grid strong {
  color: var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.3;
}

.choice-grid small {
  color: var(--muted);
  font-size: 0.55rem;
  line-height: 1.3;
}

.choice-grid input:checked + span {
  color: var(--white);
  background: var(--navy);
  border-color: var(--navy);
  box-shadow: 3px 3px 0 var(--coral);
}

.choice-grid input:checked + span strong,
.choice-grid input:checked + span small {
  color: inherit;
}

.choice-grid input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.number-control,
.select-control {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.7rem;
  padding: 0.4rem 0.6rem 0.4rem 0.8rem;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.number-control > span:last-child {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.number-control input {
  width: 72px;
  min-height: 36px;
  padding: 0 0.5rem;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--line-dark);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-weight: 900;
  text-align: right;
}

.number-control input:disabled {
  background: var(--paper-deep);
  opacity: 0.6;
}

.range-control {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.range-control + .range-control {
  margin-top: 1rem;
}

.range-control > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-control strong {
  color: var(--ink);
  font-size: 0.75rem;
}

.range-control output,
.range-control .range-output {
  min-width: 42px;
  padding: 0.15rem 0.35rem;
  color: var(--white);
  background: var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 900;
  text-align: center;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  margin: 0;
  appearance: none;
  background: var(--line);
  border-radius: 0;
}

input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  appearance: none;
  background: var(--coral);
  border: 3px solid var(--white);
  border-radius: 0;
  box-shadow: 0 0 0 2px var(--navy);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--coral);
  border: 3px solid var(--white);
  border-radius: 0;
  box-shadow: 0 0 0 2px var(--navy);
}

.select-control select {
  min-width: 92px;
  min-height: 36px;
  padding: 0 0.65rem;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--line-dark);
  font-weight: 900;
}

.export-section {
  border-bottom: 0;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.download-button {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  text-align: left;
  background: var(--yellow);
  border: 2px solid var(--navy);
  box-shadow: 3px 3px 0 var(--navy);
}

.download-button.primary {
  color: var(--white);
  background: var(--coral);
}

.download-button:not(:disabled):hover {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--navy);
}

.download-button > span:first-child {
  display: grid;
}

.download-button strong {
  font-size: 0.78rem;
}

.download-button small {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.57rem;
  opacity: 0.75;
}

.privacy-note {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.55;
}

.privacy-note span {
  display: grid;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--white);
  background: var(--navy);
  font-size: 0.68rem;
}

.next-stage {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto;
  gap: clamp(1.5rem, 5vw, 4rem);
  align-items: center;
  margin-top: clamp(3rem, 7vw, 6rem);
  padding: clamp(1.5rem, 4vw, 3rem);
  color: var(--white);
  background: var(--navy);
  border: 2px solid var(--navy-dark);
  box-shadow: 6px 6px 0 var(--coral);
}

.next-stage .eyebrow {
  color: var(--yellow);
}

.next-stage h2 {
  max-width: 12ch;
  margin: 0;
  font-size: clamp(1.7rem, 3.2vw, 3rem);
  letter-spacing: -0.04em;
  line-height: 1.08;
}

.next-stage > p {
  margin: 0;
  color: #dbe8ff;
  font-size: 0.9rem;
}

.next-stage > a {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  color: var(--navy);
  background: var(--white);
  font-size: 0.74rem;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.ad-break {
  width: min(100%, 970px);
  min-height: 112px;
  margin: clamp(3rem, 6vw, 5rem) auto 0;
  padding: 0.65rem 1rem 1rem;
  text-align: center;
  background: var(--white);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.ad-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.55rem;
}

.pixel-display-ad {
  display: block;
  width: 100%;
  min-height: 90px;
}

footer {
  display: grid;
  width: 100%;
  grid-template-columns: auto 1fr auto;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem max(1rem, calc((100vw - 1440px) / 2));
  color: #b9c9e7;
  background: var(--navy-dark);
  border-top: 5px solid var(--yellow);
  font-size: 0.72rem;
}

footer p {
  margin: 0;
}

.footer-brand {
  color: var(--white);
  font-size: 0.9rem;
  font-weight: 900;
  text-decoration: none;
}

footer nav {
  display: flex;
  gap: 1rem;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: 1rem;
  width: min(calc(100% - 2rem), 360px);
  padding: 0.9rem 1rem;
  color: var(--white);
  background: var(--navy);
  border: 2px solid var(--white);
  box-shadow: 4px 4px 0 var(--coral);
  font-size: 0.8rem;
  font-weight: 800;
}

.toast.error {
  background: #8f1d2c;
}

body[data-candidates="open"] .preview-panel {
  position: static;
}

.crop-canvas-frame {
  position: relative;
  cursor: crosshair;
  touch-action: none;
}

.focus-marker {
  position: absolute;
  z-index: 2;
  width: 24px;
  height: 24px;
  border: 2px solid var(--white);
  box-shadow:
    0 0 0 2px var(--coral),
    3px 3px 0 rgba(9, 29, 71, 0.65);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.focus-marker::before,
.focus-marker::after {
  position: absolute;
  background: var(--coral);
  content: "";
}

.focus-marker::before {
  top: 9px;
  left: -7px;
  width: 34px;
  height: 2px;
}

.focus-marker::after {
  top: -7px;
  left: 9px;
  width: 2px;
  height: 34px;
}

.preview-actions {
  grid-column: 1 / -1;
}

.candidate-button {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  color: var(--white);
  text-align: left;
  background: var(--navy);
  border: 2px solid var(--navy);
  box-shadow: 3px 3px 0 var(--yellow);
}

.candidate-button:not(:disabled):hover {
  color: var(--navy);
  background: var(--yellow);
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--navy);
}

.candidate-button > span:first-child {
  display: grid;
}

.candidate-button strong {
  font-size: 0.78rem;
}

.candidate-button small {
  font-size: 0.58rem;
  opacity: 0.75;
}

.candidate-drawer {
  padding: 1.2rem;
  background: var(--blue-soft);
  border-top: 2px solid var(--navy);
}

.candidate-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.candidate-heading h3 {
  margin: 0;
  color: var(--navy);
  font-size: 1rem;
}

.candidate-note {
  margin: 0.55rem 0 1rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.6;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.candidate-card {
  min-width: 0;
  padding: 0.65rem;
  background: var(--white);
  border: 1px solid var(--navy);
}

.candidate-card.recommended {
  border-width: 2px;
  box-shadow: 4px 4px 0 var(--coral);
}

.candidate-card-header {
  display: flex;
  min-height: 38px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.candidate-card-header > span:first-child {
  display: grid;
}

.candidate-card-header strong {
  color: var(--navy);
  font-size: 0.73rem;
}

.candidate-card-header small {
  color: var(--muted);
  font-size: 0.55rem;
}

.candidate-score {
  padding: 0.15rem 0.35rem;
  color: var(--white);
  background: var(--navy);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.63rem;
  font-weight: 900;
}

.candidate-preview {
  display: grid;
  min-height: 150px;
  margin-top: 0.5rem;
  place-items: center;
  padding: 0.45rem;
  overflow: hidden;
  background: var(--paper-deep);
  border: 1px solid var(--line);
}

.candidate-preview canvas {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  image-rendering: pixelated;
}

.candidate-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.55rem 0;
}

.candidate-metrics span {
  padding: 0.12rem 0.3rem;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.5rem;
}

.candidate-apply {
  width: 100%;
  min-height: 42px;
  color: var(--navy);
  background: var(--yellow);
  border: 1px solid var(--navy);
  font-size: 0.68rem;
  font-weight: 900;
}

.candidate-card.recommended .candidate-apply {
  color: var(--white);
  background: var(--coral);
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.history-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--navy);
  background: var(--paper);
  border: 1px solid var(--line-dark);
  font-size: 1.2rem;
  font-weight: 900;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.preset-grid button {
  display: grid;
  min-height: 58px;
  align-content: center;
  padding: 0.45rem 0.55rem;
  text-align: left;
  background: var(--white);
  border: 1px solid var(--line-dark);
}

.preset-grid button:hover,
.preset-grid button[aria-pressed="true"] {
  color: var(--white);
  background: var(--navy);
  border-color: var(--navy);
  box-shadow: 3px 3px 0 var(--coral);
}

.preset-grid strong {
  font-size: 0.72rem;
}

.preset-grid small {
  font-size: 0.55rem;
  opacity: 0.72;
}

.preset-status {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.61rem;
}

.subcontrol {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.subcontrol-label {
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
}

.fit-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 0.55rem;
}

.dither-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 0.55rem;
}

.focus-controls {
  margin-top: 0.9rem;
  padding: 0.85rem;
  background: var(--paper);
  border: 1px solid var(--line);
}

.focus-controls[aria-disabled="true"] {
  opacity: 0.48;
}

.range-control.compact {
  margin-top: 0;
}

.range-control.compact + .range-control.compact {
  margin-top: 0.85rem;
}

.lock-control {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.7rem;
  align-items: center;
  margin-top: 0.85rem;
  padding: 0.75rem;
  background: var(--paper);
  border: 1px solid var(--line);
}

.lock-control input {
  width: 24px;
  height: 24px;
  accent-color: var(--navy);
}

.lock-control > span {
  display: grid;
}

.lock-control strong {
  color: var(--navy);
  font-size: 0.75rem;
}

.lock-control small {
  color: var(--muted);
  font-size: 0.58rem;
}

.palette-editor {
  display: grid;
  max-height: 156px;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 0.45rem;
  margin-top: 0.75rem;
  overflow-y: auto;
}

.palette-color {
  display: grid;
  min-width: 0;
  justify-items: center;
  gap: 0.15rem;
}

.palette-color input {
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--navy);
}

.palette-color input:disabled {
  opacity: 0.55;
}

.palette-color span {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.5rem;
}

.region-guide {
  margin: 0 0 0.8rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.6;
}

.display-stage { display:grid; place-items:center; min-height:220px; margin:.65rem 0; padding:1rem; overflow:hidden; background:#080b12; border:1px solid var(--navy); }
.display-stage canvas { max-width:100%; max-height:320px; image-rendering:pixelated; }
.display-mode-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
.display-controls { display:grid; gap:.55rem; }
.display-color-controls { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.55rem; }
.display-color-controls label { display:flex; min-height:46px; align-items:center; justify-content:space-between; padding:.45rem .6rem; border:1px solid var(--line-dark); font-size:.62rem; font-weight:800; }
.display-color-controls input { width:44px; height:32px; padding:0; border:1px solid var(--navy); }
.display-section > .download-button { width:100%; margin-top:.7rem; }
.animation-controls { display:grid; gap:.55rem; }
.animation-actions { display:grid; grid-template-columns:2fr 1fr; gap:.5rem; margin-top:.7rem; }
.animation-actions button { min-height:46px; color:var(--white); background:var(--navy); border:1px solid var(--navy); font-weight:900; }
.animation-actions button:last-child { color:var(--navy); background:var(--white); }

.region-selection-status {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 0.65rem;
  align-items: center;
  padding: 0.7rem;
  background: var(--paper);
  border: 1px solid var(--line-dark);
}

.region-selection-status > span:last-child {
  display: grid;
}

.region-selection-status strong {
  color: var(--navy);
  font-size: 0.73rem;
}

.region-selection-status small {
  color: var(--muted);
  font-size: 0.57rem;
}

.region-selection-swatch {
  width: 42px;
  height: 42px;
  background-image:
    linear-gradient(45deg, #d8dce6 25%, transparent 25%),
    linear-gradient(-45deg, #d8dce6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8dce6 75%),
    linear-gradient(-45deg, transparent 75%, #d8dce6 75%);
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
  border: 2px solid var(--navy);
}

.region-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.region-action-grid button,
.region-structure-actions button {
  display: grid;
  min-height: 54px;
  align-content: center;
  padding: 0.45rem 0.55rem;
  text-align: left;
  background: var(--white);
  border: 1px solid var(--line-dark);
}

.region-action-grid button:not(:disabled):hover,
.region-structure-actions button:not(:disabled):hover {
  color: var(--white);
  background: var(--navy);
  border-color: var(--navy);
}

.region-action-grid strong,
.region-structure-actions strong {
  font-size: 0.68rem;
}

.region-action-grid small,
.region-structure-actions small {
  color: var(--muted);
  font-size: 0.51rem;
}

.region-action-grid button:not(:disabled):hover small,
.region-structure-actions button:not(:disabled):hover small {
  color: #dbe8ff;
}

.region-structure-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.region-structure-actions #region-layer {
  color: var(--white);
  background: var(--coral);
  border-color: var(--navy);
}

.part-layer-panel {
  margin-top: 0.8rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.part-layer-panel > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.part-layer-panel > div > strong {
  color: var(--navy);
  font-size: 0.7rem;
}

.part-layer-list {
  display: grid;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.part-layer-empty {
  color: var(--muted);
  font-size: 0.6rem;
}

.part-layer-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.45rem;
  background: var(--blue-soft);
  border: 1px solid var(--navy);
}

.part-layer-item > span {
  display: grid;
  min-width: 0;
}

.part-layer-item input {
  min-width: 0;
  padding: 0.25rem 0.35rem;
  background: var(--white);
  border: 1px solid var(--line-dark);
  font-size: 0.65rem;
  font-weight: 800;
}

.part-layer-item small {
  margin-top: 0.15rem;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.5rem;
}

.part-layer-remove {
  min-height: 40px;
  padding: 0 0.55rem;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--navy);
  font-size: 0.58rem;
  font-weight: 900;
}

@media (max-width: 1120px) {
  .editor-shell {
    grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  }

  .preview-panel {
    position: static;
  }

  .candidate-preview {
    min-height: 120px;
  }

  .preview-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-view="compare"] .preview-figure {
    min-height: 190px;
  }

  body[data-view="compare"] .canvas-frame {
    min-height: 150px;
  }

  body[data-view="compare"] .canvas-frame canvas {
    max-height: 180px;
  }

  .next-stage {
    grid-template-columns: 1fr 1fr;
  }

  .next-stage > a {
    justify-self: start;
  }
}

@media (max-width: 820px) {
  .site-header {
    min-height: 68px;
  }

  .local-badge {
    display: none;
  }

  main {
    width: min(calc(100% - 1.25rem), 720px);
    padding-top: 2.5rem;
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .hero h1 {
    font-size: clamp(3rem, 12.5vw, 5.5rem);
  }

  .hero-copy {
    max-width: 620px;
  }

  .editor-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body[data-view="compare"] .preview-figure {
    min-height: 0;
  }

  body[data-view="compare"] .canvas-frame {
    min-height: 280px;
  }

  body[data-view="compare"] .canvas-frame canvas {
    max-height: 330px;
  }

  .next-stage {
    grid-template-columns: 1fr;
  }

  .next-stage h2 {
    max-width: 16ch;
  }
}

@media (max-width: 600px) {
  .site-header {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
    border-bottom-width: 4px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand strong {
    font-size: 0.92rem;
  }

  .brand small {
    font-size: 0.57rem;
  }

  .home-link {
    padding: 0 0.55rem;
    font-size: 0.72rem;
  }

  main {
    width: min(calc(100% - 1rem), 540px);
    padding: 2rem 0 3.5rem;
  }

  .hero {
    margin-bottom: 2rem;
  }

  .hero h1 {
    font-size: clamp(2.8rem, 14vw, 4.4rem);
    letter-spacing: -0.07em;
  }

  .hero-copy > p {
    font-size: 0.94rem;
    line-height: 1.8;
  }

  .editor-shell {
    gap: 0.85rem;
  }

  .preview-panel,
  .controls-panel {
    box-shadow: 3px 3px 0 rgba(16, 45, 106, 0.14);
  }

  .mobile-live-preview:not([hidden]) {
    position: sticky;
    z-index: 15;
    top: 0.5rem;
    display: grid;
    grid-template-columns: minmax(112px, 36%) minmax(0, 1fr);
    gap: 0.65rem;
    padding: 0.65rem;
    color: var(--white);
    background: var(--navy-dark);
    border-bottom: 3px solid var(--coral);
    box-shadow: 0 5px 12px rgba(9, 29, 71, 0.24);
  }

  .mobile-live-canvas-button {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 112px;
    place-items: center;
    padding: 0.35rem;
    overflow: hidden;
    background: var(--paper-deep);
    border: 2px solid var(--white);
  }

  .mobile-live-canvas-frame {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    overflow: hidden;
  }

  .mobile-live-canvas-frame canvas {
    display: block;
    max-width: 100%;
    max-height: 106px;
    object-fit: contain;
    image-rendering: pixelated;
  }

  .region-action-grid,
  .region-structure-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mobile-live-preview[data-mode="original"] .mobile-live-canvas-frame canvas {
    image-rendering: auto;
  }

  .mobile-preview-expand {
    position: absolute;
    right: 0.25rem;
    bottom: 0.25rem;
    padding: 0.12rem 0.28rem;
    color: var(--white);
    background: rgba(9, 29, 71, 0.88);
    font-size: 0.52rem;
    font-weight: 900;
  }

  .mobile-live-details {
    display: grid;
    min-width: 0;
    align-content: space-between;
    gap: 0.45rem;
  }

  .mobile-live-heading {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.45rem;
  }

  .mobile-live-heading > span:first-child {
    display: grid;
    min-width: 0;
  }

  .mobile-live-heading small {
    color: var(--yellow);
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 0.48rem;
    font-weight: 900;
    letter-spacing: 0.08em;
  }

  .mobile-live-heading strong {
    font-size: 0.76rem;
  }

  .mobile-live-stats {
    display: grid;
    flex: 0 0 auto;
    justify-items: end;
    color: #bfd0f3;
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 0.52rem;
    line-height: 1.35;
  }

  .mobile-preview-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem;
  }

  .mobile-preview-switcher button {
    min-height: 38px;
    padding: 0.3rem;
    color: #dbe8ff;
    background: transparent;
    border: 1px solid #8da0c2;
    font-size: 0.62rem;
    font-weight: 900;
  }

  .mobile-preview-switcher button[aria-pressed="true"] {
    color: var(--navy-dark);
    background: var(--yellow);
    border-color: var(--yellow);
  }

  .mobile-live-details p {
    margin: 0;
    color: #bfd0f3;
    font-size: 0.52rem;
    line-height: 1.35;
  }

  .panel-heading {
    min-height: 78px;
    padding: 0.8rem;
  }

  .preview-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .view-switcher {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .display-case {
    min-height: 382px;
    padding: 0.75rem;
  }

  .display-label {
    margin-right: 1rem;
    margin-left: 1rem;
  }

  .empty-state {
    min-height: 320px;
    padding: 1rem;
  }

  .preview-grid {
    min-height: 320px;
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-view="compare"] .preview-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-view="compare"] .preview-figure {
    min-height: 0;
  }

  body[data-view="compare"] .canvas-frame,
  .canvas-frame {
    min-height: 250px;
  }

  body[data-view="compare"] .canvas-frame canvas,
  .canvas-frame canvas {
    max-height: 285px;
  }

  .preview-footer {
    grid-template-columns: 1fr;
    gap: 0.8rem;
    padding: 0.9rem;
  }

  .render-stats {
    justify-content: space-between;
    gap: 0.5rem;
  }

  .palette {
    max-width: none;
    justify-content: flex-start;
  }

  .candidate-drawer {
    padding: 0.9rem;
  }

  .candidate-grid {
    gap: 0.55rem;
  }

  .candidate-preview {
    min-height: 125px;
  }

  .control-section {
    padding: 1rem 0.9rem;
  }

  .control-section legend {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.1rem;
  }

  .size-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dither-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-grid label > span {
    min-height: 62px;
  }

  .color-grid label > span {
    min-height: 58px;
  }

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

  .download-button {
    min-height: 60px;
  }

  .next-stage {
    margin-right: 0.2rem;
    margin-left: 0.2rem;
    padding: 1.35rem;
    box-shadow: 4px 4px 0 var(--coral);
  }

  .ad-break {
    min-height: 82px;
    padding-right: 0;
    padding-left: 0;
  }

  .pixel-display-ad {
    min-height: 60px;
  }

  footer {
    grid-template-columns: 1fr;
    gap: 0.65rem;
    padding: 1.25rem 1rem;
  }
}

@media (max-width: 365px) {
  .home-link {
    width: 44px;
    overflow: hidden;
    justify-content: center;
    color: transparent;
  }

  .home-link span {
    color: var(--white);
  }

  .hero h1 {
    font-size: 2.65rem;
  }

  .color-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .candidate-grid,
  .preset-grid {
    grid-template-columns: 1fr;
  }

  .render-stats strong {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
