:root {
  --bg: #0d1013;
  --bg-2: #13171b;
  --panel: #171c21;
  --panel-2: #1d232a;
  --line: #2a323b;
  --line-2: #38424d;
  --text: #e6e9ec;
  --muted: #8b96a1;
  --dim: #5d6873;
  --accent: #f0b429;
  --accent-ink: #1a1405;
  --danger: #e5534b;
  --ok: #57ab5a;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --r: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(240, 180, 41, 0.06), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(13, 16, 19, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font: 600 17px/1.1 var(--mono); letter-spacing: 0.06em; }
.brand-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex: none; }

.btn {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 500; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--panel-2); border-color: var(--dim); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(229,83,75,.4); background: transparent; }
.btn.danger:hover { background: rgba(229,83,75,.1); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--danger); }
.icon-btn { background: none; border: 1px solid transparent; color: var(--muted); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* Controls */
.controls { padding: 28px 0 8px; }
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 0 14px; height: 52px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240,180,41,.15); }
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; font-size: 16px; }
.search input::-webkit-search-cancel-button { filter: invert(.6); }
kbd { font: 12px var(--mono); color: var(--muted); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 7px; }

.filter-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.chip:hover { border-color: var(--dim); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--zc, var(--muted)); }
.chip .n { font: 12px var(--mono); color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on .n { color: var(--bg); opacity: .6; }
.selects { display: flex; gap: 8px; }
select {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 7px 10px; font-size: 13.5px; cursor: pointer;
}
.result-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.result-line #resultCount { font-family: var(--mono); color: var(--text); }
.note { color: var(--dim); }

/* Grid */
.grid {
  display: grid; gap: 14px; padding: 12px 0 40px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  position: relative; text-align: left; cursor: pointer;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  overflow: hidden;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--zc);
}
.card:hover { border-color: var(--line-2); transform: translateY(-2px); box-shadow: 0 10px 30px -12px rgba(0,0,0,.6); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-name { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.card-loc { font: 12px var(--mono); color: var(--muted); margin-top: 3px; }
.card-loc b { color: var(--zc); font-weight: 600; }
.card-spot { color: #c4cbd2; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: auto; }
.aka { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
mark { background: rgba(240,180,41,.28); color: inherit; border-radius: 2px; padding: 0 1px; }

.status {
  font: 600 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid currentColor; border-radius: 4px; padding: 2px 6px; flex: none;
}
.status.Active { color: var(--ok); }
.status.Contested { color: var(--accent); }
.status.Regional { color: #b083f0; }
.status.Deprecated { color: var(--dim); text-decoration: line-through; }

.pips { display: inline-flex; gap: 3px; flex: none; }
.pips i { width: 14px; height: 5px; border-radius: 2px; background: var(--line-2); }
.pips i.on { background: var(--pc); }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty-title { font-size: 18px; color: var(--text); font-weight: 600; margin-bottom: 6px; }

.foot {
  border-top: 1px solid var(--line); padding-top: 18px; padding-bottom: 28px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; color: var(--dim); font-size: 13px;
}
.foot-actions { display: flex; gap: 16px; }

/* Modals */
.modal {
  border: 1px solid var(--line-2); border-radius: 14px; padding: 0;
  background: var(--panel); color: var(--text);
  width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.8);
}
.modal::backdrop { background: rgba(5,7,9,.72); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }

/* Detail */
.d-hero { padding: 22px 22px 18px; border-bottom: 1px solid var(--line); position: relative; }
.d-hero::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--zc); }
.d-kicker { font: 12px var(--mono); color: var(--muted); letter-spacing: .04em; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.d-kicker b { color: var(--zc); }
.d-name { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 4px; line-height: 1.1; }
.d-aka { color: var(--muted); font-size: 14px; }
.d-close { position: absolute; top: 14px; right: 14px; }
.d-body { padding: 20px 22px 8px; display: grid; gap: 20px; }
.d-section h3 { margin: 0 0 8px; font: 600 11.5px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.d-section p { margin: 0; }
.d-spot { background: var(--bg-2); border: 1px solid var(--line); border-left: 3px solid var(--zc); border-radius: 8px; padding: 12px 14px; }
.d-story { font-size: 15.5px; line-height: 1.7; color: #d5dade; }
.d-tactics { background: rgba(240,180,41,.06); border: 1px solid rgba(240,180,41,.2); border-radius: 8px; padding: 12px 14px; }
.d-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.d-meta > div { background: var(--bg-2); padding: 10px 12px; }
.d-meta dt { font: 11px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
.d-meta dd { margin: 3px 0 0; font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font: 12px var(--mono); color: var(--muted); background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px; cursor: pointer; }
.tag:hover { color: var(--text); border-color: var(--line-2); }

/* Form */
#editForm { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.form-grid { padding: 18px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; overflow-y: auto; }
.form-grid label, .form-grid .label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.span2 { grid-column: span 2; }
.hint { font-weight: 400; color: var(--dim); }
.form-grid input:not([type=range]), .form-grid select, .form-grid textarea {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; font-size: 14px; color: var(--text); font-weight: 400;
}
.form-grid textarea { resize: vertical; line-height: 1.5; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: none; border-color: var(--accent); }
input[type=range] { accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .brand-sub { display: none; }
  #randomBtn { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .d-name { font-size: 28px; }
  .selects { width: 100%; }
  .selects select { flex: 1; }
  .note { display: none; }
}
