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

body {
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', Arial, sans-serif;
}

canvas {
  display: block;
}

#loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: #e0e0e0;
}

#loading h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: #fff;
}

#loading-anim {
  border-radius: 12px;
  margin-bottom: 1.5rem;
  box-shadow: 0 0 30px rgba(79, 195, 247, 0.15);
}

#loading p {
  font-size: 1.1rem;
  margin-bottom: 2rem;
  color: #aaa;
}

#loading .progress-bar {
  width: 300px;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}

#loading .progress-fill {
  height: 100%;
  width: 0%;
  background: #4fc3f7;
  border-radius: 3px;
  transition: width 0.3s;
}

#loading .status {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #888;
}

#hud {
  position: fixed;
  bottom: 20px;
  left: 20px;
  color: #fff;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.5);
  padding: 10px 15px;
  border-radius: 8px;
  pointer-events: none;
  line-height: 1.6;
  z-index: 10;
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  display: none;
}

#instructions {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  text-align: center;
  z-index: 50;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.7);
  padding: 40px 60px;
  border-radius: 16px;
}

#instructions h2 {
  font-size: 1.8rem;
  margin-bottom: 1rem;
}

#instructions p {
  font-size: 1rem;
  color: #ccc;
  margin-bottom: 0.5rem;
}

#location-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 0;
  z-index: 60;
  color: #fff;
  width: 420px;
  max-height: 70vh;
  overflow-y: auto;
}

.location-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#location-close {
  cursor: pointer;
  color: #888;
  font-size: 0.9rem;
}

#location-close:hover {
  color: #fff;
}

.location-cat {
  padding: 8px 20px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #44bbff;
  background: rgba(68, 187, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.location-item {
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.15s;
}

.location-item:hover {
  background: rgba(68, 187, 255, 0.15);
}

.location-item .loc-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.location-item .loc-desc {
  font-size: 0.8rem;
  color: #888;
}

.location-item.active {
  background: rgba(68, 187, 255, 0.25);
  border-left: 3px solid #44bbff;
}

#teleport-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 80;
  color: #fff;
}

.teleport-text {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

#daynight-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 20;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
#daynight-btn:hover {
  background: rgba(255,255,255,0.15);
}

#walls-btn {
  position: fixed;
  top: 20px;
  left: 140px;
  z-index: 20;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s;
}
#walls-btn:hover {
  background: rgba(255,255,255,0.15);
}

#interaction-prompt {
  display: none;
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 10px 24px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 1rem;
  text-align: center;
  backdrop-filter: blur(4px);
  pointer-events: none;
  white-space: nowrap;
}

#floor-indicator {
  display: none;
  position: fixed;
  top: 60px;
  left: 20px;
  z-index: 20;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.85rem;
  pointer-events: none;
}

#fade-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 90;
}
#fade-overlay.active {
  opacity: 1;
}

#controls-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 0;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  pointer-events: none;
  z-index: 10;
}

#minimap {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
  z-index: 10;
  pointer-events: none;
}

#minimap canvas {
  width: 100%;
  height: 100%;
}

.city-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 16px;
}

.city-btn {
  padding: 8px 6px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.city-btn:hover {
  background: rgba(68, 187, 255, 0.2);
  border-color: rgba(68, 187, 255, 0.4);
}

.city-btn.active {
  background: rgba(68, 187, 255, 0.3);
  border-color: #44bbff;
  color: #fff;
}

#address-search {
  display: flex;
  padding: 10px 14px;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#address-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
}

#address-input:focus {
  border-color: #44bbff;
  background: rgba(255, 255, 255, 0.12);
}

#address-input::placeholder {
  color: #666;
}

#address-go {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #44bbff;
  color: #000;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

#address-go:hover {
  background: #66ccff;
}

#address-results {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s;
}

#address-results.has-results {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.address-result-item {
  padding: 10px 20px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  color: #ccc;
}

.address-result-item:hover {
  background: rgba(68, 187, 255, 0.15);
  color: #fff;
}

.address-error {
  padding: 10px 20px;
  font-size: 0.85rem;
  color: #ff6666;
}

.location-subcat {
  padding: 6px 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #999;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

/* Discovery toast notification */
#discovery-toast {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 14px 28px;
  background: rgba(10, 30, 20, 0.92);
  border: 1px solid rgba(80, 220, 120, 0.5);
  border-radius: 10px;
  color: #fff;
  font-size: 1rem;
  text-align: center;
  backdrop-filter: blur(8px);
  pointer-events: none;
  transition: top 0.4s ease-out, opacity 0.4s ease;
  opacity: 0;
  white-space: nowrap;
}

#discovery-toast.show {
  top: 30px;
  opacity: 1;
}

#discovery-toast.fade-out {
  top: 30px;
  opacity: 0;
}

#discovery-toast .toast-icon {
  font-size: 1.2rem;
  margin-right: 8px;
}

#discovery-toast .toast-name {
  font-weight: 700;
  color: #50dc78;
}

/* Explorer panel overlay */
#explorer-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(80, 220, 120, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 400px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0;
}

.explorer-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.explorer-header .explorer-progress {
  font-size: 0.85rem;
  color: #50dc78;
  font-weight: 600;
}

#explorer-close {
  cursor: pointer;
  color: #888;
  font-size: 0.9rem;
}

#explorer-close:hover {
  color: #fff;
}

.explorer-cat {
  padding: 8px 20px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #50dc78;
  background: rgba(80, 220, 120, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.explorer-item {
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 10px;
}

.explorer-item .exp-check {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: transparent;
}

.explorer-item.discovered .exp-check {
  border-color: #50dc78;
  background: rgba(80, 220, 120, 0.2);
  color: #50dc78;
}

.explorer-item .exp-info {
  flex: 1;
}

.explorer-item .exp-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.explorer-item.discovered .exp-name {
  color: #fff;
}

.explorer-item:not(.discovered) .exp-name {
  color: #666;
}

.explorer-item .exp-desc {
  font-size: 0.78rem;
  color: #888;
}

.explorer-item:not(.discovered) .exp-desc {
  color: #444;
}

/* Customization panel */
#customize-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(79, 195, 247, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 360px;
  padding: 0;
}

.cust-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#cust-close {
  cursor: pointer;
  color: #888;
  font-size: 0.9rem;
}

#cust-close:hover {
  color: #fff;
}

.cust-section {
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.cust-section:last-child {
  border-bottom: none;
  padding-bottom: 16px;
}

.cust-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4fc3f7;
  margin-bottom: 10px;
}

.cust-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cust-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.cust-swatch:hover {
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

.cust-swatch.selected {
  border-color: #4fc3f7;
  box-shadow: 0 0 8px rgba(79, 195, 247, 0.5);
}

/* ==================== Meeting Panel ==================== */

#meeting-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(0, 200, 255, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 340px;
  padding: 0;
}

.meeting-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#meeting-close {
  cursor: pointer;
  color: #888;
  font-size: 0.9rem;
}
#meeting-close:hover {
  color: #fff;
}

#meeting-status {
  padding: 8px 20px;
  font-size: 0.85rem;
  color: #0cf;
  background: rgba(0, 200, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#meeting-join-section {
  padding: 20px;
  text-align: center;
}

#meeting-create-btn {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(0, 200, 255, 0.4);
  border-radius: 8px;
  background: rgba(0, 200, 255, 0.15);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
#meeting-create-btn:hover {
  background: rgba(0, 200, 255, 0.3);
}

.meeting-divider {
  margin: 14px 0;
  color: #666;
  font-size: 0.8rem;
}

.meeting-join-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#meeting-join-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  font-family: monospace;
}
#meeting-join-input::placeholder {
  text-transform: none;
  letter-spacing: normal;
  font-family: 'Segoe UI', Arial, sans-serif;
  color: #666;
}

#meeting-join-btn {
  padding: 10px 20px;
  border: 1px solid rgba(0, 200, 255, 0.4);
  border-radius: 6px;
  background: rgba(0, 200, 255, 0.15);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}
#meeting-join-btn:hover {
  background: rgba(0, 200, 255, 0.3);
}

#meeting-active-section {
  padding: 16px 20px;
}

.meeting-code-row {
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: #aaa;
}

.meeting-code {
  font-family: monospace;
  font-size: 1.3rem;
  font-weight: bold;
  color: #0cf;
  letter-spacing: 3px;
  user-select: all;
  cursor: pointer;
}

#meeting-participants {
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}

.meeting-participant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #ccc;
}
.meeting-participant.speaking {
  background: rgba(0, 200, 255, 0.1);
  color: #fff;
}

.speaking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  flex-shrink: 0;
  transition: background 0.15s;
}
.meeting-participant.speaking .speaking-dot {
  background: #0f0;
  box-shadow: 0 0 6px rgba(0, 255, 0, 0.5);
}

.meeting-controls {
  display: flex;
  gap: 8px;
}

#meeting-mute-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}
#meeting-mute-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}
#meeting-mute-btn.muted {
  background: rgba(255, 60, 60, 0.2);
  border-color: rgba(255, 60, 60, 0.4);
  color: #f66;
}

.meeting-leave {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255, 60, 60, 0.4);
  border-radius: 6px;
  background: rgba(255, 60, 60, 0.15);
  color: #f66;
  cursor: pointer;
  transition: background 0.2s;
}
.meeting-leave:hover {
  background: rgba(255, 60, 60, 0.3);
}

.party-saved-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.party-saved-code {
  font-family: monospace;
  font-size: 0.95rem;
  color: #0f9;
  letter-spacing: 2px;
  font-weight: 600;
}
.party-saved-info {
  flex: 1;
  font-size: 0.75rem;
  color: #888;
}
.party-saved-rejoin {
  padding: 4px 12px !important;
  font-size: 0.78rem !important;
  width: auto !important;
  border-color: rgba(0, 255, 150, 0.3) !important;
}

/* ==================== Escape Room Panel ==================== */

#escape-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(0, 200, 255, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 420px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  display: none;
  flex-direction: column;
}
.escape-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #0cf;
  flex-shrink: 0;
}
#escape-close { cursor: pointer; color: #888; }
#escape-content { padding: 16px 20px; }

.escape-progress-bar {
  font-size: 0.85rem;
  color: #0cf;
  margin-bottom: 8px;
  font-weight: 600;
}
.escape-timer {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fc0;
  text-align: center;
  margin-bottom: 12px;
  font-family: monospace;
}
.escape-setup {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #ddd;
  margin-bottom: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
}
.escape-clue {
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid rgba(0, 200, 255, 0.2);
  border-radius: 6px;
  background: rgba(0, 200, 255, 0.05);
}
.escape-clue-label {
  font-size: 0.75rem;
  color: #0cf;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.escape-clue-text { font-size: 0.9rem; color: #eee; }
.escape-answer-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.escape-answer-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.95rem;
}
#escape-submit-btn {
  padding: 10px 20px;
  border: 1px solid rgba(0, 200, 255, 0.5);
  border-radius: 6px;
  background: rgba(0, 200, 255, 0.15);
  color: #0cf;
  font-weight: 600;
  cursor: pointer;
}
#escape-submit-btn:hover { background: rgba(0, 200, 255, 0.25); }
.escape-hint-row { margin-bottom: 8px; }
#escape-hint-btn {
  padding: 6px 14px;
  border: 1px solid rgba(255, 200, 0, 0.3);
  border-radius: 6px;
  background: rgba(255, 200, 0, 0.08);
  color: #fc0;
  font-size: 0.82rem;
  cursor: pointer;
}
#escape-hint-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.escape-result { padding: 8px 10px; border-radius: 6px; margin-top: 8px; font-size: 0.9rem; }
.escape-correct { background: rgba(80, 220, 120, 0.1); border: 1px solid rgba(80, 220, 120, 0.3); color: #50dc78; }
.escape-incorrect { background: rgba(255, 60, 60, 0.1); border: 1px solid rgba(255, 60, 60, 0.3); color: #f66; }
.escape-complete { text-align: center; padding: 20px; }
.escape-complete h3 { color: #0cf; margin-bottom: 12px; }
.escape-final-time { font-size: 1.2rem; color: #fc0; font-family: monospace; margin-bottom: 12px; }
.escape-summary { font-size: 0.9rem; color: #ddd; line-height: 1.5; }

/* ==================== Chronicle Panel ==================== */

#chronicle-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 12, 20, 0.95);
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 420px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  display: none;
  flex-direction: column;
}
.chronicle-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #e74c3c;
  flex-shrink: 0;
}
#chronicle-close { cursor: pointer; color: #888; }
#chronicle-content { padding: 16px 20px; }

.chronicle-setup h3 { font-size: 0.95rem; color: #aaa; margin: 12px 0 8px; }
.chronicle-classes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chronicle-class-card {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.chronicle-class-card:hover { border-color: rgba(255, 255, 255, 0.3); }
.chronicle-class-card.selected { border-color: #e74c3c; background: rgba(231, 76, 60, 0.1); }
.chronicle-class-name { font-weight: 600; font-size: 0.95rem; }
.chronicle-class-abilities { font-size: 0.75rem; color: #888; margin-top: 2px; }

.chronicle-dm-choice { display: flex; gap: 8px; margin-bottom: 16px; }
.chronicle-dm-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: #aaa;
  cursor: pointer;
  font-size: 0.85rem;
}
.chronicle-dm-btn.active { border-color: #e74c3c; color: #e74c3c; background: rgba(231, 76, 60, 0.1); }
.chronicle-start-btn {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(231, 76, 60, 0.5);
  border-radius: 8px;
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.chronicle-start-btn:hover { background: rgba(231, 76, 60, 0.25); }

.chronicle-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.chronicle-my-class { font-weight: 600; font-size: 1rem; }
.chronicle-session-id { font-size: 0.75rem; color: #555; font-family: monospace; }

.chronicle-abilities { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chronicle-ability-btn {
  padding: 6px 14px;
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: 6px;
  background: rgba(231, 76, 60, 0.1);
  color: #e74c3c;
  font-size: 0.82rem;
  cursor: pointer;
}
.chronicle-ability-btn:hover { background: rgba(231, 76, 60, 0.2); }

.chronicle-action-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.chronicle-action-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.9rem;
}
.chronicle-action-row button, #chronicle-action-send {
  padding: 8px 16px;
  border: 1px solid rgba(231, 76, 60, 0.4);
  border-radius: 6px;
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  font-weight: 600;
  cursor: pointer;
}

.chronicle-dm-panel { margin-top: 12px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 12px; }
.chronicle-dm-label { font-size: 0.8rem; color: #888; margin-bottom: 8px; text-transform: uppercase; }
.chronicle-dm-panel textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.9rem;
  resize: vertical;
  font-family: inherit;
}
.chronicle-dm-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chronicle-dm-controls button {
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: #aaa;
  font-size: 0.8rem;
  cursor: pointer;
}
.chronicle-dm-controls button:hover { background: rgba(255, 255, 255, 0.1); }
#chronicle-dm-send { border-color: rgba(231, 76, 60, 0.4); color: #e74c3c; }
#chronicle-dm-assist-btn { border-color: rgba(180, 100, 255, 0.4); color: #b464ff; }

.chronicle-dice-btn {
  padding: 6px 12px;
  border: 1px solid rgba(241, 196, 15, 0.3) !important;
  color: #f1c40f !important;
  font-weight: 600;
}
.chronicle-player-roll { margin: 8px 0; }

.chronicle-end-btn {
  width: 100%;
  margin-top: 16px;
  padding: 8px;
  border: 1px solid rgba(255, 60, 60, 0.3);
  border-radius: 6px;
  background: rgba(255, 60, 60, 0.05);
  color: #f66;
  font-size: 0.85rem;
  cursor: pointer;
}
.chronicle-end-btn:hover { background: rgba(255, 60, 60, 0.15); }
.chronicle-inactive { color: #555; font-style: italic; text-align: center; padding: 20px; }

/* ==================== Narrative Panel ==================== */

#narrative-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 45vh;
  max-height: 400px;
  background: rgba(10, 10, 20, 0.95);
  border-top: 1px solid rgba(180, 100, 255, 0.3);
  z-index: 60;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.narrative-header {
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.narrative-controls { display: flex; gap: 8px; align-items: center; }
.narrative-ctrl-btn {
  padding: 4px 10px;
  border: 1px solid rgba(180, 100, 255, 0.3);
  border-radius: 4px;
  background: rgba(180, 100, 255, 0.1);
  color: #b464ff;
  font-size: 0.75rem;
  cursor: pointer;
}
.narrative-ctrl-btn:hover { background: rgba(180, 100, 255, 0.2); }
#narrative-close { cursor: pointer; color: #888; margin-left: 8px; }
#narrative-close:hover { color: #fff; }

#narrative-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  font-size: 0.88rem;
  line-height: 1.6;
}
.narrative-entry { margin-bottom: 10px; }
.narrative-narration { color: #ddd; }
.narrative-action { color: #4fc3f7; }
.narrative-speaker { font-weight: 600; color: #8cf; }
.narrative-location { color: #fc0; font-style: italic; }
.narrative-location-icon { margin-right: 4px; }
.narrative-error { color: #f66; font-style: italic; }
.narrative-system { color: #888; font-style: italic; font-size: 0.8rem; }

#narrative-thinking {
  padding: 8px 16px;
  color: #b464ff;
  font-style: italic;
  font-size: 0.85rem;
  animation: thinking-pulse 1.5s ease-in-out infinite;
}
@keyframes thinking-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

#narrative-choices {
  padding: 4px 16px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.narrative-choice-btn {
  padding: 6px 14px;
  border: 1px solid rgba(180, 100, 255, 0.4);
  border-radius: 6px;
  background: rgba(180, 100, 255, 0.1);
  color: #d4a0ff;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
}
.narrative-choice-btn:hover { background: rgba(180, 100, 255, 0.25); }

.narrative-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}
#narrative-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.9rem;
}
#narrative-input::placeholder { color: #555; }
#narrative-input:focus { border-color: rgba(180, 100, 255, 0.5); outline: none; }
#narrative-input:disabled { opacity: 0.4; }
#narrative-send-btn {
  padding: 8px 16px;
  border: 1px solid rgba(180, 100, 255, 0.4);
  border-radius: 6px;
  background: rgba(180, 100, 255, 0.15);
  color: #b464ff;
  font-weight: 600;
  cursor: pointer;
}
#narrative-send-btn:hover { background: rgba(180, 100, 255, 0.3); }

/* ==================== Party Panel ==================== */

#party-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(0, 255, 150, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 360px;
  max-width: 90vw;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0;
}
.party-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#party-close { cursor: pointer; color: #888; }
#party-close:hover { color: #fff; }
#party-status {
  padding: 8px 20px;
  font-size: 0.85rem;
  color: #0f9;
  background: rgba(0, 255, 150, 0.05);
}
#party-join-section { padding: 20px; }
#party-join-section button {
  width: 100%;
  padding: 10px;
  border: 1px solid rgba(0, 255, 150, 0.4);
  border-radius: 8px;
  background: rgba(0, 255, 150, 0.1);
  color: #0f9;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
#party-join-section button:hover { background: rgba(0, 255, 150, 0.2); }
.party-divider {
  text-align: center;
  color: #555;
  font-size: 0.8rem;
  margin: 14px 0;
}
.party-join-row {
  display: flex;
  gap: 8px;
}
.party-join-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
}
.party-join-row input::placeholder { color: #555; letter-spacing: 0; text-transform: none; }
.party-join-row button {
  width: auto !important;
  padding: 8px 14px !important;
  font-size: 0.85rem !important;
}
#party-active-section { padding: 16px 20px; }
.party-code-row {
  font-size: 0.9rem;
  color: #aaa;
  margin-bottom: 12px;
}
.party-code {
  font-family: monospace;
  font-size: 1.3rem;
  color: #0f9;
  letter-spacing: 3px;
  font-weight: bold;
}
.party-member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.party-member-name { font-size: 0.9rem; font-weight: 500; }
.party-member-tags { font-size: 0.75rem; color: #888; }
.party-tether-btn {
  margin-left: auto;
  font-size: 0.75rem;
  color: #4fc3f7;
  cursor: pointer;
  padding: 2px 8px;
  border: 1px solid rgba(79, 195, 247, 0.3);
  border-radius: 4px;
}
.party-tether-btn:hover { background: rgba(79, 195, 247, 0.15); }
.party-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.party-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: #aaa;
}
#party-leave-btn {
  border-color: rgba(255, 60, 60, 0.3);
  color: #f66;
}
#party-leave-btn:hover { background: rgba(255, 60, 60, 0.15); }
.party-mode-buttons {
  display: flex;
  gap: 8px;
}
.party-theme-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.party-theme-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.party-theme-input::placeholder { color: #555; }
.party-mode-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid rgba(180, 100, 255, 0.3);
  border-radius: 6px;
  background: rgba(180, 100, 255, 0.1);
  color: #b464ff;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}
.party-mode-btn:hover { background: rgba(180, 100, 255, 0.2); }

/* ==================== Touch Controls ==================== */

#touch-joystick {
  display: none;
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.25);
  z-index: 50;
  touch-action: none;
}
#touch-joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transition: transform 0.05s;
}
#touch-action {
  display: none;
  position: fixed;
  bottom: 170px;
  right: 55px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(79, 195, 247, 0.2);
  border: 2px solid rgba(79, 195, 247, 0.5);
  color: #4fc3f7;
  font-size: 13px;
  font-weight: bold;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}
#touch-action.active {
  background: rgba(79, 195, 247, 0.5);
}

#gps-toggle {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 8px 18px;
  border-radius: 20px;
  background: rgba(10, 15, 25, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #aaa;
  font-size: 13px;
  font-weight: bold;
  z-index: 50;
  cursor: pointer;
  user-select: none;
}
#gps-toggle.active {
  border-color: rgba(80, 220, 120, 0.6);
  color: #50dc78;
}

#gps-status {
  display: none;
  position: fixed;
  top: 52px;
  right: 16px;
  padding: 4px 12px;
  border-radius: 12px;
  background: rgba(10, 15, 25, 0.8);
  font-size: 11px;
  z-index: 50;
}
#gps-status.gps-good { color: #50dc78; }
#gps-status.gps-weak { color: #fc6; }
#gps-status.gps-searching { color: #aaa; }

#compass-toggle {
  display: none;
  position: fixed;
  top: 80px;
  right: 16px;
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(10, 15, 25, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #aaa;
  font-size: 18px;
  z-index: 50;
  cursor: pointer;
  user-select: none;
}
#compass-toggle.active {
  border-color: rgba(80, 180, 255, 0.6);
  color: #4fc3f7;
}
#quest-toggle {
  display: none;
  position: fixed;
  top: 120px;
  right: 16px;
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(10, 15, 25, 0.85);
  border: 1px solid rgba(255, 204, 0, 0.3);
  color: #fc0;
  font-size: 13px;
  font-weight: bold;
  z-index: 50;
  cursor: pointer;
  user-select: none;
}

/* Show mobile-only controls on mobile */
/* DEBUG: show GPS/compass on all devices (remove after debugging) */
#gps-toggle, #compass-toggle { display: flex !important; }

@media (max-width: 1024px) and (pointer: coarse) {
  #touch-joystick, #touch-action, #gps-toggle, #compass-toggle, #quest-toggle { display: flex; }
  #gps-status { display: block; }
}

/* ==================== Quest Panel ==================== */

#quest-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 25, 0.95);
  border: 1px solid rgba(255, 204, 0, 0.3);
  border-radius: 12px;
  z-index: 60;
  color: #fff;
  width: 400px;
  max-width: 90vw;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0;
}
.quest-header {
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.quest-header #quest-close {
  cursor: pointer;
  color: #888;
}
.quest-item {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.quest-item.active {
  background: rgba(255, 204, 0, 0.05);
  border-left: 3px solid #fc0;
}
.quest-item.completed {
  opacity: 0.5;
}
.quest-item-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}
.quest-item.active .quest-item-name { color: #fc0; }
.quest-item.completed .quest-item-name { color: #6a6; }
.quest-item-desc {
  font-size: 0.82rem;
  color: #999;
  margin-bottom: 6px;
}
.quest-item-step {
  font-size: 0.8rem;
  color: #7bf;
  margin-bottom: 6px;
}
.quest-item-btn {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 4px;
}
.quest-item-btn.start {
  background: rgba(255, 204, 0, 0.15);
  border: 1px solid rgba(255, 204, 0, 0.4);
  color: #fc0;
}
.quest-item-btn.abandon {
  background: rgba(255, 60, 60, 0.1);
  border: 1px solid rgba(255, 60, 60, 0.3);
  color: #f66;
}
.quest-item-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.quest-badge {
  font-size: 0.7rem;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.quest-badge-easy { color: #6f6; border: 1px solid rgba(100, 255, 100, 0.2); }
.quest-badge-medium { color: #fc6; border: 1px solid rgba(255, 200, 0, 0.2); }
.quest-badge-hard { color: #f66; border: 1px solid rgba(255, 100, 100, 0.2); }
.quest-item-inventory {
  font-size: 0.78rem;
  color: #b464ff;
  margin: 4px 0;
}
.quest-item-reward {
  font-size: 0.78rem;
  color: #fc0;
  margin-top: 2px;
}
.quest-empty {
  padding: 30px 20px;
  text-align: center;
  color: #666;
  font-style: italic;
}

/* ==================== Quest HUD ==================== */

#quest-hud {
  position: fixed;
  top: 54px;
  left: 12px;
  padding: 6px 14px;
  background: rgba(10, 15, 25, 0.75);
  border: 1px solid rgba(255, 204, 0, 0.25);
  border-radius: 8px;
  font-size: 0.78rem;
  color: #fc0;
  z-index: 15;
  max-width: 50vw;
  pointer-events: none;
}

/* ==================== Quest Toast ==================== */

#quest-toast {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 14px 28px;
  background: rgba(10, 25, 15, 0.92);
  border: 1px solid rgba(255, 204, 0, 0.5);
  border-radius: 10px;
  color: #fc0;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  transition: top 0.4s ease-out, opacity 0.4s ease;
  opacity: 0;
  pointer-events: none;
}
#quest-toast.show {
  top: 30px;
  opacity: 1;
}
#quest-toast.fade-out {
  top: 30px;
  opacity: 0;
}

/* ==================== Exchange Prompt ==================== */

#exchange-prompt {
  display: none;
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  background: rgba(10, 20, 30, 0.92);
  border: 1px solid rgba(80, 220, 120, 0.5);
  border-radius: 12px;
  padding: 14px 20px;
  text-align: center;
  max-width: 90vw;
}
.exchange-text {
  color: #ccc;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.exchange-btn {
  display: inline-block;
  padding: 8px 24px;
  border-radius: 8px;
  background: rgba(80, 220, 120, 0.2);
  border: 1px solid rgba(80, 220, 120, 0.5);
  color: #50dc78;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
}
.exchange-btn:active {
  background: rgba(80, 220, 120, 0.4);
}
