/* World experience styles: full-viewport canvas, overlays, HUD, touch, fallback. */

.world-body {
  background: var(--night-deep);
  overflow: hidden;
  height: 100dvh;
}

.world-body.world-mode--open {
  overflow: auto;
}

#world-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  /* Above the accessible fallback (z:10) but under HUD (z:30) and overlays (z:40). */
  z-index: 20;
}

/* --- Overlays ----------------------------------------------------------- */

.world-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: var(--night-deep);
  color: var(--night-text);
  transition: opacity var(--medium) var(--ease), visibility var(--medium) var(--ease);
}

/* --- Accessibility: WCAG AA text contrast on the dark world surfaces ---- */
.world-body .skip-link { background: var(--night-raised); color: var(--night-text); }
.world-welcome .btn--ghost { color: var(--night-text); border-color: var(--night-rule); }
.world-welcome .btn--ghost:hover { color: var(--accent-bright); border-color: var(--accent-bright); }
.world-fallback .label { color: var(--night-muted); }
.world-fallback .muted { color: var(--night-muted); }
.world-fallback .meta { color: var(--night-muted); }
.world-fallback .entry__title { color: var(--night-text); }
.world-fallback .btn--quiet { color: var(--accent-bright); }
.world-hud__brand { color: var(--night-text); }
.world-hud__progress { color: var(--accent-bright); }

@media (prefers-reduced-motion: reduce) {
  .world-loading__title { transition: none; }
  .world-progress { transition: none; }
}

.world-overlay[data-state="hidden"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.world-loading__inner {
  text-align: center;
  display: grid;
  gap: var(--space-s);
  justify-items: center;
}

.world-loading__title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  margin: 0;
}

.world-progress {
  width: min(18rem, 70vw);
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--night-rule);
  overflow: hidden;
}

.world-progress__bar {
  width: 0%;
  height: 100%;
  background: var(--accent-bright);
  transition: width 200ms var(--ease);
}

.world-loading__note {
  font-size: var(--step--1);
  color: var(--night-muted);
  margin: 0;
}

/* --- Welcome ------------------------------------------------------------ */

.world-welcome {
  max-width: 34rem;
  background: var(--night-raised);
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-m);
  padding: var(--space-l);
  display: grid;
  gap: var(--space-s);
  text-align: center;
}

.world-welcome__eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-bright);
  margin: 0;
}

.world-welcome__heading {
  font-family: var(--font-display);
  font-size: var(--step-3);
  line-height: 1.25;
  margin: 0;
}

.world-welcome__body {
  color: var(--night-muted);
  font-size: var(--step--1);
  line-height: 1.6;
  margin: 0;
}

.world-controls-help {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-xs) var(--space-m);
  text-align: left;
  padding: var(--space-s);
  background: var(--night);
  border-radius: var(--radius-m);
}

.world-controls-help__label {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--night-muted);
}

.world-controls-help__keys {
  margin: 0.2rem 0 0;
  font-size: var(--step--1);
  color: var(--night-text);
}

kbd {
  display: inline-block;
  min-width: 1.4rem;
  text-align: center;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-s);
  background: var(--night-raised);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.world-welcome__note {
  font-size: var(--step--1);
  color: var(--night-muted);
  margin: 0;
}

.world-welcome__note a {
  color: var(--accent-bright);
}

/* --- HUD ----------------------------------------------------------------- */

.world-hud {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: none;
}

.world-hud[data-state="visible"] {
  display: block;
}

.world-hud__top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  padding: 0.7rem clamp(0.8rem, 3vw, 1.6rem);
}

.world-hud__brand {
  pointer-events: auto;
  color: var(--night-text);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--step--1);
  background: color-mix(in srgb, var(--night-deep) 82%, transparent);
  border: 1px solid var(--night-rule);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-m);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 9.5rem;
}

.world-hud__brand:hover {
  color: var(--accent-bright);
}

.world-hud__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  pointer-events: auto;
}

.world-hud__progress {
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--accent-bright);
  background: color-mix(in srgb, var(--night-deep) 82%, transparent);
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-m);
  padding: 0.45rem 0.7rem;
}

.world-hud__button {
  font-size: var(--step--1);
  color: var(--night-muted);
  background: color-mix(in srgb, var(--night-deep) 82%, transparent);
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-m);
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

.world-hud__button:hover,
.world-hud__button[aria-pressed="true"] {
  color: var(--night-text);
  border-color: var(--accent-bright);
}

/* --- Map ----------------------------------------------------------------- */

.world-map {
  position: absolute;
  top: 3.6rem;
  right: clamp(0.8rem, 3vw, 1.6rem);
  width: min(320px, 76vw);
  height: auto;
  background: color-mix(in srgb, var(--night-deep) 88%, transparent);
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-m);
  pointer-events: auto;
}

.world-map[hidden] {
  display: none;
}

/* --- Destination panel ---------------------------------------------------- */

.world-panel {
  position: absolute;
  left: 50%;
  bottom: clamp(1rem, 4vw, 2.4rem);
  transform: translate(-50%, 0);
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(24rem, 62vh);
  overflow-y: auto;
  background: color-mix(in srgb, var(--night-raised) 94%, transparent);
  border: 1px solid var(--night-rule);
  border-radius: var(--radius-m);
  padding: var(--space-m);
  color: var(--night-text);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  transition: opacity var(--medium) var(--ease), transform var(--medium) var(--ease);
}

.world-panel[data-state="hidden"] {
  opacity: 0;
  transform: translate(-50%, 1rem);
  pointer-events: none;
}

.world-panel__close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--night-rule);
  background: var(--night);
  color: var(--night-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.world-panel__close:hover {
  color: var(--night-text);
  border-color: var(--accent-bright);
}

.world-panel__eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-bright);
  margin: 0 0 0.35rem;
}

.world-panel__title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1.25;
  margin: 0 0 var(--space-s);
}

.world-panel__body {
  font-size: var(--step--1);
  line-height: 1.6;
  color: var(--night-muted);
}

.world-panel__body p {
  margin-bottom: 0.6rem;
}

.world-panel__body h3 {
  font-family: var(--font-display);
  font-size: var(--step-0);
  color: var(--night-text);
  margin: 0.8rem 0 0.3rem;
}

.world-panel__body ul {
  padding-left: 1.1rem;
  margin: 0.4rem 0;
}

.world-panel__image {
  width: 100%;
  border-radius: var(--radius-s);
  border: 1px solid var(--night-rule);
  margin-bottom: var(--space-s);
}

.world-panel__collectible {
  font-size: var(--step--1);
  color: var(--accent-bright);
  margin: 0.6rem 0;
}

.world-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: var(--space-s);
}

/* --- Touch controls -------------------------------------------------------- */

.world-touch {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 1.2rem calc(1.2rem + env(safe-area-inset-bottom));
  pointer-events: none;
}

.world-touch[hidden] {
  display: none;
}

.world-joystick {
  position: relative;
  width: 7.5rem;
  height: 7.5rem;
  border-radius: 50%;
  border: 1px solid var(--night-rule);
  background: color-mix(in srgb, var(--night-deep) 70%, transparent);
  pointer-events: auto;
  touch-action: none;
}

.world-joystick__stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
  background: var(--accent-bright);
  transform: translate(-50%, -50%);
}

.world-touch__actions {
  display: grid;
  gap: 0.5rem;
  justify-items: stretch;
  pointer-events: auto;
}

.world-touch__button {
  min-width: 5.4rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-m);
  border: 1px solid var(--night-rule);
  background: color-mix(in srgb, var(--night-deep) 78%, transparent);
  color: var(--night-text);
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.world-touch__button:active {
  border-color: var(--accent-bright);
  color: var(--accent-bright);
}

/* --- Fallback (accessible, always in DOM) ----------------------------------- */

.world-fallback {
  position: relative;
  z-index: 10;
  padding-block: var(--space-xl);
  background: var(--night-deep);
  color: var(--night-text);
  min-height: 100dvh;
}

.world-fallback h2 {
  color: var(--night-text);
}

.world-fallback .entry {
  border-bottom-color: var(--night-rule);
}

.world-fallback .entry__title a,
.world-fallback .entry__title {
  color: var(--night-text);
}

.world-fallback .entry__body {
  color: var(--night-muted);
}

.world-fallback .entry__body a {
  color: var(--accent-bright);
}

.world-fallback .btn--quiet {
  color: var(--accent-bright);
}

/* --- Accessibility: WCAG AA text contrast on the dark world surfaces ---- */
.world-body .skip-link { background: var(--night-raised); color: var(--night-text); }
.world-welcome .btn--ghost { color: var(--night-text); border-color: var(--night-rule); }
.world-welcome .btn--ghost:hover { color: var(--accent-bright); border-color: var(--accent-bright); }
.world-fallback .label { color: var(--night-muted); }
.world-fallback .muted { color: var(--night-muted); }
.world-fallback .meta { color: var(--night-muted); }
.world-fallback .entry__title { color: var(--night-text); }
.world-fallback .btn--quiet { color: var(--accent-bright); }
.world-hud__brand { color: var(--night-text); }
.world-hud__progress { color: var(--accent-bright); }

/* --- Reduced motion ----------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .world-overlay,
  .world-panel {
    transition: none;
  }
}
