:root {
  --bg: #0d0d0f;
  --panel: rgba(18, 18, 22, 0.86);
  --text: #f3efe8;
  --muted: #b5ada2;
  --accent: #f2c46d;
  --line: rgba(255, 255, 255, 0.12);
  --radius: 14px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
#viewer, #viewer canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button {
  font: 600 14px/1 system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
button:hover { background: rgba(255, 255, 255, 0.16); }
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: #1b1408; border-color: transparent; }
button.primary:hover { background: #ffd58a; }
button.ghost { background: rgba(0, 0, 0, 0.35); backdrop-filter: blur(8px); }

/* Loader */
#loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 20; transition: opacity 0.6s ease; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-card { width: min(320px, 80vw); text-align: center; }
.loader-title { font-size: 22px; margin-bottom: 16px; }
.bar { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }
#loader-text { font: 12px system-ui, sans-serif; color: var(--muted); margin-top: 10px; }

/* Top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 16px 16px;
  background: linear-gradient(rgba(0,0,0,0.55), transparent);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#tour-title { font-size: 20px; letter-spacing: 0.02em; text-shadow: 0 1px 8px rgba(0,0,0,0.6); }
.top-actions { display: flex; gap: 8px; }

/* Pins */
#pins { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.pin {
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%;
  display: grid; place-items: center;
  font: 700 14px system-ui, sans-serif; color: #1b1408;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(242, 196, 109, 0.7), 0 2px 10px rgba(0,0,0,0.5);
  pointer-events: auto; cursor: pointer; border: 2px solid #fff6e0;
  animation: pulse 2.2s ease-out infinite;
  transition: opacity 0.25s ease, transform 0.15s ease;
  padding: 0;
}
.pin:hover { transform: scale(1.12); }
.pin.hidden { opacity: 0; pointer-events: none; }
.pin.active { animation: none; background: #fff; }
.pin .label {
  position: absolute; left: 50%; top: 42px; transform: translateX(-50%);
  white-space: nowrap; font: 600 12px system-ui, sans-serif; color: var(--text);
  background: rgba(0,0,0,0.65); padding: 5px 9px; border-radius: 8px;
  opacity: 0; transition: opacity 0.15s ease; pointer-events: none;
}
.pin:hover .label { opacity: 1; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(242, 196, 109, 0.65), 0 2px 10px rgba(0,0,0,0.5); }
  70% { box-shadow: 0 0 0 16px rgba(242, 196, 109, 0), 0 2px 10px rgba(0,0,0,0.5); }
  100% { box-shadow: 0 0 0 0 rgba(242, 196, 109, 0), 0 2px 10px rgba(0,0,0,0.5); }
}

/* Info panel */
#panel {
  position: fixed; z-index: 6;
  right: 20px; bottom: 20px; width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 120px); overflow: auto;
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 22px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  transform: translateY(0); opacity: 1;
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1), opacity 0.35s ease;
}
#panel.entering { transform: translateY(16px); opacity: 0; }
.panel-meta { font: 600 11px system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
#panel h2 { margin: 8px 0 4px; font-size: 26px; font-weight: 600; line-height: 1.15; }
#panel-subtitle { color: var(--muted); font-style: italic; margin-bottom: 14px; }
#panel-text { font-size: 16px; line-height: 1.55; }
#panel-text p { margin: 0 0 12px; }
.panel-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

#hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 3;
  font: 13px system-ui, sans-serif; color: var(--muted);
  background: rgba(0,0,0,0.45); padding: 8px 14px; border-radius: 999px;
  transition: opacity 0.5s ease; pointer-events: none;
}
#hint.gone { opacity: 0; }

/* Editor */
#editor {
  position: fixed; z-index: 7; left: 16px; top: 80px; width: 300px;
  max-height: calc(100vh - 100px); overflow: auto;
  background: rgba(10,10,12,0.92); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; font: 13px system-ui, sans-serif;
}
#editor h3 { margin: 0 0 6px; font-size: 15px; }
#editor .row { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
#editor button { padding: 7px 10px; font-size: 12px; }
#editor label { display: block; margin: 8px 0; color: var(--muted); }
#editor input, #editor textarea {
  display: block; width: 100%; margin-top: 4px; padding: 6px 8px;
  background: #18181c; color: var(--text); border: 1px solid var(--line); border-radius: 6px; font: 13px system-ui, sans-serif;
}
#editor .small { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  #panel { left: 16px; right: 16px; bottom: 16px; width: auto; max-height: 48vh; padding: 18px 18px 12px; }
  #panel h2 { font-size: 22px; }
  #tour-title { font-size: 16px; }
  #hint { bottom: 14px; white-space: nowrap; font-size: 12px; }
  #editor { left: 8px; right: 8px; width: auto; top: 70px; max-height: 45vh; }
}
@media (prefers-reduced-motion: reduce) {
  .pin { animation: none; }
}
