/* BlueStar admin. A work tool: warm paper surfaces, one ink-blue accent for the action that matters on each screen,
   hashes and ids in monospace because they are data to be compared character by character.
   System fonts only: the page CSP has no font-src and a tool should not wait for a webfont.
   Dials: ENERGY 1 / RHYTHM 2 / MOTION 1 (hover and focus only). */
:root {
  color-scheme: light;
  --bg: #e9e6df;
  --panel: #f8f7f3;
  --panel-2: #efede6;
  --line: #d6d2c6;
  --line-strong: #b9b4a5;
  --text: #1b1f27;
  --muted: #565c68;
  --accent: #1f47c9;
  --accent-hover: #17389f;
  --accent-ink: #ffffff;
  --accent-soft: #dfe6fa;
  --danger: #a32a20;
  --danger-soft: #f6dcd8;
  --ok: #1b6a42;
  --ok-soft: #d8eee1;
  --warn: #7d5200;
  --warn-soft: #f5e6bf;
  --nav: #1b1f27;
  --nav-text: #c8ccd4;
  --nav-w: 208px;
  --radius: 6px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.wrap { overflow-wrap: anywhere; }
h1 { font-size: 22px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 12.5px; color: var(--muted); font-weight: 700; margin: 20px 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.hint-inline { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; margin: 6px 0; }
.error { color: var(--danger); margin: 8px 0 0; }
.pad { padding: 8px 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.notice { background: var(--warn-soft); color: #4d3200; border: 1px solid #dcc27a; border-radius: var(--radius); padding: 8px 12px; margin: 0 0 14px; font-size: 13.5px; }

/* Controls */
input, textarea, select {
  width: 100%;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 9px;
  font: inherit;
}
input::placeholder, textarea::placeholder { color: #6d727d; }
input:hover:not(:disabled), textarea:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--text); }
input:disabled, textarea:disabled, select:disabled { background: var(--panel-2); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
input[aria-invalid="true"] { border-color: var(--danger); }
textarea { resize: vertical; }
select { cursor: pointer; }
input[type="checkbox"], input[type="radio"] { cursor: pointer; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
label[for], label.switch { cursor: pointer; }
.btn {
  display: inline-block;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 13px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #fff; border-color: var(--text); }
.btn:active { background: var(--panel-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; background: var(--panel-2); border-color: var(--line); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: #112c7d; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 9px; }
.btn-quiet:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-quiet:active { background: var(--line); }
.btn-quiet:disabled { background: transparent; border-color: transparent; }
.btn-danger { background: transparent; border-color: #cf8d86; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger:active { background: #efc6c0; }
.btn-danger:disabled { background: transparent; border-color: #e3bbb6; }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger-solid:hover { background: #82201a; border-color: #82201a; }
.btn-danger-solid:active { background: #66180f; }
.danger-text { color: var(--danger); }
.btn-nav { background: transparent; color: var(--nav-text); border-color: #3b424e; width: 100%; }
.btn-nav:hover { background: #2a303b; color: #fff; border-color: #5a6372; }
.btn-nav:active { background: #353c49; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; padding: 28px 28px 24px; }
.login-brand, .nav-brand { margin: 0 0 18px; font-weight: 800; font-size: 15px; letter-spacing: -0.005em; }
.login-brand span, .nav-brand span { color: var(--muted); font-weight: 600; }
.nav-brand span { color: #8f97a5; }
.lead { color: var(--muted); margin: 0 0 20px; }
.login-card .hint { margin-top: 16px; }

/* Shell: dark rail on the left carries navigation; the stage holds one view at a time */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
.nav {
  background: var(--nav); color: var(--nav-text);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px 14px;
}
.nav-brand { color: #fff; padding: 0 8px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; flex: 1; align-content: start; }
.nav-list a {
  display: block; padding: 8px 10px; border-radius: var(--radius);
  color: var(--nav-text); text-decoration: none; font-weight: 600;
}
.nav-list a:hover { background: #2a303b; color: #fff; }
.nav-list a:active { background: #353c49; }
.nav-list a[aria-current="page"] { background: #fff; color: var(--text); }
.nav a:focus-visible, .nav button:focus-visible { outline-color: #9db4ff; }
.nav-foot { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid #333a46; }
.nav-user { font-size: 13px; padding: 0 4px; overflow-wrap: anywhere; }
.stage { min-width: 0; padding-bottom: 76px; }
.view { padding: 22px clamp(16px, 2.6vw, 32px) 32px; }
#view-catalog { padding: 0; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

/* Facts list (settings, licence detail) */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 14px 0 0; font-size: 13.5px; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; min-width: 0; }
.facts-wide { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; max-width: 760px; }

/* Membership stats: one ruled strip, numbers in tabular figures, no cards */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 0 0 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stat { padding: 10px 14px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat dd { margin: 2px 0 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Tables */
.list-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.list-search { flex: 1 1 260px; max-width: 380px; }
.list-bar .seg { flex: none; }
.list-bar .seg button { padding: 6px 12px; }
.tbl-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; transition: opacity 120ms; }
.tbl-wrap.is-loading { opacity: 0.6; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 6px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.tbl td { padding: 5px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.num { text-align: right; }
.col-src { white-space: nowrap; }
.tbl tbody tr.lic:hover { background: #fff; }
.tbl tr.is-open td { background: var(--accent-soft); border-bottom-color: #b5c3ef; }
.cell-end { text-align: right; }
.row-toggle {
  background: transparent; border: 0; padding: 3px 6px; margin: -3px -6px; border-radius: 4px;
  color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.row-toggle:hover { background: var(--accent-soft); }
.row-toggle:active { background: #c9d5f5; }
.state { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 4px; }
.state-active { background: var(--ok-soft); color: var(--ok); }
.state-expired { background: var(--warn-soft); color: var(--warn); }
.state-revoked { background: var(--danger-soft); color: var(--danger); }
.col-note { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-row td { padding: 0; background: var(--panel-2); }
.detail { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 8px 28px; padding: 6px 16px 18px; }
.detail h3 { margin-top: 12px; }
.tbl-inner { background: var(--panel); border: 1px solid var(--line); }
.tbl-inner tbody tr:last-child td { border-bottom: 0; }
.tbl-inner td { border-bottom: 1px solid var(--line); }
.actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.actions .row { gap: 6px; }
.days { width: 76px; }
.more { padding: 10px; text-align: center; border-top: 1px solid var(--line); }
.state-box { background: var(--panel); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 20px; text-align: center; color: var(--muted); }
.state-box p { margin: 0 auto 10px; max-width: 460px; }
.state-box-error { border-style: solid; border-color: #cf8d86; color: var(--danger); }
.code-out { font-family: var(--mono); font-size: 18px; font-weight: 700; letter-spacing: 0.04em; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0 4px; user-select: all; overflow-wrap: anywhere; }

/* Catalog: list and editor side by side, stacked on narrow screens */
.app { display: grid; grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); min-height: 100vh; }
.games { border-right: 1px solid var(--line-strong); background: var(--panel); padding: 18px 14px; }
.editor { padding: 22px clamp(16px, 2.6vw, 32px) 40px; max-width: 1000px; }
.back { display: none; margin-bottom: 8px; }

.add-form { margin-bottom: 16px; }
.add-form .row { flex-wrap: nowrap; }
.list-tools { display: grid; gap: 8px; margin-bottom: 10px; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: #fff; }
.seg button {
  flex: 1; background: transparent; color: var(--muted); border: 0; padding: 6px; font: inherit; font-size: 13px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { background: var(--panel-2); color: var(--text); }
.seg button:active { background: var(--line); }
.seg button[aria-pressed="true"]:hover { background: #000; color: #fff; }
.seg button[aria-pressed="true"] { background: var(--text); color: #fff; }
.seg button:focus-visible { outline-offset: -3px; }
.seg.source { margin-bottom: 12px; }

.game-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.game-item {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  padding: 5px; color: inherit; font: inherit; cursor: pointer;
}
.game-item:hover { background: var(--panel-2); }
.game-item:active { background: var(--line); }
.game-item[aria-current="true"] { background: var(--accent-soft); border-color: #a9b9ee; }
.game-item img { width: 92px; height: 43px; object-fit: cover; border-radius: 3px; background: var(--line); flex: none; }
.game-meta { display: grid; min-width: 0; flex: 1; }
.game-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-sub { color: var(--muted); font-size: 12.5px; font-family: var(--mono); }
.tag { font-size: 11.5px; font-weight: 700; border-radius: 4px; padding: 1px 6px; flex: none; }
.tag-hidden { background: var(--warn-soft); color: var(--warn); }

/* Editor */
.editor-empty { color: var(--muted); padding-top: 12vh; max-width: 420px; }
.editor-empty h2 { color: var(--text); margin-bottom: 6px; }
.editor-head { display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: 20px; align-items: start; margin-bottom: 20px; }
.header-preview { width: 100%; height: auto; aspect-ratio: 460 / 215; object-fit: cover; border-radius: var(--radius); background: var(--line); }
.appid { margin: 0 0 12px; color: var(--muted); font-family: var(--mono); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14.5px; font-weight: 400; margin: 0; }
.switch input { width: 17px; height: 17px; accent-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.field.wide { grid-column: 1 / -1; }
.field.end { display: flex; align-items: end; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 30px 0 12px; padding-top: 14px; border-top: 1px solid var(--line-strong); }

.presets { display: grid; gap: 14px; }
.preset { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px 16px; }
.preset:first-child { border-color: var(--line-strong); }
.preset-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.preset-num { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.preset:first-child .preset-num { color: var(--accent); }
.preset > .field { margin-top: 18px; }

.pairs { display: grid; gap: 6px; justify-items: start; }
.pair { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: 6px; width: 100%; }
.mods { display: grid; gap: 10px; justify-items: start; }
.mod { width: 100%; padding: 10px 0; border-top: 1px solid var(--line); }
.danger-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line-strong); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 3px 1px 8px; font-size: 13px; }
.chip-x { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 3px 5px; }
.chip-x:hover { color: var(--danger); }
.chip-x:active { color: #66180f; }
.builds { display: grid; gap: 8px; justify-items: start; }
.build-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; width: 100%; }
.build-row, .explore-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.by-date { flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 4px; }
.by-date label { width: 100%; margin: 0; }
.by-date input, .by-date select { width: auto; }
.refix-mod-list { display: grid; gap: 6px; margin: 6px 0 4px 28px; }
/* A header that failed to load (src removed by app.js) keeps its space but not the broken-image glyph. */
img:not([src]) { visibility: hidden; }

/* Publish bar: the one place the accent fills a button in the catalog */
.publish-bar {
  position: fixed; left: var(--nav-w); right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px clamp(16px, 2.6vw, 32px);
  background: var(--panel); border-top: 2px solid var(--text);
}
body:not([data-view="catalog"]) .publish-bar { display: none; }
#pending-text { font-weight: 600; }

.dialog {
  width: min(560px, 94vw); background: var(--panel); color: var(--text);
  border: 1px solid var(--text); border-radius: 8px; padding: 22px;
}
.dialog-sm { width: min(440px, 94vw); }
.dialog::backdrop { background: rgba(27, 31, 39, 0.55); }
.dialog h2 { margin-bottom: 12px; }
.summary, .error-list { margin: 0 0 16px; padding-left: 18px; }
.error-list { color: var(--danger); }
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: #fff; border-radius: var(--radius);
  padding: 9px 16px; margin: 0; max-width: 92vw; font-size: 13.5px;
}

/* Tablet and below: the rail becomes a top bar; the catalog list and editor stack */
@media (max-width: 1100px) {
  .col-note { display: none; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4) { border-left: 0; }
  .stat:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px; }
  .nav-brand { margin: 0; }
  .nav-list { display: flex; flex: 1; gap: 4px; flex-wrap: wrap; }
  .nav-foot { display: flex; align-items: center; border: 0; padding: 0; }
  .btn-nav { width: auto; }
  .publish-bar { left: 0; }
  .app { grid-template-columns: 1fr; min-height: 0; }
  .games { border-right: 0; border-bottom: 1px solid var(--line-strong); }
  body.editing .games { display: none; }
  body:not(.editing) .editor { display: none; }
  .back { display: inline-block; }
  .editor-head { grid-template-columns: 1fr; }
  .pair { grid-template-columns: 1fr; }
  .detail { grid-template-columns: 1fr; }
  .list-search { max-width: none; flex-basis: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat, .stat:nth-child(4) { border-left: 0; border-top: 1px solid var(--line); }
  .stat:nth-child(odd) { border-right: 1px solid var(--line); }
  .stat:nth-child(-n+2) { border-top: 0; }
}
@media (max-width: 520px) {
  .btn, .seg button { padding: 10px 14px; min-height: 44px; }
  .list-bar .seg { width: 100%; }
  .tbl td, .tbl th { padding-inline: 8px; }
  .nav-list a { padding: 10px; }
  .view { padding-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
