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

:root {
  --green: #33ff33;
  --dim-green: #1a8c1a;
  --amber: #ffb000;
  --cyan: #00ffff;
  --red: #ff4444;
  --bg: #0a0a0a;
  --glow: 0 0 6px rgba(51, 255, 51, 0.4);
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--green);
  font-family: 'VT323', monospace;
  font-size: 18px;
  line-height: 1.4;
  overflow: hidden;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  z-index: 9999;
}

.screen { display: none; height: 100%; height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

#joinScreen {
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

#bootLog {
  text-align: left;
  white-space: pre;
  color: var(--dim-green);
  font-size: 16px;
  margin-bottom: 1.5rem;
  min-height: 180px;
}
#bootLog .ok { color: var(--green); }

.ascii-banner {
  white-space: pre;
  text-align: center;
  color: var(--green);
  text-shadow: var(--glow);
  font-size: 18px;
  margin-bottom: 2rem;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.ascii-banner.visible { opacity: 1; }

.join-prompt {
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.join-prompt.visible { opacity: 1; }
.join-prompt span { color: var(--amber); white-space: pre; }

.pin-prompt {
  display: none;
  align-items: center;
  gap: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  margin-top: 0.5rem;
}
.pin-prompt.visible { display: flex; opacity: 1; }
.pin-prompt span { color: var(--cyan); white-space: pre; }
.pin-prompt .pin-error { color: var(--red); font-size: 16px; margin-top: 0.3rem; }
#pinInput { width: 8ch; -webkit-text-security: square; }

input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--green);
  font-family: 'VT323', monospace;
  font-size: 18px;
  caret-color: transparent;
}

.input-wrap {
  position: relative;
  flex: 1;
}
.input-wrap input { width: 100%; }
.block-cursor {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  width: 10px;
  height: 1.15em;
  background: var(--green);
  pointer-events: none;
  animation: cursorBlink 1s step-end infinite;
  display: none;
}
input:focus ~ .block-cursor { display: block; }
@keyframes cursorBlink {
  50% { background: transparent; }
}

#usernameInput { width: 20ch; }
.join-prompt .input-wrap { flex: 0 0 auto; }

#chatScreen { height: 100%; height: 100dvh; }

.header {
  padding: 0.25rem 1rem;
  border-bottom: 1px solid #1a1a1a;
  color: var(--dim-green);
  display: flex;
  justify-content: space-between;
  font-size: 16px;
}

#terminal {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  scroll-behavior: smooth;
}

#terminal::-webkit-scrollbar { width: 6px; }
#terminal::-webkit-scrollbar-track { background: transparent; }
#terminal::-webkit-scrollbar-thumb { background: #1a3a1a; border-radius: 3px; }

.line {
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: lineIn 0.4s ease-out;
}

@keyframes lineIn {
  0%   { opacity: 0; text-shadow: 0 0 20px rgba(51, 255, 51, 0.9), 0 0 40px rgba(51, 255, 51, 0.5); }
  40%  { opacity: 1; text-shadow: 0 0 12px rgba(51, 255, 51, 0.6), 0 0 24px rgba(51, 255, 51, 0.3); }
  100% { opacity: 1; text-shadow: none; }
}

.line .ts { color: var(--dim-green); }
.line .nick { color: var(--amber); }
.line .own-nick { color: var(--green); font-weight: bold; }
.line .mention { color: var(--red); font-weight: bold; text-shadow: 0 0 6px rgba(255, 68, 68, 0.4); }
.line.system { color: var(--dim-green); font-style: italic; }
.line.motd { color: var(--amber); }
.line.whisper { color: var(--cyan); }
.line.emote { color: var(--amber); }
.line.roll { color: var(--amber); }
.line.error { color: var(--red); }
.line.who { color: var(--cyan); }
.line.info { color: var(--dim-green); }

.line .msg-id {
  color: #2a2a2a;
  font-size: 13px;
  cursor: default;
  user-select: all;
}
.line .msg-id:hover { color: var(--dim-green); }

.line.broadcast {
  color: var(--red);
  font-weight: bold;
  border: 1px solid var(--red);
  padding: 4px 8px;
  margin: 4px 0;
  animation: broadcastFlash 1s ease-in-out 3;
  text-shadow: 0 0 8px rgba(255, 68, 68, 0.6);
}
@keyframes broadcastFlash {
  0%, 100% { border-color: var(--red); background: rgba(255, 68, 68, 0.05); }
  50% { border-color: #ff8800; background: rgba(255, 68, 68, 0.15); }
}

.line.ascii-art {
  white-space: pre;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(0, 255, 255, 0.3);
  line-height: 1.1;
  margin: 0;
  animation: none;
}


.pinned-area {
  border-bottom: 1px solid #1a1a1a;
  background: rgba(255, 176, 0, 0.03);
  max-height: 130px;
  overflow-y: auto;
  display: none;
}
.pinned-area.has-pins { display: block; }
.pinned-item {
  padding: 2px 1rem;
  font-size: 15px;
  color: var(--amber);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pinned-item .pin-label {
  color: var(--dim-green);
  font-size: 13px;
  flex-shrink: 0;
}
.pinned-item .pin-text {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pinned-item .pin-text .nick { color: var(--amber); }
.pinned-item .unpin-btn {
  background: none;
  border: none;
  color: var(--dim-green);
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
  padding: 0 0.3rem;
  flex-shrink: 0;
}
.pinned-item .unpin-btn:hover { color: var(--red); }

.dnd-badge {
  color: var(--red);
  font-size: 14px;
  margin-left: 0.5rem;
}

.decrypt-target {
  color: var(--green);
}
.decrypt-active .decrypt-target {
  text-shadow: 0 0 4px rgba(51, 255, 51, 0.6);
}

#screensaver {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: var(--bg);
  display: none;
  cursor: none;
}
#screensaver.active { display: block; }
#screensaverCanvas { width: 100%; height: 100%; }

#typingBar {
  padding: 0 1rem;
  height: 1.4em;
  color: var(--dim-green);
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
}

.input-row {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-top: 1px solid #1a1a1a;
}

.input-row .prompt { color: var(--green); margin-right: 0.25rem; white-space: pre; }

#messageInput {
  width: 100%;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.5rem;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 4px var(--green); }
.status-dot.disconnected { background: var(--red); box-shadow: 0 0 4px var(--red); }

/* ── Radio ─────────────────────────────────── */
.radio-bar {
  padding: 0.4rem 1rem;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 16px;
  color: var(--dim-green);
  background: rgba(10, 10, 10, 0.8);
  user-select: none;
}

.radio-label {
  color: var(--amber);
  letter-spacing: 2px;
  font-size: 14px;
  flex-shrink: 0;
}

.radio-btn {
  background: none;
  border: 1px solid #2a2a2a;
  color: var(--green);
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 0 0.4rem;
  cursor: pointer;
  line-height: 1.4;
  transition: border-color 0.15s, text-shadow 0.15s;
}
.radio-btn:hover {
  border-color: var(--green);
  text-shadow: var(--glow);
}
.radio-btn.active {
  color: var(--amber);
  border-color: var(--amber);
  text-shadow: 0 0 6px rgba(255, 176, 0, 0.4);
}

.radio-station-name {
  color: var(--green);
  text-shadow: var(--glow);
  min-width: 14ch;
  text-align: center;
  flex-shrink: 0;
}
.radio-station-name .genre {
  color: var(--dim-green);
  font-size: 14px;
}

.radio-eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
  flex-shrink: 0;
}
.radio-eq .bar {
  width: 3px;
  background: var(--green);
  box-shadow: 0 0 3px rgba(51, 255, 51, 0.3);
  transition: height 0.12s ease;
  min-height: 2px;
}
.radio-eq.idle .bar {
  height: 2px !important;
  background: var(--dim-green);
  box-shadow: none;
}

.radio-vol {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  margin-left: auto;
}
.radio-vol-label { color: var(--dim-green); font-size: 14px; }

.radio-vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 70px;
  height: 4px;
  background: #1a3a1a;
  border-radius: 0;
  outline: none;
  cursor: pointer;
}
.radio-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px;
  height: 14px;
  background: var(--green);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(51, 255, 51, 0.4);
}
.radio-vol-slider::-moz-range-thumb {
  width: 8px;
  height: 14px;
  background: var(--green);
  border: none;
  border-radius: 0;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(51, 255, 51, 0.4);
}

.radio-expand-btn {
  background: none;
  border: none;
  color: var(--dim-green);
  font-family: 'VT323', monospace;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0 0.2rem;
}
.radio-expand-btn:hover { color: var(--green); }

.radio-stations {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border-bottom: none;
  background: rgba(5, 5, 5, 0.9);
}
.radio-stations.open {
  max-height: 300px;
  border-bottom: 1px solid #1a1a1a;
}
.radio-stations-inner {
  padding: 0.4rem 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.2rem 1.5rem;
}
.radio-station-item {
  padding: 0.15rem 0.4rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  color: var(--dim-green);
  font-size: 15px;
  border: 1px solid transparent;
}
.radio-station-item:hover {
  color: var(--green);
  border-color: #1a3a1a;
}
.radio-station-item.active {
  color: var(--amber);
  border-color: rgba(255, 176, 0, 0.2);
}
.radio-station-item .sgenre { color: var(--dim-green); font-size: 13px; }

/* Autocomplete Popup */
.autocomplete-popup {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: #111;
  border: 1px solid var(--dim-green);
  border-bottom: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  font-family: 'VT323', monospace;
  font-size: 16px;
}
.autocomplete-popup.visible {
  display: block;
}
.autocomplete-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  color: var(--green);
}
.autocomplete-item:hover,
.autocomplete-item.selected {
  background: #1a3a1a;
  color: #fff;
}
.autocomplete-item .ac-label {
  flex-shrink: 0;
}
.autocomplete-item .ac-desc {
  color: var(--dim-green);
  margin-left: 1.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.autocomplete-item.selected .ac-desc {
  color: #5c5;
}

/* ── Dead Internet: Ghost & Ambient Lines ── */
.line.ghost {
  color: #1a4a1a;
  font-style: italic;
  opacity: 0.65;
}
.line.ghost .ghost-nick {
  color: #1a4a1a;
}

.line.ambient {
  color: var(--dim-green);
  font-style: italic;
  opacity: 0.7;
}

/* ── Dead Internet: Visual Decay Effects ─── */
.glitch-active {
  animation: glitchLine 400ms linear;
}
@keyframes glitchLine {
  0%   { transform: translateX(0);   color: inherit;    text-shadow: none; }
  20%  { transform: translateX(-3px); color: var(--amber); text-shadow: 2px 0 var(--cyan), -2px 0 var(--red); }
  40%  { transform: translateX(2px);  color: inherit;    text-shadow: -1px 0 var(--red), 1px 0 var(--cyan); opacity: 0.8; }
  60%  { transform: translateX(-1px); color: var(--amber); text-shadow: 1px 0 var(--cyan); }
  80%  { transform: translateX(1px);  color: inherit;    text-shadow: none; opacity: 0.9; }
  100% { transform: translateX(0);    color: inherit;    text-shadow: none; }
}

body.scanline-stutter::after {
  animation: scanlineJump 150ms steps(3);
}
@keyframes scanlineJump {
  0%   { background-position: 0 0;   opacity: 0.15; }
  33%  { background-position: 0 3px; opacity: 0.25; }
  66%  { background-position: 0 -2px; opacity: 0.20; }
  100% { background-position: 0 0;   opacity: 0.15; }
}

.cursor-jitter {
  animation: cursorJitter 300ms linear !important;
}
@keyframes cursorJitter {
  0%   { transform: translateY(-50%) translate(0, 0); }
  25%  { transform: translateY(-50%) translate(2px, -1px); }
  50%  { transform: translateY(-50%) translate(-1px, 2px); }
  75%  { transform: translateY(-50%) translate(1px, -1px); }
  100% { transform: translateY(-50%) translate(0, 0); }
}

/* ── Mobile ───────────────────────────────── */
@media (max-width: 600px) {
  html, body { font-size: 16px; }

  #joinScreen { padding: 1rem; }

  #bootLog {
    font-size: 13px;
    min-height: 120px;
    white-space: pre-wrap;
    word-break: break-all;
  }

  .ascii-banner {
    font-size: 11px;
    margin-bottom: 1rem;
    overflow-x: auto;
  }

  .header { padding: 0.25rem 0.5rem; font-size: 14px; }

  /* Radio bar: wrap and hide non-essential items */
  .radio-bar {
    padding: 0.3rem 0.5rem;
    gap: 0.4rem;
    font-size: 14px;
    flex-wrap: wrap;
  }
  .radio-eq { display: none; }
  .radio-station-name { min-width: 0; font-size: 14px; }
  .radio-vol { gap: 0.2rem; }
  .radio-vol-slider { width: 50px; }

  .radio-stations-inner {
    grid-template-columns: 1fr;
    padding: 0.3rem 0.5rem;
  }

  #terminal { padding: 0.5rem; }

  .input-row { padding: 0.4rem 0.5rem; }

  /* Show native caret on touch devices instead of custom block cursor */
  input { caret-color: var(--green); }
  .block-cursor { display: none !important; }

  .pinned-area { max-height: 80px; }
  .pinned-item { padding: 2px 0.5rem; font-size: 13px; }
}
