:root {
  --ink: #0b0d10;
  --paper: #f2ede3;
  --gold: #d9b36c;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* Vignette and grain live in the grade shader now. As DOM layers they forced
 * the compositor to read the full-screen WebGL canvas back into a blended layer
 * (mix-blend-mode: multiply) and re-composite every frame, which is where the
 * occasional whole-screen black flash came from. */
/* ------------------------------------------------------------------ */
/* HUD                                                                 */
/* ------------------------------------------------------------------ */
.hud {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  padding: clamp(20px, 3.2vw, 46px) clamp(20px, 3.6vw, 60px);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.hud__brand {
  align-self: start;
  justify-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.brand-name {
  color: rgba(242,237,227,.8);
  font-size: 10px;
  letter-spacing: .23em;
  padding-left: .23em;
  text-shadow: 0 1px 8px rgba(0,0,0,.6);
}

.brand-logo {
  display: block;
  width: clamp(72px, 7.5vw, 104px);
  height: auto;
}

.hud__title {
  align-self: end;
  justify-self: start;
  text-align: left;
  max-width: min(42ch, 86vw);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.65);
}

.hud__title .desc {
  font-size: clamp(11px, 1.05vw, 14px);
  line-height: 2;
  letter-spacing: 0.12em;
  color: rgba(238, 233, 222, 0.66);
}

.hud__hint {
  justify-self: end;
  align-self: end;
  font-size: 10px;
  letter-spacing: 0.24em;
  color: rgba(238, 233, 222, 0.5);
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 4px;
}

.hud__hint .sep { opacity: 0.4; }

/* ------------------------------------------------------------------ */
/* loader                                                              */
/* ------------------------------------------------------------------ */
.loading {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background:
    radial-gradient(60% 60% at 50% 45%, rgba(22, 27, 32, 0.9), rgba(6, 8, 10, 0.985));
  transition: opacity 1.6s cubic-bezier(0.4, 0, 0.2, 1), visibility 1.6s;
}

.loading.is-done {
  opacity: 0;
  visibility: hidden;
}

.loading__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.loading__ring {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(217, 179, 108, 0.18);
  border-top-color: rgba(217, 179, 108, 0.95);
  animation: spin 1.1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading__label {
  font-size: 10px;
  letter-spacing: 0.42em;
  color: rgba(238, 233, 222, 0.6);
  max-width: 70vw;
  text-align: center;
  line-height: 1.8;
}

.loading__label.is-error {
  color: #ff9d92;
  letter-spacing: 0.02em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  max-width: 82vw;
}

.loading__bar {
  width: 168px;
  height: 1px;
  background: rgba(238, 233, 222, 0.12);
  overflow: hidden;
}

.loading__bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(217, 179, 108, 0.1), rgba(217, 179, 108, 0.95));
  transition: width 0.4s ease;
}

@media (max-width: 720px) {
  .hud { padding: 18px 18px 22px; }
  .hud__title { max-width: none; width: 100%; }
  .hud__hint { display: none; }
  .hud__title .desc { font-size: 11px; }
}

/* A lightweight static landscape remains available when 3D cannot run. */
.loading.is-failed {
  transition: none;
  opacity: 1;
  visibility: visible;
  background:
    radial-gradient(circle at 24% 28%, #f1d49a 0 3%, transparent 15%),
    radial-gradient(ellipse at 25% 120%, #263c30 0 46%, transparent 46.5%),
    radial-gradient(ellipse at 80% 110%, #435643 0 48%, transparent 48.5%),
    linear-gradient(#283642, #8e9993 58%, #344937 59%);
}
.is-failed .loading__inner {
  padding: 28px;
  margin: 20px;
  border-radius: 12px;
  background: rgba(6, 8, 10, 0.78);
}
.is-failed .loading__ring,
.is-failed .loading__bar,
.scene-failed .hud,
.scene-failed .grain { display: none; }
#retry {
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 10px 24px;
  cursor: pointer;
  font: inherit;
}
#retry:focus-visible { outline: 2px solid var(--paper); outline-offset: 4px; }
.low-quality .grain { display: none; }

.is-night .grain { opacity: 0.012; }

.music-toggle {
  position:fixed;top:clamp(20px,3.2vw,46px);right:clamp(20px,3.6vw,60px);
  z-index:5;border:1px solid rgba(242,237,227,.25);border-radius:20px;
  padding:7px 13px;background:rgba(11,13,16,.25);color:rgba(242,237,227,.8);
  font-family:inherit;font-size:11px;line-height:1.4;cursor:pointer;backdrop-filter:blur(8px);
}
.music-toggle:focus-visible{outline:2px solid var(--gold);outline-offset:4px;}
.music-toggle[hidden]{display:none;}
@media(max-width:720px){.music-toggle{top:15px;right:18px;}}

/* Center hint asking for the first click that unlocks the background music. */
.sound-hint {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  padding: 14px 26px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(10, 14, 12, 0.52);
  color: rgba(255, 255, 255, 0.86);
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.65);
  font-size: 15px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  white-space: nowrap;
  pointer-events: none;
  /* the one-shot intro is listed last so it wins while it runs, then hands
     opacity back to the idle pulse */
  animation: sound-hint-pulse 3.2s ease-in-out infinite, sound-hint-in 0.5s ease-out;
  transition: opacity 0.45s ease;
}
@keyframes sound-hint-in {
  from { opacity: 0; transform: translate(-50%, -46%); }
  to { opacity: 0.72; transform: translate(-50%, -50%); }
}
.sound-hint[hidden] { display: none; }
@keyframes sound-hint-pulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}
@media (max-width: 720px) {
  .sound-hint { font-size: 13px; padding: 12px 18px; letter-spacing: 0.16em; }
}
