:root {
  --bg: #e9edf1;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #5d6b79;
  --line: #d3dae2;
  --action: #1f5fa8;
  --action-ink: #ffffff;
  --stamp: #ffe600;
  --off: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151b22;
    --panel: #1e2630;
    --ink: #e4e9ee;
    --muted: #9aa7b4;
    --line: #34404c;
    --action: #4a8ad6;
    --off: #ef7a72;
  }
}
:root[data-theme="dark"] {
  --bg: #151b22;
  --panel: #1e2630;
  --ink: #e4e9ee;
  --muted: #9aa7b4;
  --line: #34404c;
  --action: #4a8ad6;
  --off: #ef7a72;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Barlow", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

/* Header */
.top { padding: 20px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 16px; max-width: 1400px; margin: 0 auto; }
.mark {
  background: #2b3a2e;
  color: var(--stamp);
  font-weight: 700;
  font-size: 1.6rem;
  padding: 6px 12px;
  border-radius: 4px;
  letter-spacing: 1px;
}
.top h1 { margin: 0; font-size: 1.5rem; }
.top p { margin: 2px 0 0; color: var(--muted); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
}
.setup { position: sticky; top: 16px; }
@media (max-width: 900px) { .setup { position: static; } }

h2 { font-size: 1.05rem; margin: 18px 0 8px; }
h2:first-child { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Controls */
label { font-weight: 600; font-size: 0.9rem; }
label.block { display: block; margin-top: 10px; }
input[type="text"], input[type="date"], input[type="time"], select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
#stampText { font-size: 1.1rem; font-weight: 700; }
input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--action); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.row[hidden] { display: none; }

.modes { display: flex; flex-wrap: wrap; gap: 6px; }
.modes label {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 5px 12px;
  cursor: pointer;
  font-weight: 600;
}
.modes input { accent-color: var(--action); }
.modes label:has(input:checked) { border-color: var(--action); color: var(--action); }

.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-weight: 400; cursor: pointer; }
.check input { accent-color: var(--action); width: 16px; height: 16px; }

.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { border-color: var(--action); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.wide { width: 100%; margin-top: 14px; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; }

/* Preview */
.preview-wrap { margin-top: 14px; }
#previewCanvas { width: 100%; height: auto; border-radius: 6px; display: none; background: #000; }
#previewCanvas.show { display: block; }

/* Progress */
.progress { margin-top: 12px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--action); transition: width 0.15s; }

/* Review */
.review-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.empty {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}
.card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  cursor: zoom-in;
  background: #000;
}
.card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 0.85rem;
}
.card .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .check { margin: 0; flex-shrink: 0; }
.card.off img { opacity: 0.35; }
.card.off .name { color: var(--off); text-decoration: line-through; }

.export {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.export-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* Viewer */
dialog#viewer {
  width: min(96vw, 1400px);
  max-height: 96vh;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #0d1116;
  color: #fff;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.8); }
.viewer-body { display: flex; justify-content: center; }
#viewerImg { max-width: 100%; max-height: 82vh; object-fit: contain; }
.viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
#viewerName { flex: 1; min-width: 120px; overflow-wrap: anywhere; }
.viewer-bar .btn { background: #26303b; color: #fff; border-color: #3a4652; }
.viewer-bar .check { margin: 0; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}