:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1d1b18;
  --muted: #6b665e;
  --line: #ddd8cf;
  --accent: #b3261e;
  --accent-text: #ffffff;
  --ok: #1e7a3c;
  --bad: #b3261e;
  --tile: #ebe7e0;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --card: #1f1d18;
    --text: #ece8e1;
    --muted: #a39d92;
    --line: #36332c;
    --accent: #e0574c;
    --accent-text: #15140f;
    --ok: #5cc27e;
    --bad: #ff7b70;
    --tile: #2a2721;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.hidden { display: none !important; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 12px 0 4px; }
input, textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; margin-top: 16px; }
button:disabled { opacity: 0.6; cursor: wait; }
button.link { border: none; background: none; color: var(--muted); padding: 4px 8px; text-decoration: underline; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--card);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.bad { color: var(--bad); border-color: var(--bad); }

.layout { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.options { display: grid; grid-template-columns: 2fr 1fr 0.7fr 1fr; gap: 0 12px; }
@media (max-width: 640px) {
  .two-col, .options { grid-template-columns: 1fr 1fr; }
  .options > div:first-child { grid-column: 1 / -1; }
}
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
details textarea { margin-top: 8px; }
.prompt-text { margin: 0 0 12px; word-break: break-word; }
.label-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.label-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.small-button { padding: 4px 12px; font-size: 0.85rem; margin-bottom: 4px; }
.preview { margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.preview-label { font-weight: 600; font-size: 0.85rem; }
.preview .link { font-size: 0.85rem; padding: 0; }
.prompt-preview { margin: 6px 0 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile {
  position: relative; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--tile); aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
}
.tile img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.tile-label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; font-size: 0.75rem;
  background: color-mix(in srgb, var(--card) 85%, transparent); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.placeholder { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 12px; flex-direction: column; }
.placeholder.running { color: var(--text); animation: pulse 1.6s ease-in-out infinite; }
.placeholder.error { color: var(--bad); }
@keyframes pulse { 50% { opacity: 0.55; } }

dialog { border: none; border-radius: var(--radius); padding: 0; max-width: min(1000px, 96vw); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.7); }
#viewer-img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto; background: #fff; }
.viewer-info { padding: 12px 16px 16px; }
#viewer-text { white-space: pre-wrap; margin: 0 0 12px; word-break: break-word; }
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger.armed { background: var(--bad); color: var(--card); font-weight: 600; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-card p { margin: 6px 0 0; }
.login-card button { width: 100%; }
