/* The host bots' panel. The page follows the system's light or dark; a bot's lobby, the buttons,
   the key form and the confirmation are drawn as Warcraft III draws them (its stone, gold trim
   and button bevels, from the game's UI textures) in both. */

:root {
  --page: #ebe5d7;
  --surface: #fbf8f1;
  --surface-sunk: #f2ede1;
  --ink: #241e13;
  --muted: #6e6553;
  --rule: #dad0ba;
  --accent: #8a6410;
  --good: #2b7a46;
  --warn: #9a5f06;
  --bad: #b0281c;
  --info: #2a5a96;
  --special: #6b3fa0;
  --chat: #255d9c;
  --daemon: #7a5a0c;
  --problem-tint: #fbe7e3;
  --shadow: 0 1px 2px rgb(60 45 20 / 0.08), 0 6px 20px rgb(60 45 20 / 0.06);

  /* The game's own look: the same in light and dark. */
  --game-ink: #f1e9d2;
  --game-muted: #9d9a8c;
  --game-faint: #6f6e66;
  --game-gold: #ffcc00;
  --game-gold-soft: #e0b84a;
  --game-danger: #ff8a6b;
  --game-row: rgb(4 8 16 / 0.42);
  --game-row-line: rgb(255 255 255 / 0.07);
  --game-me: rgb(255 204 0 / 0.1);
  --game-shade: #131b2b;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --gutter: 16px;

  /* Warcraft III's player colours, by index. */
  --player-0: #ff0303;
  --player-1: #0042ff;
  --player-2: #1ce6b9;
  --player-3: #540081;
  --player-4: #fffc00;
  --player-5: #fe8a0e;
  --player-6: #20c000;
  --player-7: #e55bb0;
  --player-8: #959697;
  --player-9: #7ebff1;
  --player-10: #106246;
  --player-11: #4e2a04;
  --player-12: #9b0000;
  --player-13: #0000c3;
  --player-14: #00eaff;
  --player-15: #be00fe;
  --player-16: #ebcd87;
  --player-17: #f8a48b;
  --player-18: #bfff80;
  --player-19: #dcb9eb;
  --player-20: #282828;
  --player-21: #ebf0ff;
  --player-22: #00781e;
  --player-23: #a46f33;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0c0f15;
    --surface: #161a23;
    --surface-sunk: #10131a;
    --ink: #e8e2d1;
    --muted: #979080;
    --rule: #2a303d;
    --accent: #f0c24a;
    --good: #5cc983;
    --warn: #e4aa48;
    --bad: #f27a6b;
    --info: #8ab4ee;
    --special: #c49bf2;
    --chat: #8fbcf0;
    --daemon: #e2be62;
    --problem-tint: #2c1716;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

.page {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font-body);
}

/* --- the masthead and the connection --- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px var(--gutter) 14px;
}

.masthead__brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-right: auto; }

.masthead__title {
  margin: 0;
  font: 600 24px/1.1 var(--font-display);
  color: var(--accent);
  letter-spacing: 0.01em;
}

.masthead__summary { margin: 0; color: var(--muted); }

.masthead__key {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.masthead__key:hover { color: var(--ink); border-color: var(--muted); }

.masthead__signout { margin: 0; }

.link {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.link__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.link--live .link__dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.link--live { color: var(--good); }
.link--connecting .link__dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.link--down .link__dot { background: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
.link--down { color: var(--bad); }
.link--key .link__dot { background: var(--warn); }
.link--key { color: var(--warn); }

@keyframes pulse { 50% { opacity: 0.3; } }

@media (prefers-reduced-motion: reduce) {
  .link__dot { animation: none !important; }
}

/* --- the game's look: framed stone, gold trim --- */

.lobby,
.gate__form,
.confirm {
  border: 18px solid transparent;
  border-image: url("/panel/lobby-frame.png") 28 / 18px round;
  background: var(--game-shade) url("/panel/stone.jpg") repeat;
  background-clip: padding-box;
  color: var(--game-ink);
}

/* A Warcraft III menu button: the stone, its bevelled gold edge, a glow under the pointer. */
.button {
  min-height: 38px;
  padding: 2px 16px;
  border: 10px solid transparent;
  border-image: url("/panel/button.png") 16 / 10px stretch;
  border-radius: 6px;
  background: var(--game-shade) url("/panel/stone.jpg") center / 256px repeat;
  color: var(--game-gold);
  font: 600 14px/1.2 var(--font-display);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px #000;
  cursor: pointer;
}

.button:hover:not(:disabled) {
  background:
    url("/panel/glow.png") center / 100% 100% no-repeat,
    var(--game-shade) url("/panel/stone.jpg") center / 256px repeat;
  color: #fff3b0;
}

.button:active:not(:disabled) {
  border-image-source: url("/panel/button-down.png");
  padding: 3px 15px 1px 17px;
}

.button:focus-visible { outline: 2px solid var(--game-gold); outline-offset: 2px; }
.button:disabled { filter: grayscale(1) brightness(0.8); opacity: 0.55; cursor: default; }
.button--danger { color: var(--game-danger); }
.button--danger:hover:not(:disabled) { color: #ffc2b0; }
.button--quiet { color: var(--game-muted); }
a.button { display: inline-flex; align-items: center; text-decoration: none; }

/* --- the key form --- */

.gate {
  display: grid;
  place-items: center;
  padding: 32px var(--gutter) 48px;
}

.gate__form {
  display: grid;
  gap: 10px;
  width: min(100%, 420px);
  padding: 14px 18px 18px;
}

.gate__title { margin: 0; font: 600 20px/1.2 var(--font-display); color: var(--game-gold); }
.gate__note { margin: 0; color: var(--game-muted); font-size: 14px; }
.gate__label { font-size: 13px; color: var(--game-muted); }

.gate__input {
  padding: 8px 10px;
  border: 1px solid rgb(255 204 0 / 0.35);
  border-radius: 4px;
  background: rgb(0 0 0 / 0.45);
  color: var(--game-ink);
  font: 15px var(--font-mono);
}

.gate__input:focus { outline: 2px solid var(--game-gold); outline-offset: 1px; }
.gate__buttons { display: flex; gap: 8px; margin-top: 4px; }

/* --- the bots --- */

.bots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 36rem), 1fr));
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
}

.bots--stale .bot { opacity: 0.6; filter: saturate(0.5); }

.bots-empty {
  max-width: 36rem;
  margin: 24px auto;
  padding: 0 var(--gutter);
  color: var(--muted);
  text-align: center;
}

.bot {
  container: bot / inline-size;
  min-width: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: opacity 0.3s;
}

.bot__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "offline" "facts" "lobby" "commands" "log";
  gap: 14px;
  padding: 16px;
}

.bot__head { grid-area: head; display: flex; align-items: center; gap: 12px; min-width: 0; }

.bot__presence {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
}

.bot--online .bot__presence {
  background: var(--good);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 20%, transparent);
}

.bot__title { min-width: 0; margin-right: auto; }

.bot__name {
  margin: 0;
  font: 600 19px/1.2 var(--font-display);
  overflow-wrap: anywhere;
}

.bot__account { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.bot__offline {
  grid-area: offline;
  margin: 0;
  padding: 8px 12px;
  border-left: 3px solid var(--warn);
  border-radius: 4px;
  background: var(--surface-sunk);
  color: var(--muted);
  font-size: 14px;
}

.bot--offline .bot__name { color: var(--muted); }
.bot--offline .lobby { filter: saturate(0.4) brightness(0.85); }

/* The lobby's state, at a glance. */
.state {
  flex: none;
  padding: 3px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
}

.state--offline { color: var(--muted); border-style: dashed; }
.state--signed-out { color: var(--bad); }
.state--idle { color: var(--muted); }
.state--creating { color: var(--warn); }
.state--advertising { color: var(--info); }
.state--open { color: var(--good); }
.state--started { color: var(--special); }

.facts {
  grid-area: facts;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-sunk);
}

.facts__item { min-width: 0; }
.facts__item--wide { flex: 1 1 14rem; }
.facts__label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.facts__value { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* --- the lobby, team by team and slot by slot --- */

.lobby { grid-area: lobby; padding: 6px 8px 10px; min-width: 0; }

.lobby__name {
  margin: 0;
  padding: 2px 4px 8px;
  font: 600 16px/1.25 var(--font-display);
  color: var(--game-gold);
  text-shadow: 0 1px 2px #000;
  overflow-wrap: anywhere;
}

.lobby__none { margin: 4px 4px 2px; color: var(--game-muted); font-style: italic; }
.lobby__teams { display: grid; gap: 10px; }

.team__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 4px 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid rgb(255 204 0 / 0.25);
}

.team__name {
  margin: 0 auto 0 0;
  font: 600 13px/1.3 var(--font-display);
  color: var(--game-gold-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.team__count { color: var(--game-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.team__slots { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }

.slot {
  display: grid;
  grid-template-columns: 1.6rem 0.9rem minmax(0, 1fr) auto 2.6rem;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 2px 8px;
  border: 1px solid var(--game-row-line);
  border-radius: 3px;
  background: var(--game-row);
  font-size: 13.5px;
}

.slot__number { color: var(--game-faint); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }

.slot__swatch {
  width: 0.9rem;
  height: 0.9rem;
  border: 1px solid rgb(0 0 0 / 0.6);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
  background: var(--game-faint);
}

.slot__who { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
.slot__name { overflow-wrap: anywhere; }
.slot__race, .slot__handicap { color: var(--game-muted); font-size: 12px; white-space: nowrap; }
.slot__handicap { text-align: right; font-variant-numeric: tabular-nums; }

.slot__empty {
  grid-column: 2 / -1;
  color: var(--game-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.slot--closed { background: rgb(0 0 0 / 0.55); }
.slot--closed .slot__empty { color: var(--game-faint); }
.slot--computer .slot__name { color: var(--game-muted); }

.slot--me { background: var(--game-me); border-color: rgb(255 204 0 / 0.45); }
.slot--me .slot__name { color: var(--game-gold); font-weight: 600; }

.slot__badge {
  padding: 0 6px;
  border: 1px solid rgb(255 204 0 / 0.6);
  border-radius: 3px;
  color: var(--game-gold);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.slot__download { display: inline-flex; align-items: center; gap: 6px; color: var(--game-muted); font-size: 11.5px; }

.slot__progress {
  appearance: none;
  width: 64px;
  height: 6px;
  border: 0;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.12);
  overflow: hidden;
}

.slot__progress::-webkit-progress-bar { background: rgb(255 255 255 / 0.12); }
.slot__progress::-webkit-progress-value { background: var(--game-gold-soft); }
.slot__progress::-moz-progress-bar { background: var(--game-gold-soft); }

.slot__swatch--0 { background: var(--player-0); }
.slot__swatch--1 { background: var(--player-1); }
.slot__swatch--2 { background: var(--player-2); }
.slot__swatch--3 { background: var(--player-3); }
.slot__swatch--4 { background: var(--player-4); }
.slot__swatch--5 { background: var(--player-5); }
.slot__swatch--6 { background: var(--player-6); }
.slot__swatch--7 { background: var(--player-7); }
.slot__swatch--8 { background: var(--player-8); }
.slot__swatch--9 { background: var(--player-9); }
.slot__swatch--10 { background: var(--player-10); }
.slot__swatch--11 { background: var(--player-11); }
.slot__swatch--12 { background: var(--player-12); }
.slot__swatch--13 { background: var(--player-13); }
.slot__swatch--14 { background: var(--player-14); }
.slot__swatch--15 { background: var(--player-15); }
.slot__swatch--16 { background: var(--player-16); }
.slot__swatch--17 { background: var(--player-17); }
.slot__swatch--18 { background: var(--player-18); }
.slot__swatch--19 { background: var(--player-19); }
.slot__swatch--20 { background: var(--player-20); }
.slot__swatch--21 { background: var(--player-21); }
.slot__swatch--22 { background: var(--player-22); }
.slot__swatch--23 { background: var(--player-23); }

@container bot (max-width: 26rem) {
  .slot { grid-template-columns: 1.3rem 0.8rem minmax(0, 1fr) 2.4rem; gap: 6px; }
  .slot__race { display: none; }
}

/* --- the commands --- */

.commands { grid-area: commands; display: grid; gap: 6px; }
.commands__buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.commands__pending, .commands__note { margin: 0; font-size: 13.5px; }
.commands__pending { color: var(--warn); }
.commands__note:empty { display: none; }
.commands__note--ok { color: var(--good); }
.commands__note--error { color: var(--bad); }

/* --- the log --- */

.log { grid-area: log; display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.log__head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }

.log__title {
  margin: 0 auto 0 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.log__filters { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; border: 0; }
.log__legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.filter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.filter:has(.filter__box:checked) { color: var(--ink); background: var(--surface-sunk); }
.filter__box { margin: 0; accent-color: var(--accent); }
.filter--chat:has(.filter__box:checked) { border-color: color-mix(in srgb, var(--chat) 50%, transparent); }
.filter--problem:has(.filter__box:checked) { border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.filter--daemon:has(.filter__box:checked) { border-color: color-mix(in srgb, var(--daemon) 50%, transparent); }

.log__lines {
  max-height: 20rem;
  min-height: 6rem;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface-sunk);
  list-style: none;
  font: 12.5px/1.5 var(--font-mono);
}

.log__empty { display: none; margin: 0; color: var(--muted); font-size: 13px; }
.log--empty .log__empty { display: block; }
.log--empty .log__lines { display: none; }

.log--hide-chat .line--chat,
.log--hide-problem .line--problem,
.log--hide-daemon .line--daemon,
.log--hide-log .line--log { display: none; }

.line {
  display: grid;
  grid-template-columns: auto 4.6em minmax(0, 1fr);
  gap: 8px;
  padding: 1px 10px;
}

.line__time { color: var(--muted); font-variant-numeric: tabular-nums; }
.line__kind { color: var(--muted); font-size: 11px; line-height: 1.75; text-transform: uppercase; letter-spacing: 0.04em; }
.line__text { overflow-wrap: anywhere; white-space: pre-wrap; }

.line--chat .line__kind, .line--chat .line__text { color: var(--chat); }
.line--daemon .line__kind, .line--daemon .line__text { color: var(--daemon); }
.line--problem { background: var(--problem-tint); }
.line--problem .line__kind, .line--problem .line__text { color: var(--bad); }

@container bot (max-width: 26rem) {
  .line { grid-template-columns: auto minmax(0, 1fr); gap: 0 8px; }
  .line__kind { display: none; }
  .line--chat, .line--problem, .line--daemon { border-left: 2px solid currentColor; }
  .line--chat { color: var(--chat); }
  .line--daemon { color: var(--daemon); }
  .line--problem { color: var(--bad); }
}

/* --- the confirmation --- */

.confirm {
  width: min(calc(100% - 2 * var(--gutter)), 440px);
  padding: 0;
}

.confirm::backdrop { background: rgb(0 0 0 / 0.55); }
.confirm__form { display: grid; gap: 10px; padding: 12px 16px 16px; }
.confirm__title { margin: 0; font: 600 19px/1.25 var(--font-display); color: var(--game-gold); }
.confirm__text { margin: 0; color: var(--game-ink); }
.confirm__buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

@media (max-width: 480px) {
  .masthead { padding-top: 14px; }
  .masthead__title { font-size: 21px; }
  .bot__layout { padding: 12px; gap: 12px; }
  .lobby { border-width: 14px; border-image-width: 14px; padding: 4px 4px 8px; }
}

/* Wide enough: the lobby beside its log. */
@container bot (min-width: 60rem) {
  .bot__layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas:
      "head head"
      "offline offline"
      "facts facts"
      "lobby log"
      "commands log";
  }

  .log { min-height: 0; }
  .log__lines { max-height: none; flex: 1 1 0; }
}
