:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #646b78;
  --line: #e2e5ea;
  --line-strong: #cfd4dc;
  --accent: #2f5fb3;
  --accent-soft: #e9f0fb;
  --danger: #b42318;
  --radius: 10px;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; }
.top-actions { display: flex; gap: 6px; }

.layout {
  display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.25fr);
  gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto;
}
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.preview { position: sticky; top: 70px; align-self: start; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.card h2 { font-size: 13px; font-weight: 650; margin: 0 0 10px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary h2 { display: inline; }
details.card summary::after { content: "Show"; float: right; color: var(--accent); font-size: 12px; }
details[open].card summary::after { content: "Hide"; }
details[open].card summary { margin-bottom: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field input, .field select {
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 9px; background: #fff; width: 100%;
}
.field input:focus, .field select:focus, .grid input:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field.inline input { width: 64px; }
.field.color input { padding: 2px; height: 34px; width: 52px; }
.field.grow { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: end; }
.check { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; }
.checks .check { margin: 0; }

button {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 7px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { background: #f1f3f6; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 6px 8px; }
button.ghost:hover { background: var(--accent-soft); }
button.icon.danger { color: var(--danger); border-color: transparent; background: transparent; align-self: end; margin-bottom: 10px; }
button:disabled { opacity: .45; cursor: default; }

.series-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.series-tabs button { padding: 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.series-tabs button.active { background: var(--accent-soft); border-color: var(--accent); }
.series-tabs .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.series-meta { display: flex; gap: 10px; align-items: flex-start; }

.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
.seg button { flex: 1; border: 0; border-radius: 0; font-size: 13px; padding: 7px 6px; white-space: normal; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.active { background: var(--accent); color: #fff; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; line-height: 1.45; }
.hint.small { font-size: 12px; margin: 0; }

.grid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; }
.grid th:last-child, .grid td:last-child { border-right: 0; }
.grid tr:last-child td { border-bottom: 0; }
.grid th { background: #f7f8fa; font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px 8px; text-align: left; white-space: nowrap; }
.grid th.x, .grid td.x { background: #fbfbfc; }
.grid th.sub { font-weight: 500; font-size: 11px; padding: 3px 8px; }
.grid input { border: 0; width: 100%; min-width: 64px; padding: 7px 8px; background: transparent; font-variant-numeric: tabular-nums; }
.grid td.del { width: 30px; text-align: center; background: #fff; }
.grid td.del button { border: 0; background: none; color: #a0a6b0; padding: 4px 6px; font-size: 15px; line-height: 1; }
.grid td.del button:hover { color: var(--danger); }
.grid-actions { display: flex; gap: 4px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

.preview-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview-img { position: relative; background: #fff; min-height: 240px; display: flex; align-items: center; justify-content: center; }
.preview-img img { width: 100%; display: block; transition: opacity .15s; }
.preview-img.loading img { opacity: .55; }
.status { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--muted); }
.status.error { position: static; color: var(--danger); background: #fef3f2; border-top: 1px solid #fecdca; padding: 10px 14px; width: 100%; font-size: 13px; }
.preview-img.has-error { flex-direction: column; }
.downloads { display: flex; gap: 6px; padding: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.stats table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
.stats th, .stats td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats th { color: var(--muted); font-weight: 600; font-size: 12px; }
.stats .series-title { font-weight: 650; margin: 14px 0 6px; }
.stats .series-title:first-child { margin-top: 0; }
.stats .removed { color: var(--danger); }
.stats .fit { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; line-height: 1.6; }
.stats .fit b { color: var(--ink); font-weight: 600; }
.stats .table-wrap { overflow-x: auto; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .preview { position: static; order: -1; }
}
@media (max-width: 520px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .top { padding: 10px 12px; }
  .seg { flex-direction: column; }
  .seg button + button { border-left: 0; border-top: 1px solid var(--line-strong); }
}
.span2 { grid-column: span 2; }

/* welcome popup */
dialog#welcome {
  border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px 18px;
  width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(16, 24, 40, .18);
  color: var(--ink);
}
dialog#welcome::backdrop { background: rgba(16, 24, 40, .35); backdrop-filter: blur(2px); }
dialog#welcome h2 { margin: 0 0 8px; font-size: 18px; letter-spacing: -0.01em; }
dialog#welcome p { margin: 0 0 12px; line-height: 1.5; }
dialog#welcome .fine { color: var(--muted); font-size: 12.5px; }
dialog#welcome form { display: flex; justify-content: flex-end; margin: 4px 0 0; }
.engine-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  background: #f7f8fa; border-radius: 8px; padding: 8px 10px; }
.engine-line.ok { color: #067647; background: #ecfdf3; }
.engine-line.bad { color: var(--danger); background: #fef3f2; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #c9ced6; border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: none; }
.engine-line.ok .spinner, .engine-line.bad .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-img .boot { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  color: var(--muted); padding: 60px 24px; font-size: 13.5px; line-height: 1.5; }
.empty[hidden] { display: none; }
.empty strong { color: var(--ink); font-size: 15px; font-weight: 600; }
.stats .placeholder { color: var(--muted); font-size: 13px; margin: 0; }
