/* /madang: a walkable 3D yard. Colors come only from theme.css tokens.
 * Without JS or WebGL the page is a plain list (.fallback). With the 3D view up,
 * html gets .is-3d: the stage fills the screen and the list stays for screen readers only.
 * Controls are round "orbs" and cream glass: exit and the live count top-left, sound top-right,
 * jar shortcuts across the top, my bag of luck bottom-left, the action jar bottom-right. */

.madang-page { margin: 0; }

/* ---------- plain list (no JS / no WebGL) ---------- */
.fallback {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 48px var(--gutter) 64px;
}
.fallback h1 { font-size: var(--fs-h2); font-weight: var(--weight-title); letter-spacing: var(--tracking-title); line-height: 1.2; }
.fallback .sub { margin-top: 8px; color: var(--color-ink-soft); font-size: var(--fs-sub); }
.danji-list { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 12px; }
.danji-list li { padding: 16px; border: 1px solid var(--color-line); border-radius: 16px; background: var(--color-surface); }
.danji-list h2 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.danji-list h2::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--tone, var(--color-ink-soft)); }
.danji-list p + p { margin-top: 4px; }
[data-accent="amber"] { --tone: var(--color-amber); }
[data-accent="leaf"] { --tone: var(--scene-pine); }
[data-accent="ink"] { --tone: var(--color-ink); }

.is-3d .fallback {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  padding: 0;
}
.is-3d .madang-page { overflow: hidden; overscroll-behavior: none; }

/* ---------- stage ---------- */
.stage {
  position: fixed;
  inset: 0;
  background: var(--scene-fog);
  touch-action: none;
  cursor: grab;
}
.stage.is-dragging { cursor: grabbing; }
.stage canvas { display: block; width: 100%; height: 100%; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--color-bg);
  color: var(--color-ink-soft);
  transition: opacity var(--dur-section) ease;
}
.loading.is-done { opacity: 0; pointer-events: none; }

/* ---------- top: orbs, live count, jar shortcuts ---------- */
.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
.hud-left {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
}
.hud-right {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}
/* Bokjori (a lucky straw scoop): the one bokchae entry. */
.bokjori svg { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.bokjori .bj-body { fill: var(--scene-straw); stroke: var(--scene-straw-deep); stroke-width: 1.4; }
.bokjori .bj-handle { fill: var(--scene-straw-deep); }
.bokjori .bj-weave { stroke: var(--scene-straw-deep); stroke-width: 1; opacity: 0.7; }
.bokjori .bj-tie { stroke: var(--color-vermilion); stroke-width: 2.2; }
.bokjori:hover svg { transform: rotate(-8deg); transition: transform 200ms ease; }

.orb {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--scene-ui-glass);
  color: var(--color-ink);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(var(--nav-blur));
  cursor: pointer;
}
.orb img { width: 28px; height: 28px; }
.orb svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.orb .mute { display: inline; }
.orb .wave { display: none; }
.orb[aria-pressed="true"] .mute { display: none; }
.orb[aria-pressed="true"] .wave { display: inline; }

.presence {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-glass);
  box-shadow: var(--shadow-soft);
  font-size: 13px;
  font-weight: var(--weight-title);
}
.presence i { width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent-green); }

.travel {
  pointer-events: auto;
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  max-width: calc(100% - 140px);
  padding: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-glass);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(var(--nav-blur));
}
.travel::-webkit-scrollbar { display: none; }
.travel button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-ink);
  font: inherit;
  font-size: 14px;
  font-weight: var(--weight-title);
  white-space: nowrap;
  cursor: pointer;
}
.travel button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--color-ink-soft)); }
.travel button:hover, .travel button.is-here { background: var(--color-surface); }

.hud-hint {
  position: absolute;
  left: 50%;
  top: calc(76px + env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-veil);
  color: var(--color-on-accent);
  font-size: 13px;
  white-space: nowrap;
  transition: opacity 600ms ease;
}
.hud-hint.is-gone { opacity: 0; }

.ritual-banner {
  position: fixed;
  left: 50%;
  top: calc(120px + env(safe-area-inset-top));
  z-index: 11;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  font-weight: var(--weight-title);
  text-align: center;
}

/* ---------- over the scene: my name, the magpie's words ---------- */
.name-chip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 4px;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-glass);
  box-shadow: var(--shadow-soft);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  will-change: transform;
}
/* Other people's names: quieter than mine, no "me" dot. */
.name-chip.guest-chip {
  z-index: 8;
  padding: 2px 9px;
  font-size: 11px;
  color: var(--color-ink-soft);
  box-shadow: none;
}
.name-chip.guest-chip[hidden] {
  display: none;
}
.name-chip .me {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-vermilion);
  color: var(--color-on-accent);
  font-size: 11px;
  font-weight: var(--weight-title);
}

.bubble {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9;
  max-width: min(260px, 70vw);
  margin: 0;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  font-weight: var(--weight-title);
  line-height: 1.45;
  pointer-events: none;
  will-change: transform;
  animation: pop 260ms ease-out;
}
.bubble-host { font-weight: var(--weight-body); }
.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--color-surface);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px;
}
@keyframes pop { from { opacity: 0; scale: 0.85; } to { opacity: 1; scale: 1; } }

/* The jar's answer, floating above it. */
.oracle {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9;
  margin: 0;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--color-amber), 0 0 36px 8px var(--color-amber);
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: var(--weight-title);
  letter-spacing: var(--tracking-title);
  white-space: nowrap;
  pointer-events: none;
  will-change: transform;
  animation: oracle 3.6s ease both;
}
@keyframes oracle {
  0% { opacity: 0; scale: 0.7; }
  12% { opacity: 1; scale: 1.06; }
  20% { scale: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; scale: 1.02; }
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(76px + env(safe-area-inset-top));
  z-index: 12;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 32px);
  text-align: center;
  font-weight: var(--weight-title);
  pointer-events: none;
}
.toast:not(:empty) { padding: 8px 16px; border-radius: var(--radius-pill); background: var(--color-surface); box-shadow: var(--shadow-soft); }

.near {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  z-index: 12;
  transform: translateX(-50%);
  height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-vermilion);
  color: var(--color-on-accent);
  font: inherit;
  font-size: var(--fs-button);
  font-weight: var(--weight-button);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- bottom-left: what I gathered today ---------- */
.bag {
  position: fixed;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 10px;
  border-radius: 20px;
  background: var(--scene-ui-glass);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(var(--nav-blur));
}
.bag span { display: grid; line-height: 1.15; }
.bag small { color: var(--color-ink-soft); font-size: 11px; }
.bag strong { font-size: 22px; font-weight: var(--weight-title); }
.bag.is-bump img { animation: bump 500ms ease; }
@keyframes bump { 40% { transform: scale(1.25) rotate(-8deg); } }

/* ---------- bottom-right: the action jar ---------- */
.fab {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 13;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.fab-main {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-amber);
  color: var(--color-ink);
  font: inherit;
  font-size: 12px;
  font-weight: var(--weight-title);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform 200ms ease;
}
.fab-main svg { fill: var(--color-surface); stroke: var(--color-amber-deep); stroke-width: 1.4; margin-bottom: -6px; }
.fab-main[aria-expanded="true"] { transform: rotate(-8deg) scale(0.94); }
.fab-menu { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.fab-menu button {
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-glass);
  color: var(--color-ink);
  font: inherit;
  font-size: 15px;
  font-weight: var(--weight-title);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(var(--nav-blur));
  cursor: pointer;
  animation: slide-in 220ms ease-out both;
}
.fab-menu button:nth-child(2) { animation-delay: 40ms; }
.fab-menu button:nth-child(1) { animation-delay: 80ms; }
@keyframes slide-in { from { opacity: 0; transform: translateY(12px); } }

.orb:focus-visible, .travel button:focus-visible, .fab-main:focus-visible, .fab-menu button:focus-visible, .near:focus-visible {
  outline: 2px solid var(--color-ink);
  outline-offset: 2px;
}

/* ---------- jar panel: a side card on wide screens, a bottom card on phones ---------- */
.sheet {
  position: fixed;
  z-index: 20;
  overflow-y: auto;
  border-radius: 20px;
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  right: calc(14px + env(safe-area-inset-right));
  top: 50%;
  width: 360px;
  max-height: calc(100svh - 180px);
  transform: translateY(-50%);
  padding: 0 0 20px;
  animation: from-side var(--dur-section) ease-out;
}
.sheet::before { content: ""; display: block; height: 10px; background: var(--tone, var(--color-amber)); }
.sheet > * { margin-left: 20px; margin-right: 20px; }
.sheet h2 { margin-top: 16px; font-size: 20px; font-weight: var(--weight-title); }
.sheet .guide { color: var(--color-ink-soft); font-size: var(--fs-small); }
.sheet p + p { margin-top: 6px; }
.sheet .actions { justify-content: flex-start; margin-top: 16px; }
.sheet button:not(.btn),
.coin-row button,
.wish-list button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--color-ink);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.sheet button.sheet-close {
  position: absolute;
  top: 18px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-ink-soft);
}
.sheet button.sheet-close:hover { background: var(--color-line); color: var(--color-ink); }
.sheet button.sheet-close svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.sheet h2 { padding-right: 36px; }
.coin-row, .wish-list, .jar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sheet .jar-actions button { border-color: var(--color-amber-deep); font-weight: var(--weight-title); }
@keyframes from-side { from { opacity: 0; transform: translate(24px, -50%); } }
/* Phones: keep the yard in view. No shortcut bar (people walk to each place); the panel is a
 * slim card at the very bottom, and while it is open the bag and the action jar step aside
 * (js/madang.js also lifts the view so I stay above the card). */
@media (max-width: 760px) {
  .travel { display: none; }
  .sheet {
    left: 50%;
    right: auto;
    top: auto;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: calc(100% - 20px);
    max-height: 46svh;
    transform: translateX(-50%);
    padding-bottom: 14px;
    border-radius: 18px;
    animation-name: from-below;
  }
  .sheet::before { height: 6px; }
  .sheet > * { margin-left: 16px; margin-right: 16px; }
  .sheet h2 { margin-top: 10px; font-size: 17px; }
  .sheet button.sheet-close { top: 8px; right: 6px; }
  .sheet p { font-size: 14px; line-height: 1.45; }
  .sheet p + p { margin-top: 2px; }
  .sheet .actions { margin-top: 10px; }
  .sheet .actions .btn { min-height: 44px; }
  .coin-row, .wish-list, .jar-actions { gap: 6px; margin-top: 10px; }
  .sheet button:not(.btn), .coin-row button, .wish-list button { min-height: 40px; padding: 0 14px; font-size: 14px; }
  .jar-actions button { flex: 1 1 0; padding: 0 8px; }
  .is-sheet-open .bag, .is-sheet-open .fab, .is-sheet-open .near { display: none; }
  @keyframes from-below { from { opacity: 0; transform: translate(-50%, var(--rise)); } }
}

/* ---------- idle veil ---------- */
.idle {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--color-bg-veil);
  font-size: var(--fs-sub);
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .bubble, .oracle, .fab-menu button, .bag.is-bump img { animation: none; }
  .loading, .hud-hint, .fab-main { transition: none; }
}

/* Pavilion names above the roofs (tap to walk there). */
.place-tag {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--scene-ui-glass);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(var(--nav-blur));
  color: var(--color-ink);
  font: inherit;
  font-size: 14px;
  font-weight: var(--weight-title);
  white-space: nowrap;
  cursor: pointer;
  will-change: transform;
}
.place-tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--color-ink-soft)); }
.place-tag:focus-visible { outline: 2px solid var(--color-ink); outline-offset: 2px; }
