:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fbfaf7;
  --canvas: #e9e8e2;
  --text: #252623;
  --muted: #656c64;
  --line: #deded6;
  --accent: #a74429;
  --soft: #f6ddd1;
  --shadow: 0 12px 30px #18241815;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    16px/1.5 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
body.dark {
  color-scheme: dark;
  --bg: #171d1e;
  --surface: #202729;
  --canvas: #111718;
  --text: #f0eee7;
  --muted: #b9c1b6;
  --line: #3a4242;
  --accent: #f0a285;
  --soft: #4d332c;
  --shadow: 0 12px 30px #0003;
}
button,
input,
select {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover {
  border-color: var(--accent);
  background: var(--soft);
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
  font-weight: 650;
}
.primary:hover {
  filter: brightness(0.94);
  background: var(--accent);
}
body.dark .primary {
  color: #241b15;
}
.link {
  border: 0;
  color: var(--accent);
  background: none;
  padding: 12px 0;
}
.active {
  background: var(--soft);
  border-color: var(--accent);
}
input,
select {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  padding: 0;
}
input[type="checkbox"] {
  accent-color: var(--accent);
}
header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 0;
  background: none;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.7px;
}
.brand img {
  width: 36px;
  height: 36px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.offline {
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--muted);
}
#project-title {
  max-width: 35vw;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  font-weight: 650;
}
#home {
  max-width: 1340px;
  margin: auto;
  padding: 28px;
}
.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--surface);
  overflow: hidden;
}
.hero-copy {
  padding: 42px 32px;
  align-self: center;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 750;
}
h1 {
  font-size: clamp(34px, 4vw, 48px);
  line-height: 1.14;
  letter-spacing: -1.6px;
  margin: 26px 0;
}
h2 {
  font-size: 25px;
  letter-spacing: -0.6px;
}
.hero-copy > p:not(.eyebrow) {
  max-width: 470px;
  color: var(--muted);
  line-height: 1.8;
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
}
.hero-art {
  margin: 24px;
  padding: 22px;
  border-radius: 20px;
  background: #dcd8c9;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 12px;
  color: #34483e;
}
.hero-art canvas {
  width: 100%;
  box-shadow: 8px 12px 20px #0003;
  image-rendering: pixelated;
}
.hero-art strong {
  font-size: 12px;
  letter-spacing: 2px;
  margin-top: 8px;
}
.hero-art small {
  font-size: 13px;
  color: #53675d;
}
.features {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin: 24px 4px;
  color: var(--muted);
  font-size: 14px;
}
.features span:before {
  content: "✓";
  color: var(--accent);
  margin-right: 8px;
}
.workbench {
  margin: 32px 0;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.section-title input {
  width: 280px;
}
.muted {
  color: var(--muted);
  font-size: 14px;
}
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.recent {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.recent img {
  width: 100%;
  aspect-ratio: 1.6;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}
.recent .info {
  padding: 14px;
}
.recent h3 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
}
.recent .actions {
  margin-top: 12px;
}
.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
}
footer {
  font-size: 13px;
  color: var(--muted);
  padding: 16px 0;
}
a {
  color: var(--accent);
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.toolbar > * {
  flex-shrink: 0;
}
.toolbar button {
  font-size: 14px;
  padding: 8px 12px;
}
.toolbar label {
  font-size: 14px;
  white-space: nowrap;
}
#tools {
  display: flex;
  gap: 5px;
}
#active-color {
  max-width: 160px;
}
.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  height: calc(100dvh - 185px);
  min-height: 320px;
}
.workspace {
  position: relative;
  background: var(--canvas);
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 24px;
}
.canvas-stage {
  display: flex;
  gap: 16px;
  margin: auto;
  flex-shrink: 0;
  transform-origin: center;
  touch-action: none;
}
.canvas-stage canvas {
  width: min(65dvh, calc(100vw - 350px));
  height: auto;
  aspect-ratio: 1;
  box-shadow: var(--shadow);
  image-rendering: pixelated;
  flex-shrink: 0;
  touch-action: none;
}
.canvas-stage.compare canvas {
  width: min(49dvh, calc((100vw - 380px) / 2));
}
.zoom {
  position: sticky;
  bottom: 0;
  right: 0;
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface);
  align-self: flex-end;
  margin-left: -150px;
  z-index: 2;
  box-shadow: var(--shadow);
}
.zoom button {
  border: 0;
  padding: 6px 12px;
}
aside {
  background: var(--surface);
  padding: 22px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid var(--line);
}
aside h3 {
  font-size: 12px;
  letter-spacing: 2px;
  margin: 0 0 12px;
}
aside h4 {
  margin: 12px 0 0;
}
aside small {
  font-size: 12px;
  line-height: 1.8;
  color: var(--muted);
  margin: 14px 0;
}
aside img {
  width: 100%;
  height: 115px;
  object-fit: cover;
  border-radius: 10px;
}
dl {
  font-size: 14px;
  margin: 14px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 8px;
}
dd {
  margin: 0;
  font-weight: 650;
}
dt {
  color: var(--muted);
}
#source-name {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#status {
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  max-height: 100px;
  overflow: auto;
}
#progress-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: var(--surface);
}
progress {
  accent-color: var(--accent);
  max-width: 280px;
  width: 30%;
}
#stage-label {
  flex: 1;
  font-size: 14px;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(800px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  box-shadow: 0 24px 100px #0004;
}
dialog[open] {
  display: flex;
  flex-direction: column;
}
dialog::backdrop {
  background: #13201d77;
  backdrop-filter: blur(3px);
}
.dialog-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 {
  margin: 0;
  font-size: 23px;
  flex: 1;
}
.dialog-header button {
  border: 0;
}
#modal-body {
  overflow: auto;
  padding: 20px 24px;
  min-height: 0;
}
#modal-actions {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
#modal-body h3 {
  margin: 22px 0 10px;
  font-size: 18px;
}
#modal-body h3:first-child {
  margin-top: 0;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 0;
}
.check small {
  display: block;
  color: var(--muted);
}
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.palette-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 3px;
}
.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  font-size: 14px;
}
.swatch:has(input:checked) {
  border-color: var(--accent);
  background: var(--soft);
}
.color-dot {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 1px solid #8885;
  border-radius: 50%;
  flex-shrink: 0;
}
.crop-preview {
  width: min(100%, 440px);
  aspect-ratio: 1;
  display: block;
  margin: auto;
  border-radius: 12px;
}
.material-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.material-row .quantity {
  margin-left: auto;
  font-weight: 650;
}
.assembly-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.module-map {
  display: grid;
  gap: 4px;
  margin: 18px 0;
  width: max-content;
  max-width: 100%;
}
.module-map button {
  padding: 4px;
  width: 30px;
  font-size: 12px;
  border-radius: 5px;
}
.module-map button.complete {
  background: #3e795d;
  color: white;
}
#assembly-canvas {
  display: block;
  width: min(100%, 570px);
  height: auto;
  margin: 16px auto;
  touch-action: none;
}
#assembly-progress {
  width: 100%;
  max-width: none;
}
.export-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.note {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
}
.error {
  color: #bb432c;
}
button:focus-visible {
  position: relative;
  z-index: 4;
}
@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .hero-art {
    width: min(440px, calc(100% - 48px));
    justify-self: center;
  }
  .hero-copy {
    padding: 28px;
  }
  .editor-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 1fr) auto;
    height: calc(100dvh - 185px);
    min-height: 350px;
  }
  .workspace {
    padding: 16px;
  }
  aside {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 10px;
    gap: 8px;
    overflow: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  aside h3,
  aside img,
  aside h4,
  aside small,
  #source-name,
  #rename,
  #crop {
    display: none;
  }
  aside dl {
    grid-column: 1/-1;
    display: flex;
    justify-content: space-between;
    gap: 4px;
    margin: 2px 0;
    font-size: 12px;
  }
  aside dt:nth-of-type(n + 4),
  aside dd:nth-of-type(n + 4) {
    display: none;
  }
  aside button {
    font-size: 14px;
    padding: 8px;
  }
  .canvas-stage canvas {
    width: min(53dvh, calc(100vw - 38px));
  }
  .canvas-stage.compare canvas {
    width: calc((100vw - 55px) / 2);
  }
  .columns {
    grid-template-columns: 1fr;
  }
  .offline {
    display: none;
  }
}
@media (max-width: 520px) {
  header {
    padding: 12px 14px;
    gap: 10px;
  }
  .brand {
    font-size: 19px;
  }
  .brand img {
    width: 30px;
    height: 30px;
  }
  #project-title {
    display: none;
  }
  .header-actions {
    gap: 5px;
  }
  .header-actions button {
    font-size: 13px;
    padding: 9px;
  }
  #home {
    padding: 16px;
  }
  .hero-copy {
    padding: 24px;
  }
  h1 {
    font-size: 34px;
  }
  .hero-art {
    margin: 16px;
    width: calc(100% - 32px);
    padding: 16px;
  }
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }
  .section-title input {
    width: 100%;
  }
  .features {
    gap: 14px;
  }
  .dialog-header,
  #modal-actions {
    padding: 12px 16px;
  }
  #modal-body {
    padding: 16px;
  }
  .swatches {
    grid-template-columns: 1fr 1fr;
  }
  .swatch {
    font-size: 12px;
    gap: 5px;
    padding: 6px;
  }
  .color-dot {
    width: 18px;
    height: 18px;
  }
  .editor-body {
    min-height: 330px;
  }
  .toolbar {
    padding: 8px;
  }
  .module-map button {
    width: 24px;
  }
  .note {
    font-size: 13px;
  }
  #status {
    font-size: 12px;
  }
}

.image-drop {
  border: 2px dashed var(--muted, #748079);
  border-radius: 18px;
  padding: 28px 20px;
  text-align: center;
  margin-top: 20px;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.image-drop.dragging {
  border-color: #b34e2d;
  background: #b34e2d20;
}
.drop-symbol {
  font-size: 40px;
  color: #b34e2d;
}
#drop-error {
  color: #bf4030;
  min-height: 1.5em;
}
