:root {
  --bg: #f3efe6;
  --panel: #fffdf8;
  --ink: #2b241c;
  --muted: #6f6355;
  --line: #ddd3c2;
  --accent: #2f8a3e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1df;
  --viewer: radial-gradient(circle at 50% 40%, #e9f3e4, #cfdcc6);
  --error: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 6px 20px rgba(60, 40, 20, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --panel: #221f1a;
    --ink: #eee6d8;
    --muted: #a99c89;
    --line: #3a342b;
    --accent: #49b35a;
    --accent-ink: #0d1a0f;
    --accent-soft: #233322;
    --viewer: radial-gradient(circle at 50% 40%, #2c3a2a, #161c15);
    --error: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { font-family: "Silkscreen", system-ui, sans-serif; font-weight: 400; margin: 0; }
a { color: var(--accent); }

.top { text-align: center; padding: 28px 16px 8px; }
.top h1 { font-size: clamp(32px, 7vw, 52px); color: var(--accent); letter-spacing: 1px; }
.top p { margin: 4px 0 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.3fr) minmax(280px, 1fr);
  gap: 16px;
  max-width: 1400px;
  margin: 16px auto;
  padding: 0 16px;
  align-items: start;
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr 1fr; } .downloads { grid-column: 1 / -1; } }
@media (max-width: 720px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel h2 { font-size: 18px; margin-bottom: 12px; }
.panel h2 + * { margin-top: 0; }
.panel > h2:not(:first-child) { margin-top: 20px; }

.dropzone {
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone canvas { display: none; max-width: 100%; max-height: 380px; }
.dropzone.has-photo canvas { display: block; }
.dropzone.has-photo .dz-text { position: absolute; inset: auto 8px 8px; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 13px; }
.dropzone.has-photo .dz-text small { display: none; }
.dz-text { padding: 16px; color: var(--muted); }
.dz-text strong { color: var(--accent); }

.status { font-size: 13px; color: var(--muted); margin: 8px 0 0; min-height: 1.5em; }
.status[data-kind="ok"] { color: var(--accent); }
.status[data-kind="error"] { color: var(--error); }
.status[data-kind="busy"]::after { content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { display: grid; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 4px; }
fieldset label:has(select) { grid-column: 1 / -1; }
fieldset label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
input[type="color"] { width: 40px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; flex: none; }
select, input[type="text"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; min-width: 0;
}
fieldset select { max-width: 60%; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 12px; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 4px 8px; font-size: 13px; }
#shuffle { margin-top: 12px; width: 100%; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.row.between { justify-content: space-between; margin-top: 0; margin-bottom: 12px; }
.row.between h2 { margin: 0; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--ink); padding: 6px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.viewer { width: 100%; aspect-ratio: 1 / 1; display: block; border-radius: 10px; background: var(--viewer); cursor: grab; touch-action: none; }
.viewer:active { cursor: grabbing; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.row .hint { margin: 0 0 0 auto; }

.editor-wrap { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.editor-wrap summary { cursor: pointer; font-weight: 600; }
.editor {
  display: block; width: 100%; max-width: 512px; aspect-ratio: 1 / 1; margin-top: 10px;
  image-rendering: pixelated; cursor: crosshair; touch-action: none; border-radius: 6px;
  background: repeating-conic-gradient(rgba(128,128,128,.25) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}

.name { display: flex; flex-direction: column; gap: 4px; font-size: 14px; margin-bottom: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }
.card h3 { font-size: 15px; }
.card p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.card .row { margin-top: 8px; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 16px 16px 32px; }
.inline { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; margin-top: 8px; }
.look { margin-top: 12px; display: grid; gap: 8px; }
.look label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.look label[hidden] { display: none; }
