:root {
  --bg: #030704;
  --panel: #07120a;
  --line: #00ff4c;
  --line-dim: #1b6b34;
  --txt: #8cffb2;
  --txt-dim: #66b882;
  --danger: #ff3838;
  --danger-strong: #ff5c5c;
  --danger-bg: rgba(96, 10, 10, 0.38);
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
  --radius: 4px;
  --fast: 140ms;
  --normal: 220ms;
}

* {
  box-sizing: border-box;
}

body.terminal-bg {
  margin: 0;
  min-height: 100vh;
  font-family: "Courier New", Consolas, monospace;
  font-size: clamp(14px, 1.1vw, 16px);
  line-height: 1.35;
  color: var(--txt);
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 255, 76, 0.03),
      rgba(0, 255, 76, 0.03) 2px,
      transparent 2px,
      transparent 4px
    ),
    var(--bg);
}

.terminal-shell {
  width: min(980px, calc(100vw - 32px));
  margin: clamp(18px, 3vw, 32px) auto;
}

.terminal-title {
  margin: 0 0 var(--space-4) 0;
  text-align: center;
  font-size: clamp(1.45rem, 2.2vw, 2.1rem);
  letter-spacing: 1.5px;
  color: #f5f24e;
  text-shadow: 0 0 8px rgba(245, 242, 78, 0.45);
}

.panel {
  border: 1px solid var(--line);
  background: rgba(2, 12, 4, 0.9);
  border-radius: var(--radius);
  padding: clamp(16px, 2.5vw, 24px);
  box-shadow: 0 0 18px rgba(0, 255, 76, 0.14);
}

.panel h2 {
  margin: 0 0 var(--space-4) 0;
  font-size: clamp(1.05rem, 1.5vw, 1.35rem);
  letter-spacing: 1px;
  text-align: center;
  color: #e7e149;
}

.grid-form {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: var(--space-4);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  color: var(--txt);
  font-size: 0.9rem;
  letter-spacing: 0.4px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line-dim);
  background: #031007;
  color: var(--txt);
  border-radius: var(--radius);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease, background-color var(--normal) ease;
}

input:focus,
select:focus {
  border-color: var(--line);
  box-shadow: 0 0 0 1px rgba(0, 255, 76, 0.25);
  background: #04130a;
}

button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 42px;
  padding: 10px 14px;
  cursor: pointer;
  background: #0c2c10;
  color: var(--txt);
  letter-spacing: 0.5px;
  transition: transform var(--fast) ease, filter var(--fast) ease, box-shadow var(--fast) ease;
}

button:hover {
  filter: brightness(1.14);
  box-shadow: 0 0 10px rgba(0, 255, 76, 0.2);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  width: auto;
  background: #0f3d15;
  font-weight: 700;
}

.btn-danger {
  background: #3a0808;
  border-color: #8f1c1c;
}

.btn-ghost {
  background: transparent;
}

.btn-small,
.btn-kick {
  padding: 6px 10px;
  min-height: 34px;
  width: auto;
}

.btn-kick {
  background: #3b0909;
  border-color: #9a2121;
}

.status.error {
  margin-top: 10px;
  color: #ff7979;
}

.hidden {
  display: none;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  font-weight: 700;
  font-size: clamp(0.85rem, 1.2vw, 1rem);
}

.room-code-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.room-code-wrap {
  border: 1px solid var(--line);
  padding: var(--space-2);
  display: grid;
  gap: var(--space-2);
}

.room-code-button {
  width: 100%;
  min-height: unset;
}

.room-code-button:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
}

.room-code {
  font-size: clamp(26px, 7vw, 54px);
  font-weight: 900;
  text-align: center;
  letter-spacing: 6px;
  color: #031106;
  background: var(--line);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.room-code:hover {
  filter: brightness(1.04);
}

.target-wrap {
  border: 1px dashed var(--line-dim);
  padding: var(--space-2);
  display: grid;
  gap: var(--space-2);
  align-content: center;
}

.target-secret-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-dim);
  border-radius: var(--radius);
  background: rgba(2, 12, 4, 0.9);
  width: 100%;
  justify-content: center;
  min-height: 50px;
  user-select: none;
  touch-action: none;
}

.target-secret-button:hover {
  border-color: var(--line);
  box-shadow: 0 0 8px rgba(0, 255, 76, 0.22);
}

.target-secret-button:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
}

.target-secret-button:active {
  filter: brightness(1.05);
}

.target-secret-code {
  font-weight: 800;
  letter-spacing: 1.6px;
  padding: 2px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.target-secret-code.masked {
  background: #111;
  filter: blur(5px);
  color: transparent;
  letter-spacing: 2.4px;
  text-shadow: 0 0 8px #0f0;
}

.target-secret-code.revealed {
  background: transparent;
  color: #8cffb2;
  filter: none;
  opacity: 1;
  text-shadow: 0 0 6px rgba(140, 255, 178, 0.28);
}

.target-secret-button:active .target-secret-code {
  filter: none;
  opacity: 1;
}

.target-emoji {
  font-size: 1.22rem;
  line-height: 1;
  min-width: 24px;
  text-align: center;
}

.firewall-toggle {
  width: 100%;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  font-weight: 700;
}

.firewall-toggle-track {
  width: 56px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line-dim);
  background: #08220f;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  transition: background-color var(--fast) ease, border-color var(--fast) ease;
}

.firewall-toggle-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--txt);
  box-shadow: 0 0 6px rgba(140, 255, 178, 0.28);
  transform: translateX(0);
  transition: transform var(--fast) ease, background-color var(--fast) ease;
}

.firewall-toggle-text {
  min-width: 34px;
  text-align: right;
  letter-spacing: 0.6px;
}

.firewall-toggle.on {
  background: #3a0808;
  border-color: #8f1c1c;
  color: #ffd0d0;
}

.firewall-toggle.on .firewall-toggle-track {
  background: #511111;
  border-color: #b53d3d;
}

.firewall-toggle.on .firewall-toggle-thumb {
  transform: translateX(28px);
  background: #ffd0d0;
}

.firewall-toggle.off {
  background: #0f3d15;
  border-color: var(--line);
  color: var(--txt);
}

.firewall-toggle.off .firewall-toggle-track {
  background: #0b2a13;
  border-color: var(--line-dim);
}

.firewall-toggle:hover {
  box-shadow: 0 0 10px rgba(0, 255, 76, 0.18);
}

.firewall-toggle:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px rgba(0, 255, 76, 0.2);
}

.dim.tiny {
  font-size: 0.76rem;
  letter-spacing: 0.2px;
}

.dim {
  color: var(--txt-dim);
}

.meta-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.drawer {
  border: 1px solid var(--line-dim);
  border-radius: var(--radius);
  padding: var(--space-2);
  margin-bottom: var(--space-3);
}

.drawer summary {
  cursor: pointer;
  font-weight: 700;
}

.sessions-list {
  margin-top: var(--space-2);
  display: grid;
  gap: var(--space-1);
}

.player-drawer {
  border: 1px dashed var(--line-dim);
  border-radius: var(--radius);
  padding: 8px;
}

.player-drawer > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font-weight: 700;
}

.session-summary-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  border: 1px solid var(--line-dim);
  color: var(--txt-dim);
  background: rgba(8, 28, 14, 0.9);
}

.progress-wrap {
  border: 1px solid var(--line-dim);
  border-radius: var(--radius);
  padding: var(--space-2);
  margin-bottom: var(--space-3);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: var(--txt-dim);
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line-dim);
  background: #06180b;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2e8f40, #84ff9d);
  transition: width var(--normal) ease;
}

.status-badge.online {
  color: #b8ffd1;
  border-color: rgba(88, 220, 140, 0.8);
  background: rgba(8, 42, 20, 0.9);
}

.status-badge.kicked {
  color: #ffc5c5;
  border-color: rgba(220, 88, 88, 0.85);
  background: rgba(52, 10, 10, 0.9);
}

.status-badge.disconnected {
  color: #ffe6a8;
  border-color: rgba(214, 166, 69, 0.82);
  background: rgba(49, 33, 7, 0.9);
}

.player-drawer > summary::-webkit-details-marker {
  display: none;
}

.session-log {
  border-top: 1px dashed var(--line-dim);
  margin-top: 8px;
  padding-top: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.feed {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 240px;
  max-height: 360px;
  overflow-y: auto;
  padding: var(--space-2);
  background: #030a04;
  margin-bottom: var(--space-3);
  scroll-behavior: smooth;
}

.chat-feed {
  min-height: 360px;
}

.feed-row {
  margin-bottom: var(--space-1);
  line-height: 1.45;
  letter-spacing: 0.2px;
  font-size: clamp(0.92rem, 1.1vw, 1rem);
  word-break: break-word;
}

.feed-row.system {
  color: var(--txt-dim);
  text-shadow: 0 0 1px rgba(102, 184, 130, 0.18);
}

.feed-row.agent {
  color: #9effdf;
  text-shadow: 0 0 1px rgba(158, 255, 223, 0.2);
}

.feed-row.player {
  color: #c6ffbf;
  text-shadow: 0 0 1px rgba(198, 255, 191, 0.2);
}

.feed-row.breach {
  color: var(--danger-strong);
  font-weight: 700;
  background: var(--danger-bg);
  border: 1px solid rgba(255, 92, 92, 0.65);
  border-left: 4px solid var(--danger-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-shadow: 0 0 2px rgba(255, 92, 92, 0.35);
}

.feed-row.breach::before {
  content: "⚠ ";
  color: #ffd0d0;
}

.actions-row,
.input-row,
.chat-head {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.chat-head {
  justify-content: space-between;
  margin-bottom: var(--space-2);
  font-size: 0.95rem;
}

.input-row input {
  flex: 1;
  min-width: 0;
}

.terminal-input-row {
  border: 1px solid var(--line-dim);
  border-radius: var(--radius);
  background: #04110a;
  padding: 4px 10px;
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}

.terminal-input-row:focus-within {
  border-color: var(--line);
  box-shadow: 0 0 0 1px rgba(0, 255, 76, 0.25);
}

.terminal-prompt {
  color: var(--line);
  font-weight: 700;
  letter-spacing: 0.4px;
  min-width: 44px;
  user-select: none;
}

.terminal-input-row input {
  border: none;
  background: transparent;
  min-height: 36px;
  padding: 6px 2px;
  box-shadow: none;
}

.terminal-input-row input:focus {
  border: none;
  box-shadow: none;
  background: transparent;
}

.player-secondary-actions {
  justify-content: flex-start;
  gap: 10px;
  margin-top: 6px;
}

.player-secondary-actions .btn-ghost,
.player-secondary-actions .btn-danger {
  min-width: 116px;
}

.protocol {
  border: 1px dashed var(--line-dim);
  border-radius: var(--radius);
  margin-top: var(--space-2);
  padding: var(--space-2);
  color: var(--txt-dim);
}

.protocol p {
  margin: 0 0 6px;
}

.protocol p:last-child {
  margin-bottom: 0;
}

@media (max-width: 960px) {
  .terminal-shell {
    width: min(980px, calc(100vw - 20px));
  }

  .panel {
    padding: 16px;
  }
}

@media (max-width: 760px) {
  .terminal-shell {
    width: calc(100vw - 12px);
    margin: 10px auto;
  }

  .terminal-title {
    margin-bottom: var(--space-3);
  }

  .room-code-row,
  .meta-row,
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar {
    gap: 8px;
  }

  .panel h2 {
    text-align: left;
  }

  .actions-row {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-feed {
    min-height: 300px;
  }

  .input-row {
    flex-direction: row;
    align-items: stretch;
  }

  .player-secondary-actions {
    margin-top: 2px;
  }

  .room-code {
    letter-spacing: 4px;
    font-size: clamp(24px, 11vw, 44px);
  }
}

@media (max-width: 520px) {
  .input-row {
    flex-direction: column;
  }

  .player-secondary-actions {
    flex-direction: row;
    justify-content: stretch;
  }

  .player-secondary-actions .btn-ghost,
  .player-secondary-actions .btn-danger {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ── Near-Limit Attempt Warning ── */
.attempts-warning {
  color: #ffd866 !important;
  text-shadow: 0 0 6px rgba(255, 216, 102, 0.4);
  animation: pulse-warn 1.5s ease-in-out infinite;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.attempts-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.3px;
  border: 1px solid var(--line-dim);
  color: var(--txt-dim);
  background: rgba(8, 28, 14, 0.8);
}

.attempts-tag.warning {
  color: #ffd866;
  border-color: rgba(255, 190, 50, 0.75);
  background: rgba(60, 40, 5, 0.85);
  animation: pulse-warn 1.5s ease-in-out infinite;
}

/* ── Status Badge Extensions ── */
.status-badge.caught {
  color: #ffc5c5;
  border-color: rgba(220, 88, 88, 0.85);
  background: rgba(52, 10, 10, 0.9);
}

.status-badge.breached {
  color: #ffd0d0;
  border-color: rgba(255, 92, 92, 0.8);
  background: rgba(60, 8, 8, 0.9);
  animation: pulse-warn 2s ease-in-out infinite;
}

.status-badge.terminated {
  color: #ccc;
  border-color: rgba(150, 150, 150, 0.6);
  background: rgba(30, 30, 30, 0.9);
}

/* ── Topbar Status Styling ── */
.topbar-status {
  text-align: center;
}

.topbar-status.online {
  color: #b8ffd1;
}

.topbar-status.standby {
  color: var(--txt-dim);
}

.topbar-status.breached,
.topbar-status.caught {
  color: var(--danger-strong);
  animation: pulse-warn 1.5s ease-in-out infinite;
}

.topbar-status.disconnected,
.topbar-status.terminated {
  color: #ffe6a8;
}

/* ── Post-Outcome Debrief Strip ── */
.debrief-strip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-top: var(--space-3);
  background: rgba(2, 18, 6, 0.95);
  box-shadow: 0 0 16px rgba(0, 255, 76, 0.12);
}

.debrief-header {
  font-weight: 700;
  letter-spacing: 1.2px;
  margin-bottom: var(--space-2);
  color: #e7e149;
  font-size: 1.05rem;
}

.debrief-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.debrief-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.debrief-outcome {
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.debrief-outcome.breached {
  color: var(--danger-strong);
  text-shadow: 0 0 4px rgba(255, 92, 92, 0.4);
}

.debrief-outcome.caught {
  color: #ffc5c5;
  text-shadow: 0 0 4px rgba(255, 160, 160, 0.3);
}

.debrief-outcome.terminated {
  color: #ccc;
}

.debrief-strip .btn-primary {
  width: 100%;
  margin-top: var(--space-2);
}
