@font-face {
  font-family: "Silkscreen";
  src: url("fonts/Silkscreen-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "VT323";
  src: url("fonts/VT323-Regular.ttf") format("truetype");
  font-display: swap;
}

:root, :root[data-theme="light"] {
  --bg: #f0eee6;
  --surface: #faf9f5;
  --surface2: #ffffff;
  --ink: #3d3d3a;
  --muted: #6b6b63;
  --accent: #c96442;
  --accent2: #d97757;
  --border: #2a2a28;
  --green: #3fa34d;
  --offline: #9a9a90;
  --hover: #f3efe6;
  --grid: #d9d5c7;
  --img-bg: #14140f;
  --err-bg: #f6d9d0;
  --err-fg: #7a2f1c;
  --shadow: 4px 4px 0 var(--border);
  --shadow-sm: 3px 3px 0 var(--border);
}
:root[data-theme="dark"] {
  --bg: #1e1d1a;
  --surface: #28251f;
  --surface2: #2f2b25;
  --ink: #ece6d6;
  --muted: #9c9587;
  --accent: #d97757;
  --accent2: #e0876a;
  --border: #5b554a;
  --green: #6cc26b;
  --offline: #555048;
  --hover: #3a352d;
  --grid: #423c34;
  --img-bg: #0a0a08;
  --err-bg: #4a2a22;
  --err-fg: #f4c4b3;
  --shadow: 4px 4px 0 #000;
  --shadow-sm: 3px 3px 0 #000;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "VT323", "Courier New", monospace;
  font-size: 20px;
  -webkit-font-smoothing: none;
}

.head {
  font-family: "Silkscreen", monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---------- top bar ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 3px solid var(--border);
}
header h1 {
  font-family: "Silkscreen", monospace;
  font-size: 16px;
  color: var(--accent);
  margin-right: 4px;
}
#status { color: var(--muted); font-size: 19px; }
.spacer { flex: 1 1 40px; }

.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.group label {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  color: var(--muted);
}

button, .btn {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface2);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
}
button:hover, .btn:hover { background: var(--hover); }
button:active, .btn:active { transform: translate(2px, 2px); box-shadow: none; }
button.on { background: var(--accent); color: #fff; }

input[type="range"] { accent-color: var(--accent); width: 110px; }
.rate-val { font-size: 18px; min-width: 34px; }

/* ---------- grid ---------- */
/* Monitor dashboard grid — scoped so it doesn't bleed onto /team etc. */
main#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 16px;
  padding: 16px;
  align-content: start;
}

.tile {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  cursor: zoom-in;
}
.tile .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 2px solid var(--border);
}
.tile .bar.foot { border-bottom: 0; border-top: 2px solid var(--border); }
.tile .name {
  font-family: "Silkscreen", monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile .meta { color: var(--muted); font-size: 18px; }
.dot {
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  background: var(--offline);
  flex: none;
}
.tile.onln .dot { background: var(--green); }
.tile img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--img-bg);
  image-rendering: pixelated;
}
.tile.offline { opacity: .55; }
.tile.offline img { filter: grayscale(1); }

.badge {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  background: var(--green);
  color: #06210b;
  border: 2px solid var(--border);
  padding: 3px 7px;
}
.tile.green {
  border-color: var(--green);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink {
  50% { box-shadow: 0 0 0 4px var(--green), var(--shadow); }
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-family: "Silkscreen", monospace;
  font-size: 12px;
}

/* ---------- modal ---------- */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 15, .82);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
#modal.show { display: flex; }
#modal .box {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 96vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
#modal .box .bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
}
#modal img {
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  background: var(--img-bg);
  image-rendering: pixelated;
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login h1 {
  font-family: "Silkscreen", monospace;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 6px;
}
.login p { color: var(--muted); margin-bottom: 18px; font-size: 18px; }
.login input[type="password"] {
  width: 100%;
  font-family: "VT323", monospace;
  font-size: 22px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 10px 12px;
  margin-bottom: 14px;
}
.login input[type="password"]:focus { outline: 2px solid var(--accent); }
.login button {
  width: 100%;
  font-size: 12px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
}
.login .err {
  background: var(--err-bg);
  border: 2px solid var(--accent);
  color: var(--err-fg);
  padding: 8px;
  margin-bottom: 14px;
  font-size: 17px;
}

@media (max-width: 600px) {
  header h1 { font-size: 13px; }
  main { padding: 10px; gap: 10px; }
  body { font-size: 19px; }
}

/* ============ TEAM PAGE ============ */
.team-main {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.team-main > * { min-width: 0; }

.cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
}
.card {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-label {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
}
.card-value {
  font-family: "VT323", monospace;
  font-size: 28px;
  color: var(--ink);
}
.card.green .card-value { color: var(--green); }
.card.red .card-value { color: var(--accent); }

.panels {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}
.ipanel {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  padding: 14px;
}
.ipanel-title {
  font-family: "Silkscreen", monospace;
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.muted { color: var(--muted); font-size: 17px; }

.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.form-row > * { flex: 1 1 110px; }
.form-row > button { flex: 0 1 auto; }
.form-col { display: flex; flex-direction: column; gap: 8px; }
.form-col label {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  color: var(--muted);
}

input[type="text"], input[type="number"], select {
  font-family: "VT323", monospace;
  font-size: 19px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 6px 9px;
}
input:focus, select:focus { outline: 2px solid var(--accent); }
button.primary {
  background: var(--accent);
  color: #fff;
}
button.danger {
  background: var(--err-bg);
  color: var(--err-fg);
  border-color: var(--accent);
}
button.danger:hover { background: var(--accent); color: #fff; }

/* tables (key-value rows) */
.table { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row {
  display: grid;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  min-width: 0;
}
.row > * { min-width: 0; overflow: hidden; text-overflow: ellipsis;
           white-space: nowrap; }
.row.players {
  grid-template-columns:
    minmax(120px, 1.6fr) minmax(80px, 1fr) minmax(60px, 0.7fr)
    minmax(60px, 0.7fr) minmax(80px, 1fr) minmax(60px, 0.7fr)
    minmax(70px, 0.9fr) auto;
}
.row.players .h, .row.actives .h, .row.finished .h {
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  color: var(--muted);
}
.row.actives {
  grid-template-columns:
    minmax(140px, 1.8fr) minmax(70px, 0.8fr) minmax(110px, 1fr)
    minmax(60px, 0.6fr) auto;
}
.row.finished {
  grid-template-columns:
    minmax(140px, 1.8fr) minmax(70px, 0.8fr) minmax(70px, 0.8fr)
    minmax(70px, 0.8fr) minmax(70px, 0.8fr) minmax(110px, 1fr) auto;
}
.row .pl { font-family: "Silkscreen", monospace; font-size: 11px; }
a.pl {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
a.pl:hover { color: var(--accent); border-bottom-color: var(--accent); }
.row.arch { opacity: .55; }
.chip {
  font-family: "Silkscreen", monospace;
  font-size: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 5px;
  margin-left: 6px;
}
button.del-t, button.edit-t, button.arch, button.unarch {
  padding: 6px 8px; font-size: 9px;
  background: var(--surface);
}
button.del-t { color: var(--accent); }
#dateFilter button.on, #archToggleBtn.on { background: var(--accent); color: #fff; }
.row .v { font-family: "VT323", monospace; font-size: 19px; }
.row .v.pos { color: var(--green); }
.row .v.neg { color: var(--accent); }
.row .actions {
  display: flex; gap: 6px; overflow: visible; justify-content: flex-end;
}
.row .actions button { padding: 6px 8px; font-size: 9px; flex: 0 0 auto; }

@media (max-width: 800px) {
  .row.players, .row.actives, .row.finished {
    grid-template-columns: 1fr 1fr;
  }
  .row.players .h, .row.actives .h, .row.finished .h { display: none; }
  .row .actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* charts */
.charts {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
}
.chart-box {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  padding: 12px;
}
.chart-title {
  font-family: "Silkscreen", monospace;
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.chart-box canvas { display: block; width: 100%; height: 220px; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  font-family: "VT323", monospace;
  font-size: 17px;
}
.legend .sw {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  vertical-align: middle;
  margin-right: 6px;
}

/* modal (team) */
.modal {
  position: fixed; inset: 0; display: none;
  background: rgba(20,20,15,.82);
  align-items: center; justify-content: center;
  padding: 24px; z-index: 30;
}
.modal.show { display: flex; }
.modal .box {
  background: var(--surface2);
  border: 3px solid var(--border);
  box-shadow: var(--shadow);
  width: 100%; max-width: 420px;
}
.modal .box .bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-bottom: 2px solid var(--border);
}
.modal .box .body { padding: 14px; }
.modal .err {
  background: var(--err-bg); border: 2px solid var(--accent);
  color: var(--err-fg); padding: 8px; font-size: 17px;
}

