: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 */
#entry {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(ellipse at 50% 40%, rgba(42, 33, 24, 0.55), rgba(42, 33, 24, 0.9));
  transition: opacity 0.9s; z-index: 5;
}
#entry.gone { opacity: 0; pointer-events: none; }
.entry-card { text-align: center; max-width: 360px; }
#entry-img {
  width: 132px; height: 166px; object-fit: cover; border-radius: 8px; border: 3px solid var(--gold);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
}
.entry-card h1 { font-family: var(--serif); font-weight: 500; font-size: 1.9rem; margin: 18px 0 6px; letter-spacing: 0.01em; }
#entry-tagline { margin: 0 0 22px; opacity: 0.9; }
#who { display: inline-flex; gap: 4px; padding: 4px; margin: 0 0 16px; border-radius: 999px; background: rgba(246, 238, 221, 0.12); border: 1px solid rgba(246, 238, 221, 0.25); }
#who button { padding: 7px 20px; border-radius: 999px; border: 0; background: transparent; font-size: 0.92rem; letter-spacing: 0.02em; }
#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: 18px 0 0; font-size: 0.8rem; opacity: 0.7; }

/* 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: 41px; padding: 6px 2px 5px; }
  #actions .lbl { font-size: 0.58rem; }
  #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; }
}
