:root {
  --bg: #0a0e14;
  --bg-panel: #131924;
  --bg-panel-hover: #171e2b;
  --bg-input: #0d1218;
  --border: rgba(230, 237, 243, 0.09);
  --border-strong: rgba(230, 237, 243, 0.16);
  --text: #e9eef4;
  --text-muted: #8b98a9;
  --text-dim: #5a6577;
  --accent-on: #38d996;
  --accent-on-dim: rgba(56, 217, 150, 0.14);
  --accent-off: #6b7684;
  --accent-primary: #4fa8ff;
  --accent-primary-dim: rgba(79, 168, 255, 0.14);
  --accent-danger: #ff6161;
  --accent-danger-dim: rgba(255, 97, 97, 0.14);
  --radius: 10px;
  --font-sans: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
}

/* hi-tech backdrop, layered back-to-front:
   body::before  perspective grid
   body::after   drifting ambient glows
   #bgCanvas     animated node network (bg.js)
   .bg-scan      scanline sweep + vignette                                    */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -4;
  background-image:
    linear-gradient(rgba(79, 168, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 168, 255, 0.055) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(ellipse 95% 75% at 50% 0%, black 35%, transparent 88%);
  -webkit-mask-image: radial-gradient(ellipse 95% 75% at 50% 0%, black 35%, transparent 88%);
  animation: gridflow 18s linear infinite;
}

@keyframes gridflow {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 0 46px, 46px 0; }
}

body::after {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -3;
  background-image:
    radial-gradient(38vw 38vw at 8% 6%, rgba(79, 168, 255, 0.16), transparent 60%),
    radial-gradient(32vw 32vw at 96% 18%, rgba(56, 217, 150, 0.11), transparent 60%),
    radial-gradient(30vw 30vw at 40% 100%, rgba(255, 97, 97, 0.07), transparent 60%);
  filter: blur(10px);
  animation: drift 26s ease-in-out infinite alternate;
}

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(1.5%, -1.5%) scale(1.04); }
  100% { transform: translate(-1.5%, 1%) scale(1); }
}

.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
}

.bg-scan {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.014) 0px,
      rgba(255, 255, 255, 0.014) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(ellipse 120% 90% at 50% 45%, transparent 55%, rgba(4, 7, 11, 0.55) 100%);
}

/* a single bright line sweeping down, like a scanner */
.bg-scan::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 22vh;
  top: -22vh;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(79, 168, 255, 0.05) 45%,
    rgba(79, 168, 255, 0.09) 50%,
    rgba(79, 168, 255, 0.05) 55%,
    transparent
  );
  animation: sweep 9s linear infinite;
}

@keyframes sweep {
  0%   { transform: translateY(0); }
  100% { transform: translateY(140vh); }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after,
  .bg-scan::after { animation: none; }
  .bg-canvas { display: none; }
}

a { color: var(--accent-primary); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:disabled { cursor: default; opacity: 0.5; }

/* ---------- shared: status dot ---------- */
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}
.dot-on {
  background: var(--accent-on);
  box-shadow: 0 0 0 3px var(--accent-on-dim);
  animation: pulse 2.2s ease-in-out infinite;
}
.dot-off { background: var(--accent-off); }
.dot-unknown { background: var(--text-dim); }
.dot-pending {
  background: var(--accent-primary);
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-on-dim); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .dot-on, .dot-pending { animation: none; }
}

/* ---------- login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}

.login-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}
.login-mark-text {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.login-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 24px;
}

.login-error {
  background: var(--accent-danger-dim);
  color: var(--accent-danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin: 0 0 18px;
}

.login-form {
  display: grid;
  gap: 14px;
  text-align: left;
}

.login-form label {
  display: grid;
  gap: 6px;
}

.login-form span {
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.login-form input {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14.5px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
}
.login-form input:focus {
  border-color: var(--accent-primary);
}

.login-form button {
  margin-top: 6px;
  background: var(--accent-primary);
  color: #061421;
  font-weight: 600;
  font-size: 14.5px;
  padding: 12px;
  border-radius: 8px;
  transition: filter 0.15s;
}
.login-form button:hover { filter: brightness(1.08); }
.login-form button:focus-visible,
input:focus-visible,
.btn-ghost:focus-visible,
.btn-toggle:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 20, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-user {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
}

.btn-ghost {
  font-size: 12.5px;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  border-radius: 7px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ---------- dashboard ---------- */
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

.note {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 24px;
  max-width: 60ch;
}

.budget-bar {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
}
.budget-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 9px;
}
.budget-head span:first-child {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-size: 11px;
}
#budgetLabel {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.budget-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-panel-hover);
  overflow: hidden;
}
.budget-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 999px;
  transition: width 0.3s ease, background 0.2s;
}
.budget-fill.over { background: var(--accent-danger); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  background: rgba(19, 25, 36, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}
.card:has(.dot-on) {
  border-color: rgba(56, 217, 150, 0.35);
}
.card:has(.dot-on):hover {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(56, 217, 150, 0.2);
}

.card-art {
  position: relative;
  aspect-ratio: 460 / 215;
  background: var(--bg-panel-hover);
  overflow: hidden;
  /* own compositing layer so the scaled child clips cleanly (no subpixel seam) */
  transform: translateZ(0);
  isolation: isolate;
}
.card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* always slightly overscanned so edge pixels never land on the clip boundary */
  transform: scale(1.025);
  transition: transform 0.35s ease;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform;
}
.card:hover .card-art img { transform: scale(1.07); }

.card-art-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(10, 14, 20, 0.92) 0%, rgba(10, 14, 20, 0.25) 42%, transparent 62%);
  pointer-events: none;
}

.card-status-float {
  position: absolute;
  left: 12px;
  bottom: 10px;
  z-index: 1;
}

.card-body {
  padding: 16px 18px 18px;
  display: grid;
  gap: 14px;
}

.card-title h2 {
  font-size: 15.5px;
  margin: 0 0 4px;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.connect {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

.card-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text);
  background: rgba(10, 14, 20, 0.6);
  backdrop-filter: blur(6px);
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: fit-content;
}

.status-label {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.btn-toggle {
  position: relative;
  overflow: hidden;
  padding: 11px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border-strong);
  transition: filter 0.15s, background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.2s;
}

/* diagonal shine sweep on hover */
.btn-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.22) 48%, transparent 66%);
  transform: translateX(-120%);
  transition: transform 0.5s ease;
  pointer-events: none;
}
.btn-toggle:hover:not(:disabled)::before { transform: translateX(120%); }
.btn-toggle:hover:not(:disabled) { transform: translateY(-1px); }
.btn-toggle:active:not(:disabled) { transform: translateY(0); }

.btn-toggle.state-start {
  background: var(--accent-primary-dim);
  color: var(--accent-primary);
  border-color: rgba(79, 168, 255, 0.3);
}
.btn-toggle.state-start:hover:not(:disabled) {
  filter: brightness(1.2);
  border-color: rgba(79, 168, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(79, 168, 255, 0.2), 0 6px 18px rgba(79, 168, 255, 0.22);
}

.btn-toggle.state-stop {
  background: var(--accent-danger-dim);
  color: var(--accent-danger);
  border-color: rgba(255, 97, 97, 0.3);
}
.btn-toggle.state-stop:hover:not(:disabled) {
  filter: brightness(1.2);
  border-color: rgba(255, 97, 97, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 97, 97, 0.2), 0 6px 18px rgba(255, 97, 97, 0.22);
}

.btn-toggle.state-pending {
  background: var(--bg-panel-hover);
  color: var(--text-dim);
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.card-actions .btn-toggle { margin: 0; }

.btn-restart {
  width: 40px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.2s, background 0.15s;
}
.btn-restart:hover:not(:disabled) {
  color: var(--accent-primary);
  background: var(--accent-primary-dim);
  border-color: rgba(79, 168, 255, 0.45);
  box-shadow: 0 0 0 1px rgba(79, 168, 255, 0.15), 0 6px 16px rgba(79, 168, 255, 0.2);
  transform: translateY(-1px) rotate(35deg);
}
.btn-restart:active:not(:disabled) { transform: translateY(0) rotate(90deg); }
.btn-restart:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .btn-toggle::before { display: none; }
  .btn-toggle:hover:not(:disabled),
  .btn-restart:hover:not(:disabled) { transform: none; }
}

.card-error {
  grid-column: 1 / -1;
  background: var(--accent-danger-dim);
  color: var(--accent-danger);
  font-size: 12px;
  padding: 9px 11px;
  border-radius: 7px;
  line-height: 1.4;
}

/* ---------- badges over the art ---------- */
.card-badges {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.badge {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  background: rgba(10, 14, 20, 0.66);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 4px 9px;
  white-space: nowrap;
}
.badge-players.badge-active {
  color: var(--accent-on);
  border-color: rgba(56, 217, 150, 0.35);
}

/* ---------- copy-to-clipboard address ---------- */
.connect {
  position: relative;
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 3px 7px;
  margin-left: -7px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.connect:hover {
  color: var(--accent-primary);
  background: var(--accent-primary-dim);
  border-color: rgba(79, 168, 255, 0.25);
}
.connect:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
.connect-copied {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent-on-dim);
  color: var(--accent-on);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.connect.is-copied .connect-copied { opacity: 1; }
.connect.is-copied .connect-text { opacity: 0; }

/* ---------- console button ---------- */
.card-actions { grid-template-columns: 1fr auto auto; }

.btn-console {
  width: 40px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.2s;
}
.btn-console:hover:not(:disabled) {
  color: var(--accent-on);
  background: var(--accent-on-dim);
  border-color: rgba(56, 217, 150, 0.45);
  box-shadow: 0 0 0 1px rgba(56, 217, 150, 0.15), 0 6px 16px rgba(56, 217, 150, 0.18);
  transform: translateY(-1px);
}
.btn-console:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ---------- top strip: budget + auto-shutdown ---------- */
.panel-strip {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 14px;
  margin-bottom: 14px;
  align-items: stretch;
}
.panel-strip .budget-bar { margin-bottom: 0; }

.autoshut {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  align-content: start;
}
.autoshut-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.autoshut-body {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.autoshut-body input {
  width: 68px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s;
}
.autoshut-body input:focus { border-color: var(--accent-primary); }
.autoshut-note {
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* switch */
.switch { display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px;
  height: 21px;
  border-radius: 999px;
  background: var(--bg-panel-hover);
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  padding: 0 2px;
  transition: background 0.2s, border-color 0.2s;
}
.switch-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .switch-track {
  background: var(--accent-on-dim);
  border-color: rgba(56, 217, 150, 0.5);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(17px);
  background: var(--accent-on);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ---------- console modal ---------- */
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 11, 0.72);
  backdrop-filter: blur(3px);
}

.modal-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(80vh, 720px);
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
}
.modal-head-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.follow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}

.modal-log {
  flex: 1;
  margin: 0;
  padding: 14px 18px;
  overflow: auto;
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-rcon {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.modal-rcon input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s;
}
.modal-rcon input:focus { border-color: var(--accent-primary); }
.modal-rcon button {
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent-primary-dim);
  color: var(--accent-primary);
  border: 1px solid rgba(79, 168, 255, 0.3);
  transition: filter 0.15s;
}
.modal-rcon button:hover { filter: brightness(1.2); }

.modal-rcon-note {
  margin: 0;
  padding: 0 18px 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 100px;
  overflow: auto;
}
.modal-rcon-note.is-error { color: var(--accent-danger); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .panel-strip { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 14px; }
  .topbar-mark { font-size: 14px; }
  .topbar-user { display: none; }
  .wrap { padding: 18px 14px 40px; }

  .grid { gap: 14px; }
  .card-body { padding: 14px 15px 16px; }

  /* bigger tap targets on phones */
  .btn-toggle { padding: 13px; font-size: 14px; }
  .btn-restart, .btn-console { width: 46px; }
  .connect { padding: 6px 8px; font-size: 12px; }

  .modal { padding: 0; }
  .modal-panel {
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
  }
  .modal-log { font-size: 11px; }
  .modal-rcon { padding: 10px 14px; }
  .modal-rcon button { padding: 12px 16px; }
}
