:root {
  --bg: #f1f0ec;
  --panel: #ffffff;
  --line: #e8e6e0;
  --line-strong: #dedbd3;
  --ink: #171717;
  --muted: #74716a;
  --soft: #f7f6f3;
  --accent: #15803d;
  --accent-top: #1c9a4c;
  --accent-edge: #0f6a31;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand img { display: block; height: 24px; width: auto; }
.brand { margin: 0; display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; letter-spacing: -0.015em; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  color: #fff; background: linear-gradient(#2b2b2b, #141414);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), 0 1px 2px rgba(0, 0, 0, .18);
}
.top-actions { display: flex; gap: 10px; }

/* ---------- buttons (secondary / primary / accent) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  font: inherit; font-weight: 600; font-size: 14px; letter-spacing: -0.015em; line-height: 1;
  color: var(--ink); background: #fff;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(23, 23, 23, .05);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: background-color .15s, box-shadow .15s, filter .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--soft); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(23, 23, 23, .14); }
.btn:disabled { opacity: .42; cursor: default; box-shadow: none; }

.btn.primary {
  color: #f6f6f6;
  background: linear-gradient(#2c2c2c, #161616);
  border: 1px solid #0c0c0c;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .13), 0 1px 2px rgba(0, 0, 0, .22);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(#363636, #1d1d1d); }

.btn.accent {
  color: #ffffff;
  background: linear-gradient(var(--accent-top), var(--accent));
  border: 1px solid var(--accent-edge);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(10, 70, 30, .25);
}
.btn.accent:hover:not(:disabled) { filter: brightness(1.04); background: linear-gradient(var(--accent-top), var(--accent)); }
.btn.primary:focus-visible, .btn.accent:focus-visible { box-shadow: 0 0 0 3px rgba(23, 23, 23, .18); }

.btn .icon { flex: none; }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: 9px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100% - 60px); }
.panel { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
/* pinned to the bottom of the panel so it stays reachable while scrolling the settings */
.panel-foot {
  position: sticky; bottom: 0; margin-top: auto; padding: 14px 20px 18px;
  background: linear-gradient(rgba(255, 255, 255, 0), #fff 18px); border-top: 1px solid var(--line);
}
.btn.block { width: 100%; }

/* segmented mode switch */
.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 16px 20px; padding: 4px;
  background: var(--soft); border: 1px solid var(--line); border-radius: var(--radius);
}
.tab {
  height: 32px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-weight: 600; font-size: 13px; letter-spacing: -0.01em;
  color: var(--muted); cursor: pointer; transition: background-color .15s, color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); background: #fff; box-shadow: 0 1px 2px rgba(23, 23, 23, .08), 0 0 0 1px var(--line); }

.group { padding: 18px 20px; border-top: 1px solid var(--line); }
.group h3 { margin: 0 0 10px; font-size: 13px; font-weight: 650; letter-spacing: -0.01em; }
.group-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.group-head h3 { margin: 0; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 38px; color: var(--muted); }
.row output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.row input[type=text], .row input[type=number], .row select {
  width: 92px; height: 32px; padding: 0 10px;
  font: inherit; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink); text-align: right;
  background: var(--soft); border: 1px solid var(--line); border-radius: 9px;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.row select {
  width: 150px; text-align: left; cursor: pointer;
  /* custom chevron: the native arrow ignores padding and sits flush on the right edge */
  appearance: none; -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%2374716a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px 12px;
}
.row input:hover, .row select:hover { border-color: var(--line-strong); }
.row input:focus, .row select:focus { outline: none; background-color: #fff; border-color: #a8a49b; box-shadow: 0 0 0 3px rgba(23, 23, 23, .08); }

/* custom checkbox: native ones can't take a larger corner radius */
.row.check input {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 20px; height: 20px; margin: 0;
  border: 1.5px solid var(--line-strong); border-radius: 6px;
  background: #fff center / 12px 12px no-repeat;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.row.check input:hover { border-color: #a8a49b; }
.row.check input:checked {
  border-color: var(--ink);
  background-color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-4.9' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.row.check input:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(23, 23, 23, .14); }

.range { width: 100%; margin: 6px 0 10px; accent-color: var(--ink); cursor: pointer; }
.hist canvas { display: block; width: 100%; height: 44px; background: var(--soft); border: 1px solid var(--line); border-radius: 9px; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.swatch { width: 24px; height: 24px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; padding: 20px; overflow: hidden; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 30px; }
.status { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewport {
  position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden;
  background: conic-gradient(#f4f3ef 25%, #fff 0 50%, #f4f3ef 0 75%, #fff 0) 0 0 / 22px 22px;
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 1px 2px rgba(23, 23, 23, .04);
}
/* Layers are pinned to the viewport box so a large image can never make it taller
   than the window; object-fit / preserveAspectRatio scale the content down to fit. */
.viewport img, .viewport canvas, #svgHost { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); }
.viewport img, .viewport canvas { object-fit: contain; }
.viewport canvas { image-rendering: pixelated; }
.viewport img.faded { opacity: .25; }
#svgHost svg { display: block; width: 100%; height: 100%; }
.drop-hint {
  position: absolute; inset: 12px; display: grid; place-items: center;
  border: 1.5px dashed var(--line-strong); border-radius: 12px;
  color: var(--muted); text-align: center; line-height: 1.6; cursor: pointer; background: rgba(255, 255, 255, .55);
  transition: border-color .15s, background-color .15s, color .15s;
}
.meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; }
  .viewport { flex: none; height: 60vh; }
  .top { height: auto; padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
}

/* clickable drop zone */
.drop-hint strong { color: var(--ink); font-weight: 600; }
.drop-hint .sub { font-size: 13px; }
.drop-hint:hover { border-color: #a8a49b; background: rgba(255, 255, 255, .8); }
.drop-hint:focus-visible { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 23, 23, .12); }

/* language picker (header) */
.lang-pick {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 10px; color: var(--muted);
  border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff;
}
.lang-pick:hover { border-color: var(--line-strong); color: var(--ink); }
.lang-pick select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  font: inherit; font-weight: 600; font-size: 13px; color: inherit; cursor: pointer; padding-right: 2px;
}
.lang-pick select:focus { outline: none; }
.lang-pick:focus-within { box-shadow: 0 0 0 3px rgba(23, 23, 23, .12); }
@media (max-width: 720px) { .lang-pick { display: none; } }
