:root {
  --bg: #efede8;
  --panel: #faf9f6;
  --card: #ffffff;
  --fg: #1f1d1a;
  --muted: #74706a;
  --faint: #a19c94;
  --line: #e2ded6;
  --accent: #8a4b2a;
  --accent-soft: #f3e8e1;
  --on-accent: #ffffff;
  --viewer: #d8d5cf;
  --input: #ffffff;
  --err: #a32020;
  --warn: #9a6200;
  --warn-soft: #fbefd9;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18171a;
    --panel: #1f1e21;
    --card: #262529;
    --fg: #ebe8e2;
    --muted: #a39e96;
    --faint: #6f6b66;
    --line: #36343a;
    --accent: #e0a07a;
    --accent-soft: #3a2b22;
    --on-accent: #1b1410;
    --viewer: #111113;
    --input: #2d2c31;
    --err: #ff8a80;
    --warn: #f0b85a;
    --warn-soft: #3a2f1c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--input); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 11px; cursor: pointer; color: var(--fg);
}
button:hover, .btn:hover { border-color: var(--accent); }
.btn input { display: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
button.primary:disabled { opacity: .55; cursor: progress; }
button.small { padding: 3px 9px; font-size: 12px; }
button.wide { width: 100%; margin: 10px 0 4px; }
button.icon { background: none; border: none; padding: 2px 6px; font-size: 16px; color: var(--muted); border-radius: 4px; }
button.icon:hover:not(:disabled) { background: var(--card); color: var(--fg); }
button.icon:disabled { opacity: .3; cursor: default; }
button.link, label.link {
  display: inline; background: none; border: none; padding: 0; color: var(--accent);
  cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- panel ---------- */
#panel {
  width: 344px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); position: relative;
}
.top { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 14px; }
.brand { font: 600 18px/1 Georgia, serif; letter-spacing: .01em; }
.projbtn {
  flex: 1; min-width: 0; justify-content: space-between;
  background: none; border-color: transparent; color: var(--muted); padding: 4px 8px;
}
.projbtn:hover { background: var(--card); color: var(--fg); border-color: var(--line); }
#projNameLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { font-size: 10px; opacity: .7; }
.undo { display: flex; gap: 2px; }

.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; background: none; border: none; border-radius: 0; border-bottom: 2px solid transparent;
  padding: 8px 4px 7px; color: var(--muted); font-weight: 500;
}
.tabs button:hover { color: var(--fg); border-color: transparent; border-bottom-color: var(--line); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.panels { flex: 1; overflow-y: auto; padding: 12px 12px 24px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 12px 12px; margin-bottom: 10px;
}
.card h3 { margin: 0 0 3px; font-size: 13px; font-weight: 600; }
.lead { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.desc { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.35; margin-top: 3px; }

.field { margin: 12px 0 2px; }
.fhead { display: flex; align-items: baseline; gap: 6px; margin-bottom: 3px; }
.fhead > label:first-child { font-weight: 500; }
.fhead output { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; }
.fhead > .link, .fhead > .unit, .fhead > .rangenum { margin-left: auto; }
.unit-label { color: var(--faint); font-size: 11px; }
.unit { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; }
.fhead .unit { margin-top: 0; }

input[type=text], input[type=number], select, textarea {
  background: var(--input); border: 1px solid var(--line); border-radius: 5px; padding: 4px 7px; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input.short { width: 76px; }
input.rangenum { width: 64px; padding: 1px 5px; text-align: right; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; margin: 6px 0; }
input[type=range] { width: 100%; margin: 2px 0; accent-color: var(--accent); cursor: pointer; }

.grid2, .grid4 { display: grid; gap: 6px; margin-top: 8px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid4 { grid-template-columns: repeat(4, 1fr); }
label.mini { display: block; font-size: 11px; color: var(--muted); margin-top: 6px; }
label.mini input { margin-top: 2px; }

/* switches */
label.switch { display: flex; align-items: center; gap: 9px; margin: 12px 0 0; cursor: pointer; font-weight: 500; }
label.switch input {
  appearance: none; width: 30px; height: 17px; border-radius: 9px; background: var(--line);
  position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 0;
}
label.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
label.switch input:checked { background: var(--accent); }
label.switch input:checked::after { transform: translateX(13px); }
label.switch.big { font-size: 13.5px; }
label.switch + .desc { margin-left: 39px; }
.indent { margin-left: 39px; }

.resetbtn { width: 100%; color: var(--muted); background: none; border-style: dashed; margin-top: 2px; }

.filebox { display: flex; align-items: center; gap: 10px; }
.fileinfo { margin: 8px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.fileinfo b { color: var(--fg); font-weight: 600; }

details.more { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 8px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; user-select: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸"; display: inline-block; width: 1.1em; transition: transform .1s; }
details.more[open] summary::before { transform: rotate(90deg); }
details.more summary:hover { color: var(--fg); }

/* segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--input); }
.seg.full { display: flex; width: 100%; margin-top: 8px; }
.seg button { border: none; border-radius: 0; background: none; padding: 4px 10px; color: var(--muted); flex: 1; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg.full button { padding: 5px 4px; font-size: 12px; }

/* style cards */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cards button { flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 1px; text-align: left; padding: 8px; }
.cards button b { font-weight: 600; }
.cards button small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.cards button.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.sw { display: block; width: 100%; height: 10px; border-radius: 3px; margin-bottom: 5px; }
.sw-gray { background: linear-gradient(90deg, #dcdad5, #141414); }
.sw-grad { background: linear-gradient(90deg, #1f4fa8, #7a1f1f); }
.sw-img { background: linear-gradient(90deg, #2b4c9b, #6aa2c8, #e8d36a, #c4582c, #3a2a1c); }
.sw-wght { height: 10px; display: flex; align-items: center; gap: 8px; font: 15px/10px Georgia, serif; color: var(--fg); background: none; }
.sw-wght span:nth-child(1) { font-weight: 300; opacity: .6; }
.sw-wght span:nth-child(2) { font-weight: 500; }
.sw-wght span:nth-child(3) { font-weight: 900; }

/* looks */
.looks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.looks button { padding: 4px 11px; border-radius: 14px; font-size: 12px; }
.looks button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.colors { display: flex; gap: 14px; margin-top: 12px; }
.colors label { font-size: 11px; color: var(--muted); }
.colors input, .colorpick input {
  display: block; width: 52px; height: 28px; border: 1px solid var(--line); border-radius: 5px;
  padding: 1px; background: var(--input); margin-top: 2px; cursor: pointer;
}
.colorpick { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.colorpick input { margin: 0; }
#pickBtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* popovers */
.popover {
  position: absolute; z-index: 20; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 12px;
}
.pophead { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 6px; }
.pophead:first-child { margin-top: 0; }
.poprow { display: flex; gap: 6px; margin: 8px 0; }
.projpop { top: 44px; left: 10px; right: 10px; }
.field-inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.projlist { border: 1px solid var(--line); border-radius: 6px; max-height: 340px; overflow-y: auto; margin-bottom: 8px; }
.projitem { display: flex; gap: 8px; align-items: center; padding: 6px; cursor: pointer; border-bottom: 1px solid var(--line); }
.projitem:last-child { border-bottom: none; }
.projitem:hover { background: var(--bg); }
.projitem.current { background: var(--accent-soft); }
.projitem img, .projitem .nothumb { width: 36px; height: 50px; object-fit: cover; background: var(--viewer); flex: none; border-radius: 2px; }
.projitem .meta { flex: 1; min-width: 0; }
.projitem .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.projitem .meta span { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projitem button, .exportitem button { border: none; background: none; color: var(--faint); padding: 2px 6px; }
.projitem button:hover, .exportitem button:hover { color: var(--err); }

.exportwrap { position: relative; }
.exportpop { right: 0; top: calc(100% + 6px); width: 300px; cursor: default; }
label.radio { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; cursor: pointer; }
label.radio span { color: var(--muted); font-size: 12px; }
label.radio b { color: var(--fg); font-weight: 600; font-size: 13px; margin-right: 4px; }
label.radio input { accent-color: var(--accent); }
.exportlist { display: flex; flex-direction: column; gap: 2px; max-height: 200px; overflow-y: auto; }
.exportlist .desc { margin: 0; }
.exportitem { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.exportitem a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.exportitem span { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.jobbox { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; flex-wrap: wrap; }
.jobbox progress { flex: 1; min-width: 150px; accent-color: var(--accent); }
.jobbox .muted { font-size: 11px; width: 100%; order: 3; }

/* ---------- main ---------- */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#toolbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.spacer { flex: 1; }
.muted { color: var(--muted); font-variant-numeric: tabular-nums; }
button.zl { min-width: 60px; font-variant-numeric: tabular-nums; }

#viewer { flex: 1; position: relative; overflow: hidden; background: var(--viewer); cursor: grab; touch-action: none; }
#viewer.dragging { cursor: grabbing; }
#viewer.picking, #viewer.picking * { cursor: crosshair !important; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; display: flex; gap: 24px; }
.pane { margin: 0; background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.22); position: relative; overflow: hidden; }
.pane img { display: block; width: 100%; height: 100%; user-select: none; }
.pane img.tile { position: absolute; width: auto; height: auto; }
#msg {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 18px; max-width: 440px; text-align: center; box-shadow: var(--shadow);
}
#msg.err { color: var(--err); }

.empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100% - 32px));
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px;
  box-shadow: var(--shadow); cursor: default;
}
.empty h2 { margin: 0 0 12px; font: 600 20px/1.2 Georgia, serif; }
.empty ol { list-style: none; padding: 0; margin: 0 0 10px; }
.empty li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.empty li div { flex: 1; }
.empty li small { display: block; color: var(--muted); }
.empty li.done div { opacity: .55; }
.empty li.done .num { background: var(--accent); color: var(--on-accent); }
.empty p { margin: 4px 0 0; font-size: 12px; }
.num {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.drophint {
  position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 12px;
  display: grid; place-items: center; font-size: 18px; color: var(--accent);
  background: color-mix(in srgb, var(--panel) 85%, transparent); pointer-events: none;
}

#statusbar {
  display: flex; align-items: center; gap: 12px; padding: 5px 12px; border-top: 1px solid var(--line);
  background: var(--panel); font-size: 12px; position: relative; min-height: 31px;
}
.status { color: var(--muted); white-space: nowrap; }
.status.busy::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px;
  border-radius: 50%; background: var(--accent); animation: pulse 1s infinite;
}
.status.err { color: var(--err); }
@keyframes pulse { 50% { opacity: .2; } }
.summary { color: var(--fg); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.warnchip { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 1px 9px; cursor: pointer; white-space: nowrap; }
#tileInfo, #timing { white-space: nowrap; }
.detailspop { right: 8px; bottom: calc(100% + 6px); width: 330px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.stats .warn { color: var(--warn); }
.levels { display: flex; align-items: flex-end; height: 44px; gap: 1px; }
.levels div { flex: 1; min-height: 1px; border: 1px solid var(--line); border-bottom: none; }

@media (max-width: 820px) {
  body { flex-direction: column; }
  #panel { width: auto; max-height: 55vh; border-right: none; border-bottom: 1px solid var(--line); }
  main { min-height: 45vh; }
}
.field input[type=range] + .desc { margin-top: 0; }
input[type=range] { height: 18px; }
.panels, .projlist, .exportlist { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
