:root {
  --bg: #0f1419; --panel: #1a212b; --panel2: #222b37; --line: #2c3744;
  --text: #e6edf3; --muted: #8b98a5; --accent: #4493f8;
  --on: #2ea043; --off: #6e7681; --warn: #d29922; --bad: #f85149;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1rem; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.topbar h1 a { color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.badge-admin {
  background: var(--accent); color: #001; font-size: .7rem; font-weight: 700;
  padding: .1rem .4rem; border-radius: .3rem; text-transform: uppercase;
}
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; }

.summary { color: var(--muted); margin: 0 0 1rem; }

.grid {
  display: grid; gap: .8rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.group-head {
  grid-column: 1 / -1;
  margin: .6rem 0 0; padding-bottom: .25rem;
  font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
.group-head:first-child { margin-top: 0; }

.card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: .6rem; padding: .9rem 1rem;
}
.card.off { opacity: .65; }
.card h2 { font-size: 1rem; margin: 0 0 .5rem; padding-right: 7rem; display: flex; align-items: center; gap: .5rem; }

.dot { width: .7rem; height: .7rem; border-radius: 50%; flex: none; }
.dot.on { background: var(--on); box-shadow: 0 0 6px var(--on); }
.dot.off { background: var(--off); }

.players { font-size: 1.8rem; font-weight: 700; }
.players .max { font-size: 1rem; color: var(--muted); font-weight: 400; }
.players.unknown { color: var(--muted); font-size: 1.3rem; }

.statusline { color: var(--muted); font-size: .85rem; }
.kind-tag { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }

/* admin extras */
.meta { display: grid; grid-template-columns: auto 1fr; gap: .15rem .8rem; font-size: .85rem; margin-top: .6rem; }
.meta dt { color: var(--muted); }
.meta dt[title] { cursor: help; text-decoration: underline dotted var(--line); text-underline-offset: 3px; }
summary[title], .alerts-panel[title] > summary { cursor: help; }
.meta dd { margin: 0; }
.pill { display: inline-block; padding: .05rem .45rem; border-radius: .8rem; font-size: .72rem; font-weight: 600; }
.pill.on { background: rgba(46,160,67,.18); color: #56d364; }
.pill.off { background: rgba(110,118,129,.18); color: var(--muted); }
.pill.warn { background: rgba(210,153,34,.18); color: #e3b341; }
.pill.bad { background: rgba(248,81,73,.18); color: #ff7b72; }
.names { margin: .4rem 0 0; font-size: .85rem; }
.names .who { color: var(--text); }
.note { color: var(--warn); font-size: .8rem; margin-top: .4rem; }

.boxbar {
  display: flex; flex-wrap: wrap; gap: 1.2rem; background: var(--panel2);
  border: 1px solid var(--line); border-radius: .6rem; padding: .7rem 1rem; margin-bottom: 1rem;
}
.boxbar .stat b { font-size: 1.1rem; }
.boxbar .stat span { color: var(--muted); font-size: .8rem; display: block; }
.boxbar .stat b.ok { color: #56d364; }
.boxbar .stat b.warn { color: #e3b341; }
.boxbar .stat b.bad { color: #ff7b72; }

/* login */
.login-wrap { max-width: 340px; margin: 3rem auto; }
.login-wrap input[type=password] {
  width: 100%; padding: .6rem; border-radius: .4rem; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; margin: .5rem 0;
}
.btn {
  background: var(--accent); color: #001; border: none; border-radius: .4rem;
  padding: .55rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.error { color: var(--bad); margin: .5rem 0; }

.controls { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.ctl {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: .35rem; padding: .35rem .7rem; font: inherit; font-size: .82rem; cursor: pointer;
}
.ctl:hover:not(:disabled) { filter: brightness(1.15); }
.ctl:disabled { opacity: .5; cursor: progress; }
.ctl.go { border-color: var(--on); color: #56d364; }
.ctl.warn { border-color: var(--warn); color: #e3b341; }
.ctl.danger { border-color: var(--bad); color: #ff7b72; }

.toast {
  position: sticky; top: 3.2rem; z-index: 8; margin-bottom: 1rem;
  padding: .6rem .9rem; border-radius: .4rem; font-size: .9rem;
}
.toast.ok { background: rgba(46,160,67,.18); border: 1px solid var(--on); color: #56d364; }
.toast.err { background: rgba(248,81,73,.18); border: 1px solid var(--bad); color: #ff7b72; }

.alerts-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: .6rem; padding: .6rem 1rem; margin-bottom: 1rem;
}
.alerts-panel summary { cursor: pointer; font-weight: 600; }
.alerts-form { display: flex; flex-direction: column; gap: .6rem; margin-top: .8rem; max-width: 520px; }
.alerts-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.alerts-form label.ck { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
.alerts-form input[type=text], .alerts-form input[type=number], .alerts-form select {
  padding: .45rem; border-radius: .4rem; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit;
}
.alerts-btns { display: flex; gap: .5rem; margin-top: .3rem; }
.pp-row { display: flex; align-items: center; gap: .4rem; }
.pp-row input[type=number] { width: 6.5rem; }

.prow { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .2rem 0; }
.prow .who { font-size: .9rem; }
.prow-btns { display: flex; gap: .3rem; }
.prow-btns .ctl { padding: .15rem .5rem; font-size: .72rem; }

#chat-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
#chat-modal[hidden] { display: none; }
.chat-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: .6rem;
  width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column;
}
.chat-head { display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: .7rem 1rem; min-height: 200px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.chat-line { padding: .1rem 0; white-space: pre-wrap; word-break: break-word; }
.chat-line.muted { color: var(--muted); }
.chat-send { display: flex; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--line); }
.chat-send input { flex: 1; padding: .5rem; border-radius: .4rem; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; }

.certnote {
  display: flex; align-items: flex-start; gap: .8rem;
  background: rgba(210,153,34,.14); border-bottom: 1px solid var(--warn);
  color: #e3b341; padding: .65rem 1rem; font-size: .85rem; line-height: 1.45;
}
.certnote[hidden] { display: none; }
.certnote-body { flex: 1; }
.certnote-body strong { color: #e3b341; }
.certnote-x {
  background: none; border: none; color: #e3b341; cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: .1rem .3rem; flex: none;
}
.certnote-x:hover { color: #fff; }

.srvname { color: var(--text); font-size: .82rem; margin: .1rem 0 .3rem; opacity: .85; }
.cardfoot { margin-top: .6rem; }
.joinbtn {
  position: absolute; top: .7rem; right: .8rem; z-index: 1;
  background: var(--panel2); color: var(--accent); border: 1px solid var(--accent);
  border-radius: .35rem; padding: .3rem .55rem; font: inherit; font-size: .78rem; cursor: pointer;
}
.joinbtn:hover { background: var(--accent); color: #001; }

/* thin horizontal divider — forces the action buttons onto the row below */
.ctl-divider {
  flex-basis: 100%; width: 100%; height: 1px; margin: .15rem 0;
  background: var(--line);
}

#join-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
#join-modal[hidden] { display: none; }
.join-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: .6rem;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
}
.join-head { display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.join-body { padding: .8rem 1rem 1.1rem; }
.join-srv { margin: 0 0 .3rem; color: var(--muted); }
.join-addr { margin: .2rem 0 .8rem; }
.join-body code {
  background: var(--panel2); border: 1px solid var(--line); border-radius: .3rem;
  padding: .1rem .4rem; font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text);
}
.join-steps { margin: 0; padding-left: 1.2rem; }
.join-steps li { margin: .35rem 0; line-height: 1.45; }

#logs-modal, #script-modal, #backups-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
#logs-modal[hidden], #script-modal[hidden], #backups-modal[hidden] { display: none; }
.bk-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem;
  padding: .45rem .2rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bk-meta { font-size: .82rem; }
.bk-btns { display: flex; gap: .35rem; align-items: center; }
a.ctl { text-decoration: none; display: inline-flex; align-items: center; }
.script-body {
  margin: .2rem 1rem; padding: .7rem; min-height: 300px; flex: 1; resize: vertical;
  border: 1px solid var(--line); border-radius: .4rem;
  background: var(--panel2); color: var(--text);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem;
  line-height: 1.4; white-space: pre; overflow: auto;
}
.logs-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: .6rem;
  width: 100%; max-width: 860px; max-height: 85vh; display: flex; flex-direction: column;
}
.logs-head { display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.logs-head span { display: flex; gap: .8rem; align-items: center; }
.logs-body {
  margin: 0; flex: 1; overflow: auto; padding: .7rem 1rem; min-height: 240px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem;
  line-height: 1.4; white-space: pre-wrap; word-break: break-word; color: var(--muted);
}

.foot { text-align: center; color: var(--muted); font-size: .78rem; padding: 1.5rem 0; }
.pubnote { text-align: center; color: var(--muted); font-size: .82rem; margin: 1.6rem auto 0;
  max-width: 640px; padding: .7rem 1rem; border: 1px solid var(--line); border-radius: .5rem;
  background: var(--panel); }

/* top nav */
.topbar nav .navlink { padding: .3rem .6rem; border-radius: .4rem; }
.topbar nav .navlink.active { background: var(--panel2, rgba(255,255,255,.08)); font-weight: 600; }

/* page chrome */
.page-title { margin: .2rem 0 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* settings page */
.settings-section { max-width: 620px; margin: 0 0 1.6rem; padding: 1rem 1.2rem;
  border: 1px solid var(--line); border-radius: .6rem; background: var(--panel); }
.settings-section h3 { margin: 0 0 .6rem; }
.settings-fs { border: 1px solid var(--line); border-radius: .5rem; padding: .5rem .8rem; }
.settings-fs legend { color: var(--muted); font-size: .8rem; padding: 0 .3rem; }

/* backups page */
.bk-servers { display: flex; flex-direction: column; gap: 1rem; }
.bk-server { max-width: 820px; }
.bk-server h3 { margin: 0 0 .5rem; display: flex; align-items: center; gap: .4rem; }
.bk-controls { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .4rem; }
.bk-keep-wrap { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; }
.bk-keep { width: 4rem; }
.bk-list { display: flex; flex-direction: column; }
/* Add-server: the per-game options are rendered into #as-extra */
#as-extra { display: flex; flex-direction: column; gap: .6rem; }
#as-extra:empty { display: none; }
/* Shared-ports confirmation (Add a server) */
#ports-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
#ports-modal[hidden] { display: none; }
#ports-modal .join-box { max-width: 560px; }
#ports-modal .join-body p { margin: 0 0 .7rem; line-height: 1.5; }
#ports-modal ul { margin: 0 0 .8rem; padding-left: 1.2rem; }
#ports-modal li { margin: .3rem 0; line-height: 1.45; }
.ports-list { background: var(--panel2); border: 1px solid var(--line); border-radius: .4rem;
  padding: .5rem .8rem .5rem 1.6rem !important; }
.ports-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap;
  padding: .7rem 1rem; border-top: 1px solid var(--line); }

/* Games panel (install a game) */
.games-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .7rem; max-width: 760px; }
.game-row { display: flex; gap: .8rem; align-items: center; justify-content: space-between;
  background: var(--panel2); border: 1px solid var(--line); border-radius: .5rem; padding: .6rem .8rem; }
.game-row .g-main { min-width: 0; }
.game-row .g-title { font-weight: 600; color: var(--text); }
.game-row .g-about, .game-row .g-need { font-size: .8rem; color: var(--muted); line-height: 1.4; }
.game-row .g-need.bad { color: #e3b341; }
.game-row .g-side { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; white-space: nowrap; }
.games-job { margin-top: .7rem; max-width: 760px; }
.games-job-text { font-size: .85rem; margin-bottom: .3rem; }
.bar { height: .55rem; background: var(--panel2); border: 1px solid var(--line); border-radius: 1rem; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }

/* "Can friends connect?" dialog */
#reach-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 1rem; }
#reach-modal .join-box { max-width: 600px; }
#reach-modal .join-body p { margin: 0 0 .7rem; line-height: 1.5; }
.reach-v { border: 1px solid var(--line); border-radius: .5rem; padding: .6rem .8rem; background: var(--panel2); }
.reach-v.good { border-color: #2ea043; }
.reach-v.warn { border-color: var(--warn); }
.reach-t { border-collapse: collapse; margin: 0 0 .8rem; width: 100%; font-size: .88rem; }
.reach-t th, .reach-t td { text-align: left; padding: .3rem .6rem; border-bottom: 1px solid var(--line); }

/* the hidden attribute must win over our display rules (labels/panels are flex) */
[hidden] { display: none !important; }

/* first-run setup page + getting-started checklist */
.setup-wrap { max-width: 460px; }
.setup-wrap form { display: flex; flex-direction: column; gap: .7rem; }
.setup-wrap label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--muted); }
.setup-note { font-size: .78rem; margin: -.3rem 0 .2rem; }
.checklist { display: flex; flex-direction: column; gap: .45rem; margin-top: .7rem; max-width: 760px; }
.check-row { display: flex; gap: .7rem; align-items: flex-start; background: var(--panel2);
  border: 1px solid var(--line); border-radius: .5rem; padding: .55rem .8rem; }
.check-row .mark { font-size: 1.05rem; line-height: 1.3; }
.check-row .c-title { font-weight: 600; color: var(--text); }
.check-row.done .c-title { color: var(--muted); text-decoration: line-through; }
.check-row .c-help { font-size: .8rem; color: var(--muted); line-height: 1.4; }
.check-row .c-go { margin-left: auto; white-space: nowrap; }

/* licence terms on the Add-a-server form and the Games list */
label.ck.eula { align-items: flex-start; line-height: 1.4; flex-basis: 100%; }
label.ck.eula input { margin-top: .2rem; flex: none; }
.eula-note { font-size: .82rem; color: var(--muted); line-height: 1.4; flex-basis: 100%; }
label.ck.eula a, .eula-note a, .game-row .g-need a, #games-terms a { color: var(--accent, #58a6ff); text-decoration: underline; }
