/* ==========================================================================
   Ravens — cohesive dark techy theme
   Used by every page. One stylesheet to rule them all.
   ========================================================================== */

:root {
  /* core palette — steel + sand (austere, flat) */
  --bg:            #0d0f12;
  --bg-elev:       #14171c;
  --bg-elev-2:     #1a1e24;
  --panel:         #15181d;
  --border:        #262a31;
  --border-strong: #353b44;

  --text:          #d6d9de;
  --text-dim:      #9aa0a8;
  --text-faint:    #5f656e;

  /* team colours — used ONLY for the drones in the viewer + role words */
  --blue:          #4a90d9;
  --blue-dim:      #2c5f93;
  --red:           #d65a5a;
  --red-dim:       #8f3a3a;
  /* one restrained accent: sand / ochre */
  --accent:        #b6a06a;
  --accent-dim:    #8a784a;
  --amber:         #b6a06a;

  --shadow:        none;
  --radius:        4px;
  --radius-sm:     3px;

  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* flat backdrop with a faint hairline grid (no glow, no gradient) */
body {
  background-image:
    linear-gradient(rgba(255,255,255,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.012) 1px, transparent 1px);
  background-size: 44px 44px, 44px 44px;
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 2.4rem; margin: 0 0 0.4em; }
h2 { font-size: 1.6rem; margin: 1.8em 0 0.6em; }
h3 { font-size: 1.2rem; margin: 1.4em 0 0.4em; }

code, kbd, pre { font-family: var(--mono); }
code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.88em;
  color: var(--accent);
}
pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.5;
}
pre code { background: none; border: none; padding: 0; color: var(--text); }

/* ============================ Layout ============================ */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.container-wide { max-width: 1480px; }

section { margin: 3rem 0; }

/* ============================ Nav ============================ */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13,15,18,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand:hover { text-decoration: none; }
.brand .accent { color: var(--accent); }
.nav-links {
  display: flex;
  gap: 0.2rem;
  margin-left: auto;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--text-dim);
  padding: 0.4rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ============================ Hero ============================ */
.hero {
  padding: 4.5rem 0 2.5rem;
  text-align: center;
  position: relative;
}
.hero h1 {
  font-size: 3.2rem;
  margin-bottom: 0.3em;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}
.hero .tagline {
  font-size: 1.25rem;
  color: var(--text-dim);
  max-width: 640px;
  margin: 0 auto 1.8rem;
}
.hero .sub {
  font-size: 1rem;
  color: var(--text-faint);
  max-width: 560px;
  margin: 0 auto;
}

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-elev-2); border-color: var(--accent-dim); text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #15110a;
}
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

/* ============================ Cards / panels ============================ */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.2rem;
  margin-top: 1.5rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover { border-color: var(--border-strong); }
.card h3 { margin-top: 0; color: var(--text); }
.card .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

/* austere uppercase section eyebrow (DeepTraffic-style section labels) */
.eyebrow {
  font: 600 0.72rem/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: block;
  margin-bottom: 0.5rem;
}

/* feature chips for teams */
.team-blue { color: var(--blue); font-weight: 600; }
.team-red  { color: var(--red);  font-weight: 600; }

/* ============================ Tables ============================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
thead th {
  text-align: left;
  padding: 0.7rem 0.9rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-strong);
  font-weight: 600;
}
tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: var(--bg-elev); }
tbody tr:last-child td { border-bottom: none; }

.lb-table td.rank { font-family: var(--mono); color: var(--text-dim); width: 3rem; }
.lb-table tr.top-1 td.rank { color: var(--amber); font-weight: 700; }
.lb-table tr.top-2 td.rank { color: #cdd6e0; }
.lb-table tr.top-3 td.rank { color: #cd7f32; }
.lb-table td.team { font-weight: 600; color: var(--text); }
.lb-table td.elo  { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  font-size: 0.78rem;
  font-family: var(--mono);
  border: 1px solid var(--border-strong);
}
.badge-w { color: var(--accent); border-color: var(--accent-dim); }
.badge-l { color: var(--red);    border-color: var(--red-dim); }

/* ============================ Spec / rules tables ============================ */
.spec-table td:first-child { color: var(--text-dim); width: 38%; font-family: var(--mono); font-size: 0.88rem; }
.spec-table td:last-child { font-weight: 500; }

dl.contract { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.2rem; }
dl.contract dt { font-family: var(--mono); color: var(--accent); }
dl.contract dd { margin: 0; color: var(--text-dim); }

/* ============================ Replay viewer ============================ */
.viewer-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);   /* dvh: avoids the mobile browser-chrome jump */
  background: #05070b;
}
#viewer-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#viewer-canvas-wrap canvas { display: block; }

/* HUD overlay */
.hud {
  position: absolute;
  top: 1rem; left: 1rem;
  background: rgba(8,12,18,0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
  pointer-events: none;
  min-width: 190px;
}
.hud .hud-row { display: flex; justify-content: space-between; gap: 1.2rem; padding: 0.12rem 0; }
.hud .hud-row .k { color: var(--text-dim); }
.hud .hud-row .v { font-weight: 600; }
.hud .v.blue { color: var(--blue); }
.hud .v.red  { color: var(--red); }
.hud .v.hp   { color: var(--amber); }
.hud-title {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

/* result banner */
.result-banner {
  position: absolute;
  top: 1rem; left: 50%;
  transform: translateX(-50%);
  background: rgba(8,12,18,0.9);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.4rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: center;
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.result-banner.show { opacity: 1; }
.result-banner.red  { border-color: var(--red-dim);  color: var(--red);  box-shadow: 0 0 30px rgba(255,93,93,0.2); }
.result-banner.blue { border-color: var(--blue-dim); color: var(--blue); box-shadow: 0 0 30px rgba(61,169,252,0.2); }
.result-banner .reason { display:block; font-size: 0.8rem; font-weight: 500; color: var(--text-dim); margin-top: 0.15rem; }

/* legend */
.legend {
  position: absolute;
  bottom: 1rem; left: 1rem;
  background: rgba(8,12,18,0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
  pointer-events: none;
}
.legend .li { display: flex; align-items: center; gap: 0.5rem; padding: 0.1rem 0; color: var(--text-dim); }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.legend .dot.blue { background: var(--blue); }
.legend .dot.red  { background: var(--red); }
.legend .dot.target { border-radius: 2px; background: var(--amber); }

/* controls bar */
.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.2rem;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.controls .ctrl-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.12s;
}
.controls .ctrl-btn:hover { background: var(--border); }
.controls .ctrl-btn.active { background: var(--accent-dim); border-color: var(--accent); color: #04130d; }
.controls .play-btn { min-width: 3.5rem; font-weight: 700; }
.controls .speed-group { display: flex; gap: 0.3rem; }
.controls .scrub-wrap { flex: 1; display: flex; align-items: center; gap: 0.7rem; min-width: 200px; }
.controls .tick-label { font-family: var(--mono); font-size: 0.82rem; color: var(--text-dim); white-space: nowrap; }
input[type="range"].scrubber {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}
input[type="range"].scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #04130d;
  cursor: pointer;
}
input[type="range"].scrubber::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #04130d;
  cursor: pointer;
}

/* ============================ Forms ============================ */
.form-field { margin-bottom: 1.3rem; }
.form-field label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 600;
  font-size: 0.92rem;
}
.form-field .hint { font-weight: 400; color: var(--text-faint); font-size: 0.85rem; }
input[type="text"], input[type="password"], input[type="file"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92rem;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(92,225,185,0.12);
}
input[type="file"] {
  cursor: pointer;
  padding: 0.55rem 0.9rem;
}
input[type="file"]::file-selector-button {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.8rem;
  margin-right: 0.9rem;
  cursor: pointer;
  font-family: var(--sans);
  font-weight: 600;
}

.caps-list {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin: 1.2rem 0;
}
.cap {
  flex: 1;
  min-width: 130px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  text-align: center;
}
.cap .cap-val { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.cap .cap-label { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.2rem; }

.notice {
  margin-top: 1.5rem;
  padding: 1rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid;
  display: none;
}
.notice.show { display: block; }
.notice.info  { border-color: var(--amber); background: rgba(255,200,87,0.08); color: var(--amber); }
.notice.ok    { border-color: var(--accent-dim); background: rgba(92,225,185,0.08); color: var(--accent); }
.notice.err   { border-color: var(--red-dim); background: rgba(255,93,93,0.08); color: var(--red); }
.notice .notice-title { font-weight: 700; margin-bottom: 0.3rem; }

/* ============================ Fights playlist ============================ */
.fights-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.2rem;
  align-items: start;
}
.playlist { display: flex; flex-direction: column; gap: 0.6rem; }
.playlist-item {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.playlist-item:hover { border-color: var(--border-strong); background: var(--bg-elev); }
.playlist-item.active { border-color: var(--accent); background: rgba(92,225,185,0.06); }
.playlist-item .pl-idx {
  font-family: var(--mono);
  color: var(--text-faint);
  font-size: 0.9rem;
  min-width: 1.4rem;
}
.playlist-item.active .pl-idx { color: var(--accent); }
.playlist-item .pl-meta .pl-title { font-weight: 600; font-size: 0.95rem; }
.playlist-item .pl-meta .pl-sub { font-size: 0.82rem; color: var(--text-dim); }
.playlist-item .pl-now {
  margin-left: auto;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--accent);
  opacity: 0;
}
.playlist-item.active .pl-now { opacity: 1; }

.fights-viewer {
  position: relative;
  background: #05070b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.fights-viewer #viewer-canvas-wrap { min-height: 520px; }

@media (max-width: 820px) {
  .fights-layout { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2.4rem; }
  h1 { font-size: 1.9rem; }
}

/* ============================ Footer ============================ */
.footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 2rem 0;
  color: var(--text-faint);
  font-size: 0.88rem;
  text-align: center;
}
.footer a { color: var(--text-dim); }

/* loading / error states */
.loading-msg, .error-msg {
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--mono);
}
.error-msg { color: var(--red); }

.text-dim { color: var(--text-dim); }
.mono { font-family: var(--mono); }
ul.tight { padding-left: 1.2rem; }
ul.tight li { margin: 0.3rem 0; }

/* seed/baseline badge on the leaderboard */
.seed-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05em 0.5em;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--amber);
  border: 1px solid var(--amber);
  vertical-align: middle;
}

/* ============================ Responsive ============================ */
/* Students mostly watch on phones — make sure nothing overflows and the
   viewer + controls stay usable, while desktop stays centered/contained. */
@media (max-width: 820px) {
  .nav-links { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-inner { gap: 0.8rem; }
  section { margin: 2.2rem 0; }
}

@media (max-width: 640px) {
  html, body { font-size: 15px; }
  .container { padding: 0 1rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.3rem; }
  section { margin: 1.8rem 0; }
  .hero { padding: 2.5rem 0 1.5rem; }
  .hero h1 { font-size: 2.1rem; }
  .hero .tagline { font-size: 1.05rem; }
  .hero .sub { font-size: 0.95rem; }
  .panel { padding: 1.1rem; }

  /* wide tables scroll horizontally inside their panel instead of overflowing */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lb-table, .spec-table { min-width: 500px; }
  th, td { white-space: nowrap; }

  /* stack the contract definition list */
  dl.contract { grid-template-columns: 1fr; gap: 0.1rem; }
  dl.contract dt { margin-top: 0.6rem; }

  /* full-width, tappable buttons */
  .btn-row { flex-direction: column; align-items: stretch; }
  .btn { width: 100%; justify-content: center; }

  /* viewer: shrink overlays so they don't cover the dogfight; full-width scrubber */
  .viewer-shell { height: calc(100dvh - 52px); }
  .hud { top: 0.6rem; left: 0.6rem; padding: 0.55rem 0.7rem; font-size: 0.74rem; min-width: 138px; }
  .legend { bottom: 0.6rem; left: 0.6rem; padding: 0.45rem 0.6rem; font-size: 0.7rem; }
  .controls { gap: 0.55rem; padding: 0.6rem 0.7rem; }
  .controls .scrub-wrap { order: 3; flex-basis: 100%; min-width: 0; }
  .result-banner { font-size: 0.9rem; padding: 0.55rem 0.9rem; max-width: 92%; }
}
