* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #000000;
  touch-action: none;
  font-family: 'Press Start 2P', monospace, sans-serif;
}

/* Layer 0: Game Canvas - Stretches to full screen */
#gameCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: #000000;
}

/* Layer 1: Overlay UI Layer */
#ui-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100;
  pointer-events: none;
  overflow: hidden;
}

/* Retro HUD Boxes Common Style */
.retro-box {
  background: rgba(13, 17, 23, 0.88);
  border: 2px solid #58a6ff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7), 0 0 10px rgba(88, 166, 255, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
}

/* Task HUD (Top-Left) */
#task-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: min(90vw, 360px);
  padding: 8px 12px;
  z-index: 220;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.2s ease, border-color 0.3s ease;
}

.task-hud-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 8px;
  color: #f59e0b;
  border-bottom: 1px solid rgba(245, 158, 11, 0.4);
  padding-bottom: 4px;
  text-transform: uppercase;
}

.task-icon {
  font-size: 11px;
}

.task-hud-body {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 8px;
  line-height: 1.4;
  color: #e6edf3;
}

.task-arrow {
  color: #22c55e;
  font-size: 9px;
  animation: pulseArrow 1s infinite alternate;
}

@keyframes pulseArrow {
  from { opacity: 0.6; transform: translateX(0); }
  to { opacity: 1; transform: translateX(2px); }
}

.task-pulse {
  animation: taskGlow 0.8s ease;
}

@keyframes taskGlow {
  0% { transform: scale(1); border-color: #22c55e; box-shadow: 0 0 20px #22c55e; }
  50% { transform: scale(1.04); border-color: #22c55e; box-shadow: 0 0 25px #22c55e; }
  100% { transform: scale(1); border-color: #58a6ff; }
}

/* Bits Collectible HUD (Top-Center-Right) */
#bits-hud {
  position: absolute;
  top: 14px;
  right: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-color: #a855f7;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7), 0 0 10px rgba(168, 85, 247, 0.4);
  z-index: 220;
}

#bits-hud-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  image-rendering: pixelated;
  animation: bitFloat 2s infinite ease-in-out;
}

@keyframes bitFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.08); }
}

.bits-text {
  font-size: 9px;
  color: #f3e8ff;
}

.bits-text strong {
  color: #c084fc;
}

/* Admin Toggle Button */
#admin-toggle-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(22, 27, 34, 0.88);
  border: 1px solid rgba(88, 166, 255, 0.6);
  color: #c9d1d9;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  z-index: 250;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: all 0.2s ease;
}

#admin-toggle-btn:hover {
  background: rgba(56, 139, 253, 0.9);
  transform: rotate(30deg) scale(1.06);
}

/* Dialogue Box */
#dialogue-container {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 680px);
  aspect-ratio: 987 / 224;
  max-height: 160px;
  z-index: 200;
  pointer-events: auto;
  cursor: pointer;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-14px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

#dialogue-box {
  position: relative;
  width: 100%;
  height: 100%;
}

#dialogue-bg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7));
}

#dialogue-avatar-container {
  position: absolute;
  left: 2.8%;
  top: 18%;
  width: 15%;
  height: 68%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 4px;
}

#dialogue-avatar {
  max-height: 96%;
  max-width: 96%;
  object-fit: contain;
  image-rendering: pixelated;
}

#dialogue-speaker {
  position: absolute;
  left: 22%;
  top: 6%;
  width: 32%;
  height: 22%;
  color: #ffffff;
  font-size: clamp(7px, 1.35vw, 12px);
  font-weight: bold;
  display: flex;
  align-items: center;
  text-shadow: 1px 1px 0 #0f381e;
  overflow: hidden;
  white-space: nowrap;
}

#dialogue-id-badge {
  position: absolute;
  right: 6%;
  top: 7%;
  font-size: clamp(5px, 0.85vw, 8px);
  color: #93c5fd;
  background: rgba(15, 23, 42, 0.7);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(147, 197, 253, 0.4);
}

#dialogue-text-container {
  position: absolute;
  left: 22%;
  top: 34%;
  width: 70%;
  height: 54%;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
}

#dialogue-text {
  color: #1a1a1a;
  font-size: clamp(6px, 1.15vw, 10.5px);
  line-height: 1.55;
  font-weight: 600;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
  word-break: break-word;
}

#dialogue-arrow {
  position: absolute;
  right: 5%;
  bottom: 12%;
  color: #1a1a1a;
  font-size: clamp(7px, 1.1vw, 10px);
  animation: bounceArrow 0.8s infinite alternate;
}

@keyframes bounceArrow {
  from { transform: translateY(0); }
  to { transform: translateY(3px); }
}

.hidden {
  display: none !important;
}

/* Mobile Controls Overlay */
#mobile-controls {
  display: none;
  position: absolute;
  bottom: 16px;
  left: 0;
  width: 100%;
  padding: 0 16px;
  box-sizing: border-box;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 150;
}

.mobile-dpad, .mobile-actions {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.75);
  border: 2px solid rgba(88, 166, 255, 0.7);
  color: #f0f6fc;
  font-family: inherit;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  touch-action: manipulation;
}

.touch-btn:active, .touch-btn.active {
  background: rgba(56, 139, 253, 0.85);
  transform: scale(0.92);
  border-color: #ffffff;
}

.action-btn {
  font-size: 9px;
}

.primary-btn {
  background: rgba(31, 111, 235, 0.8);
  border-color: #58a6ff;
  width: 64px;
  height: 64px;
  font-size: 10px;
}

.interact-btn {
  background: rgba(34, 197, 94, 0.85);
  border-color: #4ade80;
  color: #ffffff;
  font-size: 8px;
}

.interact-btn:active, .interact-btn.active {
  background: rgba(22, 163, 74, 0.95);
  border-color: #ffffff;
}

/* Screen Size Adaptations */
@media (hover: none) and (pointer: coarse), (max-width: 900px) {
  #mobile-controls {
    display: flex;
  }
}

@media (max-width: 768px) {
  #dialogue-container {
    width: 94vw;
    top: 60px;
  }
  #task-hud {
    max-width: 60vw;
  }
  #bits-hud {
    right: 54px;
    padding: 4px 8px;
    font-size: 7px;
  }
}

@media (max-height: 500px) {
  #dialogue-container {
    width: min(76vw, 480px);
    top: 45px;
    max-height: 95px;
  }
  #admin-toggle-btn {
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    font-size: 13px;
  }
  #task-hud {
    top: 6px;
    left: 6px;
    padding: 4px 8px;
  }
  #bits-hud {
    top: 6px;
    right: 42px;
  }
}

/* Layer 2: Admin Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  pointer-events: auto;
}

.modal-content {
  background: #161b22;
  border: 3px solid #388bfd;
  border-radius: 8px;
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px;
  color: #f0f6fc;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9), 0 0 20px rgba(56, 139, 253, 0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #30363d;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.modal-header h2 {
  font-size: 12px;
  color: #58a6ff;
}

.close-btn {
  background: transparent;
  border: none;
  color: #8b949e;
  font-size: 22px;
  cursor: pointer;
}

.close-btn:hover {
  color: #f85149;
}

/* Admin Tabs */
.admin-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid #30363d;
  padding-bottom: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  background: #21262d;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 9px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.tab-btn:hover {
  background: #30363d;
  color: #f0f6fc;
}

.tab-btn.active {
  background: #1f6feb !important;
  color: #ffffff !important;
  border-color: #58a6ff !important;
  box-shadow: 0 0 10px rgba(88, 166, 255, 0.6) !important;
}

.tab-pane {
  display: none !important;
}

.tab-pane.active {
  display: block !important;
}

/* Asset Manager Grid */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.asset-card {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.asset-card label {
  font-size: 8.5px;
  color: #c9d1d9;
}

.asset-card input[type="file"] {
  font-size: 8px;
  color: #8b949e;
}

/* Audio Master Section */
.audio-master-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.volume-controls-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 12px;
}

.vol-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.vol-control label {
  font-size: 8px;
  color: #58a6ff;
}

.vol-control input[type="range"] {
  accent-color: #58a6ff;
  cursor: pointer;
}

.section-title {
  font-size: 10px;
  color: #58a6ff;
  margin-top: 6px;
}

.section-desc {
  font-size: 7.5px;
  color: #8b949e;
  line-height: 1.4;
}

.section-desc code {
  color: #79c0ff;
  background: rgba(110, 118, 129, 0.2);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Global Audio Manager Card */
.global-audio-card {
  background: #0d1726;
  border: 2px solid #58a6ff;
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), 0 0 12px rgba(88, 166, 255, 0.25);
}

.global-audio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid rgba(88, 166, 255, 0.3);
  padding-bottom: 8px;
}

.global-audio-title {
  font-size: 9px;
  color: #79c0ff;
  font-weight: bold;
}

.global-audio-details {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.global-audio-controls-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.global-audio-controls-row .play-btn {
  background: #238636;
  border-color: #2ea043;
  color: #ffffff;
}

.global-audio-controls-row .play-btn:hover {
  background: #2ea043;
}

.global-audio-controls-row .pause-btn {
  background: #9e6a03;
  border-color: #d29922;
  color: #ffffff;
}

.global-audio-controls-row .pause-btn:hover {
  background: #bb8009;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 7.5px;
  color: #c9d1d9;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: #58a6ff;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.global-upload-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.global-audio-footer-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.voice-badge.disabled-voice {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid #ef4444;
}

/* Quick Voice Upload Box */
.quick-voice-box {
  background: #111b27;
  border: 2px dashed #388bfd;
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 0 10px rgba(56, 139, 253, 0.2);
}

.quick-voice-header {
  font-size: 9px;
  color: #58a6ff;
  font-weight: bold;
}

.quick-voice-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-voice-row label {
  font-size: 7.5px;
  color: #c9d1d9;
}

.retro-select {
  background: #161b22;
  border: 1px solid #30363d;
  color: #f0f6fc;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 8px;
  border-radius: 4px;
}

.retro-file-input {
  background: #161b22;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 8px;
  border-radius: 4px;
}

.upload-status-msg {
  font-size: 7.5px;
  line-height: 1.4;
}

.upload-status-msg.loading {
  color: #f59e0b;
}

.upload-status-msg.success {
  color: #4ade80;
}

.audio-list-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}

.audio-item-card {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audio-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8px;
}

.dialogue-id-tag {
  color: #58a6ff;
}

.voice-badge {
  font-size: 7px;
  padding: 2px 6px;
  border-radius: 4px;
}

.voice-badge.has-voice {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid #22c55e;
}

.voice-badge.no-voice {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid #475569;
}

.audio-dialogue-preview {
  font-size: 8px;
  line-height: 1.45;
  color: #c9d1d9;
  background: #161b22;
  padding: 8px;
  border-radius: 4px;
  border-left: 3px solid #58a6ff;
}

.speaker-tag {
  color: #f59e0b;
  font-weight: bold;
}

.audio-player-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #161b22;
  padding: 8px;
  border-radius: 4px;
}

.real-audio-player {
  width: 100%;
  height: 34px;
  accent-color: #58a6ff;
}

.audio-file-meta {
  font-size: 7px;
  color: #8b949e;
}

.audio-file-meta strong {
  color: #c9d1d9;
}

.audio-file-selector-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #161b22;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #30363d;
}

.audio-file-selector-row .file-label {
  font-size: 7.5px;
  color: #58a6ff;
}

.audio-file-selector-row input[type="file"] {
  font-size: 8px;
  color: #c9d1d9;
}

.audio-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Dialogue Tester in Modal */
.dialogue-tester {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.dialogue-tester label {
  font-size: 8.5px;
  color: #58a6ff;
}

.dialogue-tester input, .dialogue-tester textarea {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 8px;
  color: #f0f6fc;
  font-family: inherit;
  font-size: 8px;
}

.dialogue-tester textarea {
  resize: vertical;
  min-height: 50px;
}

/* Story Master View */
.story-master-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.story-header-box {
  background: #0d1117;
  border: 1px solid #58a6ff;
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story-header-box h3 {
  font-size: 9.5px;
  color: #f59e0b;
}

.story-header-box p {
  font-size: 8px;
  color: #c9d1d9;
}

.story-stages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story-stage-row {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 8px;
}

.story-stage-row.active-stage {
  border-color: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.08);
}

.stage-num {
  color: #58a6ff;
  font-weight: bold;
}

.active-stage .stage-num {
  color: #22c55e;
}

.stage-task {
  color: #e6edf3;
}

.stage-dlg {
  color: #8b949e;
  font-size: 7.5px;
  border-top: 1px dashed #30363d;
  padding-top: 4px;
}

/* Buttons */
.retro-btn {
  background: #238636;
  border: 1px solid #2ea043;
  color: #ffffff;
  font-family: inherit;
  font-size: 7.5px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.retro-btn:hover {
  background: #2ea043;
}

.danger-btn {
  background: #da3633;
  border-color: #f85149;
}

.danger-btn:hover {
  background: #b62324;
}

.modal-footer {
  border-top: 1px solid #30363d;
  padding-top: 12px;
  display: flex;
  justify-content: flex-end;
}
