:root {
  --bg: #060b12;
  --panel: #0e1725;
  --panel-border: #1de6ff;
  --text: #c9f8ff;
  --muted: #78b8c4;
  --accent: #00ffc6;
  --warn: #ff5f6d;
  --gold: #ffd166;
  --scroll-track: rgba(7, 14, 24, 0.88);
  --scroll-thumb: rgba(0, 255, 198, 0.62);
  --scroll-thumb-hover: rgba(29, 230, 255, 0.72);
}

html {
  height: 100%;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border: 1px solid rgba(29, 230, 255, 0.2);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    var(--scroll-thumb) 0%,
    rgba(29, 230, 255, 0.62) 100%
  );
  border: 1px solid rgba(29, 230, 255, 0.5);
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(0, 255, 198, 0.35);
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    180deg,
    var(--scroll-thumb-hover) 0%,
    rgba(0, 255, 198, 0.75) 100%
  );
  box-shadow: 0 0 10px rgba(0, 255, 198, 0.5);
}

body {
  margin: 0;
  height: 100%;
  font-family: "Share Tech Mono", monospace;
  background:
    radial-gradient(circle at 10% 15%, rgba(0, 255, 198, 0.12), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(29, 230, 255, 0.17), transparent 35%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.02) 0,
    rgba(255, 255, 255, 0.02) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: screen;
  z-index: 100;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  min-height: 0;
}

.panel {
  border: 1px solid rgba(29, 230, 255, 0.5);
  background: linear-gradient(145deg, rgba(14, 23, 37, 0.95), rgba(8, 13, 22, 0.95));
  border-radius: 14px;
  box-shadow: 0 0 24px rgba(29, 230, 255, 0.18);
  padding: 1rem;
}

.hidden {
  display: none !important;
}

.jackin-screen {
  max-width: 520px;
  margin: auto;
  display: grid;
  gap: 0.6rem;
  max-height: 100%;
  overflow-y: auto;
}

.welcome-screen {
  max-width: 760px;
  margin: auto;
  display: grid;
  gap: 0.9rem;
  max-height: 100%;
  overflow-y: auto;
}

.welcome-header {
  display: grid;
  gap: 0.25rem;
}

.welcome-body {
  display: grid;
  gap: 0.8rem;
  border: 1px solid rgba(29, 230, 255, 0.25);
  border-radius: 10px;
  padding: 1rem;
  background: rgba(4, 12, 20, 0.55);
}

.welcome-body h2 {
  margin: 0;
}

.welcome-body p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.welcome-runner-line {
  color: var(--accent) !important;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(0, 255, 198, 0.45);
}

.welcome-warning {
  color: var(--gold) !important;
}

#welcome-continue-btn {
  justify-self: start;
  min-width: 220px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.auth-block {
  display: grid;
  gap: 0.5rem;
  border: 1px solid rgba(29, 230, 255, 0.25);
  border-radius: 10px;
  padding: 0.7rem;
  background: rgba(4, 12, 20, 0.55);
}

.auth-block h2 {
  margin: 0;
}

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

.glitch {
  position: relative;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-shadow: 0 0 8px rgba(0, 255, 198, 0.7);
  margin: 0;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  width: 100%;
  overflow: hidden;
}

.glitch::before {
  top: -2px;
  text-shadow: -2px 0 #ff4da6;
  animation: glitch-a 3s infinite linear alternate-reverse;
}

.glitch::after {
  top: 2px;
  text-shadow: 2px 0 #00e5ff;
  animation: glitch-b 2s infinite linear alternate-reverse;
}

@keyframes glitch-a {
  0% { clip-path: inset(15% 0 70% 0); }
  50% { clip-path: inset(60% 0 20% 0); }
  100% { clip-path: inset(35% 0 40% 0); }
}

@keyframes glitch-b {
  0% { clip-path: inset(55% 0 20% 0); }
  50% { clip-path: inset(10% 0 72% 0); }
  100% { clip-path: inset(75% 0 5% 0); }
}

.byline {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

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

h2 {
  margin: 0 0 0.8rem;
}

input,
textarea,
select,
button {
  outline: none;
  border: 1px solid rgba(29, 230, 255, 0.45);
  background: rgba(5, 12, 20, 0.9);
  color: var(--text);
  font: inherit;
  padding: 0.7rem;
  border-radius: 10px;
}

textarea {
  resize: none;
}

input:focus {
  border: 1px solid rgba(255, 255, 255, 1);
}

button {
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

button:hover {
  box-shadow: 0 0 14px rgba(0, 255, 198, 0.35);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.warn {
  border-color: rgba(255, 95, 109, 0.6);
  color: #ffc7ce;
}

.divider {
  text-align: center;
  color: var(--muted);
  margin: 0.5rem 0;
}

.main-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.brand-header {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.hud-top {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.hud-top > div {
  min-width: 0;
}

.hud-top .brand-header .glitch {
  font-size: clamp(1rem, 1.9vw, 1.35rem);
  line-height: 1.05;
  white-space: nowrap;
}

.hud-top .brand-header .byline {
  font-size: 0.72rem;
  line-height: 1;
}

.hud-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-value {
  font-size: 1.2rem;
  color: var(--accent);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
  flex-wrap: nowrap;
}

.node-card.current {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.4);
}

.node-card.captured {
  border-color: var(--accent);
  background: rgba(0, 255, 198, 0.08);
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.admin-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.75rem;
  border: 1px solid rgba(29, 230, 255, 0.35);
  border-radius: 10px;
  padding: 0.8rem;
  min-height: 0;
  background: rgba(4, 10, 16, 0.78);
  overflow: hidden;
}

.session-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.admin-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  align-items: end;
}

.admin-control {
  display: grid;
  gap: 0.35rem;
}

.admin-users-body,
.admin-sessions-body {
  overflow: auto;
  min-height: 0;
  height: 100%;
}

.admin-sessions-body {
  display: flex;
  flex-direction: column;
}

.admin-users-body table {
  width: 100%;
  border-collapse: collapse;
}

.admin-users-body th,
.admin-users-body td {
  text-align: left;
  border-bottom: 1px solid rgba(120, 184, 196, 0.25);
  padding: 0.45rem;
  vertical-align: top;
}

.admin-user-row td {
  font-weight: 700;
  color: var(--text);
}

.admin-user-detail-row td {
  border-bottom: 1px solid rgba(120, 184, 196, 0.18);
  padding-top: 0.1rem;
  padding-bottom: 0.65rem;
}

.admin-user-detail {
  display: grid;
  gap: 0.2rem;
  background: rgba(4, 12, 20, 0.35);
  padding: 0.45rem 0;
}

.admin-user-detail p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.admin-user-detail span {
  color: var(--text);
}

.admin-session-card {
  border: 1px solid rgba(29, 230, 255, 0.25);
  border-radius: 10px;
  padding: 0.7rem;
  margin-bottom: 0.65rem;
  background: rgba(5, 12, 20, 0.82);
  min-height: 0;
}

.admin-session-card:last-child {
  margin-bottom: 0;
}

.admin-session-card:only-child {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  flex: 1 1 auto;
}

.admin-session-meta {
  margin: 0 0 0.45rem;
  color: var(--gold);
  font-size: 0.8rem;
}

.admin-session-feed {
  min-height: 0;
}

.admin-session-card:only-child .admin-session-feed {
  height: 100%;
  max-height: none;
}

.admin-session-empty {
  margin: 0;
  color: var(--muted);
}

.matrix-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.node-grid {
  display: grid;
  gap: 0.6rem;
  overflow-y: auto;
  min-height: 0;
  align-content: start;
  padding-right: 0.15rem;
}

.node-card {
  text-align: left;
  display: grid;
  gap: 0.4rem;
  padding: 0.8rem;
}

.node-card h3 {
  margin: 0;
  font-size: 1rem;
}

.node-card p {
  margin: 0;
  color: var(--muted);
}

.node-meta {
  margin: 0;
}

.node-status,
.node-points {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.node-status {
  color: #ff9f9f;
}

.node-points {
  color: var(--muted);
}

.node-card.captured .node-status {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(0, 255, 198, 0.7);
}

.matrix-toggle {
  display: none;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.message-list {
  border: 1px solid rgba(29, 230, 255, 0.35);
  border-radius: 12px;
  padding: 0.8rem;
  overflow-y: auto;
  min-height: 220px;
  height: 100%;
  background: rgba(4, 10, 16, 0.78);
}

.message {
  margin-bottom: 0.8rem;
}

.message:last-child {
  margin-bottom: 0;
}

.message .role {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--gold);
}

.message.user .role {
  color: var(--accent);
}

.message p {
  margin: 0.2rem 0 0;
  white-space: pre-wrap;
}

.message-pending {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-top: 0.4rem;
  border: 2px solid rgba(0, 255, 198, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pending-spin 0.8s linear infinite;
}

@keyframes pending-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.access-code {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(0, 255, 198, 0.7);
  font-weight: 700;
}

.leaked-token {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 209, 102, 0.85);
  font-weight: 700;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

#chat-input {
  field-sizing: content;
  max-height: calc(5lh + 1.4rem);
  overflow-y: auto;
}

.capture-flash {
  position: fixed;
  left: 50%;
  top: 1rem;
  transform: translateX(-50%) translateY(-14px);
  opacity: 0;
  pointer-events: none;
  background: rgba(0, 255, 198, 0.9);
  color: #04120d;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  z-index: 120;
  transition: opacity 220ms ease, transform 220ms ease;
}

.capture-flash.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  animation: pulse 1.2s ease-in-out infinite;
}

.capture-flash.warn {
  background: rgba(255, 95, 109, 0.92);
  color: #150608;
}

@keyframes pulse {
  0%,
  100% { box-shadow: 0 0 0 rgba(0, 255, 198, 0.1); }
  50% { box-shadow: 0 0 20px rgba(0, 255, 198, 0.8); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 110;
}

.modal-card {
  width: min(840px, calc(100vw - 2rem));
  max-height: 80vh;
  overflow: auto;
  border-radius: 12px;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid rgba(29, 230, 255, 0.45);
}

.matrix-modal-card {
  width: min(520px, calc(100vw - 2rem));
}

.signup-token-card {
  max-width: min(620px, calc(100vw - 2rem));
  display: grid;
  gap: 0.65rem;
}

.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.leaderboard-body table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-body th,
.leaderboard-body td {
  text-align: left;
  border-bottom: 1px solid rgba(120, 184, 196, 0.25);
  padding: 0.55rem;
}

.leaderboard-body tr.mine {
  background: rgba(255, 209, 102, 0.18);
}

@media (max-width: 960px) {
  .hud-top {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .hud-top .brand-header {
    width: 100%;
  }

  .hud-top .brand-header .glitch {
    white-space: normal;
  }

  .hud-actions {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .matrix-panel {
    display: none;
  }

  .matrix-toggle {
    display: inline-flex;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .admin-controls {
    grid-template-columns: 1fr;
  }

  #welcome-continue-btn {
    width: 100%;
  }
}
