:root {
  --bg: #1b1a17;
  --panel: #242220;
  --panel-2: #2c2a26;
  --line: #3a372f;
  --text: #ede7dd;
  --muted: #9a948a;
  --amber: #e2a33d;
  --amber-dim: #8a682c;
  --teal: #6fb7b0;
  --danger: #d8694f;
  --radius: 3px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Source Serif 4", Georgia, serif;
  min-height: 100vh;
}
.mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}
input,
select,
textarea,
button {
  font-family: inherit;
}

/* header */
header.top {
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
header.top h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
header.top h1 .mark {
  color: var(--amber);
}
header.top p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  font-family: "IBM Plex Mono", monospace;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  gap: 1px;
  background: var(--line);
}
@media (max-width: 1080px) {
  .app {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel);
  padding: 18px 20px 26px;
  overflow: auto;
}

.field-group {
  margin-bottom: 22px;
}
.field-group h2 {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--amber);
  letter-spacing: 0.4px;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin: 10px 0 4px;
}
label:first-child {
  margin-top: 0;
}
input[type="text"],
input[type="number"],
input[type="url"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-size: 13.5px;
  font-family: "IBM Plex Mono", monospace;
}
textarea {
  resize: vertical;
  min-height: 52px;
  line-height: 1.4;
}
input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: var(--teal);
}
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
button:hover {
  border-color: var(--amber-dim);
}
button.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1b1a17;
  font-weight: 600;
}
button.primary:hover {
  background: #eeb75c;
}
button.ghost {
  background: transparent;
}
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
}
.tabs button {
  flex: 1;
  border-radius: 0;
}
.tabs button.active {
  background: var(--amber);
  color: #1b1a17;
  border-color: var(--amber);
  font-weight: 600;
}

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s;
}
.dropzone.drag {
  border-color: var(--amber);
  color: var(--amber);
}
.dropzone strong {
  color: var(--text);
  display: block;
  font-size: 13px;
  margin-bottom: 3px;
}

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
  font-family: "IBM Plex Mono", monospace;
}
.error-msg {
  font-size: 12px;
  color: var(--danger);
  margin-top: 6px;
  font-family: "IBM Plex Mono", monospace;
  display: none;
}
.error-msg.show {
  display: block;
}

/* stage (middle) */
.stage-wrap {
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.toolbar .spacer {
  flex: 1;
}
.zoombtn {
  width: 26px;
  height: 26px;
  padding: 0;
  line-height: 1;
  font-size: 15px;
}
.stage-scroll {
  flex: 1;
  overflow: auto;
  padding: 32px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 420px;
}
.stage {
  position: relative;
  line-height: 0;
  touch-action: none;
  user-select: none;
}
.stage img#workImage {
  display: block;
  max-width: none;
  pointer-events: none;
}
.stage-empty {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  padding: 60px 20px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  width: 420px;
  max-width: 80vw;
}

.cropbox {
  position: absolute;
  border: 1.5px solid var(--teal);
  background: rgba(111, 183, 176, 0.14);
  box-shadow: 0 0 0 2000px rgba(20, 19, 17, 0.55);
  cursor: move;
}
.cropbox .tag {
  position: absolute;
  top: -22px;
  left: -1.5px;
  background: var(--teal);
  color: #12211f;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
}
.handle {
  position: absolute;
  width: 11px;
  height: 11px;
  background: var(--teal);
  border: 1.5px solid #12211f;
  border-radius: 2px;
}
.handle.n {
  top: -6px;
  left: calc(50% - 5.5px);
  cursor: ns-resize;
}
.handle.s {
  bottom: -6px;
  left: calc(50% - 5.5px);
  cursor: ns-resize;
}
.handle.e {
  right: -6px;
  top: calc(50% - 5.5px);
  cursor: ew-resize;
}
.handle.w {
  left: -6px;
  top: calc(50% - 5.5px);
  cursor: ew-resize;
}
.handle.nw {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}
.handle.se {
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
}
.handle.ne {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}
.handle.sw {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

/* output panel */
.preview-wrap {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.preview-scale-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  font-family: "IBM Plex Mono", monospace;
}
.code-box {
  position: relative;
}
#outputCode {
  min-height: 210px;
  font-size: 12.5px;
  white-space: pre;
}
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 4px 9px;
}
.copy-btn.copied {
  background: var(--teal);
  border-color: var(--teal);
  color: #12211f;
}
