:root {
  --ink: #1a1613;
  --paper: #efe6d6;
  --paper-2: #f7f1e6;
  --line: #b9a98e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: #efe6d6; color: var(--ink); }

body {
  font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  /* matches the artwork's own paper gradient so letterboxing never shows as a hard band */
  background: linear-gradient(#efe6d6 0%, #cdbfa6 100%) fixed;
  min-height: 100dvh;
}

/* ---------- chrome ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 56px;
  padding: 0 clamp(12px, 3vw, 28px);
  background: rgba(239, 230, 214, 0.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.bar h1 {
  margin: 0;
  font: 500 1rem/1 var(--serif);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.bar .sub {
  font-size: 0.78rem;
  color: #6b5f50;
  letter-spacing: 0.02em;
}
.bar .spacer { flex: 1; }

.lang {
  border: 1px solid var(--ink);
  background: transparent;
  color: inherit;
  font: 600 0.72rem/1 var(--sans);
  letter-spacing: 0.12em;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 2px;
}
.lang:hover, .lang:focus-visible { background: var(--ink); color: var(--paper-2); }

/* ---------- scene ---------- */

.scene-wrap {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#stage {
  position: relative;
  aspect-ratio: var(--ar, 1.6);
  /* fit the viewport height without distorting: width follows the scene's own ratio */
  width: min(100%, calc((100dvh - 56px) * var(--ar, 1.6)));
  margin: 0 auto;
}

#stage > img.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}

.obj {
  position: absolute;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: center;
  transition: transform 160ms ease, filter 160ms ease;
  -webkit-tap-highlight-color: transparent;
}
.obj img { display: block; width: 100%; height: auto; pointer-events: none; }
.obj:hover, .obj:focus-visible { filter: drop-shadow(0 6px 10px rgba(60, 40, 20, 0.45)); outline: none; }
.obj:focus-visible { outline: 1px dashed var(--ink); outline-offset: 6px; }
.obj:hover, .obj:focus-visible { transform: translate(-50%, -50%) rotate(var(--rot)) scale(1.07); }

body:has(dialog[open]) { overflow: hidden; }

/* ---------- reader ---------- */

dialog {
  border: 0;
  padding: 0;
  width: min(660px, 94vw);
  max-height: 88dvh;
  background: var(--paper-2);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(20, 14, 8, 0.5);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(26, 22, 19, 0.5);
  backdrop-filter: blur(3px);
}

.dlg-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 22px 26px 14px;
  background: var(--paper-2);
  border-bottom: 1px solid rgba(185, 169, 142, 0.55);
}
.dlg-head h2 {
  margin: 0;
  font: 400 clamp(1.25rem, 3vw, 1.7rem)/1.2 var(--serif);
  letter-spacing: -0.01em;
}
.dlg-head .id {
  display: block;
  font: 600 0.66rem/1 var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #8a7b66;
  margin-bottom: 8px;
}
.close {
  margin-left: 4px;
  border: 0;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #6b5f50;
  padding: 2px 6px;
}
.dlg-head .lang { margin-left: auto; }
.close:hover, .close:focus-visible { color: var(--ink); }

.dlg-body { padding: 8px 26px 30px; }
.dlg-body > :first-child { margin-top: 1.1em; }
.dlg-body p { margin: 0 0 1em; }
.dlg-body img { max-width: 100%; height: auto; margin: 1.2em 0; }
.dlg-body blockquote {
  margin: 1.4em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 2px solid var(--line);
  color: #6b5f50;
  font-size: 0.92rem;
}
.dlg-body a { color: inherit; text-underline-offset: 3px; }

.hint {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5d5247;
  background: rgba(247, 241, 230, 0.8);
  padding: 6px 12px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity 600ms;
}
.hint.gone { opacity: 0; }

@media (max-width: 720px) {
  .scene-wrap {
    display: flex;
    align-items: center;
    height: calc(100dvh - 56px);
  }
  #stage { width: 215vw; max-height: none; flex: 0 0 auto; }
  .bar .sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .obj, .hint { transition: none; }
}
