/* ==========================================================================
   TVX NG DESIGN SYSTEM  (loaded last: tokens.css -> tvx.css -> tvx-ui.css -> this)
   ONE vocabulary for every page: gold = primary action, cyan = secondary
   action / selection / focus, slate slabs with the voxel bevel, pixel type for
   labels and the body font for reading. Layered over the existing class names
   (tvx-btn, tvx-card, CTFd .btn / .form-control / .table / .alert / .card), so
   templates and their JS hooks keep working unchanged.
   No animation loops; transitions drop under Reduce Motion.
   ========================================================================== */
:root {
  --ds-gold: #f5b942;
  --ds-gold-hi: #ffd780;
  --ds-gold-lo: #b9811c;
  --ds-gold-ink: #2a1a02;
  --ds-cyan: #22d3ee;
  --ds-cyan-hi: #7eeaff;
  --ds-cyan-lo: #0e7f95;
  --ds-cyan-ink: #032029;
  --ds-ok: #4ade80;
  --ds-warn: #fbbf24;
  --ds-bad: #ff6b6b;
  --ds-ink: #eef4f2;
  --ds-ink-2: #b3c4bd;
  --ds-ink-3: #7f938a;
  --ds-slab: #252b33;
  --ds-slab-2: #1b2027;
  --ds-slab-3: #12161b;
  --ds-line: #3a434e;
  --ds-line-hi: #56616e;
  --ds-glass: rgba(10, 14, 18, 0.86);
  --ds-bevel: inset 0 2px 0 rgba(255, 255, 255, 0.09), inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  --ds-drop: 0 3px 0 rgba(0, 0, 0, 0.45);
  --ds-focus: 0 0 0 2px #0b0f0e, 0 0 0 4px var(--ds-cyan);
  --ds-space-1: 4px; --ds-space-2: 8px; --ds-space-3: 12px; --ds-space-4: 16px; --ds-space-5: 24px; --ds-space-6: 32px;
  --ds-t: 140ms;
  --ds-font-label: var(--tvx-font-pixel, "Silkscreen", monospace);
  --ds-font-body: var(--tvx-font-body, system-ui, sans-serif);
}

/* specificity: html + two classes beats the screens' :is(...) .tvx-btn (0,2,0) */
/* ---- Buttons --------------------------------------------------------------- */
html .tvx-btn.tvx-btn-gold, html .tvx-btn.tvx-btn-primary,
.btn.btn-primary, .btn-primary:not(.tvx-btn) {
  background: linear-gradient(to bottom, var(--ds-gold-hi), var(--ds-gold) 45%, var(--ds-gold-lo));
  border: 2px solid #5a3a08;
  color: var(--ds-gold-ink);
  text-shadow: 0 1px 0 rgba(255, 236, 180, 0.45);
  box-shadow: var(--ds-bevel), var(--ds-drop);
}
html .tvx-btn.tvx-btn-gold:hover, html .tvx-btn.tvx-btn-primary:hover, .btn.btn-primary:hover {
  color: var(--ds-gold-ink);
  box-shadow: var(--ds-bevel), var(--ds-drop), 0 0 0 1px rgba(255, 214, 120, 0.7), 0 0 18px rgba(245, 185, 66, 0.35);
}
html .tvx-btn.tvx-btn-cyan, html .tvx-btn.tvx-btn-accent, .btn.btn-info, .btn.btn-outline-primary {
  background: linear-gradient(to bottom, #1d3a44, #142a32);
  border: 2px solid var(--ds-cyan-lo);
  color: var(--ds-cyan-hi);
  text-shadow: none;
  box-shadow: var(--ds-bevel), var(--ds-drop);
}
html .tvx-btn.tvx-btn-cyan:hover, html .tvx-btn.tvx-btn-accent:hover, .btn.btn-info:hover, .btn.btn-outline-primary:hover {
  color: #fff;
  border-color: var(--ds-cyan);
  box-shadow: var(--ds-bevel), var(--ds-drop), 0 0 14px rgba(34, 211, 238, 0.3);
}
html .tvx-btn.tvx-btn-quiet, .btn.btn-secondary, .btn.btn-outline-secondary {
  background: var(--ds-slab-2);
  border: 2px solid var(--ds-line);
  color: var(--ds-ink-2);
  box-shadow: var(--ds-bevel);
}
html .tvx-btn.tvx-btn-quiet:hover, .btn.btn-secondary:hover, .btn.btn-outline-secondary:hover { color: var(--ds-ink); border-color: var(--ds-line-hi); }
html .tvx-btn:focus-visible, html .btn:focus-visible { outline: none; box-shadow: var(--ds-bevel), var(--ds-focus); }
html .tvx-btn:disabled, html .tvx-btn[aria-disabled="true"], html .btn:disabled {
  opacity: 0.45; cursor: not-allowed; transform: none; filter: saturate(0.4);
}
.tvx-btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.tvx-btn.is-loading::after {
  content: ""; position: absolute; inset: 50% auto auto 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  background: currentColor; color: var(--ds-ink);
  box-shadow: 16px 0 0 currentColor, -16px 0 0 currentColor;
  animation: ds-dots 0.9s steps(3) infinite;
}
@keyframes ds-dots { 0% { opacity: 1; } 50% { opacity: 0.35; } 100% { opacity: 1; } }

/* ---- Graphics settings (Settings > Video) ------------------------------------ */
.tvx-gfx { display: flex; flex-direction: column; gap: var(--ds-space-3); }
.tvx-gfx-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: var(--ds-space-2);
}
.tvx-gfx-preset {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 82px;
  padding: 10px 10px 12px;
  text-align: left;
  font: inherit;
  color: var(--ds-ink-2);
  background: var(--ds-slab-2);
  border: 2px solid var(--ds-line);
  box-shadow: var(--ds-bevel);
  cursor: pointer;
  transition: border-color var(--ds-t), box-shadow var(--ds-t), color var(--ds-t);
}
.tvx-gfx-preset:hover { border-color: var(--ds-line-hi); color: var(--ds-ink); }
.tvx-gfx-preset:focus-visible { outline: none; box-shadow: var(--ds-bevel), var(--ds-focus); }
.tvx-gfx-preset.is-on {
  color: var(--ds-ink);
  border-color: var(--ds-gold);
  background: linear-gradient(to bottom, #2e2a1f, var(--ds-slab-2));
  box-shadow: var(--ds-bevel), 0 0 0 1px rgba(245, 185, 66, 0.5), 0 0 16px rgba(245, 185, 66, 0.18);
}
.tvx-gfx-preset-name {
  font-family: var(--ds-font-label);
  font-size: calc(0.86rem * var(--tvx-ui-scale, 1));
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: inherit;
}
.tvx-gfx-preset.is-on .tvx-gfx-preset-name { color: var(--ds-gold-hi); }
.tvx-gfx-preset-desc { font-size: calc(0.74rem * var(--tvx-ui-scale, 1)); line-height: 1.3; color: var(--ds-ink-3); }
.tvx-gfx-preset.is-on .tvx-gfx-preset-desc { color: var(--ds-ink-2); }
.tvx-gfx-tag {
  position: absolute; top: -9px; right: 6px;
  padding: 1px 6px;
  font-family: var(--ds-font-label); font-size: 0.6rem; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ds-cyan-ink); background: var(--ds-cyan);
  border: 1px solid #0b5563;
}
.tvx-gfx-tag[hidden] { display: none; }
.tvx-gfx-sub {
  margin: var(--ds-space-2) 0 0;
  font-family: var(--ds-font-label);
  font-size: calc(0.74rem * var(--tvx-ui-scale, 1));
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ds-ink-3);
}
.tvx-gfx-confirm {
  padding: var(--ds-space-3);
  border: 2px solid var(--ds-warn);
  background: rgba(251, 191, 36, 0.08);
}
.tvx-gfx-confirm[hidden] { display: none; }
.tvx-gfx-confirm-text { margin: 0 0 var(--ds-space-2); color: var(--ds-ink); font-size: calc(0.84rem * var(--tvx-ui-scale, 1)); }
.tvx-gfx-warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tvx-gfx-warnings:empty { display: none; }
.tvx-gfx-warning {
  padding: 8px 10px 8px 12px;
  font-size: calc(0.8rem * var(--tvx-ui-scale, 1));
  color: var(--ds-ink);
  background: var(--ds-slab-3);
  border-left: 4px solid var(--ds-warn);
}
.tvx-gfx-warning[data-level="info"] { border-left-color: var(--ds-cyan); color: var(--ds-ink-2); }
.tvx-gfx-custom {
  display: flex; flex-direction: column; gap: 8px;
  padding: var(--ds-space-3);
  border: 2px solid var(--ds-line);
  background: var(--ds-slab-3);
}
.tvx-gfx-custom[hidden] { display: none; }
.tvx-gfx-custom-rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 22px; }
.tvx-gfx-diag {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 6px; margin: 0;
}
.tvx-gfx-diag > div { background: var(--ds-slab-3); border: 1px solid var(--ds-line); padding: 6px 9px; min-width: 0; }
.tvx-gfx-diag .tvx-gfx-diag-wide { grid-column: 1 / -1; }
.tvx-gfx-diag dt {
  font-family: var(--ds-font-label); font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ds-ink-3);
}
.tvx-gfx-diag dd {
  margin: 2px 0 0; color: var(--ds-ink); font-family: var(--tvx-font-mono, monospace);
  font-size: calc(0.78rem * var(--tvx-ui-scale, 1)); overflow-wrap: anywhere;
}

/* ---- Graphics advisory / announcement (over the game) ------------------------ */
.tvx-gfx-notice {
  position: fixed;
  z-index: 2147483000;
  left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 24px));
  padding: 12px 14px;
  background: var(--ds-glass);
  border: 2px solid var(--ds-cyan-lo);
  box-shadow: var(--ds-bevel), 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--ds-ink);
  backdrop-filter: none;
}
.tvx-gfx-notice[hidden] { display: none; }
.tvx-gfx-notice[data-level="warn"] { border-color: var(--ds-warn); }
.tvx-gfx-notice-text { margin: 0 0 10px; font-size: 0.86rem; line-height: 1.45; }
.tvx-gfx-notice-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

:focus-visible { outline-color: var(--ds-cyan); }

@media (prefers-reduced-motion: reduce) {
  .tvx-gfx-preset, .tvx-btn, .btn { transition: none !important; }
  .tvx-btn.is-loading::after { animation: none; }
}
html[data-tvx-motion="reduced"] .tvx-gfx-preset, html[data-tvx-motion="reduced"] .tvx-btn { transition: none !important; }

/* ---- CTFd content routes (scoreboard, users, teams, team, account, notifications,
        sponsors, about, challenge pages): ONE world backdrop + scrim behind every
        standalone screen, the same recipe About already used, so leaving the game
        for a CTFd page no longer drops onto flat black. Auth gates keep their own
        brighter backdrop. Browsers without :has() keep the plain background. -- */
body.tvx:has(.tvx-screen-standalone:not(.tvx-gate))::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #0e1412;
  background-image:
    radial-gradient(ellipse at center, rgba(5, 8, 7, 0) 45%, rgba(5, 8, 7, 0.55) 100%),
    linear-gradient(rgba(7, 10, 9, 0.72), rgba(7, 10, 9, 0.86)),
    image-set(url("../img/world/backdrop-1920.webp") 1x, url("../img/world/backdrop-3840.webp") 2x);
  background-size: cover;
  background-position: center, center, center 62%;
  background-repeat: no-repeat;
}
.tvx-screen.tvx-screen-standalone { z-index: 1; }
body.tvx:has(.tvx-screen-standalone) .tvx-footer { position: relative; z-index: 1; }
/* the hotbar dock floats over the bottom of the page: keep the last row clear */
.tvx-screen.tvx-screen-standalone:not(.tvx-gate) { padding-bottom: calc(clamp(32px, 6vh, 64px) + 92px); }
.tvx-screen-standalone .tvx-screen-frame {
  background: rgba(14, 18, 22, 0.82);
  border: 2px solid var(--ds-line);
  box-shadow: var(--ds-bevel), 0 18px 40px rgba(0, 0, 0, 0.35);
  padding: clamp(14px, 2.2vw, 24px);
}

/* ---- Top navigation on CTFd routes: readable size, gold "you are here" --------- */
.tvx-nav { background: rgba(8, 11, 13, 0.92); border-bottom-color: var(--ds-line); }
.tvx-nav-links a, .tvx-nav-links button.tvx-nav-link { font-size: 0.7rem; padding: 8px 10px; color: var(--ds-ink-2); }
.tvx-nav-links a:hover, .tvx-nav-links button.tvx-nav-link:hover { color: var(--ds-ink); background: var(--ds-slab-2); border-color: var(--ds-line); }
.tvx-nav-links a[aria-current="page"] { color: var(--ds-gold-hi); background: var(--ds-slab-2); border-color: var(--ds-line-hi); box-shadow: inset 0 -3px 0 var(--ds-gold); }
.tvx-nav-links a:focus-visible, .tvx-nav-links button.tvx-nav-link:focus-visible { outline: none; box-shadow: var(--ds-focus); }
.tvx-brand-mark {
  background: linear-gradient(135deg, var(--ds-gold-hi) 0 50%, var(--ds-gold-lo) 50% 100%);
  box-shadow: inset 3px 3px 0 rgba(255, 255, 255, 0.25), inset -3px -3px 0 rgba(0, 0, 0, 0.35), 0 0 12px rgba(245, 185, 66, 0.35);
}

/* ---- Tables, fields, alerts on CTFd routes ------------------------------------- */
.tvx-screen-standalone table th { font-family: var(--ds-font-label); font-size: 0.64rem; letter-spacing: 0.06em; color: var(--ds-ink-3); }
.tvx-screen-standalone table tbody tr:hover { background: rgba(34, 211, 238, 0.05); }
.tvx-input:focus, .tvx-screen-standalone input:focus, .tvx-screen-standalone select:focus, .tvx-screen-standalone textarea:focus {
  outline: none; border-color: var(--ds-cyan) !important; box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.25);
}

/* NG fixed drawing buffer (WebKit compatibility layer, world.js): the canvas is
   shown 1:1 at its allocated size from the stage's top-left and clipped by it. */
.tvx3d-canvas.tvx3d-fixedbuf {
  position: absolute; top: 0; left: 0;
  width: var(--tvx-buf-w) !important; height: var(--tvx-buf-h) !important;
  max-width: none; object-fit: none;
}
[data-tvx-world3d]:has(> .tvx3d-fixedbuf) { overflow: hidden; }

/* NG compact character (phones / tablets, main menu): the credits keep clear of it. */
html[data-tvx-avatar-compact="portrait"] .tvx-screen-menu .tvx-menu-corner {
  padding-right: calc(var(--tvx-avatar-cw, 120px) + 4px);
  text-align: left;
  align-items: flex-start;
}

/* ==========================================================================
   NG-rc2 PAGE LAYOUTS (unified 3D character everywhere)
   ========================================================================== */
/* full-figure character stages (profile, user page, wardrobe, no-WebGL menu) */
.tvx-av.tvx-av-full { padding: 0; background: none; box-shadow: none; }
.tvx-av.tvx-av-stage {
  width: var(--avw, 168px); height: var(--avh, 252px); padding: 0;
  background:
    radial-gradient(ellipse 60% 22% at 50% 88%, rgba(34, 211, 238, 0.16), transparent 70%),
    linear-gradient(to bottom, rgba(18, 24, 30, 0.2), rgba(10, 14, 18, 0.75));
  border: 2px solid var(--ds-line);
  box-shadow: var(--ds-bevel);
}
.tvx-av.tvx-av-stage.tvx-frame { padding: 6px; }
.tvx-av.tvx-av-stage:hover { border-color: var(--ds-cyan-lo); }
/* podium: the representative stands on the plinth in rank armour */
.tvx-av.tvx-av-podium.tvx-av-full { width: 92px; height: 138px; }
@media (max-height: 760px) and (min-width: 701px) { .tvx-av.tvx-av-podium.tvx-av-full { width: 70px; height: 104px; } }

/* Profile: hero with the character stage beside the identity */
.tvx-pf-id { display: grid !important; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: center; }
.tvx-pf-mono.has-avatar .tvx-av-stage { --avw: 176px; --avh: 264px; }
@media (max-width: 700px) {
  .tvx-pf-id { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .tvx-pf-id .tvx-pf-meta, .tvx-pf-id .tvx-pf-links { justify-content: center; }
  .tvx-pf-mono.has-avatar .tvx-av-stage { --avw: 150px; --avh: 224px; }
}
/* user page */
.tvx-player-portrait.has-avatar .tvx-av-stage { --avw: 156px; --avh: 234px; }

/* Wardrobe (shop current outfit): a real stage instead of a thumbnail */
.tvx-shop-art .tvx-av-stage { --avw: 132px; --avh: 198px; }

/* Users directory rows carry the player's character */
.tvx-dir-av { display: inline-flex; flex: 0 0 auto; }
.tvx-dir-av.has-avatar .tvx-av-sm { --av: 34px; }

/* Leaderboard on phones: names never break letter by letter */
@media (max-width: 700px) {
  .tvx-lb-slot .tvx-lb-pname { flex: 1 1 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; word-break: normal; }
  .tvx-lb-slot .tvx-av.tvx-av-podium.tvx-av-full { width: 56px; height: 84px; }
  .tvx-lb-slot .tvx-lb-rep { flex: 1 0 100%; }
}
