:root {
  --parchment: #ede0c4;
  --parchment-dark: #d8c79f;
  --ink: #2a1d10;
  --gold: #c9a24b;
  --gold-bright: #e9c874;
  --stone-dark: #0c0a10;
  --candle: #ffb347;
  --panel-shadow: rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--stone-dark);
  overflow: hidden;
  font-family: Georgia, "Palatino Linotype", Palatino, "Times New Roman", serif;
  color: var(--parchment);
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  outline: none;
}

/* Loading screen */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #221708 0%, #0c0a10 75%);
  transition: opacity 0.9s ease;
}

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

.loading-title {
  font-size: 2.4rem;
  letter-spacing: 0.12em;
  color: var(--gold-bright);
  text-align: center;
  text-shadow: 0 0 18px rgba(233, 200, 116, 0.5);
  font-variant: small-caps;
}

.loading-sub {
  margin-top: 0.8rem;
  text-align: center;
  color: var(--parchment-dark);
  font-style: italic;
  opacity: 0.8;
  animation: flicker 2.2s infinite ease-in-out;
}

@keyframes flicker {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.95; }
}

/* HUD */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 16;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.6rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(10, 8, 6, 0.65), transparent);
}

#hud-title {
  font-size: 1.3rem;
  letter-spacing: 0.08em;
  font-variant: small-caps;
  color: var(--gold-bright);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  pointer-events: auto;
}

#hud-search-wrap {
  position: relative;
  pointer-events: auto;
  width: min(320px, 42vw);
}

#search-input {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--gold);
  background: rgba(20, 15, 10, 0.72);
  color: var(--parchment);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  backdrop-filter: blur(2px);
}

#search-input::placeholder {
  color: var(--parchment-dark);
  opacity: 0.6;
}

#search-input:focus {
  border-color: var(--gold-bright);
  box-shadow: 0 0 12px rgba(201, 162, 75, 0.4);
}

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: rgba(15, 11, 7, 0.94);
  border: 1px solid var(--gold);
  border-radius: 6px;
  display: none;
}

#search-results.visible {
  display: block;
}

.search-result-item {
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(201, 162, 75, 0.15);
  font-size: 0.9rem;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.active {
  background: rgba(201, 162, 75, 0.18);
}

.search-result-title {
  color: var(--gold-bright);
}

.search-result-author {
  color: var(--parchment-dark);
  font-size: 0.78rem;
  font-style: italic;
}

/* Hint */
#hint {
  position: fixed;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 0.82rem;
  color: var(--parchment-dark);
  background: rgba(10, 8, 6, 0.55);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  pointer-events: none;
  letter-spacing: 0.02em;
  transition: opacity 0.4s ease;
}

/* Crosshair (shown while pointer is locked / walking) */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(233, 200, 116, 0.85);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  display: none;
}

body.walking #crosshair {
  display: block;
}

/* Walk prompt (shown when not pointer-locked) */
#walk-prompt {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(5, 4, 3, 0.15);
  transition: opacity 0.25s ease;
}

body.walking #walk-prompt {
  opacity: 0;
  pointer-events: none;
}

#walk-prompt-inner {
  padding: 0.9rem 1.6rem;
  border-radius: 8px;
  background: rgba(15, 11, 7, 0.75);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.02em;
}

#walk-prompt-sub {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--parchment-dark);
  font-style: italic;
}

/* Tooltip */
#tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, -140%);
  background: rgba(15, 11, 7, 0.92);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 0.35rem 0.7rem;
  border-radius: 5px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
}

#tooltip.crosshair-mode {
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -220%);
}

#tooltip.visible {
  opacity: 1;
}

/* Book reading panel */
#book-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 4, 3, 0.72);
  backdrop-filter: blur(3px);
}

#book-panel-inner {
  position: relative;
  width: min(760px, 92vw);
  height: min(84vh, 900px);
  background: linear-gradient(180deg, var(--parchment) 0%, var(--parchment-dark) 100%);
  color: var(--ink);
  border-radius: 4px;
  box-shadow: 0 30px 80px var(--panel-shadow), 0 0 0 1px var(--gold);
  padding: 2.4rem 2.6rem;
  overflow-y: auto;
}

#book-panel-close {
  position: sticky;
  float: right;
  top: 0;
  margin-left: 1rem;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: rgba(255, 255, 255, 0.25);
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

#book-panel-close:hover {
  background: rgba(0, 0, 0, 0.12);
}

#book-panel-meta {
  border-bottom: 2px solid rgba(42, 29, 16, 0.25);
  padding-bottom: 0.8rem;
  margin-bottom: 1.2rem;
}

#book-panel-title {
  font-size: 1.9rem;
  margin: 0 0 0.2rem 0;
  font-variant: small-caps;
  letter-spacing: 0.02em;
}

#book-panel-author {
  font-style: italic;
  opacity: 0.75;
}

#book-panel-content {
  line-height: 1.65;
  font-size: 1.02rem;
}

#book-panel-content h1,
#book-panel-content h2,
#book-panel-content h3 {
  font-variant: small-caps;
  color: #3a2712;
  margin-top: 1.6em;
}

#book-panel-content blockquote {
  margin: 1.2em 0;
  padding: 0.4em 1.2em;
  border-left: 3px solid var(--gold);
  font-style: italic;
  opacity: 0.85;
}

#book-panel-content hr {
  border: none;
  border-top: 1px solid rgba(42, 29, 16, 0.3);
  margin: 1.8em 0;
}

#book-panel-content a {
  color: #6b4a17;
}

#book-panel-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

#book-panel-content th,
#book-panel-content td {
  border: 1px solid rgba(42, 29, 16, 0.3);
  padding: 0.4em 0.7em;
  text-align: left;
}

.hidden {
  display: none !important;
}
