/* Spycraft panel.
 *
 * The in-game overlay is the reference, down to the numbers: a 47px header bar,
 * 7px corners, hairline rules at rgba(194,203,230,.11) and one saturated accent
 * against flat near-black. Everything here is those tokens and a handful of
 * rules on top — the panel and the menu should look like two views of one
 * program, because that is what they are.
 */

:root {
  --bg:        #060709;
  --bg-2:      #0b0d12;
  --panel:     #101219;
  --panel-2:   #161a23;
  --line:      rgba(194, 203, 230, .11);
  --line-2:    rgba(194, 203, 230, .19);
  --text:      #e8e8f0;
  --text-dim:  #8c8f9e;
  --text-off:  #676a78;
  --accent:    #b366ff;
  --accent-2:  #707af5;
  --accent-dk: #6a2fb0;
  --accent-bg: rgba(179, 102, 255, .13);
  --ok:        #4ecf79;
  --warn:      #f4b94b;
  --danger:    #ff6b6b;
  --info:      #55b8ff;

  --r:         7px;
  --r-lg:      10px;
  --head:      47px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.5 "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  background-image:
    radial-gradient(900px 460px at 12% -12%, rgba(179, 102, 255, .10), transparent 68%),
    radial-gradient(760px 420px at 102% -4%, rgba(112, 122, 245, .07), transparent 68%);
  background-attachment: fixed;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232733; border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #333949; background-clip: content-box; }

/* --- boot / gate --------------------------------------------------------- */

.boot { display: grid; place-items: center; min-height: 100vh; }
.spin {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gate { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.gate-card {
  width: 100%; max-width: 372px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px 24px 20px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .6);
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--accent); margin-bottom: 20px; }
.brand h1 {
  margin: 0; font-size: 17px; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: var(--text);
}
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); letter-spacing: .14em; text-transform: uppercase; }
.brand.small { margin: 0; gap: 9px; }
.brand.small strong { color: var(--text); letter-spacing: .15em; font-size: 13px; text-transform: uppercase; }

/* --- forms --------------------------------------------------------------- */

.stack { display: grid; gap: 13px; }
label { display: grid; gap: 5px; font-size: 12px; color: var(--text-dim); }
.hint { color: var(--text-off); }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
textarea { font: 12.5px/1.6 var(--mono); resize: vertical; min-height: 340px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dk);
  box-shadow: 0 0 0 2px rgba(179, 102, 255, .16);
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 30px; cursor: pointer; }
input[type=range] { accent-color: var(--accent); padding: 0; border: none; background: none; }
input[type=file] { padding: 6px; font-size: 12px; }
select { cursor: pointer; }
input:disabled, select:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }

button {
  font: inherit;
  padding: 8px 13px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover:not(:disabled) { background: #1e2330; border-color: rgba(194, 203, 230, .3); }
button:disabled { opacity: .4; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dk));
  border-color: #7c3fc4;
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); background: rgba(255, 255, 255, .03); }
button.danger { border-color: #5a2a2a; color: #ff9a9a; background: #1d1315; }
button.danger:hover:not(:disabled) { background: #2a181b; border-color: #7a3838; }
button.tiny { padding: 4px 9px; font-size: 12px; }

.msg { min-height: 17px; margin: 14px 0 0; font-size: 12.5px; color: var(--danger); }
.msg.ok { color: var(--ok); }

/* --- app chrome ---------------------------------------------------------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.top {
  flex: none;
  background: rgba(7, 9, 14, .96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.top-row {
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: var(--head);
}
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
#who-name { color: var(--text-dim); }

/* user / admin switch — the segmented control from the in-game sub-tab row */
.modes {
  display: flex; gap: 3px; padding: 3px;
  background: rgba(16, 18, 25, .82);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.modes button {
  border: none; background: none; border-radius: 5px;
  padding: 4px 14px; font-size: 12.5px; color: var(--text-dim);
}
.modes button:hover:not(.on) { background: rgba(255, 255, 255, .04); color: var(--text); }
.modes button.on { background: var(--accent-bg); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(179, 102, 255, .34); }

/* Remote control in the header. Deliberately quiet — it sits next to the brand
   all day, so it reads as chrome until you need it. */
.remote {
  display: flex; align-items: center; gap: 3px; padding: 3px 6px 3px 9px;
  background: rgba(16, 18, 25, .82);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.remote button {
  border: none; background: none; border-radius: 5px;
  padding: 4px 10px; font-size: 12px; color: var(--text-dim);
}
.remote button:hover:not(:disabled) { background: rgba(255, 255, 255, .05); color: var(--text); }
.remote button:disabled { opacity: .35; }

.dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--text-off);
}
.dot.on { background: var(--ok); box-shadow: 0 0 7px rgba(78, 207, 121, .8); }
.dot.off { background: #4a4f5c; }
.dot.busy { background: var(--accent); animation: pulse 1s ease-in-out infinite; margin-left: 3px; }
@keyframes pulse { 50% { opacity: .25; } }

@media (max-width: 900px) {
  /* The dot still says whether a client is there; the labels are what goes. */
  .remote button { padding: 4px 7px; font-size: 11px; }
}

/* The two settings that are only occasionally the point, folded away. */
.more { margin-top: 12px; }
.more > summary {
  cursor: pointer; font-size: 12px; color: var(--text-dim);
  padding: 4px 0; list-style: none; width: max-content;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "▸ "; color: var(--text-off); }
.more[open] > summary::before { content: "▾ "; }
.more > summary:hover { color: var(--text); }

/* The page nav: a row of underlined tabs under the header bar. It carries only
   the pages of the half you are in — switching halves swaps the whole row, which
   is the point of the split. */
.nav {
  display: flex; gap: 2px; padding: 0 14px;
  overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav button {
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  padding: 9px 12px 8px; border-radius: 0;
  border: none; border-bottom: 2px solid transparent;
  background: none; color: var(--text-dim);
}
.nav button svg { flex: none; width: 15px; height: 15px; opacity: .75; }
.nav button:hover:not(.on) { background: none; color: var(--text); }
.nav button.on { color: var(--accent); border-bottom-color: var(--accent); }
.nav button.on svg { opacity: 1; }

main { padding: 20px 20px 40px; max-width: 1280px; width: 100%; margin: 0 auto; }

@media (max-width: 700px) {
  .top-row { gap: 10px; }
  .top-row .brand.small strong { display: none; }
}

/* --- shared bits --------------------------------------------------------- */

.pill {
  font-size: 10.5px; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
  border: 1px solid var(--line-2); color: var(--text-dim); background: var(--panel-2);
  text-transform: uppercase; letter-spacing: .07em;
}
.pill.admin { color: var(--warn);   border-color: #5b452a; background: #1e1810; }
.pill.beta  { color: var(--info);   border-color: #2a4a5b; background: #101a21; }
.pill.mod   { color: var(--accent); border-color: #4a2f6b; background: #171022; }
.pill.on    { color: var(--ok);     border-color: #2b5c3c; background: #0e1a13; }
.pill.off   { color: var(--danger); border-color: #5a2a2a; background: #1d1315; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
}
.card + .card { margin-top: 14px; }
.card h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.card .sub { margin: 4px 0 0; font-size: 12.5px; color: var(--text-dim); max-width: 76ch; }
.card .sub + * { margin-top: 14px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.split { display: grid; grid-template-columns: 272px 1fr; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

.list { display: grid; gap: 4px; }
.item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px;
  border: 1px solid transparent; background: var(--bg-2);
  cursor: pointer; text-align: left; width: 100%; color: inherit;
}
.item:hover { background: var(--panel-2); }
.item.on { border-color: rgba(179, 102, 255, .34); background: var(--accent-bg); }
.item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { margin-left: auto; font-size: 11px; color: var(--text-off); font-family: var(--mono); }

.empty { padding: 30px; text-align: center; color: var(--text-off); font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--text-off); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .022); }
td.mono, .mono { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-off); }
.kv dd { margin: 0; }

code {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px; color: var(--accent);
}
.warnbox {
  border: 1px solid #5b452a; background: #191309; color: #ffd9a0;
  padding: 10px 12px; border-radius: 6px; font-size: 12.5px;
}
.notebox {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text-dim);
  padding: 11px 13px; border-radius: 6px; font-size: 12.5px; max-width: 78ch;
}

/* --- config editor: the in-game page ------------------------------------- */

/* section strip = the overlay's sidebar, sub-tab row = its segmented control */
.cfg-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 2px; }
.cfg-head h2 { font-size: 15px; }

.sections { display: flex; gap: 3px; flex-wrap: wrap; margin: 14px 0 0; }
.sections button {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 6px; font-size: 12.5px;
  border: 1px solid transparent; background: none; color: var(--text-dim);
}
.sections button svg { width: 14px; height: 14px; opacity: .75; }
.sections button:hover:not(.on) { background: rgba(255, 255, 255, .04); color: var(--text); }
.sections button.on { background: var(--accent-bg); color: var(--accent); border-color: rgba(179, 102, 255, .3); }
.sections button.on svg { opacity: 1; }
.sections button.muted { color: var(--text-off); }

.subs {
  display: inline-flex; gap: 3px; padding: 3px; margin: 14px 0 4px;
  background: rgba(16, 18, 25, .82); border: 1px solid var(--line); border-radius: var(--r);
}
.subs button {
  border: none; background: none; border-radius: 5px;
  padding: 4px 15px; font-size: 12.5px; color: var(--text-dim);
}
.subs button:hover:not(.on) { background: rgba(255, 255, 255, .04); color: var(--text); }
.subs button.on { background: var(--accent-bg); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(179, 102, 255, .34); }
.subs button.muted { color: var(--text-off); }

.page-head { margin: 14px 0 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.page-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.page-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-dim); max-width: 76ch; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 14px; margin-top: 14px; align-items: start; }
.cards.one { grid-template-columns: 1fr; }

.box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  /* Rows react to the width of their card, not of the window: two cards side by
     side are each half as wide as one, and a media query cannot tell. */
  container-type: inline-size;
}
.box > header {
  padding: 9px 13px;
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-off);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .015);
}
.box > .body { padding: 4px 13px 10px; }

/* One setting = one row: label on the left, control on the right, exactly the
   shape Ui::Row draws in the overlay. The grid of boxed inputs it replaces made
   ten checkboxes look like ten separate decisions. */
.set { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(194, 203, 230, .06); }
.set:last-child { border-bottom: none; }
.set > .txt { min-width: 0; }
.set > .txt .name { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 7px; }
.set > .txt .why { margin: 2px 0 0; font-size: 11.5px; color: var(--text-off); line-height: 1.45; }
.set > .ctl { display: flex; align-items: center; gap: 8px; justify-self: end; }
.set.changed > .txt .name::after {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 6px var(--accent);
}
.set .key {
  font-family: var(--mono); font-size: 10px; color: var(--text-off);
  border: 1px solid var(--line); border-radius: 3px; padding: 0 4px;
}
.set .num { width: 74px; text-align: right; font-family: var(--mono); font-size: 12px; padding: 5px 7px; }
.set .unit { font-size: 11px; color: var(--text-off); min-width: 26px; }
.set input[type=range] { width: 148px; }
.set select { width: auto; min-width: 150px; padding: 5px 8px; }
.set input[type=text], .set > .ctl > input:not([type]) { width: 190px; padding: 5px 8px; }
.set .swatch { width: 32px; height: 24px; padding: 2px; }
.set .hex { width: 92px; text-align: center; font-family: var(--mono); font-size: 11.5px; padding: 5px 4px; }

/* Below this the control and the label are fighting over the same 300px, and the
   label loses — a two-word name wrapped over four lines beside a slider. Stack
   them instead. */
@container (max-width: 400px) {
  .set { grid-template-columns: 1fr; }
  .set > .ctl { justify-self: start; }
  .set input[type=range] { width: 132px; }
}
@media (max-width: 560px) {
  .set { grid-template-columns: 1fr; }
  .set > .ctl { justify-self: start; }
}

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 34px; height: 19px; border-radius: 99px; flex: none;
  background: #23262f; border: 1px solid var(--line-2);
  position: relative; transition: background .14s, border-color .14s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--text-off); transition: transform .14s, background .14s;
}
.switch input:checked + .track { background: rgba(179, 102, 255, .22); border-color: var(--accent-dk); }
.switch input:checked + .track::after { transform: translateX(15px); background: var(--accent); }
.switch input:disabled + .track { opacity: .5; }
.switch .txt { font-size: 12px; color: var(--text-dim); min-width: 22px; }

.sticky-bar {
  position: sticky; bottom: 12px; margin-top: 16px; z-index: 5;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 8px;
  background: rgba(11, 13, 18, .97);
  border: 1px solid var(--line-2);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
}

/* --- admin: build source form -------------------------------------------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 14px; }
.form-grid label { gap: 5px; }
.form-grid label .why { font-size: 11px; color: var(--text-off); line-height: 1.4; }
.form-grid .wide { grid-column: 1 / -1; }

.proj { border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); overflow: hidden; }
.proj + .proj { margin-top: 10px; }
.proj > header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 11px 13px; }
.proj > .body { padding: 0 13px 13px; border-top: 1px solid var(--line); padding-top: 13px; }
.proj .slug { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }

.resolved { font-size: 12px; border-radius: 6px; padding: 9px 11px; margin-top: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .02); }
.resolved.ok { border-color: #2b5c3c; background: #0d1712; color: #b9ebc9; }
.resolved.bad { border-color: #5a2a2a; background: #1a1113; color: #ffb3b3; }
.resolved dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 6px 0 0; font-family: var(--mono); font-size: 11.5px; }
.resolved dt { opacity: .7; }
.resolved dd { margin: 0; word-break: break-all; }

/* --- permission grid ----------------------------------------------------- */

.perm-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.perm-group h4 { margin: 0 0 8px; font-size: 11px; color: var(--text-off); text-transform: uppercase; letter-spacing: .08em; }
.perm { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.perm .tri {
  width: 78px; font-size: 11px; padding: 2px 6px; border-radius: 5px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text-dim);
}
.perm .tri.grant { color: var(--ok); border-color: #2b5c3c; }
.perm .tri.deny  { color: var(--danger); border-color: #5a2a2a; }
.perm .pname { font-family: var(--mono); font-size: 11px; color: var(--text-off); }

/* A code is meant to be read out loud and typed in by hand, so it gets the room
   to be legible: monospace, wide tracking, and big enough to read off a phone. */
.codebox {
  font-family: var(--mono);
  font-size: 19px; letter-spacing: .16em;
  padding: 13px 16px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--line-2);
  color: var(--accent); text-align: center;
  user-select: all; word-break: break-all;
}

/* --- dialogs ------------------------------------------------------------- */

dialog.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 20px 22px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
}
dialog.modal::backdrop { background: rgba(3, 4, 7, .66); backdrop-filter: blur(2px); }
dialog.modal h3 { margin: 0; font-size: 15px; font-weight: 600; }
dialog.modal .sub { margin: 6px 0 0; font-size: 12.5px; color: var(--text-dim); }
dialog.modal h3 + .stack, dialog.modal .sub + .stack,
dialog.modal h3 + .list, dialog.modal .sub + .list,
dialog.modal h3 + div, dialog.modal .sub + div { margin-top: 16px; }
dialog.modal .why { font-size: 11px; color: var(--text-off); line-height: 1.4; }
dialog.modal .notebox code { display: block; font-size: 14px; letter-spacing: .04em; word-break: break-all; }

/* --- toasts -------------------------------------------------------------- */

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 14px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2);
  font-size: 12.5px; box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  animation: rise .18s ease-out;
  max-width: 380px;
}
.toast.err { border-color: #6a3030; color: #ffb0b0; }
.toast.ok  { border-color: #2b5c3c; color: #b6f0c4; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
