:root {
  --ink: #2a2118;
  --cream: #f6eedd;
  --ochre: #a8432b;
  --gold: #c9962f;
  --panel: rgba(42, 33, 24, 0.62);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--cream); font-family: var(--sans); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }

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

#hud-top {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(12px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
  pointer-events: none;
}
.brand { display: flex; flex-direction: column; gap: 2px; text-shadow: 0 1px 6px rgba(30, 20, 10, 0.65); }
#title { font-family: var(--serif); font-size: 1.15rem; letter-spacing: 0.02em; }
#count { font-size: 0.8rem; opacity: 0.92; }
.top-actions { display: flex; gap: 8px; pointer-events: auto; }
.top-actions button {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(246, 238, 221, 0.35);
  background: var(--panel); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); font-size: 1rem;
}
#player {
  display: flex; align-items: center; gap: 9px; margin-top: 8px; padding: 6px 12px 6px 6px; width: min(290px, calc(100vw - 130px));
  background: var(--panel); border: 1px solid rgba(246, 238, 221, 0.22); border-radius: 22px; pointer-events: auto;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); text-shadow: none;
}
#pl-toggle { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--ochre); color: #fff6e6; font-size: 0.8rem; line-height: 1; }
.pl-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
#pl-title { font-size: 0.74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-row { display: flex; align-items: center; gap: 7px; }
#pl-seek { flex: 1 1 auto; min-width: 0; height: 14px; margin: 0; accent-color: var(--gold); }
#pl-time { flex: 0 0 auto; font-size: 0.66rem; opacity: 0.85; font-variant-numeric: tabular-nums; }
#pl-credit { font-size: 0.68rem; color: #f0d08a; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pl-credit:empty { display: none; }
#info a { color: #f0d08a; }
#player.failed #pl-toggle, #player.failed .pl-row { display: none; }
#player.failed { padding: 7px 12px; }
#btn-info { font-family: var(--serif); font-style: italic; font-size: 1.1rem; }

#status {
  position: fixed; top: calc(134px + env(safe-area-inset-top)); left: 0; right: 0; text-align: center;
  font-size: 0.85rem; letter-spacing: 0.04em; text-shadow: 0 1px 6px rgba(30, 20, 10, 0.7); pointer-events: none;
}
#hint {
  position: fixed; left: 0; right: 0; bottom: calc(92px + env(safe-area-inset-bottom)); margin: 0; text-align: center;
  font-size: 0.78rem; opacity: 0.85; text-shadow: 0 1px 5px rgba(30, 20, 10, 0.8); pointer-events: none; padding: 0 12px;
}
#darshan-caption {
  position: fixed; left: 0; right: 0; bottom: calc(104px + env(safe-area-inset-bottom)); text-align: center;
  font-family: var(--serif); font-size: 1.25rem; letter-spacing: 0.03em; text-shadow: 0 1px 8px rgba(20, 12, 6, 0.9);
  opacity: 0; transition: opacity 0.8s; pointer-events: none; padding: 0 16px;
}
body.darshan #darshan-caption { opacity: 1; }
body.darshan #hint { opacity: 0; }

#toast {
  position: fixed; left: 50%; top: 22%; transform: translateX(-50%); background: var(--panel); padding: 8px 14px;
  border-radius: 999px; font-size: 0.85rem; opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
#toast.show { opacity: 1; }

#actions {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 6px; padding: 6px;
  max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none;
  background: var(--panel); border: 1px solid rgba(246, 238, 221, 0.22); border-radius: 18px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#actions::-webkit-scrollbar { display: none; }
#actions button {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 60px; padding: 7px 8px 6px;
  border: 0; border-radius: 13px; background: transparent; transition: background 0.15s, transform 0.1s;
}
#actions button:hover { background: rgba(246, 238, 221, 0.14); }
#actions button:active { transform: scale(0.94); background: rgba(246, 238, 221, 0.22); }
#actions .ico { font-size: 1.35rem; line-height: 1.2; }
#actions .lbl { font-size: 0.7rem; letter-spacing: 0.03em; }

/* entry: welcome on one side, a guide to the temple on the other */
#entry {
  position: fixed; inset: 0; display: flex; padding: 24px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 40%, rgba(36, 28, 20, 0.8), rgba(30, 23, 16, 0.95));
  transition: opacity 0.9s; z-index: 5;
}
#entry.gone { opacity: 0; pointer-events: none; }
/* the temple's own controls stay out of sight until the visitor has entered */
body.pre-entry #hud-top, body.pre-entry #actions, body.pre-entry #hint, body.pre-entry #status { opacity: 0; pointer-events: none; }
#hud-top, #actions, #hint { transition: opacity 0.9s; }
.entry-wrap {
  margin: auto; width: 100%; max-width: 1000px; display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 36px; align-items: center;
}
.entry-card { text-align: center; }
#entry-portraits { display: flex; justify-content: center; gap: 22px; margin: 0 0 12px; }
#entry-portraits figure { margin: 0; width: 150px; }
#entry-portraits img {
  width: 112px; height: 142px; object-fit: cover; object-position: center top; border-radius: 8px; border: 3px solid var(--gold);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5); background: rgba(0, 0, 0, 0.3);
}
#entry-portraits figcaption b { display: block; margin-top: 7px; font-family: var(--serif); font-weight: 500; font-size: 1rem; }
#entry-portraits figcaption span { display: block; font-family: var(--serif); font-style: italic; font-size: 0.88rem; color: #e9cf96; }
.entry-card h1 { font-family: var(--serif); font-weight: 500; font-size: 1.85rem; margin: 0 0 12px; letter-spacing: 0.01em; }
#entry-intro { margin: 0 auto 12px; max-width: 34ch; font-size: 0.92rem; line-height: 1.55; opacity: 0.92; }
#entry-halls {
  margin: 0 auto 16px; max-width: 36ch; padding: 9px 12px; font-size: 0.86rem; line-height: 1.5; border-radius: 12px;
  background: rgba(201, 150, 47, 0.13); border: 1px solid rgba(201, 150, 47, 0.4);
}
#entry-halls b { font-weight: 600; color: #f6e3b4; }
.guide-cards div span span { display: inline; font-size: inherit; opacity: 1; color: #f6e3b4; }
.entry-attire {
  margin: 0 0 16px; padding: 12px 14px 14px; border-radius: 14px; background: rgba(246, 238, 221, 0.06);
  border: 1px solid rgba(201, 150, 47, 0.32);
}
.entry-attire h2, .entry-guide h2 { font-family: var(--serif); font-weight: 500; font-size: 1.08rem; margin: 0 0 4px; color: #f0d08a; letter-spacing: 0.02em; }
.entry-attire p { margin: 0 0 10px; font-size: 0.82rem; line-height: 1.5; opacity: 0.9; }
#who { display: inline-flex; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(246, 238, 221, 0.1); border: 1px solid rgba(246, 238, 221, 0.22); }
#who button { display: flex; flex-direction: column; align-items: center; min-width: 104px; padding: 6px 16px; border-radius: 12px; border: 0; background: transparent; line-height: 1.25; }
#who button b { font-weight: 500; font-size: 0.95rem; letter-spacing: 0.02em; }
#who button span { font-size: 0.7rem; opacity: 0.75; }
#who button[aria-checked="true"] { background: var(--cream); color: var(--ink); }
#enter {
  display: block; margin: 0 auto; padding: 13px 30px; border-radius: 999px; border: 0; background: var(--ochre); color: #fff6e6;
  font-size: 1.02rem; letter-spacing: 0.03em; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
#enter:hover { filter: brightness(1.1); }
.entry-note { margin: 12px 0 0; font-size: 0.78rem; opacity: 0.7; }

.entry-guide { padding-left: 34px; border-left: 1px solid rgba(201, 150, 47, 0.3); }
.entry-guide h2 { font-size: 1.25rem; }
.guide-lead { margin: 0 0 14px; font-size: 0.86rem; line-height: 1.5; opacity: 0.88; }
.guide-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.guide-cards li {
  display: flex; align-items: flex-start; gap: 11px; padding: 10px 12px; border-radius: 14px;
  background: rgba(246, 238, 221, 0.07); border: 1px solid rgba(201, 150, 47, 0.3);
}
.g-ico {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem;
  background: rgba(201, 150, 47, 0.16); border: 1px solid rgba(201, 150, 47, 0.55);
}
.guide-cards li.wide { grid-column: 1 / -1; }
.guide-cards b { display: block; font-family: var(--serif); font-weight: 500; font-size: 1rem; color: #f6e3b4; margin-bottom: 1px; }
.guide-cards div span { display: block; font-size: 0.79rem; line-height: 1.42; opacity: 0.88; }
.guide-foot { margin: 12px 0 0; font-size: 0.78rem; opacity: 0.75; line-height: 1.45; }
.guide-foot + .guide-foot { margin-top: 6px; }

@media (max-width: 860px) {
  #entry { padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
  .entry-wrap { grid-template-columns: 1fr; gap: 22px; max-width: 460px; }
  .entry-guide { padding: 20px 0 0; border-left: 0; border-top: 1px solid rgba(201, 150, 47, 0.3); text-align: center; }
  .guide-cards { grid-template-columns: 1fr; text-align: left; }
  #entry-portraits { gap: 12px; }
  #entry-portraits img { width: 96px; height: 122px; }
  .entry-card h1 { font-size: 1.6rem; }
}

/* japa: prayer card in one corner, mala in the other, temple still in view */
#japa {
  position: fixed; left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right));
  bottom: calc(96px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  pointer-events: none; z-index: 4;
}
#japa > * { pointer-events: auto; }
.prayer-card {
  width: min(300px, calc(100vw - 190px)); padding: 14px 16px 12px; text-align: center; color: #3a2a17;
  background: linear-gradient(180deg, #fbf3df, #f1e2bd); border: 1px solid #c9962f; border-radius: 10px;
  box-shadow: 0 0 0 4px rgba(251, 243, 223, 0.55), 0 10px 28px rgba(20, 12, 6, 0.45);
}
#japa-mantra { font-family: var(--serif); font-size: 1.22rem; line-height: 1.45; margin: 0 0 8px; color: #7a2a17; white-space: pre-line; }
#japa-rounds { margin: 0 0 2px; font-size: 0.82rem; }
.japa-help { margin: 0 0 10px; font-size: 0.72rem; opacity: 0.75; }
.japa-btns { display: flex; gap: 8px; justify-content: center; }
.japa-btns button { padding: 6px 13px; border-radius: 999px; border: 1px solid rgba(58, 42, 23, 0.45); background: transparent; color: #3a2a17; font-size: 0.8rem; }
.japa-btns button:hover { background: rgba(58, 42, 23, 0.1); }
#japa-tap {
  position: relative; flex: 0 0 auto; width: min(190px, 40vw); aspect-ratio: 1; padding: 8px; border-radius: 50%;
  border: 1px solid rgba(201, 150, 47, 0.6); background: rgba(42, 33, 24, 0.78);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 10px 28px rgba(20, 12, 6, 0.45);
}
#japa-tap:active { transform: scale(0.97); }
#japa-ring { width: 100%; height: 100%; display: block; }
.bead { fill: #7a5f3c; transition: fill 0.2s; }
.bead.done { fill: var(--gold); }
.bead.cur { fill: #fff3d6; r: 7px; }
#japa-count { position: absolute; left: 0; right: 0; top: 31%; font-family: var(--serif); font-size: 2.5rem; line-height: 1; }
.japa-of { position: absolute; left: 0; right: 0; top: 60%; font-size: 0.72rem; opacity: 0.75; }
body.japa-open #hint, body.japa-open #darshan-caption { opacity: 0; }
#info button {
  padding: 8px 16px; border-radius: 999px; border: 1px solid rgba(246, 238, 221, 0.4); background: transparent;
}
#info button:hover { background: rgba(246, 238, 221, 0.12); }

/* info */
#info {
  max-width: min(440px, calc(100vw - 32px)); background: #2f251b; color: var(--cream); border: 1px solid rgba(201, 150, 47, 0.5);
  border-radius: 16px; padding: 20px 22px; -webkit-user-select: text; user-select: text;
}
#info::backdrop { background: rgba(20, 14, 8, 0.6); }
#info h2 { font-family: var(--serif); font-weight: 500; margin: 0 0 8px; }
#info h3 { font-size: 0.9rem; margin: 14px 0 4px; color: #e6c27a; letter-spacing: 0.04em; }
#info p { margin: 0 0 6px; font-size: 0.9rem; line-height: 1.5; }
#info button { margin-top: 12px; }

#nogl { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 30px; text-align: center; z-index: 9; }

@media (max-width: 520px) {
  #title { font-size: 1rem; }
  #actions { gap: 2px; padding: 5px; }
  #actions button { min-width: 37px; padding: 6px 1px 5px; }
  #actions .lbl { font-size: 0.54rem; }
  #actions .ico { font-size: 1.2rem; }
  #hint { font-size: 0.7rem; }
  .prayer-card { padding: 10px 10px 9px; }
  #japa-mantra { font-size: 1rem; }
  #japa-count { font-size: 1.9rem; }
}
