/* Нейтрально-серое окружение, как в просмотровой кабине: цвет ответов ничто не искажает.
   Единственный яркий цвет — маркер: им отмечено то, чем ответы различаются. */
:root {
  color-scheme: light;
  --booth: #d6d7d9;
  --paper: #f5f5f4;
  --field: #ffffff;
  --ink: #1b1c1f;
  --muted: #5a5e66;
  --line: #b9bbbf;
  --accent: #2443c4;
  --accent-ink: #ffffff;
  --mark: #ffe04a;
  --mark-ink: #1b1c1f;
  --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --booth: #24252a;
    --paper: #2f3136;
    --field: #232428;
    --ink: #ececea;
    --muted: #a6aab1;
    --line: #4a4d55;
    --accent: #9db0ff;
    --accent-ink: #11142b;
    --mark: #f2d23c;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--booth);
  color: var(--ink);
  font: 15px/1.5 'Golos Text', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.2; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); padding: 12px 16px; margin: 0; }
[hidden] { display: none !important; }

/* ---------- элементы управления ---------- */
button {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--paper); font-weight: 600; }
button.link {
  border: 0; background: none; padding: 0;
  color: var(--accent); text-decoration: underline; text-underline-offset: 3px;
}
.icon {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 4px; background: none;
  color: var(--muted);
}
.icon:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 9%, transparent); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

input, select, textarea {
  font: inherit; color: inherit;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 10px;
  width: 100%;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 4px; }
textarea { resize: vertical; }
textarea.code { font: 13px/1.5 ui-monospace, 'Cascadia Mono', Consolas, monospace; }

.tag {
  font-size: 12.5px; line-height: 1.6;
  padding: 0 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--muted);
  white-space: nowrap;
}
.tag.fmt { background: none; box-shadow: inset 0 0 0 1px var(--line); }
.letter {
  display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 4px;
  border-radius: 4px;
  background: var(--ink); color: var(--paper);
  font-size: 13px; font-weight: 700;
}

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.tagline { color: var(--muted); }
#key-btn { margin-left: auto; }
#key-btn.on { border-color: var(--accent); color: var(--accent); }
main { padding: 24px; max-width: 1840px; margin: 0 auto; }

/* ---------- список промптов ---------- */
.list-head, .prompt-list { max-width: 1100px; }
.list-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 16px; }
.list-head h1 { margin: 0; font-size: 28px; }
.list-head input { flex: 1 1 240px; max-width: 420px; }
.prompt-list { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.prompt-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 240px);
  grid-template-areas: "title count" "text count" "tags count";
  gap: 2px 24px;
  padding: 14px 18px;
  color: inherit; text-decoration: none;
  border-top: 1px solid var(--line);
}
.prompt-row:first-child { border-top: 0; }
.prompt-row:hover { background: color-mix(in srgb, var(--accent) 6%, var(--paper)); }
.pr-title { grid-area: title; font-size: 17px; font-weight: 600; }
.pr-text { grid-area: text; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-tags { grid-area: tags; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pr-count { grid-area: count; align-self: center; display: grid; justify-items: end; font-size: 14px; min-width: 0; }
.pr-count span { color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- промпт ---------- */
.prompt-head { margin-bottom: 20px; }
.back { text-underline-offset: 3px; }
.ph-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; margin: 8px 0 12px; }
.ph-title h1 { margin: 0 6px 0 0; font-size: 28px; }
.ph-tools { display: flex; }
.ptext-wrap { max-width: 92ch; padding: 12px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.ptext { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ptext.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.ptext-tools { display: flex; gap: 20px; margin-top: 8px; font-size: 14px; }

/* вкладки «Все ответы» / «Сравнение» */
.tabs {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px 24px;
  margin: 24px 0 16px;
  border-bottom: 1px solid var(--line);
}
.tab {
  margin-bottom: -1px; padding: 8px 2px;
  border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  background: none; color: var(--muted);
  font-size: 17px; font-weight: 600;
}
.tab:hover { color: var(--ink); }
.tab[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab .n { font-weight: 500; color: var(--muted); }
.tabs-tools { display: flex; gap: 8px; margin: 0 0 8px auto; }

/* галерея: превью рендерится как окно 640×400 и уменьшается вдвое — видно настоящую раскладку */
.gal-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 14px; }
.gal-bar input[type="search"] { flex: 1 1 220px; max-width: 340px; }
.gal-bar select { width: auto; }
.gal-bar .check { margin-right: 0; white-space: nowrap; }
.gal-bar .hint { margin-left: auto; font-size: 14px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, 322px); gap: 16px; }
.tile {
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden;
}
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tile-view { position: relative; width: 320px; height: 200px; overflow: hidden; background: #fff; border-bottom: 1px solid var(--line); }
.tile-frame iframe { display: block; width: 640px; height: 400px; border: 0; transform: scale(0.5); transform-origin: 0 0; pointer-events: none; }
.tile-frame pre { margin: 0; padding: 10px 12px; white-space: pre-wrap; font: 13px/1.5 'Golos Text', system-ui, sans-serif; }
.tile-pick {
  position: absolute; inset: 0;
  width: 100%; padding: 0;
  border: 0; border-radius: 0;
  background: transparent;
}
.tile-pick:hover { background: rgb(0 0 0 / 0.08); }
.tile-pick:focus-visible { outline-offset: -3px; }
.pick-mark {
  position: absolute; top: 8px; left: 8px;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border: 2px solid #fff; border-radius: 5px;
  background: rgb(255 255 255 / 0.55);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35);
  color: var(--accent-ink); font-size: 14px; font-weight: 700;
  pointer-events: none;
}
.tile.sel .pick-mark { background: var(--accent); border-color: var(--accent); }
.tile-info { display: flex; align-items: flex-start; gap: 4px; padding: 8px 4px 8px 12px; }
.tile-text { flex: 1; min-width: 0; display: grid; }
.tile-text strong, .a-params { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-params { font-size: 14px; }
.a-meta { font-size: 12.5px; color: var(--muted); }
.tile-tools { display: flex; flex-shrink: 0; }
.tile-tools .icon { width: 28px; height: 28px; }
.mark-btn { display: inline-flex; gap: 3px; width: auto; min-width: 28px; padding: 0 5px; font-size: 13px; font-weight: 600; }
.mark-btn svg { flex-shrink: 0; }
.mark-btn .n:empty { display: none; }
.mark-btn[aria-pressed="true"] { color: var(--ink); }
.mark-btn[aria-pressed="true"] svg { fill: currentColor; }
.mark-btn.favs[aria-pressed="true"] svg { fill: var(--mark); }

.compare-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin-right: auto; }

.diff { overflow-x: auto; margin-bottom: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.diff:empty { display: none; }
.diff table { width: 100%; border-collapse: collapse; font-size: 14px; }
.diff th, .diff td { padding: 6px 12px; text-align: left; vertical-align: top; border-top: 1px solid var(--line); }
.diff thead th, .diff thead td { border-top: 0; padding-bottom: 2px; }
.diff tbody th { width: 1%; white-space: nowrap; font-weight: 500; color: var(--muted); }
.diff td { max-width: 360px; overflow-wrap: anywhere; }
.differs .v, .chip.mark {
  background: var(--mark); color: var(--mark-ink);
  border-radius: 2px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.differs .v { padding: 1px 5px; margin: 0 -5px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
.grid[data-n="1"] { grid-template-columns: 1fr; }
.panel { display: flex; flex-direction: column; min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.panel header { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 6px 6px 6px 10px; }
.p-title { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.p-title strong { overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12.5px; padding: 0 6px; border-radius: 2px; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.p-tools { display: flex; flex-shrink: 0; }

/* у ответа своя страница: белая подложка, как у браузера по умолчанию */
.frame { aspect-ratio: 16 / 10; background: #fff; border-top: 1px solid var(--line); }
.grid[data-n="1"] .frame { aspect-ratio: 16 / 9; max-height: 80vh; }
.frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.grid .frame.f-text { aspect-ratio: auto; max-height: 70vh; overflow: auto; background: var(--field); }
.frame pre { margin: 0; padding: 14px 16px; white-space: pre-wrap; overflow-wrap: anywhere; font: 15px/1.6 'Golos Text', system-ui, sans-serif; }
.frame:fullscreen { aspect-ratio: auto; max-height: none; }

/* ---------- диалоги ---------- */
dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px 22px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 8px;
}
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgb(18 20 24 / 0.5); overflow: hidden; overscroll-behavior: contain; }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
dialog p { margin: 0 0 12px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 14px; font-weight: 500; }
.field small { color: var(--muted); font-size: 12.5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset.params { margin: 0 0 12px; padding: 6px 12px 12px; border: 1px solid var(--line); border-radius: 6px; }
fieldset.params p { margin: 0 0 8px; }
legend { padding: 0 4px; font-size: 14px; font-weight: 500; }
.param-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-bottom: 6px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-error { color: var(--danger); font-weight: 500; }
.form-error:empty { display: none; }
pre.source {
  max-height: 60vh; overflow: auto; margin: 0 0 8px; padding: 12px;
  background: var(--field); border-radius: 4px;
  font: 13px/1.5 ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

#toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 10;
  translate: -50% 16px; opacity: 0;
  padding: 10px 16px; border-radius: 6px;
  background: var(--ink); color: var(--paper);
  pointer-events: none;
  transition: opacity 0.2s, translate 0.2s;
}
#toast.on { opacity: 1; translate: -50% 0; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

@media (max-width: 900px) {
  main { padding: 16px; }
  .top { padding: 10px 16px; }
  .tagline { display: none; }
  .tabs-tools { margin-left: 0; }
  .gal-bar .hint { margin-left: 0; }
}
@media (max-width: 560px) {
  .prompt-row { grid-template-columns: minmax(0, 1fr); grid-template-areas: "title" "text" "tags" "count"; }
  .pr-count { justify-items: start; margin-top: 4px; }
  .row { grid-template-columns: 1fr; }
  .ph-title h1, .list-head h1 { font-size: 23px; }
  .gallery { justify-content: center; }
}
