:root {
  --bg: #0c0f17;
  --panel: #141a26;
  --panel-2: #1b2333;
  --line: #2a3550;
  --text: #e8edf6;
  --muted: #8b97b0;
  --accent: #5cc8ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "SF Pro Text", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#topbar {
  position: relative;
  z-index: 10;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, #121826, #0e131e);
  border-bottom: 1px solid var(--line);
}

.brand { color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: 2px; font-size: 15px; }
.brand .sub { color: var(--muted); font-weight: 400; letter-spacing: 1px; margin-left: 8px; font-size: 12px; }

.controls { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.controls input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 5px 8px; font-size: 12px;
}
.controls button {
  background: var(--accent); color: #06121c; border: 0; border-radius: 6px;
  padding: 6px 14px; font-weight: 600; cursor: pointer;
}
.controls button:hover { filter: brightness(1.1); }
.controls button.secondary { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.controls button.danger { background: var(--panel-2); border: 1px solid #ff8d8d; color: #ff8d8d; }

.status { padding: 3px 9px; border-radius: 999px; font-weight: 600; font-size: 11px; }
.status.off { background: #3a2230; color: #ff8aa8; }
.status.on { background: #143728; color: #57e39b; }
.planning-countdown {
  display: inline-flex; align-items: center; padding: 3px 9px; border: 1px solid rgba(255, 212, 121, 0.34);
  border-radius: 999px; background: rgba(84, 61, 22, 0.55); color: #ffd479; font-size: 11px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.planning-countdown[hidden] { display: none; }
.step { color: var(--muted); font-variant-numeric: tabular-nums; }
.home-mode #status, .home-mode #step { display: none; }

main { display: flex; height: calc(100% - 52px); }
main[hidden] { display: none; }

#home {
  overflow-y: auto;
  background:
    radial-gradient(circle at 14% 22%, rgba(92, 200, 255, 0.13), transparent 28%),
    radial-gradient(circle at 90% 80%, rgba(126, 224, 160, 0.08), transparent 25%),
    linear-gradient(135deg, #0c0f17 0%, #101724 55%, #0c0f17 100%);
}
.home-shell {
  width: min(1240px, calc(100% - 64px)); margin: auto;
  display: grid; grid-template-columns: minmax(260px, 0.8fr) minmax(520px, 1.35fr);
  gap: 72px; padding: 70px 0 90px; align-items: start;
}
.home-intro { position: sticky; top: 70px; padding-top: 34px; }
.eyebrow {
  margin: 0 0 14px; color: var(--accent); font-size: 10px; font-weight: 700;
  letter-spacing: 2.4px; text-transform: uppercase;
}
.home-intro h1 {
  margin: 0; max-width: 540px; font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(54px, 6vw, 88px); font-weight: 400; line-height: 0.93; letter-spacing: -4px;
}
.home-intro > p:last-child {
  max-width: 430px; margin: 30px 0 0; color: #aeb8ca; font-size: 16px; line-height: 1.7;
}
#game-browser {
  min-height: 500px; padding: 30px; border: 1px solid rgba(92, 200, 255, 0.17);
  border-radius: 18px; background: rgba(15, 21, 32, 0.78); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(12px);
}
.game-browser-head { display: flex; align-items: center; justify-content: space-between; }
.game-browser-head .eyebrow { margin-bottom: 5px; }
.game-browser-head h2 { margin: 0; font-family: Georgia, serif; font-size: 36px; font-weight: 400; }
#refresh-games {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
#refresh-games:hover { color: var(--text); border-color: var(--accent); }
.hosted-panel {
  margin-top: 26px; padding: 22px 0; border-top: 1px solid rgba(42, 53, 80, 0.8);
  border-bottom: 1px solid rgba(42, 53, 80, 0.8);
}
.hosted-panel + .game-list-status { margin-top: 22px; }
.hosted-panel[hidden] { display: none; }
.hosted-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
/* Start game and its tour toggle stay together at the top of the head, level
   with the title, so the collapsible intro below cannot push them off-centre. */
.hosted-start { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
/* Matches the "How this works" summary opposite it: same muted uppercase
   caption, so the two things framing the panel head read as one pair. */
.tutorial-toggle {
  display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer;
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
}
.tutorial-toggle:hover { color: var(--text); }
.tutorial-toggle input { cursor: pointer; margin: 0; }
.hosted-panel-head .eyebrow { margin-bottom: 5px; }
.hosted-panel h3 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: 0; }
.hosted-panel button {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.hosted-panel button:hover { color: var(--text); border-color: var(--accent); }
#start-hosted-game, #lobby-watch {
  border-color: transparent; background: var(--accent); color: #06121c; font-weight: 700;
}
.hosted-panel #lobby-watch:hover { color: #06121c; }
.hosted-controls {
  display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin-top: 16px;
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
}
.hosted-controls label { display: grid; gap: 5px; }
.hosted-controls select {
  min-width: 96px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
/* Always visible in the left column under the headline: the rules are the
   first thing a newcomer needs, and behind a summary they went unread. */
.intro-panel {
  margin-top: 26px; max-width: 52ch;
  border-top: 1px solid var(--line); padding-top: 16px;
}
.intro-panel-title {
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  margin: 0 0 8px;
}
.intro-panel p { margin: 0 0 8px; color: #8c98ad; font-size: 12.5px; line-height: 1.55; }
.intro-panel p:last-child { margin-bottom: 0; }
.intro-panel strong { color: #cbd6e8; font-weight: 650; }

.goal-template-panel {
  margin-top: 14px; border: 1px solid rgba(42, 53, 80, 0.8); border-radius: 8px;
  background: rgba(20, 26, 38, 0.38);
}
.goal-template-panel summary {
  padding: 9px 11px; color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; cursor: pointer;
}
.goal-template-panel[open] summary { color: var(--text); }
.hosted-goals {
  display: grid; gap: 10px; padding: 0 10px 10px;
}
.hosted-player-goal {
  display: grid; gap: 7px; padding-top: 10px; border-top: 1px solid rgba(42, 53, 80, 0.62);
}
.hosted-player-goal:first-child { padding-top: 0; border-top: 0; }
.hosted-player-goal-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.hosted-player-goal-name {
  min-width: 0; color: #cbd6e8; font-size: 13px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hosted-player-goal-owner {
  flex: none; color: #68758c; font: 10px monospace;
}
.hosted-player-goal-text {
  width: 100%; resize: vertical; min-height: 84px; background: var(--panel-2);
  color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px;
  font: 12px/1.45 "Inter", "SF Pro Text", system-ui, -apple-system, sans-serif;
}
.template-hint { margin: -2px 10px 10px; color: #68758c; font-size: 11px; }
.hosted-roster {
  display: grid; gap: 8px; margin-top: 16px;
}
.hosted-player-config {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid rgba(42, 53, 80, 0.65);
}
.hosted-player-config:first-child { border-top: 0; }
.hosted-player-config-identity { min-width: 0; display: grid; gap: 3px; }
.hosted-player-config-name {
  min-width: 0; color: #cbd6e8; font-size: 13px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hosted-player-config-owner { color: #68758c; font: 10px monospace; }
.hosted-player-config-controls { display: flex; align-items: end; justify-content: end; gap: 8px; }
.hosted-agent-field, .hosted-model-field, .hosted-handicap-field {
  display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
}
.hosted-agent-select, .hosted-model-select, .hosted-handicap-select {
  min-width: 132px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
  font-size: 12px; text-transform: none; letter-spacing: 0;
}
.hosted-handicap-select { min-width: 104px; }
.hosted-toggle {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.hosted-toggle input { cursor: pointer; }
.lobby-panel { border-bottom: 0; }
.lobby-progress {
  color: var(--accent); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.lobby-actions { display: flex; align-items: center; gap: 10px; }
.lobby-players { display: grid; gap: 8px; margin-top: 14px; }
.lobby-player {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid rgba(42, 53, 80, 0.65);
}
.lobby-player:first-child { border-top: 0; }
.lobby-name { min-width: 0; font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.lobby-owner { display: block; margin-top: 3px; color: #68758c; font: 10px monospace; }
.lobby-state {
  min-width: 74px; padding: 4px 8px; border-radius: 999px;
  background: #332c18; color: #ffd479; font-size: 10px; font-weight: 700; text-align: center;
  text-transform: uppercase;
}
.lobby-state.ready { background: #143728; color: #57e39b; }
.lobby-agent-kind {
  min-width: 112px; color: #8b97b0; font-size: 11px; font-weight: 650; text-align: right;
}
.copy-invite.copied { border-color: #57e39b; color: #57e39b; }
.game-list-status { margin: 24px 0; color: var(--muted); font-size: 12px; }
.game-list-status[hidden] { display: none; }
.game-section { margin-top: 32px; }
.game-section h3 {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px;
  color: #bdc7d9; font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
}
.game-section h3 > span:last-child {
  margin-left: auto; color: #59667e; font-variant-numeric: tabular-nums;
}
.live-pulse {
  width: 7px; height: 7px; border-radius: 50%; background: #57e39b;
  box-shadow: 0 0 0 0 rgba(87, 227, 155, 0.5); animation: pulse 2s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(87, 227, 155, 0); } }
.game-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.game-card {
  position: relative; min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 10px;
  background: linear-gradient(145deg, rgba(27, 35, 51, 0.9), rgba(19, 25, 37, 0.9));
  color: var(--text); text-decoration: none; transition: transform 160ms ease, border-color 160ms ease;
}
.game-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.game-card.finished { opacity: 0.78; }
.game-state {
  display: block; margin-bottom: 22px; color: var(--accent); font-size: 9px; font-weight: 700;
  letter-spacing: 1.4px; text-transform: uppercase;
}
.game-card.finished .game-state { color: #ffd479; }
.game-card h4 { margin: 0; overflow: hidden; text-overflow: ellipsis; font-size: 17px; white-space: nowrap; }
.game-id { margin: 5px 0 18px; overflow: hidden; color: #68758c; font: 10px monospace; text-overflow: ellipsis; }
.game-stats { display: flex; gap: 13px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.game-stats b { color: #d9e2f0; font-size: 11px; }
.game-card-actions { display: flex; gap: 7px; margin-top: 14px; }
.game-card-actions button {
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: rgba(11, 15, 23, 0.7); color: var(--text); font-size: 10px;
  cursor: pointer; transition: border-color 140ms ease;
}
.game-card-actions button:hover { border-color: var(--accent); }
.game-card-actions button.danger { color: #ff8d8d; }
.game-card-actions button.danger:hover { border-color: #ff8d8d; }
.game-empty {
  grid-column: 1 / -1; margin: 0; padding: 20px; border: 1px dashed var(--line);
  border-radius: 9px; color: var(--muted); font-size: 12px; text-align: center;
}

#graph-wrap { position: relative; flex: 1; min-width: 0; }
#graph { width: 100%; height: 100%; display: block; }

#economy-metric {
  position: absolute; top: 16px; right: 16px; min-width: 176px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(20, 26, 38, 0.9); text-align: right;
  font-variant-numeric: tabular-nums; backdrop-filter: blur(5px);
}
#economy-metric[hidden] { display: none; }
.economy-label {
  color: var(--muted); font-size: 10px; font-weight: 600;
  letter-spacing: 1.2px; text-transform: uppercase;
}
#economy-score { color: var(--accent); font-size: 30px; font-weight: 700; line-height: 1.15; }
.economy-percent { color: var(--accent); font-size: 15px; font-weight: 700; }
.economy-detail { color: var(--muted); font-size: 10px; }

#legend {
  position: absolute; left: 14px; bottom: 14px; max-width: min(420px, calc(100% - 28px));
  background: rgba(20, 26, 38, 0.85); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12px; backdrop-filter: blur(4px);
}
.legend-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.legend-title {
  color: var(--muted); font-size: 9px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
}
.legend-items { display: flex; gap: 4px 12px; flex-wrap: wrap; }
#legend .item { display: flex; align-items: center; gap: 6px; }
#legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
svg.icon { flex: none; display: block; }

#replay-controls {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(680px, calc(100% - 300px)); display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(20, 26, 38, 0.94); color: var(--muted); font-size: 11px;
  backdrop-filter: blur(5px);
}
#replay-controls[hidden] { display: none; }
#replay-controls button {
  border: 0; border-radius: 6px; padding: 5px 12px; cursor: pointer;
  background: var(--accent); color: #06121c; font-weight: 700;
}
#replay-scrubber { flex: 1; min-width: 100px; accent-color: var(--accent); }
#replay-position { min-width: 88px; font-variant-numeric: tabular-nums; }
#replay-controls select {
  margin-left: 4px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 3px;
}

#agent-logs-drawer {
  position: fixed; top: 52px; right: 0; bottom: 0; z-index: 20;
  width: min(520px, 100vw); border-left: 1px solid var(--line);
  background: rgba(13, 18, 28, 0.98); box-shadow: -22px 0 55px rgba(0, 0, 0, 0.38);
  display: flex; flex-direction: column; min-height: 0;
}
#agent-logs-drawer[hidden] { display: none; }
.agent-logs-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.agent-logs-head .eyebrow { margin-bottom: 4px; }
.agent-logs-head h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.agent-logs-head button,
.agent-logs-controls button {
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.agent-logs-head button:hover,
.agent-logs-controls button:hover { color: var(--text); border-color: var(--accent); }
.agent-logs-controls {
  display: flex; align-items: end; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid rgba(42, 53, 80, 0.72);
}
.agent-logs-controls label {
  flex: 1; min-width: 0; display: grid; gap: 5px;
  color: var(--muted); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
}
#agent-log-owner {
  width: 100%; min-width: 0; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px;
}
.agent-log-status {
  min-height: 32px; padding: 9px 14px; color: #aeb8ca; font-size: 12px;
  border-bottom: 1px solid rgba(42, 53, 80, 0.72);
}
#agent-log-output {
  flex: 1; min-height: 0; overflow: auto; padding: 10px 14px 18px;
  font: 12px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: #dbe5f5; background: #080b11;
}
.agent-log-row {
  display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 8px;
  padding: 2px 0; border-bottom: 1px solid rgba(42, 53, 80, 0.18);
}
.agent-log-row:last-child { border-bottom: 0; }
.agent-log-stream {
  color: #68758c; font-size: 10px; text-transform: uppercase; user-select: none;
}
.agent-log-row.stderr .agent-log-stream { color: #ff8aa8; }
.agent-log-line { white-space: pre-wrap; overflow-wrap: anywhere; }

#side {
  width: 340px; border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column;
}
#side section { display: flex; flex-direction: column; min-height: 0; }
#wealth-panel { border-bottom: 1px solid var(--line); }
#activity-panel { flex: 1; }
#side h2 {
  margin: 0; padding: 12px 16px 8px; font-size: 12px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
#side h2 .hint { text-transform: none; letter-spacing: 0; color: #5b6b88; font-weight: 400; }

#wealth { list-style: none; margin: 0; padding: 0 12px 12px; }
#wealth li {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
#wealth .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#wealth .name { flex: 1; }
#wealth .amt { color: var(--accent); font-weight: 600; }
#wealth .bar { height: 4px; border-radius: 2px; margin-top: 3px; opacity: 0.5; }

#activity-filters {
  display: flex; gap: 5px; padding: 0 12px 8px; flex-wrap: wrap;
}
#activity-filters button {
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px;
  background: transparent; color: var(--muted); font-size: 10px; cursor: pointer;
}
#activity-filters button:hover { color: var(--text); border-color: #425374; }
.filter-count {
  margin-left: 5px; opacity: 0.65; font-variant-numeric: tabular-nums;
}
#activity-filters button.active .filter-count { opacity: 0.85; }
#activity-filters button.active {
  color: #06121c; background: var(--accent); border-color: var(--accent);
}
#activity { flex: 1; overflow-y: auto; padding: 0 12px 14px; }
.activity-row {
  margin: 0; padding: 9px 3px; border-top: 1px solid rgba(42, 53, 80, 0.65);
  font-size: 12px; line-height: 1.4;
}
.activity-row:first-child { border-top: 0; }
.activity-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; min-width: 0; }
.activity-kind, .activity-channel {
  border-radius: 4px; padding: 1px 5px; font-size: 9px; font-weight: 700;
  letter-spacing: 0.4px; text-transform: uppercase; white-space: nowrap;
}
.activity-kind.comms { color: #5cc8ff; background: #183047; }
.activity-kind.trade { color: #ffd479; background: #40351b; }
.activity-kind.edge { color: #7ee0a0; background: #17392a; }
.activity-kind.system { color: #b78bff; background: #302547; }
.activity-channel {
  max-width: 135px; overflow: hidden; text-overflow: ellipsis;
  color: #aebbd2; background: #202a3d; text-transform: none; letter-spacing: 0;
}
.activity-actor { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.activity-step { color: var(--muted); font-size: 10px; margin-left: auto; white-space: nowrap; }
.activity-text { color: #cdd6e8; overflow-wrap: anywhere; }
.activity-empty { color: var(--muted); font-size: 12px; padding: 8px 3px; }

/* ---- guided tour ---------------------------------------------------------
   A scrim over the whole page with the current target lifted through it. The
   target keeps its own styling and stays where it is: the tour points at the
   live UI, so nothing here can drift out of sync with what it explains. */
/* The scrim and card are position:fixed, so they are laid out against the
   viewport, not this wrapper — hiding the wrapper alone leaves them painting.
   Hide the descendants explicitly or Skip appears to do nothing. */
#tutorial-overlay[hidden],
#tutorial-overlay[hidden] #tutorial-scrim,
#tutorial-overlay[hidden] #tutorial-card { display: none; }
#tutorial-scrim {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(8, 11, 18, 0.72);
}
/* A target inside an element that carries its own z-index (the topbar) is
   trapped below the scrim; the tour adds this to that ancestor for the step so
   the target can show through. !important to beat an id rule like #topbar's. */
.tutorial-raise { z-index: 901 !important; }
/* Lifted above the scrim, so the real element reads as the spotlit one. The
   stacking context is what does the work; the ring only draws attention. */
.tutorial-lift {
  position: relative; z-index: 901;
  border-radius: 10px;
  /* An INSET ring, not an outward one. Panels sit flush against the window and
     against each other, and `html, body { overflow: hidden }` clips anything
     drawn outside them — an outward ring loses whichever edge touches a border.
     Drawing inward keeps all four sides visible wherever the target sits. */
  box-shadow: inset 0 0 0 2px rgba(92, 200, 255, 0.9),
    inset 0 0 0 6px rgba(92, 200, 255, 0.14),
    inset 0 0 26px rgba(92, 200, 255, 0.12);
  transition: box-shadow 140ms ease;
}
/* A target that is filled by an opaque child — the terminal, whose xterm mount
   paints its own background — swallows the ring: a child's background paints
   over its parent's inset shadow. Draw it on an overlay above every child
   instead. The z-index clears xterm's own layers, which run to 10. */
.tutorial-lift.tutorial-lift-over { box-shadow: none; }
.tutorial-lift.tutorial-lift-over::after {
  content: ""; position: absolute; inset: 0; z-index: 20;
  pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(92, 200, 255, 0.9),
    inset 0 0 0 6px rgba(92, 200, 255, 0.14),
    inset 0 0 26px rgba(92, 200, 255, 0.12);
}
/* Small inline targets are the exception: an inset ring would sit on top of
   their own label. They are never flush with a panel edge, so an outward ring
   has room to draw and reads better at that size. */
.tutorial-lift.tutorial-lift-outset {
  padding: 2px 4px;
  box-shadow: 0 0 0 2px rgba(92, 200, 255, 0.9), 0 0 0 7px rgba(92, 200, 255, 0.16);
}
#tutorial-card {
  position: fixed; z-index: 902; width: min(340px, calc(100vw - 32px));
  padding: 15px 16px 13px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.tutorial-count {
  margin: 0 0 5px; color: var(--muted);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
}
#tutorial-card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 650; }
#tutorial-body { margin: 0; color: #a8b4c8; font-size: 12.5px; line-height: 1.55; }
.tutorial-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 13px;
}
.tutorial-actions button {
  padding: 6px 14px; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer;
}
#tutorial-next { border: 0; background: var(--accent); color: #06121c; }
#tutorial-next:hover { filter: brightness(1.08); }
.tutorial-quiet {
  margin-right: auto; border: 1px solid transparent; background: none; color: var(--muted);
}
.tutorial-quiet:hover { color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .tutorial-lift { transition: none; }
}

/* ---- player layer ---- */

.player-chip[hidden] { display: none; }
.player-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 6px 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2); color: var(--text); font-size: 12px; font-weight: 600;
}
.player-swatch { width: 10px; height: 10px; border-radius: 50%; }
.player-chip button {
  padding: 0 7px; border: 0; border-radius: 999px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 400; cursor: pointer;
}
.player-chip button:hover { color: #ff8aa8; }
.gm-btn {
  background: transparent !important; color: #ffd479 !important;
  border: 1px solid #ffd479 !important; font-weight: 600;
}

#pick-banner {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 8px 14px; border: 1px solid var(--accent); border-radius: 9px;
  background: rgba(20, 26, 38, 0.95); color: var(--text); font-size: 12px;
  backdrop-filter: blur(5px); z-index: 5;
}
#pick-banner[hidden] { display: none; }
#pick-banner button {
  margin-left: 8px; padding: 2px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}

/* inspector */
#inspector-panel { border-bottom: 1px solid var(--line); max-height: 46%; }
#inspector-panel h2 { display: flex; justify-content: space-between; align-items: center; }
.panel-close {
  border: 0; background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 0 2px;
}
.panel-close:hover { color: var(--text); }
#inspector { overflow-y: auto; padding: 0 14px 14px; font-size: 12px; }
.insp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.insp-head-icon { display: flex; flex: none; }
.insp-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.insp-title { font-size: 15px; font-weight: 700; }
.insp-id { color: var(--muted); font-family: monospace; font-size: 10px; }
.insp-recipe { color: #cdd6e8; margin-bottom: 8px; }
.insp-kind, .insp-good {
  display: inline-flex; align-items: center; gap: 5px; margin-bottom: 8px;
  padding: 2px 8px 2px 5px; border-radius: 999px; font-size: 11px; font-weight: 650;
  border: 1px solid var(--line); background: var(--panel-2);
}
.insp-kind { color: var(--muted); }
.insp-kind.unknown { color: #64708c; font-style: italic; }
.insp-good { color: #cdd6e8; }
.insp-row-icon { display: flex; flex: none; }
.insp-section { margin-top: 10px; }
.insp-section-title {
  color: var(--muted); font-size: 10px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase; margin-bottom: 5px;
}
.insp-owner-row, .insp-edge-row {
  display: flex; align-items: center; gap: 7px; padding: 3px 0;
}
.insp-edge-row { cursor: pointer; border-radius: 5px; }
.insp-edge-row:hover { background: rgba(92, 200, 255, 0.07); }
.insp-swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.insp-owner { flex: 1; }
/* Your own row in the ownership list is emphasized by weight, not hue: the
 * swatch beside it already carries your color, and an accent-blue name next to a
 * pink swatch reads as a second, contradictory identity. */
.insp-owner-row.mine .insp-owner { color: var(--text); font-weight: 700; }
.insp-shares { color: var(--muted); font-variant-numeric: tabular-nums; }
.insp-edge-desc { flex: 1; color: #cdd6e8; }
.insp-empty { color: var(--muted); }
.insp-form {
  margin-top: 12px; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel-2);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
}
.insp-field { display: flex; flex-direction: column; gap: 3px; }
.insp-field-label { color: var(--muted); font-size: 10px; }
.insp-form select, .insp-form input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 6px; font-size: 12px; max-width: 150px;
}
.insp-form input[type="number"] { width: 74px; }
.insp-form .insp-section-title { width: 100%; margin-bottom: 0; }
.insp-btn {
  border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  background: var(--accent); color: #06121c; font-weight: 700; font-size: 12px;
}
.insp-btn.danger { background: #ff8aa8; margin-top: 12px; }
.insp-btn:not(:disabled):hover { filter: brightness(1.1); }
.insp-mini-btn {
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px;
  background: transparent; color: var(--muted); font-size: 10px; cursor: pointer;
}
.insp-mini-btn:not(:disabled):hover { color: #ff8aa8; border-color: #ff8aa8; }
#inspector button:disabled, #inspector input:disabled, #inspector select:disabled {
  opacity: 0.45; cursor: not-allowed;
}

/* feed tabs + comms */
#feed-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#feed-tabs { display: flex; gap: 4px; padding: 10px 12px 8px; }
#feed-tabs button {
  border: 1px solid var(--line); border-radius: 7px 7px 0 0; padding: 4px 12px;
  background: transparent; color: var(--muted); font-size: 11px; font-weight: 600;
  letter-spacing: 0.6px; text-transform: uppercase; cursor: pointer;
}
#feed-tabs button.active { color: var(--text); background: var(--panel-2); border-bottom-color: var(--panel-2); }
#feed-tabs button[hidden] { display: none; }
.tab-page { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tab-page[hidden] { display: none; }
.comms-head { display: flex; gap: 6px; padding: 0 12px 8px; }
.comms-head select {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 6px; font-size: 12px; min-width: 0;
}
.msg-list { flex: 1; overflow-y: auto; padding: 0 12px; }
/* Operator terminal: fill the tab and give xterm a measurable box to fit into. */
#terminal-mount { flex: 1; min-height: 0; padding: 0 6px 6px 12px; background: #080b11; }
#terminal-mount .xterm { height: 100%; }
#terminal-reconnect {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
#terminal-status { flex: 1; align-self: center; font-size: 12px; color: var(--muted); }
.msg-row { padding: 7px 3px; border-top: 1px solid rgba(42, 53, 80, 0.65); font-size: 12px; }
.msg-row:first-child { border-top: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 7px; margin-bottom: 2px; }
.msg-from { font-weight: 700; }
.msg-step { color: var(--muted); font-size: 10px; margin-left: auto; }
.msg-text { color: #cdd6e8; overflow-wrap: anywhere; }
.msg-row.own .msg-text { color: var(--text); }
.msg-send { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.msg-send input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; min-width: 0;
}
.msg-send button {
  border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer;
  background: var(--accent); color: #06121c; font-weight: 700; font-size: 12px;
}

/* toasts */
#toasts {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50;
  pointer-events: none;
}
.toast {
  padding: 9px 16px; border-radius: 8px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  transition: opacity 400ms ease, transform 400ms ease;
}
.toast.ok { border-color: #2c5a41; color: #7ee0a0; }
.toast.error { border-color: #5a2c3c; color: #ff8aa8; }
.toast.gone { opacity: 0; transform: translateY(6px); }

/* graph elements */
.link { fill: none; stroke-opacity: 0.62; }
.link.selected { stroke-opacity: 1; filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.55)); }
.link-hit { fill: none; stroke: transparent; stroke-width: 14px; cursor: pointer; }
.node { cursor: pointer; }
/* Selection is the viewer's own transient state, not data, so it is drawn in
 * white — never a hue, which would read as an owner. */
.node.selected .node-ring {
  stroke: #fff; stroke-width: 2.5px;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
}
.link-label { pointer-events: none; }
.link-good-text {
  font-size: 10px; fill: var(--muted);
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px;
}
.node-label { font-size: 11px; fill: var(--text); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; text-anchor: middle; pointer-events: none; }
.node-sub { font-size: 9px; fill: var(--muted); text-anchor: middle; pointer-events: none; }

/* Icons sit in the hole of the ownership donut. Deliberately monochrome: color
 * on a node means ownership, and a per-type hue here competes with the donut it
 * is wrapped around. Asset type is carried by the glyph instead. */
.node-icon, .link-good-icon {
  fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
}
.node-icon { stroke-width: 2px; stroke: #cdd6e8; }
.node.selected .node-icon { stroke: var(--text); }
.node-icon-bg { fill: var(--bg); }
/* Route icons ride on top of the edges, so they need a halo and a slightly
 * heavier stroke to survive being scaled down to 12px. */
.link-good-icon {
  stroke-width: 2.6px; stroke: var(--muted);
  filter: drop-shadow(0 0 1.5px var(--bg)) drop-shadow(0 0 1.5px var(--bg));
}
/* Neutral ring. Selection (white, above) is the only thing that ever recolors it;
 * `unknown` varies stroke pattern rather than hue. */
.node-ring { fill: none; stroke-width: 2px; stroke: var(--line); }
.node-ring.unknown { stroke-dasharray: 3 3; }

.flow-dot { filter: drop-shadow(0 0 4px currentColor); }
.node g.pie path { stroke: #0c0f17; stroke-width: 1px; }

@media (max-width: 900px) {
  html, body { overflow: auto; }
  #topbar { height: auto; min-height: 52px; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .controls { flex-wrap: wrap; }
  .home-shell { width: min(100% - 32px, 680px); grid-template-columns: 1fr; gap: 38px; padding: 35px 0 60px; }
  .home-intro { position: static; padding-top: 0; }
  .home-intro h1 { font-size: clamp(48px, 14vw, 72px); }
  #home, #viewer { height: calc(100vh - 76px); }
  .hosted-panel-head { flex-direction: column; align-items: stretch; }
  .hosted-start { align-items: flex-start; }
  .lobby-actions { justify-content: space-between; }
  .hosted-player-config { grid-template-columns: 1fr; align-items: stretch; }
  .hosted-player-config-controls { justify-content: stretch; }
  .hosted-agent-field, .hosted-model-field, .hosted-handicap-field { flex: 1; }
  .hosted-agent-select, .hosted-model-select, .hosted-handicap-select {
    width: 100%; min-width: 0;
  }
  .lobby-player { grid-template-columns: 1fr; align-items: stretch; }
  .lobby-agent-kind { min-width: 0; text-align: left; }
}

@media (max-width: 560px) {
  .brand .sub, .controls label { display: none; }
  #game-browser { padding: 20px; }
  .game-grid { grid-template-columns: 1fr; }
  #side { width: 42%; min-width: 150px; }
  #replay-controls { width: calc(100% - 20px); bottom: 8px; flex-wrap: wrap; }
  #agent-logs-drawer { top: 0; width: 100vw; }
  .agent-logs-controls { flex-wrap: wrap; align-items: stretch; }
  .agent-logs-controls label { flex-basis: 100%; }
}
