/* Myst-Inspired Victorian Brass, Parchment & Deep-Space Aesthetic */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #06080f;
  color: #efe2c4;
  font-family: Georgia, 'Palatino Linotype', 'Book Antiqua', serif;
  user-select: none;
}

#game-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Subtle brass reticle */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 224, 150, 0.85);
  background: rgba(255, 224, 150, 0.25);
  box-shadow: 0 0 8px rgba(255, 198, 95, 0.65);
  pointer-events: none;
  z-index: 20;
}

.hud-panel {
  position: fixed;
  background: linear-gradient(160deg, rgba(24, 19, 14, 0.86), rgba(14, 11, 9, 0.92));
  border: 1px solid rgba(205, 162, 84, 0.55);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.65), inset 0 0 18px rgba(205, 162, 84, 0.08);
  border-radius: 6px;
  backdrop-filter: blur(6px);
  z-index: 30;
}

/* Top-Left Location Plaque */
#location-plaque {
  top: 16px;
  left: 16px;
  padding: 10px 16px;
  min-width: 280px;
}

.plaque-top {
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 0.4px;
  color: #f6dfb0;
}

.plaque-top .sep {
  color: #c89844;
  margin: 0 7px;
  font-size: 12px;
}

.plaque-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: #c8b693;
  font-family: 'Trebuchet MS', sans-serif;
}

.plaque-sub .sep {
  margin: 0 6px;
  opacity: 0.55;
}

.plaque-wing {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: #a88a55;
  font-family: 'Trebuchet MS', sans-serif;
}

.plaque-shadows {
  margin-top: 4px;
  font-size: 11px;
  color: #9ec8e8;
  font-family: 'Trebuchet MS', sans-serif;
  letter-spacing: 0.3px;
}

/* Top-Right Minimap */
#minimap-wrap {
  top: 16px;
  right: 16px;
  padding: 7px 8px 5px;
  cursor: pointer;
}

#minimap-canvas {
  display: block;
  border: 1px solid rgba(185, 145, 72, 0.35);
  border-radius: 3px;
  background: #0b0e17;
}

.minimap-caption {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.8px;
  color: #c5aa76;
  font-family: 'Trebuchet MS', sans-serif;
  margin-top: 4px;
}

/* Interaction Prompt */
#interact-prompt {
  position: fixed;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  padding: 9px 18px;
  background: rgba(18, 14, 10, 0.9);
  border: 1px solid rgba(235, 190, 98, 0.78);
  border-radius: 24px;
  box-shadow: 0 0 22px rgba(255, 195, 85, 0.28);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #fce9be;
  z-index: 35;
}

.key-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: linear-gradient(180deg, #dfba6b, #a0742c);
  color: #1a1208;
  font-weight: bold;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 13px;
}

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  padding: 9px 20px;
  background: rgba(20, 16, 11, 0.92);
  border: 1px solid #d4a44c;
  border-radius: 6px;
  color: #ffe9b3;
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.65);
  z-index: 60;
}

/* Bottom Controls Bar */
#controls-bar {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #cab997;
  white-space: nowrap;
}

#controls-bar b {
  color: #f3d28c;
}

.brass-btn {
  background: linear-gradient(180deg, rgba(160, 120, 52, 0.35), rgba(88, 62, 24, 0.45));
  border: 1px solid rgba(215, 170, 86, 0.6);
  color: #f6e1b2;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12px;
  transition: all 0.15s ease;
}

.brass-btn:hover {
  background: linear-gradient(180deg, rgba(208, 160, 74, 0.55), rgba(130, 92, 34, 0.65));
  border-color: #f3ce7b;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 13, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  z-index: 80;
}

.modal-card {
  background: linear-gradient(165deg, #1b1510, #100d0b);
  border: 1.5px solid #c99d4a;
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.85), inset 0 0 36px rgba(201, 157, 74, 0.1);
}

.map-card {
  width: min(1040px, 95vw);
}

.lift-card {
  width: min(470px, 92vw);
}

.reader-card {
  width: min(620px, 92vw);
}

.journal-card {
  width: min(820px, 94vw);
}

.journal-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 22px;
  align-items: start;
  margin-top: 10px;
}

@media (max-width: 720px) {
  .journal-body {
    grid-template-columns: 1fr;
  }
}

.journal-art-frame {
  border: 2px solid #c99d4a;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.7), 0 0 22px rgba(255, 200, 95, 0.16);
}

.journal-art-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.journal-text {
  font-size: 16px;
  line-height: 1.74;
  color: #efe2c4;
}

.reader-dept {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #b79455;
  font-family: 'Trebuchet MS', sans-serif;
  margin-bottom: 4px;
}

.reader-excerpt {
  margin-top: 12px;
  padding: 16px 20px;
  border-left: 3px solid #c99d4a;
  background: rgba(255, 238, 200, 0.04);
  font-size: 16.5px;
  line-height: 1.72;
  color: #f3e4c2;
  font-style: italic;
}

/* Dropped Historical Correspondence Letter Modal */
.letter-card {
  max-width: 660px;
}

.letter-kicker {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #cf9c4c;
  font-family: 'Trebuchet MS', sans-serif;
  margin-bottom: 4px;
}

.letter-sheet {
  margin-top: 10px;
  padding: 22px 26px;
  border-radius: 5px;
  background: linear-gradient(180deg, #f3e7cb 0%, #ead8b3 100%);
  border: 1px solid #b59257;
  box-shadow: inset 0 0 28px rgba(128, 88, 34, 0.18), 0 8px 26px rgba(0, 0, 0, 0.55);
  color: #241b12;
  font-family: Georgia, 'Times New Roman', serif;
  max-height: 66vh;
  overflow-y: auto;
}

.letter-salutation {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 12px;
  color: #1f160e;
}

.letter-body p {
  margin: 0 0 13px;
  font-size: 15.5px;
  line-height: 1.68;
  color: #261c12;
}

.letter-signoff {
  margin-top: 16px;
  white-space: pre-line;
  font-size: 15.5px;
  font-style: italic;
  color: #1c2b48;
}

.letter-postscript {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed rgba(96, 68, 34, 0.42);
  font-size: 13.5px;
  line-height: 1.55;
  color: #5c261c;
}

.letter-source-bar {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 5px;
  background: rgba(18, 15, 11, 0.78);
  border: 1px solid rgba(207, 156, 76, 0.42);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.letter-source-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 300px;
  min-width: 0;
}

.letter-source-badge {
  display: inline-block;
  align-self: flex-start;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(72, 184, 126, 0.18);
  border: 1px solid rgba(94, 218, 150, 0.55);
  color: #9bf0be;
}

.letter-source-badge.vignette {
  background: rgba(212, 166, 74, 0.16);
  border-color: rgba(212, 166, 74, 0.55);
  color: #f3d48c;
}

.letter-source-badge.lore {
  background: rgba(124, 182, 224, 0.15);
  border-color: rgba(124, 182, 224, 0.45);
  color: #b4def8;
}

.letter-source-note {
  font-size: 12.5px;
  line-height: 1.45;
  color: #dfd0b0;
  font-family: 'Trebuchet MS', sans-serif;
}

.letter-source-link {
  text-decoration: none;
  font-size: 12.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 20px;
  color: #f7dfaa;
  letter-spacing: 0.6px;
}

.modal-header p {
  font-size: 12.5px;
  color: #b7a27e;
  margin-top: 3px;
  font-family: 'Trebuchet MS', sans-serif;
}

.floor-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.floor-tab {
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid rgba(196, 152, 74, 0.45);
  background: rgba(38, 29, 19, 0.75);
  color: #d6c096;
  cursor: pointer;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12px;
}

.floor-tab.active {
  background: linear-gradient(180deg, #d8ad5a, #9e7228);
  color: #191208;
  font-weight: bold;
  border-color: #ffe29e;
}

.fullmap-stage {
  border: 1px solid rgba(200, 156, 76, 0.4);
  border-radius: 5px;
  overflow: hidden;
  background: #090c14;
}

#fullmap-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #cbb894;
}

.hover-info {
  margin-left: auto;
  color: #ffdf96;
  font-weight: bold;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}
.dot-you { background: #ff5d5d; box-shadow: 0 0 6px #ff5d5d; }
.dot-shadow { background: #a8c4ff; box-shadow: 0 0 6px #7898ff; }
.dot-ext { background: #64d8ff; }
.dot-stair { background: #f2a654; }
.dot-lift { background: #5dff9e; }
.dot-orb { background: #ffe066; box-shadow: 0 0 8px #ffe066; }

/* Lift Floor Pushbuttons */
.lift-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.lift-floor-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px solid rgba(208, 164, 80, 0.55);
  background: linear-gradient(180deg, rgba(64, 48, 28, 0.8), rgba(30, 22, 14, 0.9));
  color: #f6e1b2;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s ease;
}

.lift-floor-btn:hover {
  border-color: #ffe094;
  background: linear-gradient(180deg, rgba(135, 98, 42, 0.85), rgba(74, 52, 22, 0.92));
  transform: translateY(-1px);
}

.lift-floor-btn.current {
  border-color: #66ecff;
  box-shadow: 0 0 12px rgba(102, 236, 255, 0.25);
}

.lift-floor-btn .lf-code {
  font-size: 15px;
  font-weight: bold;
  color: #ffdfa0;
}

.lift-floor-btn .lf-desc {
  font-size: 11.5px;
  color: #c2ae89;
  font-family: 'Trebuchet MS', sans-serif;
  margin-top: 2px;
}

/* Title Overlay */
#title-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 42%, rgba(28, 20, 12, 0.58), rgba(4, 6, 12, 0.88));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.title-card {
  max-width: 640px;
  width: 92vw;
  text-align: center;
  padding: 34px 38px 30px;
  background: linear-gradient(170deg, rgba(24, 18, 13, 0.93), rgba(12, 10, 8, 0.96));
  border: 1.5px solid rgba(214, 168, 82, 0.72);
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.85), inset 0 0 42px rgba(214, 168, 82, 0.12);
}

.crest {
  font-size: 11.5px;
  letter-spacing: 3px;
  color: #c99d4b;
  font-family: 'Trebuchet MS', sans-serif;
  margin-bottom: 10px;
}

.title-card h1 {
  font-size: 38px;
  letter-spacing: 3.5px;
  color: #fbe6b6;
  text-shadow: 0 2px 18px rgba(255, 192, 82, 0.32);
}

.subtitle {
  margin-top: 6px;
  font-size: 15px;
  font-style: italic;
  color: #d6bc8b;
}

.lore {
  margin: 16px auto 12px;
  font-size: 14.5px;
  line-height: 1.64;
  color: #d7c7a8;
}

.lore-mid {
  margin: 0 auto 12px;
  color: #e6d7b5;
}

.lore-closing {
  margin: 0 auto 20px;
  font-style: normal;
  color: #efe1c0;
}

.lore b {
  color: #ffe29b;
}

.loading-status {
  font-size: 12.5px;
  color: #8fdcff;
  font-family: 'Trebuchet MS', sans-serif;
  margin-bottom: 12px;
}

.ghost-status {
  font-size: 13.5px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #b7d3ee;
  margin-bottom: 14px;
  letter-spacing: 0.3px;
}

.ghost-status.full {
  color: #ffbe78;
  font-weight: bold;
  padding: 8px 14px;
  border: 1px solid rgba(255, 178, 92, 0.55);
  border-radius: 6px;
  background: rgba(90, 44, 14, 0.35);
}

.idle-notice {
  font-size: 12.5px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #e8c78a;
  margin-bottom: 12px;
}

.enter-btn {
  padding: 13px 34px;
  font-size: 16px;
  font-family: Georgia, serif;
  letter-spacing: 1px;
  border-radius: 6px;
  border: 1.5px solid #f7d382;
  background: linear-gradient(180deg, #d7a84f, #986b22);
  color: #171006;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(255, 198, 92, 0.35);
  transition: all 0.18s ease;
}

.enter-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #ecc26c, #b4802a);
  transform: translateY(-1px);
  box-shadow: 0 0 32px rgba(255, 212, 118, 0.55);
}

.enter-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.title-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  font-size: 12px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #b49f78;
}

.title-controls b {
  color: #f1ce82;
}

.fade-curtain {
  position: fixed;
  inset: 0;
  background: #05070e;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease;
  z-index: 95;
}

.fade-curtain.active {
  opacity: 1;
}


/* =========================================================================
   TOUCH / MOBILE
   ========================================================================= */
.touch-only { display: none !important; }
body.touch .touch-only { display: flex !important; }
body.touch .kb-only { display: none !important; }

body.touch {
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* Floating analog joystick */
#joy-base {
  position: fixed;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 2px solid rgba(232, 188, 98, 0.55);
  background: radial-gradient(circle, rgba(40, 30, 18, 0.35), rgba(12, 9, 6, 0.55));
  box-shadow: 0 0 18px rgba(255, 196, 92, 0.18), inset 0 0 16px rgba(232, 188, 98, 0.15);
  pointer-events: none;
  z-index: 25;
}
#joy-base.sprint { border-color: rgba(120, 230, 255, 0.85); }
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, #f3d184, #a87a2e);
  border: 1px solid #ffe3a0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

/* Compact HUD with notch-safe insets */
body.touch #location-plaque {
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  min-width: 0;
  max-width: 46vw;
  padding: 6px 10px;
}
body.touch .plaque-top { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.touch .plaque-sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.touch .plaque-wing,
body.touch .plaque-shadows { font-size: 10px; }

body.touch #minimap-wrap {
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  padding: 4px 5px 3px;
}
body.touch #minimap-canvas { width: 150px; height: 75px; }
body.touch .minimap-caption span:last-child { display: none; }

body.touch #controls-bar {
  bottom: max(8px, env(safe-area-inset-bottom));
  padding: 5px 8px;
  gap: 6px;
}
body.touch .brass-btn {
  padding: 9px 12px;
  font-size: 13px;
  min-height: 38px;
}

/* Interaction prompt becomes a big, tappable button */
body.touch #interact-prompt {
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 60px);
  padding: 12px 22px;
  font-size: 15px;
  cursor: pointer;
  pointer-events: auto;
  animation: prompt-pulse 1.6s ease-in-out infinite;
}
body.touch #interact-key { font-size: 0; }
body.touch #interact-key::before { content: '\261B'; font-size: 14px; }
@keyframes prompt-pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(255, 195, 85, 0.25); }
  50% { box-shadow: 0 0 30px rgba(255, 210, 110, 0.6); }
}

body.touch #toast {
  top: auto;
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 118px);
  max-width: 90vw;
  font-size: 13px;
  text-align: center;
}

body.touch #crosshair { opacity: 0.6; }

/* Modals & title card fit small screens and scroll */
.modal-card,
.title-card {
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
#title-overlay { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

@media (max-width: 760px), (max-height: 520px) {
  .title-card { padding: 18px 18px 16px; }
  .title-card h1 { font-size: 26px; letter-spacing: 2px; }
  .subtitle { font-size: 13px; }
  .lore { font-size: 13px; line-height: 1.5; margin: 10px auto 8px; }
  .lore-mid { margin-bottom: 8px; }
  .lore-closing { margin-bottom: 12px; }
  .title-controls { gap: 8px; margin-top: 12px; font-size: 11px; }
  .modal-card { padding: 14px 14px; }
  .modal-header h2 { font-size: 17px; }
  .lift-buttons { grid-template-columns: 1fr 1fr; gap: 8px; }
  .lift-floor-btn { padding: 10px 10px; }
  .journal-text, .reader-excerpt { font-size: 14.5px; line-height: 1.6; }
  .map-legend { gap: 10px; font-size: 11px; }
  .hover-info { margin-left: 0; width: 100%; }
}

/* Phone in portrait: suggest rotating, but keep everything usable */
@media (orientation: portrait) and (max-width: 600px) {
  body.touch #location-plaque { max-width: 58vw; }
  body.touch .plaque-wing { display: none; }
  body.touch #minimap-canvas { width: 120px; height: 60px; }
  body.touch #controls-bar { flex-wrap: wrap; justify-content: center; max-width: 96vw; }
}

/* =========================================================================
   PROXIMITY SHADOW MESSAGING
   ========================================================================= */
#shadow-chat-pill {
  position: fixed;
  right: 18px;
  bottom: 72px;
  padding: 8px 16px;
  background: rgba(12, 18, 30, 0.92);
  border: 1px solid rgba(132, 206, 255, 0.72);
  border-radius: 22px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.65), 0 0 18px rgba(120, 195, 255, 0.24);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-family: 'Trebuchet MS', sans-serif;
  color: #dff2ff;
  cursor: pointer;
  z-index: 40;
  max-width: min(400px, 90vw);
  transition: transform 0.14s ease, border-color 0.14s ease;
}

#shadow-chat-pill:hover {
  transform: translateY(-1px);
  border-color: #b8e6ff;
}

#shadow-chat-pill.unread {
  border-color: #ffe08a;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.7), 0 0 24px rgba(255, 214, 110, 0.45);
  animation: chat-pill-pulse 1.5s ease-in-out infinite;
}

@keyframes chat-pill-pulse {
  0%, 100% { box-shadow: 0 0 16px rgba(132, 206, 255, 0.3); }
  50% { box-shadow: 0 0 28px rgba(255, 218, 120, 0.65); }
}

.chat-badge {
  background: linear-gradient(180deg, #8ad2ff, #3e7eb8);
  color: #081320;
}

body.touch #shadow-chat-key { font-size: 0; }
body.touch #shadow-chat-key::before { content: '\2709'; font-size: 13px; }

#shadow-chat-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-panel {
  right: 16px;
  bottom: 62px;
  width: min(350px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  border-color: rgba(140, 204, 250, 0.65);
  background: linear-gradient(165deg, rgba(16, 20, 32, 0.94), rgba(10, 12, 20, 0.96));
  z-index: 55;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(140, 204, 250, 0.25);
  background: rgba(20, 28, 46, 0.55);
}

.chat-peer-title {
  font-size: 14.5px;
  font-weight: bold;
  color: #e6f4ff;
  letter-spacing: 0.3px;
}

.chat-peer-status {
  font-size: 11px;
  color: #9bbcd9;
  font-family: 'Trebuchet MS', sans-serif;
  margin-top: 1px;
}

.chat-peer-status.out-of-range {
  color: #e8b074;
}

.chat-close-btn {
  padding: 2px 9px;
  font-size: 16px;
  line-height: 1.2;
}

.chat-peers {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(140, 204, 250, 0.18);
  background: rgba(10, 14, 24, 0.5);
}

.chat-peer-chip {
  padding: 3px 9px;
  border-radius: 12px;
  border: 1px solid rgba(140, 204, 250, 0.4);
  background: rgba(24, 34, 54, 0.7);
  color: #c8e2f8;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.chat-peer-chip.active {
  background: linear-gradient(180deg, #84ccff, #427fb5);
  color: #08121e;
  font-weight: bold;
  border-color: #bfe6ff;
}

.chat-peer-chip.unread {
  border-color: #ffe08a;
  color: #ffe9ad;
}

.chat-messages {
  height: 190px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 13px;
  touch-action: pan-y;
}

.chat-hint {
  font-size: 11.5px;
  color: #8ba4be;
  font-style: italic;
  text-align: center;
  margin: 4px 0;
}

.chat-msg {
  max-width: 86%;
  padding: 6px 10px;
  border-radius: 8px;
  line-height: 1.42;
  word-wrap: break-word;
}

.chat-msg.them {
  align-self: flex-start;
  background: rgba(42, 62, 96, 0.65);
  border: 1px solid rgba(138, 198, 248, 0.38);
  color: #eaf5ff;
}

.chat-msg.me {
  align-self: flex-end;
  background: rgba(96, 72, 34, 0.62);
  border: 1px solid rgba(224, 180, 96, 0.48);
  color: #fff0cc;
}

.chat-msg-sender {
  font-size: 10px;
  opacity: 0.72;
  margin-bottom: 2px;
  letter-spacing: 0.3px;
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(140, 204, 250, 0.22);
  background: rgba(12, 16, 26, 0.85);
}

#chat-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid rgba(140, 204, 250, 0.42);
  background: rgba(6, 9, 16, 0.9);
  color: #f2f7fc;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 13.5px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

#chat-input:focus {
  border-color: #9ad8ff;
  box-shadow: 0 0 8px rgba(130, 205, 255, 0.3);
}

#chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

body.touch #shadow-chat-pill {
  right: max(10px, env(safe-area-inset-right));
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 56px);
  padding: 10px 16px;
}

body.touch #chat-panel {
  right: max(8px, env(safe-area-inset-right));
  top: max(8px, env(safe-area-inset-top));
  bottom: auto;
  width: min(340px, calc(100vw - 16px));
}

body.touch .chat-messages {
  height: 135px;
}

body.touch #chat-input {
  font-size: 16px; /* Prevents iOS Safari auto-zoom on input focus */
}

/* =========================================================================
   CLOSE-UP 3D OBJECT INSPECTION HUD
   ========================================================================= */
.inspect-hud {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 24px));
  padding: 12px 18px;
  border-radius: 10px;
  background: linear-gradient(165deg, rgba(16, 13, 10, 0.90), rgba(10, 9, 13, 0.94));
  border: 1px solid rgba(214, 170, 92, 0.65);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.72), 0 0 24px rgba(214, 170, 92, 0.16);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  z-index: 48;
  pointer-events: auto;
}

.inspect-info {
  flex: 1;
  min-width: 0;
}

.inspect-title {
  font-size: 17px;
  font-weight: bold;
  color: #f6e7c6;
  letter-spacing: 0.4px;
  margin-top: 2px;
}

.inspect-desc {
  font-size: 13.5px;
  line-height: 1.45;
  color: #dfd2b8;
  margin-top: 4px;
  font-family: 'Trebuchet MS', sans-serif;
}

.inspect-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  flex-shrink: 0;
}

.inspect-btns {
  display: flex;
  gap: 8px;
}

.inspect-hints {
  font-size: 11.5px;
  color: #b7a482;
  font-family: 'Trebuchet MS', sans-serif;
  white-space: nowrap;
}

.inspect-hints b {
  color: #ecc983;
}

@media (max-width: 720px) {
  .inspect-hud {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 13px;
  }
  .inspect-actions {
    align-items: stretch;
  }
  .inspect-btns {
    justify-content: flex-end;
  }
  .inspect-hints {
    text-align: right;
    white-space: normal;
  }
}

/* =========================================================================
   STEAM-STYLE ACHIEVEMENT UNLOCK TOASTS & 32-BADGE SHOWCASE MODAL
   ========================================================================= */
.achievement-toast-stack {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(58px, calc(env(safe-area-inset-bottom) + 52px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 95;
  pointer-events: none;
}

.ach-toast {
  width: min(368px, calc(100vw - 28px));
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 14px;
  border-radius: 9px;
  background: linear-gradient(155deg, rgba(22, 19, 14, 0.96), rgba(12, 16, 24, 0.97));
  border: 1.5px solid rgba(236, 194, 104, 0.85);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.78), 0 0 24px rgba(236, 194, 104, 0.28);
  transform: translateY(26px) scale(0.96);
  opacity: 0;
  transition: transform 0.36s cubic-bezier(0.18, 0.88, 0.32, 1.15), opacity 0.32s ease;
  pointer-events: auto;
  cursor: pointer;
}

.ach-toast.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.ach-toast.leaving {
  transform: translateX(28px) scale(0.97);
  opacity: 0;
  transition: transform 0.36s ease, opacity 0.32s ease;
}

.ach-toast-medal {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(242, 200, 108, 0.42));
}

.ach-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.ach-toast-body {
  min-width: 0;
  flex: 1;
}

.ach-toast-kicker {
  font-size: 10px;
  letter-spacing: 1.3px;
  font-weight: bold;
  color: #f3c86b;
  font-family: 'Trebuchet MS', sans-serif;
}

.ach-toast-title {
  font-size: 15px;
  font-weight: bold;
  color: #fff3d4;
  margin-top: 2px;
}

.ach-toast-desc {
  font-size: 12px;
  line-height: 1.35;
  color: #cfc3aa;
  margin-top: 2px;
  font-family: 'Trebuchet MS', sans-serif;
}

.badges-card {
  width: min(960px, 95vw);
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 10px;
  margin-top: 12px;
  max-height: 68vh;
  overflow-y: auto;
  padding-right: 4px;
}

.ach-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(196, 162, 98, 0.25);
  background: rgba(16, 15, 19, 0.78);
  transition: border-color 0.16s ease, background 0.16s ease;
}

.ach-card.unlocked {
  border-color: rgba(234, 190, 102, 0.72);
  background: linear-gradient(155deg, rgba(38, 30, 18, 0.82), rgba(18, 22, 32, 0.88));
  box-shadow: inset 0 0 16px rgba(234, 190, 102, 0.08);
}

.ach-card.locked {
  opacity: 0.56;
  filter: grayscale(0.45);
}

.ach-card-medal {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.ach-card-info {
  min-width: 0;
  flex: 1;
}

.ach-card-cat {
  font-size: 9.5px;
  letter-spacing: 1.1px;
  color: #cfa75e;
  font-family: 'Trebuchet MS', sans-serif;
  font-weight: bold;
}

.ach-card.locked .ach-card-cat {
  color: #8b8273;
}

.ach-card-title {
  font-size: 14px;
  font-weight: bold;
  color: #f7ebd0;
  margin-top: 1px;
}

.ach-card-desc {
  font-size: 12px;
  line-height: 1.38;
  color: #c9bda6;
  margin-top: 3px;
  font-family: 'Trebuchet MS', sans-serif;
}

/* =========================================================================
   RETURNING TRAVELER COOKIE PANEL (NAME ASSIGNMENT + CLEAR RESET)
   ========================================================================= */
.hud-traveler {
  color: #ffd980;
  font-weight: bold;
}

.returning-panel {
  margin: 10px auto 12px;
  max-width: 470px;
  padding: 10px 13px;
  border-radius: 8px;
  background: rgba(18, 16, 12, 0.78);
  border: 1px solid rgba(218, 176, 98, 0.52);
  box-shadow: inset 0 0 14px rgba(218, 176, 98, 0.08);
  text-align: left;
}

.returning-summary {
  font-size: 12.5px;
  color: #ebd6ab;
  font-family: 'Trebuchet MS', sans-serif;
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}

.returning-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#traveler-name-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid rgba(214, 172, 96, 0.52);
  background: rgba(8, 9, 13, 0.90);
  color: #f9eed4;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 14px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

#traveler-name-input::placeholder {
  color: rgba(214, 198, 168, 0.55);
}

#traveler-name-input:focus {
  border-color: #f2ca78;
  box-shadow: 0 0 8px rgba(242, 202, 120, 0.28);
}

.clear-progress-btn {
  padding: 7px 13px;
  border-color: rgba(218, 136, 118, 0.62);
  color: #f5d4cb;
  flex-shrink: 0;
}

.clear-progress-btn:hover {
  border-color: #ffaba0;
  color: #fff0ed;
}

body.touch #traveler-name-input {
  font-size: 16px;
}
