/* Fief Platform web UI - shared styles (player + admin). No inline styles anywhere: CSP style-src 'self'. */

:root {
  color-scheme: light dark;
  --bg: #f4f2ee;
  --bg-elev: #ffffff;
  --bg-sunk: #e9e6e0;
  --fg: #1d1b18;
  --fg-muted: #5f5a52;
  --border: #d3cec5;
  --accent: #8a5a12;
  --accent-fg: #ffffff;
  --accent-soft: #f3e6cf;
  --danger: #b3261e;
  --danger-soft: #fbe1de;
  --ok: #2e7d32;
  --ok-soft: #dcefdc;
  --warn: #8a6100;
  --warn-soft: #fbefcc;
  --focus: #1a5fd0;
  --mark: #ffe066;
  --mark-fg: #1d1b18;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 4px 12px rgb(0 0 0 / 0.06);

  /* CS2-style rarity colours */
  --r-common: #8f9aa6;
  --r-uncommon: #5e98d9;
  --r-rare: #4b69ff;
  --r-epic: #8847ff;
  --r-legendary: #d9a22e;

  --radius: 8px;
  --gutter: 16px;
  --maxw: 1200px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --bg-elev: #201e18;
    --bg-sunk: #0f0e0b;
    --fg: #ece8df;
    --fg-muted: #a59f93;
    --border: #3a362d;
    --accent: #e0a64a;
    --accent-fg: #1a1408;
    --accent-soft: #3a2c14;
    --danger: #ff8a80;
    --danger-soft: #3d1a17;
    --ok: #81c784;
    --ok-soft: #1b3320;
    --warn: #ffd166;
    --warn-soft: #3a2f10;
    --focus: #7fb0ff;
    --mark: #8a6d00;
    --mark-fg: #fff7d6;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.3);
    --r-common: #b0c3d9;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--gutter); top: -100px; z-index: 100;
  background: var(--accent); color: var(--accent-fg); padding: 8px 12px; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

/* ---------- layout ---------- */

.site-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.site-header .inner {
  max-width: var(--maxw); margin: 0 auto; padding: 8px var(--gutter);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; margin-right: auto; }
.brand .tag { font-weight: 500; font-size: 0.75rem; color: var(--fg-muted); margin-left: 6px; }

.nav { width: 100%; order: 3; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.nav a {
  display: block; padding: 6px 10px; border-radius: var(--radius); text-decoration: none; color: var(--fg-muted);
}
.nav a:hover { background: var(--bg-sunk); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--fg); font-weight: 600; }

.auth-area { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.auth-area .who { color: var(--fg-muted); font-size: 0.9rem; }

main {
  flex: 1; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 20px var(--gutter) 40px;
}
main:focus { outline: none; }

.site-footer {
  border-top: 1px solid var(--border); color: var(--fg-muted); font-size: 0.85rem;
}
.site-footer .inner { max-width: var(--maxw); margin: 0 auto; padding: 12px var(--gutter); display: flex; flex-wrap: wrap; gap: 8px 16px; }

.mock-banner {
  background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 0.85rem; padding: 4px var(--gutter);
  border-bottom: 1px solid var(--border);
}

/* admin layout: sidebar on wide screens */
.admin-shell { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.admin-shell > * { min-width: 0; }
@media (min-width: 900px) {
  .admin-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .admin-shell .nav ul { flex-direction: column; }
}
.admin-shell .nav { order: 0; }

/* ---------- components ---------- */

.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.muted { color: var(--fg-muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.spacer { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--bg-sunk); border-radius: var(--radius); padding: 12px; }
.stat .label { font-size: 0.8rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 1.5rem; font-weight: 700; }

.btn {
  font: inherit; font-size: 0.95rem; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--fg);
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--bg-sunk); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 0.85rem; }
.btn.steam { background: #1b2838; color: #fff; border-color: #1b2838; }
.btn.discord { background: #5865f2; color: #fff; border-color: #5865f2; }
@media (prefers-color-scheme: dark) {
  .btn.steam { background: #2a475e; border-color: #66c0f4; }
}

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--bg-sunk); color: var(--fg-muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--fg); border-color: transparent; }

.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--bg-sunk); border-left: 4px solid var(--border); margin-bottom: 12px; }
.notice.info { border-left-color: var(--focus); }
.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.error { border-left-color: var(--danger); background: var(--danger-soft); }
.notice.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.notice .detail { display: block; font-size: 0.85rem; color: var(--fg-muted); margin-top: 2px; }

/* ---------- forms ---------- */

label { font-size: 0.9rem; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field .hint { font-weight: 400; font-size: 0.8rem; color: var(--fg-muted); }
.field .err { font-weight: 500; font-size: 0.8rem; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: end; }

input[type="text"], input[type="search"], input[type="number"], input[type="datetime-local"], input:not([type]),
select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; min-height: 38px; width: 100%;
}
textarea { min-height: 120px; font-family: var(--mono); font-size: 0.85rem; resize: vertical; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); outline-color: var(--danger); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }

/* ---------- tables ---------- */

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-sunk); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td input, td select { min-height: 32px; padding: 4px 8px; }
tr.changed td { background: var(--accent-soft); }
td.chat-text { word-break: break-word; min-width: 220px; }
mark { background: var(--mark); color: var(--mark-fg); border-radius: 2px; padding: 0 1px; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }

/* ---------- dialogs & toasts ---------- */

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--fg);
  padding: 20px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toasts {
  position: fixed; right: var(--gutter); bottom: var(--gutter); left: var(--gutter); z-index: 50;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 420px; width: 100%; background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--border); border-left: 4px solid var(--focus); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.toast .detail { display: block; font-size: 0.85rem; color: var(--fg-muted); }

/* ---------- items ---------- */

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
@media (max-width: 420px) { .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.item {
  --rc: var(--r-common);
  position: relative; display: flex; flex-direction: column; text-align: left;
  background: var(--bg-elev); color: var(--fg); border: 1px solid var(--border); border-radius: var(--radius);
  border-bottom: 4px solid var(--rc); overflow: hidden; font: inherit; padding: 0; min-width: 0;
}
button.item { cursor: pointer; }
button.item:hover { border-color: var(--rc); }
.item[aria-pressed="true"], .item.selected { outline: 3px solid var(--rc); outline-offset: -1px; }
.item .thumb {
  aspect-ratio: 1 / 1; width: 100%; object-fit: contain; display: block;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--rc) 35%, transparent), transparent 70%), var(--bg-sunk);
}
.item .meta { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item .name { font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 0.75rem; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .rarity-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--rc); }
.item .equipped { position: absolute; top: 6px; right: 6px; }

.rarity-common { --rc: var(--r-common); }
.rarity-uncommon { --rc: var(--r-uncommon); }
.rarity-rare { --rc: var(--r-rare); }
.rarity-epic { --rc: var(--r-epic); }
.rarity-legendary { --rc: var(--r-legendary); }
.rarity-text { color: var(--rc); font-weight: 700; }
.rarity-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--rc); margin-right: 4px; vertical-align: baseline; }

/* loadout */
.loadout { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.slot { background: var(--bg-sunk); border-radius: var(--radius); padding: 10px; display: flex; gap: 10px; align-items: center; min-width: 0; }
.slot img { width: 56px; height: 56px; object-fit: contain; border-radius: 6px; background: var(--bg-elev); flex: none; }
.slot .info { flex: 1; min-width: 0; }
.slot .info select { margin-top: 4px; }

/* ---------- crate reel ---------- */

.reel-window {
  position: relative; overflow: hidden; height: 168px; border-radius: var(--radius);
  background: var(--bg-sunk); border: 1px solid var(--border); margin: 12px 0;
}
.reel-window::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; margin-left: -1px;
  background: var(--r-legendary); box-shadow: 0 0 8px var(--r-legendary); z-index: 2;
}
.reel { display: flex; gap: 8px; padding: 12px 0; will-change: transform; }
.reel .item { flex: 0 0 132px; width: 132px; }
.reel .item .thumb { aspect-ratio: auto; height: 92px; }
.reel-result { text-align: center; }
.reel-result .item { max-width: 220px; margin: 0 auto 8px; }
.reel-result .item.revealed { animation: pop 360ms ease-out; }
@keyframes pop { from { transform: scale(0.85); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .reel-result .item.revealed { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* ---------- servers / votes ---------- */

.state-running, .state-online { color: var(--ok); }
.state-stopped, .state-offline, .state-deallocated { color: var(--fg-muted); }
.state-starting, .state-stopping { color: var(--warn); }

.bar { height: 8px; background: var(--bg-sunk); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); width: 0; }

.vote-options { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.vote-option { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.vote-option .bar { grid-column: 2 / 4; }

/* ---------- QR ---------- */
.qr-box { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.qr-box canvas { background: #fff; padding: 8px; border-radius: var(--radius); width: 216px; height: 216px; image-rendering: pixelated; }

/* ---------- diff ---------- */
.diff-old { color: var(--danger); text-decoration: line-through; word-break: break-all; }
.diff-new { color: var(--ok); font-weight: 600; word-break: break-all; }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 12px; }
  .stat .value { font-size: 1.25rem; }
}

/* ---------- small additions ---------- */
.err { color: var(--danger); }
.small.err { font-size: 0.85rem; }
.thumb-sm { width: 40px; height: 40px; object-fit: contain; border-radius: 4px; background: var(--bg-sunk); display: block; }
.row > input, .row > select { flex: 1 1 160px; width: auto; min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled .vote-option label { color: var(--fg-muted); }
#alert-badge .badge { margin-left: 2px; }
