:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #dcdcd6;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --error: #c0362c;
  --ok: #1e8a4c;
  --selected: #e7edfb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --panel: #1f1f1d;
    --text: #e8e8e3;
    --muted: #9a9a93;
    --border: #34342f;
    --accent: #5b85ea;
    --selected: #24304d;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, .button, select, input, textarea {
  font: inherit;
  color: inherit;
}
button, .button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:disabled, .button.disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 7px 18px; }
button.warn { border-color: var(--error); color: var(--error); }
select, input[type=text], input[type=password], textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}
textarea { width: 100%; resize: vertical; }

.keys-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.keys-panel h2 { font-size: 15px; margin: 0 0 4px; }
.keys-panel h3 { font-size: 13px; margin: 14px 0 6px; }
.keys-panel .field input { width: 360px; max-width: 100%; }

.keys-button { width: 100%; margin-top: 10px; }
.keys-button.active { background: var(--selected); }

main { padding: 16px; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.field > span { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.file-picker {
  display: block;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  min-width: 220px;
}
.file-picker input { display: none; }
.hint, .status { color: var(--muted); font-size: 12px; }
.error { color: var(--error); }
.pending { color: var(--muted); font-style: italic; }

.placeholder { background: var(--border); border-radius: 6px; min-width: 44px; min-height: 44px; }

button.active { background: var(--selected); border-color: var(--accent); }
.inpaint-editor {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.inpaint-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.inpaint-toolbar .hint { font-family: ui-monospace, monospace; margin-right: 8px; }
.segmented { display: inline-flex; }
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.segmented button:not(:first-child) { border-left: none; }
.segmented button:not(:first-child):not(:last-child) { border-radius: 0; }
.brush-size { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.brush-size-value { min-width: 48px; font-variant-numeric: tabular-nums; }
.inpaint-canvas-wrap { position: relative; display: inline-block; max-width: 100%; overflow: hidden; line-height: 0; }
.inpaint-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  border-radius: 6px;
  cursor: none;
  touch-action: none;
}
.brush-cursor {
  position: absolute;
  border-radius: 50%;
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}
.brush-cursor.remove { border-style: dashed; }

.inpaint-workspace { display: grid; grid-template-columns: 1fr 200px; gap: 16px; align-items: start; }
@media (max-width: 700px) {
  .inpaint-workspace { grid-template-columns: 1fr; }
}
.layer-list { order: 2; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 16px; }
.layer-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}
.layer-select { cursor: pointer; }
.layer-item:hover { background: var(--selected); }
.layer-item.active { outline: 1px solid var(--accent); outline-offset: -1px; background: var(--selected); }
.layer-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.layer-label .hint { font-family: ui-monospace, monospace; }
.layer-preview { display: block; width: 50%; height: auto; border-radius: 4px; }
.layer-preview.placeholder {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.layer-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.layer-actions .file-picker { min-width: 0; padding: 10px 6px; }
.reset-button { width: 100%; margin-top: 6px; }
