:root {
  color-scheme: dark;
  --bg: #12140f;
  --stage: #0c0d0a;
  --panel: #1c1f18;
  --line: #34382e;
  --text: #f3f0e6;
  --muted: #a39e90;
  --accent: #e2a14a;
  --accent-ink: #241804;
  --danger: #e07a62;
  --btn: #2a2e24;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", system-ui, sans-serif;
}

button, .btn, textarea, input {
  font: inherit;
  color: inherit;
}

button, .btn {
  background: var(--btn);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

button:disabled, .btn:has(input:disabled) {
  opacity: 0.45;
  cursor: not-allowed;
}

button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

button:focus-visible, textarea:focus-visible, input:focus-visible, .file-btn:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

header {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
}

.file-name {
  flex: 1;
  min-width: 8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.file-btn { position: relative; }

.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#stage {
  position: relative;
  min-height: 0;
  background: var(--stage);
  overflow: hidden;
  touch-action: none;
}

#stage[data-tool="pan"] { cursor: grab; }
#stage[data-tool="brush"],
#stage[data-tool="eraser"] { cursor: none; }
#stage.panning { cursor: grabbing; }
#drop-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(18, 20, 15, 0.55);
  outline: 4px dashed var(--accent);
  outline-offset: -16px;
}

#drop-layer[hidden] { display: none; }

#drop-layer p {
  margin: 0;
  pointer-events: none;
  font-size: 1.4rem;
  font-weight: 650;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#cursor {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px #000a;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  gap: 4px;
}

#empty[hidden] { display: none; }

.empty-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.muted { color: var(--muted); margin: 0; }

footer {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px 16px 14px;
  display: grid;
  gap: 10px;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.seg { display: flex; gap: 4px; }

.size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.size input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

.prompt-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

textarea {
  flex: 1;
  resize: vertical;
  min-height: 48px;
  max-height: 140px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

#go {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  font-weight: 650;
  min-width: 132px;
}

#sticker-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
}

#sticker-bar[hidden] { display: none; }

#sticker-apply {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  font-weight: 650;
}

.hint, #status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#status:empty { display: none; }

#status.error { color: var(--danger); }

#status.selftest {
  font-size: 1.35rem;
  font-weight: 700;
}

@media (max-width: 720px) {
  .file-name { flex-basis: 100%; order: 3; }
  .prompt-row { flex-direction: column; }
  #go { width: 100%; min-height: 44px; }
  .size input[type="range"] { width: 88px; }
  header, footer { padding-left: 12px; padding-right: 12px; }
}
