:root {
  --bg: #121316;
  --panel: #1b1d22;
  --panel-2: #23262d;
  --line: #33363f;
  --text: #e6e6e8;
  --muted: #9a9ca6;
  --accent: #c22b2b;
  --accent-2: #8b1a1a;
  --good: #3fb67b;
  --warn: #e0a73c;
  --bad: #ef5a5a;
  --focus: #6aa7ff;
  --radius: 6px;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 20px; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: #f0d6d6; }
a { color: var(--focus); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: #0c0d0f; border-bottom: 2px solid var(--accent-2);
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark {
  background: var(--accent); color: #fff; font-weight: 800; letter-spacing: .08em;
  padding: 2px 8px; border-radius: 4px; clip-path: polygon(0 0, 100% 0, 92% 100%, 0 100%);
}
.brand-text { font-weight: 600; }
.char-title { flex: 1; font-weight: 600; color: #f0d6d6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.budgets {
  position: sticky; top: 49px; z-index: 19;
  display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px;
  background: #16181c; border-bottom: 1px solid var(--line);
}
.chip {
  display: flex; flex-direction: column; min-width: 78px; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.chip .label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chip .value { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip.ok .value { color: var(--good); }
.chip.left .value { color: var(--warn); }
.chip.over { border-color: var(--bad); }
.chip.over .value { color: var(--bad); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 110px); }
.steps { border-right: 1px solid var(--line); padding: 12px 8px; background: #15161a; }
.steps-inner { position: sticky; top: 124px; }
.steps button {
  display: flex; width: 100%; align-items: center; gap: 8px; text-align: left;
  padding: 9px 10px; margin-bottom: 2px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; font: inherit;
}
.steps button:hover { background: var(--panel-2); }
.steps button.active { background: var(--accent-2); color: #fff; }
.steps .n { width: 20px; height: 20px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--panel-2); color: var(--muted); }
.steps button.active .n { background: #fff; color: var(--accent-2); }
.steps .badge { margin-left: auto; font-size: 11px; min-width: 18px; padding: 0 5px; border-radius: 9px; text-align: center; }
.steps .badge.err { background: var(--bad); color: #fff; }
.steps .badge.wrn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }

main { padding: 20px 24px 60px; max-width: 1280px; }
.step-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.step-head p { margin: 0; color: var(--muted); }
.step-foot { display: flex; justify-content: space-between; margin-top: 24px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel > h3:first-child { margin-top: 0; }
.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.cols-2-1 { display: grid; gap: 14px; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); align-items: start; }

/* ---------- controls ---------- */
.btn {
  font: inherit; cursor: pointer; border-radius: var(--radius); border: 1px solid var(--accent);
  background: var(--accent); color: #fff; padding: 6px 12px; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.danger { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger:hover { color: var(--bad); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }

input[type=text], input[type=number], input:not([type]), select, textarea {
  font: inherit; color: var(--text); background: #0f1013; border: 1px solid var(--line);
  border-radius: 4px; padding: 5px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.field input, label.field select, label.field textarea { font-size: 14px; }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.fields .wide { grid-column: span 2; }
.fields .full { grid-column: 1 / -1; }
.search { width: 100%; margin-bottom: 8px; }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.stepper button { width: 24px; height: 26px; border: 0; background: var(--panel-2); color: var(--text); cursor: pointer; font: inherit; }
.stepper button:hover { background: var(--accent-2); }
.stepper button:disabled { opacity: .3; cursor: default; background: var(--panel-2); }
.stepper span { min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
table.grid tr.cat td { background: var(--panel-2); font-weight: 600; color: #f0d6d6; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
table.grid tr.dim td { color: var(--muted); }
table.grid tr.rated td:first-child { color: #fff; font-weight: 600; }
table.grid td input[type=text], table.grid td input:not([type]) { width: 100%; }
.table-scroll { overflow-x: auto; }
.catalog { max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.catalog table.grid th { position: sticky; top: 0; background: var(--panel); z-index: 1; }

/* ---------- priority table ---------- */
.priority-table { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.priority-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.priority-table th.lvl { width: 36px; font-size: 18px; color: var(--text); }
.priority-table td {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; vertical-align: top; cursor: pointer; font-size: 12px;
}
.priority-table td:hover { border-color: var(--muted); }
.priority-table td.sel { background: #3a1414; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.priority-table td .big { font-size: 16px; font-weight: 700; display: block; }

.cards { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.card {
  text-align: left; font: inherit; color: var(--text); cursor: pointer;
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.card:hover:not(:disabled) { border-color: var(--muted); }
.card.sel { border-color: var(--accent); background: #3a1414; }
.card:disabled { opacity: .35; cursor: not-allowed; }
.card b { display: block; margin-bottom: 2px; }
.card small { color: var(--muted); }

/* ---------- misc ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { font: inherit; padding: 5px 10px; border-radius: 4px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; }
.tabs button.active { background: var(--accent-2); border-color: var(--accent); color: #fff; }
.tabs .count { color: var(--muted); font-size: 11px; margin-left: 4px; }
.tabs button.active .count { color: #f0d6d6; }

.stat-list { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.stat-list dt { color: var(--muted); }
.stat-list dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.issues { list-style: none; padding: 0; margin: 0; }
.issues li { padding: 6px 10px; border-left: 3px solid var(--warn); background: #221d14; margin-bottom: 4px; border-radius: 0 4px 4px 0; }
.issues li.error { border-left-color: var(--bad); background: #2a1616; }
.issues li .where { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-right: 6px; cursor: pointer; text-decoration: underline; }
.callout { padding: 10px 12px; border-radius: var(--radius); background: #1d2430; border: 1px solid #2f3b50; margin-bottom: 12px; }
.callout.ok { background: #14261d; border-color: #24533b; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 9px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.tag.r { border-color: var(--warn); color: var(--warn); }
.tag.f { border-color: var(--bad); color: var(--bad); }
.tag.free { border-color: var(--good); color: var(--good); }
.indent td:first-child { padding-left: 26px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(640px, 100%); max-height: 85vh; overflow: auto; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; background: #000; border: 1px solid var(--accent); padding: 8px 16px; border-radius: var(--radius); }

/* ---------- beginner guidance ---------- */
body.tips-off .tip { display: none !important; }
.term { border-bottom: 1px dotted currentColor; cursor: help; }
.term:hover { color: #fff; border-bottom-style: solid; }
.chip[data-act] { cursor: help; }
.chip[data-act]:hover { border-color: var(--muted); }
.star { color: var(--warn); }
td .tip { margin-top: 2px; font-weight: 400; }
table.grid tr.rated td:first-child .tip { color: var(--muted); font-weight: 400; }
.priority-table th .tip { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11px; margin-top: 3px; }
.card .card-desc { display: block; margin-top: 6px; }

.guide { background: #1a1f28; border: 1px solid #2f3b50; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.guide summary { cursor: pointer; font-weight: 600; color: #cfe0ff; }
.guide[open] summary { margin-bottom: 8px; }
.guide p { margin: 0 0 8px; }
.guide ul { margin: 0 0 8px; padding-left: 20px; }
.guide li { margin-bottom: 3px; }
.guide .role-advice { margin: 10px 0 6px; padding-top: 8px; border-top: 1px solid #2f3b50; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-s { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 9px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); font-size: 13px; }
.chip-s .tag { margin-left: 0; margin-right: 4px; }

.role-detail { margin-top: 12px; padding: 12px; border: 1px solid var(--accent); border-radius: var(--radius); background: #221416; }
.role-stats { grid-template-columns: auto 1fr; margin-bottom: 8px; }
.role-stats dd { text-align: left; font-weight: 400; }

.modal.wide { width: min(780px, 100%); }
.modal h4 { margin: 14px 0 6px; color: #f0d6d6; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 0 0 10px; }
.help-body li { margin-bottom: 4px; }
.glossary { margin: 0; }
.glossary > div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 2px 0 0; color: var(--muted); }
.type-list { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 10px; }
.type-list dt { font-weight: 600; color: var(--text); }
.type-list dd { margin: 0; }

/* ---------- printable sheet ---------- */
.sheet {
  --s-ink: #1a1a1a; --s-red: #7a1414; --s-line: #b9b9b9;
  background: #fff; color: var(--s-ink); padding: 18px; border-radius: var(--radius);
  font-size: 11px; line-height: 1.3; color-scheme: light;
}
.sheet .s-head { display: flex; align-items: flex-end; gap: 16px; border-bottom: 3px solid var(--s-red); padding-bottom: 6px; margin-bottom: 10px; }
.sheet .s-logo { font-size: 26px; font-weight: 900; letter-spacing: .08em; color: var(--s-red); font-style: italic; }
.sheet .s-who { flex: 1; display: grid; grid-template-columns: auto 1fr; gap: 0 8px; font-size: 12px; }
.sheet .s-who b { color: var(--s-red); text-transform: uppercase; font-size: 10px; align-self: end; }
.sheet .s-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet section { border: 1px solid var(--s-line); border-top: 0; margin-bottom: 10px; break-inside: avoid; }
.sheet section h4 {
  margin: 0; background: var(--s-red); color: #fff; font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; padding: 3px 8px; clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}
.sheet section .s-body { padding: 6px 8px; }
.sheet table { width: 100%; border-collapse: collapse; }
.sheet th { text-align: left; font-size: 9px; text-transform: uppercase; color: var(--s-red); border-bottom: 1px solid var(--s-ink); padding: 2px 3px; }
.sheet td { border-bottom: 1px solid var(--s-line); padding: 2px 3px; }
.sheet .kv { display: grid; grid-template-columns: repeat(2, auto 1fr); gap: 2px 8px; }
.sheet .kv.three { grid-template-columns: repeat(3, auto 1fr); }
.sheet .kv b { color: var(--s-red); font-size: 10px; text-transform: uppercase; white-space: nowrap; }
.sheet .kv span { border-bottom: 1px solid var(--s-line); min-height: 14px; }
.sheet .boxes { display: flex; flex-wrap: wrap; gap: 2px; width: 156px; }
.sheet .boxes i { width: 24px; height: 18px; border: 1px solid var(--s-ink); display: inline-block; position: relative; font-style: normal; font-size: 8px; }
.sheet .boxes i.x { background: #444; }
.sheet .boxes i.mod::after { content: attr(data-m); position: absolute; right: 1px; bottom: 0; }
.sheet .cm { display: flex; gap: 18px; }
.sheet .cm div > b { display: block; color: var(--s-red); font-size: 10px; text-transform: uppercase; margin-bottom: 3px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: static; flex-wrap: wrap; }
  .steps { border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  .steps-inner { position: static; display: flex; overflow-x: auto; }
  .steps button { width: auto; white-space: nowrap; }
  .cols-2-1 { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .budgets { position: static; }
  .sheet .s-cols { grid-template-columns: 1fr; }
  .fields .wide { grid-column: auto; }
}

@media print {
  @page { margin: 10mm; }
  body { background: #fff; }
  .no-print, .step-head, .step-foot, .export-panel, .guide { display: none !important; }
  .layout { display: block; }
  main { padding: 0; max-width: none; }
  .sheet { padding: 0; border-radius: 0; }
  .sheet .s-cols { grid-template-columns: 1fr 1fr; }
}
