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

:root {
  --bg-deep: #0a0a0a;
  --bg-dark: #111111;
  --text-parchment: #e8e0d4;
  --text-dim: #8a8070;
  --gold: #c4a265;
  --gold-dim: #8a7245;
  --burgundy: #6b1d1d;
  --emerald: #2d6a4f;
  --frame-wood: #2a1a0a;
  --frame-light: #3d2a15;
}

body {
  background: var(--bg-deep);
  color: var(--text-parchment);
  font-family: 'Libre Baskerville', serif;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Vignette overlay - LOW z-index, less aggressive */
.vignette-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.5) 100%);
  pointer-events: none;
  z-index: 0;
}

/* Grain overlay - LOW z-index */
.grain-overlay {
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  animation: grain 8s steps(10) infinite;
}

@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-5%, -10%); }
  20% { transform: translate(-15%, 5%); }
  30% { transform: translate(7%, -25%); }
  40% { transform: translate(-5%, 25%); }
  50% { transform: translate(-15%, 10%); }
  60% { transform: translate(15%, 0%); }
  70% { transform: translate(0%, 15%); }
  80% { transform: translate(3%, 35%); }
  90% { transform: translate(-10%, 10%); }
}

/* Hexagonal pattern background */
.hex-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='100' viewBox='0 0 56 100'%3E%3Cpath d='M28 66L0 50L0 16L28 0L56 16L56 50L28 66L28 100' fill='none' stroke='%23181818' stroke-width='0.5'/%3E%3Cpath d='M28 0L28 34L0 50L0 84L28 100L56 84L56 50L28 34' fill='none' stroke='%23151515' stroke-width='0.3'/%3E%3C/svg%3E");
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

/* Typography */
.font-heading { font-family: 'Cormorant Garamond', serif; }
.font-body { font-family: 'Libre Baskerville', serif; }
.font-mono { font-family: 'JetBrains Mono', monospace; }

/* Frame styles */
.image-frame {
  background: linear-gradient(145deg, #3d2a15, #1a0f05);
  padding: 12px;
  border: 1px solid #4a3520;
  box-shadow:
    inset 0 0 20px rgba(0,0,0,0.8),
    0 0 40px rgba(0,0,0,0.6),
    inset 2px 2px 4px rgba(255,255,255,0.05),
    inset -2px -2px 4px rgba(0,0,0,0.4);
  position: relative;
}

.image-frame::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(196,162,101,0.15);
  pointer-events: none;
}

/* Canvas pixelated rendering */
.pixel-canvas {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* Navigation grid overlay */
.nav-grid {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 5;
}

.nav-grid:hover {
  opacity: 1;
}

.nav-cell {
  border: 1px dashed rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  min-height: 44px;
}

.nav-cell:hover {
  background: rgba(196,162,101,0.12);
  border-color: rgba(196,162,101,0.3);
}

.nav-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: rgba(196,162,101,0.85);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.2s;
  text-align: center;
  padding: 2px 6px;
  background: rgba(0,0,0,0.75);
  border-radius: 2px;
  white-space: nowrap;
}

.nav-cell:hover .nav-label {
  opacity: 1;
}

/* On touch devices, show grid labels always lightly */
@media (hover: none) {
  .nav-grid {
    opacity: 0.6;
  }
  .nav-label {
    opacity: 0.8;
    font-size: 8px;
  }
}

/* Gold progress bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), #e8d5a0);
  z-index: 9999;
  transition: width 0.2s ease;
  box-shadow: 0 0 10px rgba(196,162,101,0.5);
}

/* Fade transition */
.image-transition {
  transition: opacity 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 3px; }

/* Metadata gauge */
.gauge-track {
  height: 4px;
  background: #1a1a1a;
  border-radius: 2px;
  border: 1px solid #222;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* Keyhole toggle */
.keyhole-btn {
  width: 36px;
  height: 52px;
  background: #1a1408;
  border: 1px solid var(--gold-dim);
  border-radius: 4px 0 0 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.keyhole-btn:hover {
  background: #2a2010;
  border-color: var(--gold);
}

/* Vault modal */
.vault-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,5,3,0.96);
  z-index: 1500;
  overflow-y: auto;
}

/* Mirror modal */
.mirror-modal {
  background: linear-gradient(160deg, #0f0f0f, #1a1008);
  border: 1px solid var(--gold-dim);
  padding: 32px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  border-radius: 2px;
}

/* Submission ritual input */
.ritual-input {
  background: #0a0a0a;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: 'JetBrains Mono', monospace;
  padding: 10px 14px;
  width: 100%;
  font-size: 16px;
  outline: none;
  caret-color: var(--gold);
  border-radius: 2px;
}

.ritual-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(196,162,101,0.15);
}

/* Blinking cursor effect */
@keyframes blink {
  0%, 50% { border-color: var(--gold); }
  51%, 100% { border-color: transparent; }
}

.coord-edit {
  border-bottom: 2px solid;
  animation: blink 1s infinite;
}

/* Side button styling */
.side-button {
  background: rgba(15,15,10,0.8);
  border: 1px solid rgba(196,162,101,0.2);
  color: var(--text-dim);
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  border-radius: 4px;
  min-width: 44px;
  min-height: 44px;
}

.side-button:hover, .side-button:active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(196,162,101,0.05);
  box-shadow: 0 0 15px rgba(196,162,101,0.08);
}

/* Active librarians dot */
.pulse-dot {
  width: 6px;
  height: 6px;
  background: var(--emerald);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; box-shadow: 0 0 6px var(--emerald); }
}

/* Gold glow animation */
@keyframes goldGlow {
  0% { box-shadow: 0 0 0 rgba(196,162,101,0); }
  50% { box-shadow: 0 0 40px rgba(196,162,101,0.4); }
  100% { box-shadow: 0 0 0 rgba(196,162,101,0); }
}

.gold-glow { animation: goldGlow 1.5s ease; }

/* Deep dive blur */
.diving .coord-text {
  filter: blur(4px);
  transition: filter 0.1s;
}

/* Thumbnail grid */
.adjacent-thumb {
  image-rendering: pixelated;
  border: 1px solid #222;
  cursor: pointer;
  transition: all 0.2s;
}

.adjacent-thumb:hover {
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(196,162,101,0.2);
}

/* Ornamental divider */
.ornament-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}

.ornament-divider::before,
.ornament-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .image-frame { padding: 8px; }
}

/* Vault polaroid */
.vault-polaroid {
  background: #f5f0e8;
  padding: 8px 8px 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: transform 0.3s;
}

.vault-polaroid:hover {
  transform: rotate(-1deg) scale(1.03);
}

/* Searching animation */
@keyframes searchScan {
  0% { width: 0%; }
  100% { width: 100%; }
}

.search-bar-fill {
  animation: searchScan 3s ease-in-out;
}

/* Sound toggle */
.sound-btn {
  background: none;
  border: 1px solid rgba(196,162,101,0.2);
  color: var(--text-dim);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  border-radius: 3px;
  transition: all 0.2s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sound-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* Adjacent panel slide */
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.adjacent-panel {
  animation: slideIn 0.3s ease;
}

/* Modal backdrop */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
}