:root {
  --bg: #fff;
  --ink: #000;
  --paper: #fff;
  --line: #000;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 ui-sans-serif, system-ui, sans-serif;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.tag {
  margin: 2px 0 0;
  font-size: 13px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  background: #fff;
  color: #000;
  border: 1px solid #000;
  border-radius: 0;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}

button:hover { background: #f2f2f2; }
button.on { background: #000; color: #fff; }
button.primary { background: #000; color: #fff; }
button:disabled { opacity: 0.35; cursor: default; }

.desk {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 260px;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 110px);
}

.tools, .ref-col {
  background: #fff;
  border: 1px solid #000;
  border-radius: 0;
  padding: 14px;
}

.label {
  margin: 12px 0 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.label:first-child { margin-top: 0; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1; min-width: 46%; }

input[type="range"] { width: 100%; }

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 0;
  border: 1px solid #000;
  cursor: pointer;
  padding: 0;
}

.swatch.on { outline: 2px solid #000; outline-offset: 1px; }

input[type="color"] {
  width: 100%;
  height: 34px;
  border: 1px solid #000;
  background: #fff;
  padding: 0;
}

.hint {
  margin: 16px 0 0;
  font-size: 12px;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
}

.canvas-note {
  margin: 10px 0 0;
  font-size: 12px;
  text-align: center;
}

#canvas {
  width: min(100%, 72vh);
  height: auto;
  max-height: calc(100vh - 150px);
  background: var(--paper);
  border: 1px solid #000;
  border-radius: 0;
  touch-action: none;
  cursor: crosshair;
}

.ref-frame {
  background: #fff;
  border: 1px solid #000;
  border-radius: 0;
  overflow: hidden;
}

#ref {
  display: block;
  width: 100%;
  height: auto;
}

.upload {
  display: block;
  margin-top: 12px;
  padding: 8px;
  text-align: center;
  border: 1px dashed #000;
  border-radius: 0;
  cursor: pointer;
}

.upload input { display: none; }

#ref-default {
  width: 100%;
  margin-top: 8px;
}

.layer-help {
  margin: 0 0 8px;
  font-size: 12px;
}

.layers {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 6px;
}

.layer-row .eye,
.layer-row .layer-name {
  padding: 6px 8px;
  text-align: left;
}

.layer-row.on .layer-name {
  background: #000;
  color: #fff;
}

.layer-row .eye:not(.on) {
  opacity: 0.4;
}

.tool-pop {
  position: fixed;
  z-index: 20;
  background: #fff;
  border: 1px solid #000;
  padding: 8px;
  width: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-pop[hidden] { display: none; }

.tool-pop-title {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tool-pop button {
  width: 100%;
  text-align: center;
}

.tool-pop label {
  display: block;
  margin-top: 6px;
  font-size: 12px;
}

.tool-pop input[type="range"] {
  width: 100%;
}

.size-pop {
  position: fixed;
  z-index: 20;
  background: #fff;
  border: 1px solid #000;
  padding: 10px 12px;
  width: 180px;
}

.size-pop label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
}

.size-pop input { width: 100%; }

footer {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 10px 16px 18px;
}

footer a {
  color: #000;
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .desk { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
  #canvas { width: 100%; max-height: none; }
}