html, body {
  margin: 0;
  padding: 0;
  background: #000;
  color: #0f0;
  font-family: monospace;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  margin: 0 auto;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 1;
  /* Enhanced bloom for CRT aesthetic */
  filter: contrast(1.08) saturate(1.12) brightness(1.05) drop-shadow(0 0 8px rgba(0, 255, 0, 0.3));
}

.skin-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  background: #151515;
  color: #0f0;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-family: monospace;
  font-size: 13px;
  z-index: 1000;
  outline: none;
}

.skin-toggle:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

.skin-toggle:focus {
  outline: none;
}

.editor-toggle {
  position: fixed;
  top: 12px;
  right: 160px;
  background: #151515;
  color: #ff0;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-family: monospace;
  font-size: 13px;
  z-index: 1000;
  outline: none;
}

.editor-toggle:hover {
  border-color: #ff0;
  background: #1a1a1a;
}

.editor-toggle:focus {
  outline: none;
}

.editor-toggle.active {
  border-color: #ff0;
  background: #3a3a00;
}

.version-indicator {
  position: fixed;
  bottom: 12px;
  right: 12px;
  color: #0f0;
  font-family: monospace;
  font-size: 11px;
  opacity: 0.4;
  z-index: 1000;
  pointer-events: none;
}

.authority-badge {
  position: fixed;
  bottom: 12px;
  left: 12px;
  background: #0a0a0a;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 12px;
  color: #0f0;
  font-family: monospace;
  font-size: 13px;
  z-index: 1000;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.authority-badge:hover {
  border-color: #0f0;
  background: #1a1a1a;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 255, 0, 0.2);
}

#authorityIcon {
  font-size: 18px;
  line-height: 1;
}

#authorityLabel {
  font-size: 12px;
  opacity: 0.9;
}

.hidden { display: none !important; }

.toast-notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 10, 0.95);
  border: 1px solid #f66;
  border-radius: 6px;
  padding: 16px 24px;
  color: #f66;
  font-family: monospace;
  font-size: 14px;
  z-index: 6000;
  box-shadow: 0 4px 16px rgba(255, 102, 102, 0.3);
  text-shadow: 0 0 2px rgba(255, 102, 102, 0.5);
  animation: toastFadeInOut 2s ease-in-out forwards;
  pointer-events: none;
}

@keyframes toastFadeInOut {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  10% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
}

.door-tooltip {
  position: fixed;
  background: rgba(10, 10, 10, 0.95);
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 10px 14px;
  color: #ddd;
  font-family: monospace;
  font-size: 12px;
  z-index: 4000;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  transition: opacity 0.15s ease-out;
  display: flex;
  align-items: center;
  gap: 8px;
}

.door-tooltip.allowed {
  border-color: #0f0;
  background: rgba(0, 50, 0, 0.95);
}

.door-tooltip.denied {
  border-color: #f66;
  background: rgba(50, 0, 0, 0.95);
}

.door-tooltip-icon {
  font-size: 16px;
}

.door-tooltip-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.door-tooltip-status {
  font-size: 11px;
  font-weight: bold;
}

.door-tooltip-requirement {
  font-size: 10px;
  opacity: 0.8;
}

/* Threshold Screen */
#threshold-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  color: #0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 18px;
  text-shadow: 
    0 0 2px rgba(0, 255, 0, 0.8),
    0 0 8px rgba(0, 255, 0, 0.5),
    0 0 16px rgba(0, 255, 0, 0.3),
    0 0 24px rgba(0, 255, 0, 0.2);
}

#threshold-text {
  text-align: center;
  letter-spacing: 2px;
}

/* Loading Screen */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: #000;
  color: #0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 18px;
  text-shadow: 
    0 0 2px rgba(0, 255, 0, 0.8),
    0 0 8px rgba(0, 255, 0, 0.5),
    0 0 16px rgba(0, 255, 0, 0.3),
    0 0 24px rgba(0, 255, 0, 0.2);
  opacity: 1;
  transition: opacity 0.5s ease-out;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

#loading-text {
  text-align: center;
  letter-spacing: 2px;
  animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% {
    text-shadow: 
      0 0 2px rgba(0, 255, 0, 0.8),
      0 0 8px rgba(0, 255, 0, 0.5),
      0 0 16px rgba(0, 255, 0, 0.3),
      0 0 24px rgba(0, 255, 0, 0.2);
  }
  50% {
    text-shadow: 
      0 0 4px rgba(0, 255, 0, 1),
      0 0 12px rgba(0, 255, 0, 0.7),
      0 0 24px rgba(0, 255, 0, 0.5),
      0 0 36px rgba(0, 255, 0, 0.3);
  }
}

/* Landing Page */
#landing-page {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  color: #0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 14px;
  text-shadow: 
    0 0 2px rgba(0, 255, 0, 0.8),
    0 0 8px rgba(0, 255, 0, 0.5),
    0 0 16px rgba(0, 255, 0, 0.3),
    0 0 24px rgba(0, 255, 0, 0.2);
}

#landing-content {
  white-space: pre;
  line-height: 1.2;
  font-size: 14px;
  text-shadow: 
    0 0 2px rgba(0, 255, 0, 0.8),
    0 0 8px rgba(0, 255, 0, 0.5),
    0 0 16px rgba(0, 255, 0, 0.3),
    0 0 24px rgba(0, 255, 0, 0.2);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 5000;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(2px);
  }
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-20px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10%, 30%, 50%, 70%, 90% { transform: translate(-2px, 0); }
  20%, 40%, 60%, 80% { transform: translate(2px, 0); }
}

.modal-panel {
  width: min(720px, 92vw);
  background: #0a0a0a;
  border: 1px solid #1f1f1f;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  color: #ddd;
  /* Subtle green glow for CRT aesthetic */
  text-shadow: 0 0 1px rgba(0, 255, 0, 0.35), 0 0 10px rgba(0, 255, 0, 0.10);
  position: relative;
  z-index: 1;
  animation: modalSlideIn 0.3s ease-out;
}

.screen-shake {
  animation: screenShake 0.4s ease-in-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px 12px;
  border-bottom: 1px solid #1f1f1f;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.modal-x {
  background: transparent;
  color: #aaa;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px;
}

.modal-body {
  padding: 12px;
  line-height: 1.35;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0 12px 12px 12px;
}

.btn {
  background: #151515;
  color: #ddd;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  font-family: monospace;
  outline: none;
}

.btn:hover {
  border-color: #3a3a3a;
}

.btn:focus {
  outline: none;
}

.btn.primary {
  border-color: #2c6;
  color: #cfc;
}

.editor-ui {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: transparent;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.editor-ui > * {
  pointer-events: auto;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #0a0a0a;
  border-bottom: 1px solid #2a2a2a;
  z-index: 2001;
  position: relative;
}

.toolbar-section {
  display: flex;
  gap: 8px;
}

.editor-btn {
  background: #151515;
  color: #0f0;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: monospace;
  font-size: 13px;
}

.editor-btn:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

.editor-btn-exit {
  color: #f66;
}

.editor-btn-exit:hover {
  border-color: #f66;
}

.editor-palette {
  position: fixed;
  left: 0;
  top: 49px;
  bottom: 0;
  width: 220px;
  background: #0a0a0a;
  border-right: 1px solid #2a2a2a;
  overflow-y: auto;
  z-index: 2001;
}

.palette-header {
  padding: 12px;
  font-weight: bold;
  color: #0f0;
  border-bottom: 1px solid #2a2a2a;
}

.palette-section {
  padding: 12px;
  border-bottom: 1px solid #1a1a1a;
}

.palette-label {
  font-size: 11px;
  color: #888;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.palette-tiles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.palette-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  cursor: pointer;
  font-family: monospace;
  text-align: left;
}

.palette-tile:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

.palette-tile.selected {
  border-color: #0f0;
  background: #1a3a1a;
}

.palette-tile-char {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.palette-tile-label {
  color: #ddd;
  font-size: 13px;
}

.palette-tools {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-btn {
  padding: 8px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  cursor: pointer;
  font-family: monospace;
  color: #ddd;
  text-align: left;
}

.tool-btn:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

.tool-btn.selected {
  border-color: #0f0;
  background: #1a3a1a;
}

.editor-inspector {
  position: fixed;
  right: 0;
  top: 49px;
  bottom: 0;
  width: 280px;
  background: #0a0a0a;
  border-left: 1px solid #2a2a2a;
  overflow-y: auto;
  z-index: 2001;
}

.inspector-header {
  padding: 12px;
  font-weight: bold;
  color: #0f0;
  border-bottom: 1px solid #2a2a2a;
}

.inspector-content {
  padding: 12px;
}

.inspector-empty {
  color: #666;
  font-style: italic;
  text-align: center;
  padding: 24px 12px;
}

.inspector-field {
  margin-bottom: 12px;
}

.inspector-field label {
  display: block;
  font-size: 11px;
  color: #888;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.inspector-field input,
.inspector-field select {
  width: 100%;
  padding: 6px 8px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #ddd;
  font-family: monospace;
  font-size: 13px;
}

.inspector-field input:focus,
.inspector-field select:focus {
  outline: none;
  border-color: #0f0;
}

.inspector-row {
  display: flex;
  gap: 8px;
}

.inspector-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.terminal-editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.terminal-editor-panel {
  width: min(600px, 92vw);
  max-height: 90vh;
  background: #0a0a0a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Subtle green glow for CRT aesthetic */
  text-shadow: 0 0 1px rgba(0, 255, 0, 0.35), 0 0 10px rgba(0, 255, 0, 0.10);
}

.terminal-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid #2a2a2a;
  background: #0f0f0f;
}

.terminal-editor-header h2 {
  margin: 0;
  font-size: 16px;
  color: #0f0;
  font-weight: 700;
}

.terminal-editor-content {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.editor-field {
  margin-bottom: 16px;
}

.editor-field label {
  display: block;
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.editor-field input,
.editor-field textarea {
  width: 100%;
  padding: 8px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #ddd;
  font-family: monospace;
  font-size: 13px;
  box-sizing: border-box;
}

.editor-field input:focus,
.editor-field textarea:focus {
  outline: none;
  border-color: #0f0;
}

.editor-field input[readonly] {
  color: #666;
  background: #0f0f0f;
  cursor: not-allowed;
}

.terminal-editor-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px;
  border-top: 1px solid #2a2a2a;
  background: #0f0f0f;
}

.editor-btn-primary {
  background: #1a3a1a;
  border-color: #0f0;
  color: #cfc;
}

/* Audio Indicator */
.audio-indicator {
  position: fixed;
  top: 12px;
  left: 12px;
  width: 28px;
  height: 28px;
  background: #151515;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
}

.audio-indicator:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

.audio-indicator.muted {
  color: #fff;
  background: #c31;
  border-color: #f44;
}

.audio-indicator.muted:hover {
  background: #e42;
  border-color: #f66;
}

.audio-indicator:not(.muted) {
  color: #0f0;
}

.audio-indicator.playing {
  animation: audioPlaying 0.8s ease-in-out infinite;
}

@keyframes audioPlaying {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Audio Settings */
.audio-test-btn:hover {
  border-color: #0f0;
  background: #1a1a1a;
}

input[type="range"] {
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #0f0;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #0a0a0a;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #0f0;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #0a0a0a;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #0ff;
}

input[type="range"]::-moz-range-thumb:hover {
  background: #0ff;
}

/* CRT Overlay Effects */
#crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4000;
}

#crt-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    /* Horizontal scanlines */
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.15),
      rgba(0, 0, 0, 0.15) 1px,
      transparent 1px,
      transparent 4px
    ),
    /* Vertical slot mask */
    repeating-linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.10),
      rgba(0, 0, 0, 0.10) 1px,
      transparent 1px,
      transparent 3px
    ),
    /* Radial vignette */
    radial-gradient(
      ellipse at center,
      transparent 0%,
      transparent 40%,
      rgba(0, 0, 0, 0.25) 80%,
      rgba(0, 0, 0, 0.45) 100%
    );
  mix-blend-mode: overlay;
  opacity: 0.55;
}

#crt-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.045);
  animation: crtFlicker 6s infinite;
}

@keyframes crtFlicker {
  0% { opacity: 0.045; }
  25% { opacity: 0.060; }
  50% { opacity: 0.030; }
  75% { opacity: 0.060; }
  100% { opacity: 0.045; }
}

@media (prefers-reduced-motion: reduce) {
  #crt-overlay::after {
    animation: none;
  }
}

/* CRT Warm-up Animation */
@keyframes crtWarmup {
  0% {
    opacity: 0;
    transform: scaleY(0.005) scaleX(1.2);
    filter: brightness(3);
  }
  15% {
    opacity: 0.8;
    transform: scaleY(0.1) scaleX(1.1);
    filter: brightness(2.5);
  }
  40% {
    opacity: 1;
    transform: scaleY(0.8) scaleX(1.05);
    filter: brightness(1.8);
  }
  70% {
    transform: scaleY(1.02) scaleX(1.01);
    filter: brightness(1.2);
  }
  100% {
    opacity: 1;
    transform: scaleY(1) scaleX(1);
    filter: brightness(1);
  }
}

body.crt-warmup #landing-page {
  animation: crtWarmup 1000ms ease-out;
  transform-origin: center center;
}

body.crt-warmup #crt-overlay {
  animation: crtWarmup 1000ms ease-out;
  transform-origin: center center;
}

@media (prefers-reduced-motion: reduce) {
  body.crt-warmup #landing-page {
    animation: none;
  }
  
  body.crt-warmup #crt-overlay {
    animation: none;
  }
}

/* Beast Pens Console CRT Enhancement */
.modal-body {
  text-shadow: 
    0 0 1px rgba(0, 255, 0, 0.4),
    0 0 2px rgba(0, 255, 0, 0.3),
    0 0 4px rgba(0, 255, 0, 0.2);
}

/* Keyboard Focus Indicators for BBS Navigation */
.bbs-option-highlighted {
  background: rgba(0, 255, 0, 0.15);
  box-shadow: 
    0 0 8px rgba(0, 255, 0, 0.4),
    inset 0 0 4px rgba(0, 255, 0, 0.2);
  animation: bbsOptionPulse 1.5s ease-in-out infinite;
}

@keyframes bbsOptionPulse {
  0%, 100% {
    box-shadow: 
      0 0 8px rgba(0, 255, 0, 0.4),
      inset 0 0 4px rgba(0, 255, 0, 0.2);
  }
  50% {
    box-shadow: 
      0 0 12px rgba(0, 255, 0, 0.6),
      inset 0 0 6px rgba(0, 255, 0, 0.3);
  }
}

/* Enhanced scanline effect for modals containing BBS content */
.modal-panel.bbs-console {
  position: relative;
}

.modal-panel.bbs-console::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 2px
  );
  pointer-events: none;
  z-index: 1;
  border-radius: 8px;
  opacity: 0.6;
}

.modal-panel.bbs-console .modal-body,
.modal-panel.bbs-console .modal-header,
.modal-panel.bbs-console .modal-actions {
  position: relative;
  z-index: 2;
}

/* Phosphor glow effect for modal text */
.modal-panel.bbs-console {
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.6),
    0 0 24px rgba(0, 255, 0, 0.15),
    inset 0 0 80px rgba(0, 255, 0, 0.03);
}
