:root {
  --ink: #07060a;
  --parchment: #e9dcc0;
  --gold: #d9b36a;
  --gold-dim: #9c7c43;
  --ember: #e0782a;
  --panel: rgba(14, 10, 8, 0.62);
  --panel-edge: rgba(217, 179, 106, 0.28);
  --serif: "IM Fell English", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --serif-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--parchment);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
  /* dragging to turn the case shouldn't select the title or help text */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* ---------- title card ---------- */
.title-card {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 2.4s ease 0.6s;
}
.title-card h1 {
  margin: 0;
  font-family: var(--serif-sc);
  font-weight: 400;
  font-size: clamp(20px, 3.1vw, 36px);
  letter-spacing: 0.04em;
  color: var(--gold);
}
.title-card p {
  margin: 2px 0 0;
  font-style: italic;
  font-size: clamp(13px, 1.4vw, 17px);
  color: rgba(233, 220, 192, 0.7);
}
body.ready .title-card { opacity: 1; }

/* ---------- control bar ---------- */
.controls {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 1.2s ease 1.2s, transform 1.2s ease 1.2s;
}
body.ready .controls { opacity: 1; transform: translate(-50%, 0); }

.controls button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(233, 220, 192, 0.78);
  font-family: var(--serif);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.controls button:hover { background: rgba(217, 179, 106, 0.12); color: var(--parchment); }
.controls button:focus-visible { outline: 1px solid var(--gold); outline-offset: 1px; }
.controls button[aria-pressed="true"] { color: var(--gold); background: rgba(217, 179, 106, 0.16); }
.controls svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* small link to the source, at the end of the bar */
.controls .repo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: 2px;
  border-left: 1px solid rgba(217, 179, 106, 0.18);
  border-radius: 0 999px 999px 0;
  color: rgba(233, 220, 192, 0.5);
  transition: color 0.2s;
}
.controls .repo:hover { color: var(--gold); }
.controls .repo:focus-visible { outline: 1px solid var(--gold); outline-offset: 1px; }
.controls .repo svg { width: 16px; height: 16px; }

.controls .icon-play { display: none; }
.controls button[data-action="pause"][aria-pressed="true"] .icon-play { display: inline; }
.controls button[data-action="pause"][aria-pressed="true"] .icon-pause { display: none; }

@media (max-width: 640px) {
  /* icons only, packed tighter so the whole bar fits on a phone */
  .controls { gap: 2px; padding: 4px; }
  .controls button { width: 36px; padding: 0; justify-content: center; }
  .controls .label { display: none; }
}
@media (max-width: 380px) {
  .controls button { width: 33px; }
}

/* ---------- help card ---------- */
.help {
  position: fixed;
  left: max(22px, env(safe-area-inset-left));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 62px);
  z-index: 5;
  width: min(330px, calc(100vw - 32px));
  padding: 14px 16px 14px 18px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(233, 220, 192, 0.85);
  font-size: 15px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.help[hidden] { display: none; }
body.ready .help.shown { opacity: 1; transform: none; }
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.help h2 {
  margin: 0;
  font-family: var(--serif-sc);
  font-weight: 400;
  font-size: 18px;
  color: var(--gold);
}
.help-close {
  width: 28px;
  height: 28px;
  margin: -4px -6px 0 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(233, 220, 192, 0.6);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.help-close:hover, .help-close:focus-visible { color: var(--gold); background: rgba(217, 179, 106, 0.12); outline: none; }
.help-list {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}
.help-list li {
  display: grid;
  grid-template-columns: 96px 1fr;
  column-gap: 10px;
  align-items: baseline;
  margin: 5px 0;
}
.help .gesture {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(217, 179, 106, 0.14);
  color: var(--gold);
  font-family: var(--serif-sc);
  font-size: 14px;
  text-align: center;
}
.help-tip { margin: 8px 0 6px; font-style: italic; color: rgba(233, 220, 192, 0.7); }
.help-tip strong { font-style: normal; font-weight: 400; color: var(--gold); }
.help-keys { margin: 0 0 10px; font-size: 13px; color: rgba(233, 220, 192, 0.55); }
.help kbd {
  padding: 0 5px;
  border: 1px solid rgba(217, 179, 106, 0.3);
  border-radius: 4px;
  font-family: var(--serif);
  font-size: 12px;
  color: rgba(233, 220, 192, 0.8);
}
.help-ok {
  display: block;
  margin-left: auto;
  padding: 5px 16px;
  border: 1px solid rgba(217, 179, 106, 0.45);
  border-radius: 999px;
  background: rgba(217, 179, 106, 0.08);
  color: var(--gold);
  font-family: var(--serif);
  font-size: 15px;
  cursor: pointer;
}
.help-ok:hover, .help-ok:focus-visible { background: rgba(217, 179, 106, 0.18); outline: none; }
/* a quiet maker's credit beside the button */
.help-foot { display: flex; align-items: center; gap: 12px; }
.help-credit { margin: 0; font-size: 12px; font-style: italic; color: rgba(233, 220, 192, 0.45); }
.help-credit a { color: rgba(217, 179, 106, 0.75); text-decoration: none; border-bottom: 1px solid rgba(217, 179, 106, 0.3); }
.help-credit a:hover, .help-credit a:focus-visible { color: var(--gold); border-bottom-color: var(--gold); outline: none; }
/* touch devices get finger wording; mouse users get mouse wording + keys */
body.touch .help .only-mouse,
body:not(.touch) .help .only-touch { display: none; }
@media (max-width: 640px) {
  .help {
    left: 50%;
    width: calc(100vw - 24px);
    transform: translate(-50%, 8px);
  }
  body.ready .help.shown { transform: translate(-50%, 0); }
}

/* ---------- loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 40%, #1b1410 0%, #07060a 70%);
  transition: opacity 1.6s ease, visibility 1.6s;
  z-index: 10;
}
body.ready .loader { opacity: 0; visibility: hidden; }

.loader-inner {
  width: min(520px, 100%);
  text-align: center;
}
.loader h2 {
  margin: 0 0 18px;
  font-family: var(--serif-sc);
  font-weight: 400;
  font-size: clamp(26px, 5vw, 40px);
  color: var(--gold);
  letter-spacing: 0.03em;
}
.loader blockquote {
  margin: 0 auto 28px;
  max-width: 440px;
  font-style: italic;
  font-size: clamp(15px, 2.4vw, 18px);
  line-height: 1.5;
  color: rgba(233, 220, 192, 0.75);
}
.loader-bar {
  height: 2px;
  margin: 0 auto;
  width: 60%;
  background: rgba(217, 179, 106, 0.15);
  overflow: hidden;
}
.loader-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--ember));
  transition: width 0.3s ease;
}
/* while the scripts are still downloading, show an indeterminate shimmer */
.loader:not(.started):not(.error) .loader-bar span {
  width: 30%;
  animation: loader-sweep 1.4s ease-in-out infinite;
}
@keyframes loader-sweep {
  from { transform: translateX(-110%); }
  to { transform: translateX(340%); }
}
.loader-step {
  margin: 12px 0 0;
  font-size: 14px;
  font-style: italic;
  color: rgba(233, 220, 192, 0.5);
}
.loader.error .loader-step { color: #e7a07a; }

.enter {
  margin: 26px auto 0;
  padding: 11px 26px 12px;
  border: 1px solid rgba(217, 179, 106, 0.55);
  border-radius: 999px;
  background: rgba(217, 179, 106, 0.08);
  color: var(--gold);
  font-family: var(--serif-sc);
  font-size: 19px;
  letter-spacing: 0.06em;
  cursor: pointer;
  animation: enter-glow 2.6s ease-in-out infinite;
  transition: background 0.2s, color 0.2s;
}
.enter:hover, .enter:focus-visible {
  background: rgba(217, 179, 106, 0.18);
  color: var(--parchment);
  outline: none;
}
@keyframes enter-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(224, 120, 42, 0); }
  50% { box-shadow: 0 0 22px rgba(224, 120, 42, 0.35); }
}
.loader.loaded .loader-bar,
.loader.loaded .loader-step { display: none; }

/* music choice under the enter button, so the sound is never a surprise */
.enter-music {
  display: block;
  margin: 14px auto 0;
  padding: 4px 10px;
  border: 0;
  background: transparent;
  color: rgba(233, 220, 192, 0.72);
  font-family: var(--serif);
  font-size: 15px;
  font-style: italic;
  cursor: pointer;
}
.enter-music[hidden] { display: none; }
.enter-music .note { font-style: normal; color: var(--gold); margin-right: 3px; }
.enter-music .sep { color: rgba(233, 220, 192, 0.45); margin: 0 2px; }
.enter-music .action { color: rgba(233, 220, 192, 0.45); text-decoration: underline; text-underline-offset: 3px; }
.enter-music:hover .action, .enter-music:focus-visible .action { color: var(--gold); }
.enter-music:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.enter-music[aria-pressed="false"] .note { color: rgba(233, 220, 192, 0.35); }

/* music volume */
.controls .volume {
  -webkit-appearance: none;
  appearance: none;
  align-self: center;
  width: 84px;
  height: 20px;
  margin: 0 8px 0 -4px;
  background: transparent;
  cursor: pointer;
}
.controls .volume::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold) var(--fill, 30%), rgba(233, 220, 192, 0.25) var(--fill, 30%));
}
.controls .volume::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(233, 220, 192, 0.25);
}
.controls .volume::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--gold);
}
.controls .volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--gold);
  border: 0;
}
.controls .volume::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--gold);
  border: 0;
}
.controls .volume:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.controls .volume.off { opacity: 0.45; }
@media (max-width: 640px) {
  .controls .volume { width: 52px; margin: 0 5px 0 2px; }
  .controls .repo { width: 32px; }
}
@media (max-width: 380px) {
  .controls .volume { width: 44px; }
}

.controls button[data-action="music"] .icon-off { display: none; }
.controls button[data-action="music"][aria-pressed="false"] .icon-off { display: inline; }

.fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  text-align: center;
}
