:root {
  --ink: #f1ece2;
  --muted: #b9b09f;
  --gold: #d6bd83;
  --panel: rgba(22, 20, 18, 0.92);
  --line: rgba(241, 236, 226, 0.14);
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: Inter, 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0d0c; color: var(--ink); font: 15px/1.45 var(--sans); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* phones: taps never zoom (double-tap), text never auto-grows on rotation; scrolling panes still scroll */
html, body, button, a, .overlay, #hud, #tour-bar, #caption, #panel, #toast, .popover { touch-action: manipulation; }
.panel-meta .caption, #viewer-scroll { touch-action: pan-x pan-y; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.7em; padding: 1px 6px; margin-right: 3px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font: 500 12px var(--sans); text-align: center; color: var(--ink); }
.eyebrow { margin: 0 0 6px; font: 600 11px/1 var(--sans); letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold); }
.fine { margin: 4px 0; color: var(--muted); font-size: 13px; }
.primary { border: 0; border-radius: 999px; padding: 13px 26px; background: var(--gold); color: #1b1812; font-weight: 600; letter-spacing: 0.02em; transition: transform .15s, filter .15s; }
.primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.primary:disabled { opacity: .55; cursor: progress; }

/* entrance */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at center, rgba(14,13,12,.55), rgba(14,13,12,.92)); z-index: 20; }
.intro-card { max-width: 560px; text-align: center; }
.intro-card h1 { margin: 6px 0 4px; font: 500 clamp(52px, 11vw, 96px)/1 var(--serif); letter-spacing: 0.08em; text-transform: uppercase; color: #efe6d2; }
.intro-card .sub { margin: 0 0 6px; font: italic 500 22px/1.3 var(--serif); color: var(--muted); }
.intro-card .stats { margin: 0 0 26px; font-size: 13px; color: var(--muted); }
.for-muses { margin: 22px 0 0; font-size: 12.5px; color: var(--muted); }
.for-muses a { color: var(--gold); }
.panel-meta .artist { margin: -4px 0 8px; font: italic 500 19px/1.3 var(--serif); color: var(--ink); }
.panel-meta .artist:empty { display: none; }
.help { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 18px; margin-top: 26px; font-size: 13px; color: var(--muted); }
body.touch .desktop-only, body:not(.touch) .touch-only { display: none; }

#crosshair { position: fixed; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 0 0 1px rgba(0,0,0,.35); pointer-events: none; z-index: 5; }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; pointer-events: none; z-index: 6; }
#where { font: 500 19px var(--serif); letter-spacing: .03em; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.hud-buttons { display: flex; gap: 8px; pointer-events: auto; }
.hud-buttons button, #tour-bar button { border: 1px solid var(--line); background: rgba(20,18,16,.62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.hud-buttons button:hover, #tour-bar button:hover { background: rgba(40,36,31,.8); }
.hud-buttons button { white-space: nowrap; }
#where { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  #where { font-size: 16px; }
  .hud-buttons { gap: 6px; }
  .hud-buttons button { padding: 6px 10px; font-size: 12px; }
  #tour-bar { font-size: 12px; }
}

.popover { position: fixed; top: 58px; right: 16px; width: min(320px, calc(100vw - 32px)); padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; z-index: 7; }
.popover .label { margin: 0 0 8px; font-weight: 600; font-size: 13px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: 0; background: none; padding: 7px 0; font-size: 12.5px; }
.seg button.on { background: var(--gold); color: #1b1812; font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }

/* caption plaque */
#caption { position: fixed; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; justify-items: center; gap: 1px; min-width: 220px; max-width: calc(100vw - 32px); padding: 12px 22px 11px; background: #f1ece1; color: #25221d; border-radius: 3px; box-shadow: 0 10px 30px rgba(0,0,0,.4); pointer-events: none; z-index: 5; animation: rise .25s ease-out; }
#caption .cap-title { font: italic 600 21px/1.2 var(--serif); text-align: center; }
#caption .cap-muse { font: 600 11px var(--sans); letter-spacing: .18em; text-transform: uppercase; color: #7a6a4d; }
#caption .cap-hint { font-size: 11.5px; color: #8a8378; margin-top: 3px; }
#caption .cap-hint:empty { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

#tour-bar { position: fixed; left: 50%; bottom: max(120px, calc(env(safe-area-inset-bottom) + 110px)); transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; background: rgba(20,18,16,.62); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 999px; z-index: 6; font-size: 13px; white-space: nowrap; }

/* detail panel */
#panel { position: fixed; inset: 0; margin: auto; width: min(1100px, calc(100vw - 32px)); height: min(720px, calc(100dvh - 32px)); display: grid; grid-template-columns: 1fr 300px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; z-index: 30; box-shadow: 0 30px 80px rgba(0,0,0,.55); animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.panel-img { display: grid; place-items: center; min-height: 0; padding: 28px; background: #151311; }
.panel-img img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 8px 30px rgba(0,0,0,.5); background: #222; }
.panel-meta { padding: 34px 26px; display: flex; flex-direction: column; gap: 4px; border-left: 1px solid var(--line); }
.panel-meta h2 { margin: 0 0 8px; font: 600 34px/1.1 var(--serif); }
.panel-meta .primary { margin-top: auto; }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); font-size: 22px; line-height: 1; z-index: 2; }
.panel-img { overflow: hidden; }
@media (max-width: 760px) {
  #panel { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .panel-img { padding: 14px; }
  .panel-meta { overflow: auto; max-height: 52dvh; }
  .panel-meta { border-left: 0; border-top: 1px solid var(--line); padding: 18px 20px 20px; }
  .panel-meta h2 { font-size: 27px; }
  .panel-meta .primary { margin-top: 12px; }
}

/* full size viewer */
#viewer { position: fixed; inset: 0; z-index: 40; background: #0b0a09; display: grid; grid-template-rows: 1fr auto; }
#viewer-scroll { overflow: auto; display: grid; place-items: center; min-height: 0; }
#viewer-scroll img { display: block; image-rendering: auto; }
#viewer-scroll.fit { overflow: hidden; }
#viewer-scroll.fit img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-bar { display: flex; gap: 10px; align-items: center; padding: 10px 16px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.viewer-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.viewer-bar button, .viewer-bar a { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 13px; color: var(--ink); text-decoration: none; }

/* joystick */
#joystick { position: fixed; left: 0; top: 0; width: 120px; height: 120px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(20,18,16,.25); pointer-events: none; z-index: 8; }
#joystick .knob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%; background: rgba(241,236,226,.8); }

#toast { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 9px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 13px; z-index: 9; text-align: center; animation: fade .2s; }

/* musegram edition */
.for-muses a { text-decoration: none; }
.panel-img video { max-width: 100%; max-height: 100%; background: #000; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.panel-meta .caption { margin: 0 0 10px; white-space: pre-wrap; overflow: auto; max-height: 40vh; color: #e6ddcc; font: 400 15px/1.5 var(--sans); }
.panel-actions { margin-top: auto; display: grid; gap: 8px; }
.panel-actions .primary { text-align: center; text-decoration: none; }
.ghost { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 11px 22px; color: var(--ink); }
@media (max-width: 760px) { .panel-actions { margin-top: 12px; } }

/* phones (last, so it wins over the base rules above): the tour bar rides under the hud, so the caption
   plaque at the bottom never slides under it; a long title stays on two lines */
@media (max-width: 760px) {
  #tour-bar { top: calc(max(12px, env(safe-area-inset-top)) + 48px); bottom: auto; }
  #caption .cap-title { font-size: 18px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}

/* the detail panel's picture: a flex box has a definite height, so the picture's max-height: 100% resolves
   (a grid cell doesn't) — it always fits its half and stays centred, tall or wide */
.panel-img { display: flex; align-items: center; justify-content: center; }
.panel-img img, .panel-img video { max-width: 100%; max-height: 100%; }
