:root {
  --bg: #efebe2;
  --surface: #fffaf0;
  --surface-2: #e2ddd2;
  --ink: #171512;
  --muted: #6d675e;
  --rule: #28241f;
  --accent: #ffbc42;
  --accent-2: #2aa198;
  --danger: #c94242;
  --warning: #b7791f;
  --success: #18735f;
  --info: #28628f;
  --shadow: 0 22px 55px rgba(23, 21, 18, 0.16);
  --focus: 0 0 0 4px rgba(42, 161, 152, 0.28);
  --radius-sm: 6px;
  --radius-md: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.2rem;
  --text-xl: clamp(1.8rem, 3.4vw, 3.2rem);
  --lh-tight: 1.05;
  --lh-body: 1.55;
  --dur-1: 140ms;
  --dur-2: 240ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  background:
    linear-gradient(rgba(23, 21, 18, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 21, 18, 0.055) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
}

button,
label.file-button,
select {
  border: 2px solid var(--rule);
  border-radius: var(--radius-sm);
}

button,
label.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  min-height: 44px;
  transition:
    transform var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out),
    background var(--dur-1) var(--ease-out);
}

button:hover,
label.file-button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--rule);
}

button:focus-visible,
label.file-button:focus-visible,
canvas:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: var(--space-4);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  color: var(--surface);
  background: var(--ink);
  transform: translateY(-160%);
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: var(--space-5) 0 var(--space-4);
}

.eyebrow,
.section-label {
  margin: 0 0 var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  line-height: var(--lh-tight);
  letter-spacing: 0;
}

h1 {
  font-size: var(--text-xl);
}

h2 {
  font-size: var(--text-lg);
}

.status-pill {
  min-width: 108px;
  padding: 8px 12px;
  border: 2px solid var(--rule);
  border-radius: 999px;
  background: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-align: center;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--space-5);
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto var(--space-6);
}

.stage-panel,
.control-panel {
  border: 2px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stage-panel {
  min-width: 0;
  padding: var(--space-5);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

#imageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.file-button span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid var(--rule);
  border-radius: 999px;
  line-height: 1;
}

.canvas-shell {
  position: relative;
  width: min(100%, 74vh);
  margin: 0 auto;
  aspect-ratio: 1;
  border: 2px solid var(--rule);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, rgba(23, 21, 18, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(23, 21, 18, 0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(23, 21, 18, 0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(23, 21, 18, 0.08) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

canvas.is-dragging {
  cursor: grabbing;
}

.corner-tick {
  position: absolute;
  width: 42px;
  height: 42px;
  pointer-events: none;
}

.corner-tick::before,
.corner-tick::after {
  position: absolute;
  content: "";
  background: var(--accent);
}

.corner-tick::before {
  width: 100%;
  height: 4px;
}

.corner-tick::after {
  width: 4px;
  height: 100%;
}

.tick-a {
  left: 12px;
  top: 12px;
}

.tick-b {
  right: 12px;
  top: 12px;
  transform: rotate(90deg);
}

.tick-c {
  right: 12px;
  bottom: 12px;
  transform: rotate(180deg);
}

.tick-d {
  left: 12px;
  bottom: 12px;
  transform: rotate(270deg);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

.control-section {
  padding-bottom: var(--space-4);
  border-bottom: 2px solid rgba(23, 21, 18, 0.14);
}

.control-section:last-of-type {
  border-bottom: 0;
}

.segmented,
.button-row,
.action-row {
  display: flex;
  gap: var(--space-2);
}

.segment {
  flex: 1;
  background: var(--surface-2);
}

.segment.is-active {
  background: var(--accent-2);
  color: #fffaf0;
}

.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-2) 0;
  font-size: var(--text-sm);
}

output {
  min-width: 64px;
  padding: 4px 7px;
  border: 1px solid rgba(23, 21, 18, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.45);
  font-family: var(--font-mono);
  text-align: right;
}

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

.button-row button {
  flex: 1;
  min-width: 0;
  padding-inline: var(--space-2);
  font-size: var(--text-sm);
}

.swatch-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

input[type="color"] {
  width: 58px;
  height: 44px;
  padding: 4px;
  border: 2px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

select {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-2);
  padding: 0 var(--space-3);
  background: var(--surface);
}

.action-row {
  margin-top: auto;
}

.action-row button {
  flex: 1;
}

.primary-action {
  background: var(--accent);
  font-weight: 700;
}

.secondary-action {
  background: var(--surface-2);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .canvas-shell {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar,
  .stage-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .app-shell {
    width: min(100% - 20px, 1180px);
  }

  .stage-panel,
  .control-panel {
    padding: var(--space-3);
  }

  .segmented,
  .button-row,
  .action-row {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
