/* Circle of Circles — VR Edition */

/* ॐ only: subset of Noto Serif Devanagari (SIL Open Font License, see /assets/fonts/OFL-NotoSerifDevanagari.txt) */
@font-face { font-family: 'Om Symbol'; font-style: normal; font-weight: 400; font-display: swap; src: url(/assets/fonts/om-symbol.woff2) format('woff2'); unicode-range: U+0950; }
/* EB Garamond (SIL Open Font License, see /assets/fonts/OFL.txt), latin + latin-ext subsets */
@font-face { font-family: 'EB Garamond'; font-style: italic; font-weight: 400 800; font-display: swap; src: url(/assets/fonts/ebgaramond-italic-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'EB Garamond'; font-style: italic; font-weight: 400 800; font-display: swap; src: url(/assets/fonts/ebgaramond-italic-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'EB Garamond'; font-style: normal; font-weight: 400 800; font-display: swap; src: url(/assets/fonts/ebgaramond-normal-latin-ext.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'EB Garamond'; font-style: normal; font-weight: 400 800; font-display: swap; src: url(/assets/fonts/ebgaramond-normal-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  --bg: #161616;
  --panel: rgba(16, 16, 16, 0.82);
  --panel-solid: #1c1c1c;
  --fg: #f2f2f2;
  --muted: #b5b5b5;
  --accent: #e3af00;
  --accent-ink: #1a1400;
  --line: rgba(255, 255, 255, 0.14);
  --radius: 10px;
  --tap: 44px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: 'EB Garamond', 'Om Symbol', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); }
body { overflow: hidden; -webkit-text-size-adjust: 100%; }
button, select { font: inherit; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--panel); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.toolbar .brand { font-weight: 600; letter-spacing: .02em; white-space: nowrap; margin-right: 4px; }
.toolbar .brand a { color: inherit; text-decoration: none; }
.toolbar .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }

.pager { display: flex; align-items: center; gap: 6px; }
#page-label { min-width: 9.5em; max-width: 26em; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar.is-loading #page-label::after { content: ' …'; }

.btn, .toolbar select {
  min-height: var(--tap); min-width: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06); color: var(--fg); cursor: pointer;
  transition: background .15s ease;
}
.btn:hover, .toolbar select:hover { background: rgba(255, 255, 255, 0.12); }
.btn:focus-visible, .toolbar select:focus-visible, .modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #f4c020; }
.btn.icon { padding: 0; font-weight: 600; }
.toolbar select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23f2f2f2' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  max-width: 260px; text-overflow: ellipsis;
}
.toolbar .spacer { flex: 1; }

.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: rgba(255,255,255,.08); }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

/* Offline panel lives in the help dialog on small screens and in the bar on large */
.offline { display: flex; flex-direction: column; gap: 6px; }
.offline .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.offline .bar { width: 100%; height: 6px; border-radius: 3px; background: rgba(255,255,255,.1); overflow: hidden; }
.offline .bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.offline .status { color: var(--muted); font-size: .95em; }

/* ── Scene ────────────────────────────────────────────────────────────────── */
a-scene { position: fixed; inset: 0; }
.a-enter-vr, .a-enter-ar { bottom: max(14px, env(safe-area-inset-bottom)) !important; right: 14px !important; z-index: 15 !important; }

body.in-vr .toolbar, body.in-vr .modal, body.in-vr .toast, body.in-vr .textmode { display: none !important; }
body.text-mode .toolbar { visibility: hidden; }

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.loading {
  position: fixed; inset: 0; z-index: 100; background: var(--bg); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center; padding: 24px;
  transition: opacity .8s ease; opacity: 1;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading.error .line-frame { display: none; }
.loading p small { display: block; margin-top: 8px; font-size: 14px; }
.loading code { background: rgba(255,255,255,.08); padding: 1px 6px; border-radius: 4px; }
.loading-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.loading-actions[hidden] { display: none; }
.loading .btn { text-decoration: none; display: inline-flex; align-items: center; }
.loading h1 { font-weight: 300; font-size: clamp(22px, 4vw, 34px); margin: 0; letter-spacing: .04em; }
.loading p { margin: 0; color: var(--muted); }
.loading .line-frame { width: min(320px, 70vw); height: 1px; overflow: hidden; position: relative; margin-top: 10px; }
.loading .line { position: absolute; inset: 0; background: rgba(255,255,255,.6); animation: loader 2s cubic-bezier(.4,.1,.2,1) infinite; }
@keyframes loader { 0% { transform: translateX(-100%); } 48%, 52% { transform: translateX(0); } 100% { transform: translateX(100%); } }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 22px 22px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-card h2 { margin: 0 32px 4px 0; font-weight: 600; font-size: 1.25em; }
.modal-card h3 { margin: 18px 0 6px; font-size: .85em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.modal-card p { margin: 6px 0; line-height: 1.5; }
.modal-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.modal-card dt { color: var(--muted); }
.modal-card dd { margin: 0; }
.modal-card a { color: var(--accent); }
.modal-close {
  position: absolute; top: 10px; right: 10px; width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: rgba(255,255,255,.08); color: var(--fg); font-size: 20px; cursor: pointer;
}
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.modal-card.narrow { width: min(420px, 100%); }
.modal-card .muted { color: var(--muted); font-size: .95em; }
.modal-card .btn { text-decoration: none; display: inline-flex; align-items: center; }

/* ── Segmented controls (settings) ───────────────────────────────────────── */
.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  flex: 1; min-height: var(--tap); border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--fg);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--serif);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.segmented .swatch { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(128,128,128,.6); }
[data-theme] { font-family: var(--font); }

/* ── Text mode ───────────────────────────────────────────────────────────── */
.textmode { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; --tm-bg: #f7f3ea; --tm-fg: #1d1b18; --tm-muted: #6d665b; background: var(--tm-bg); color: var(--tm-fg); }
.textmode[hidden] { display: none; }
.textmode[data-theme="sepia"] { --tm-bg: #efe2c6; --tm-fg: #3a2e21; --tm-muted: #7d6a52; }
.textmode[data-theme="night"] { --tm-bg: #141414; --tm-fg: #d9d3c7; --tm-muted: #8d877c; }
.tm-bar { display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid rgba(128,128,128,.25); background: var(--tm-bg); }
.tm-bar h2 { flex: 1; margin: 0; font: 600 17px/1.2 var(--font); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-bar .btn { color: var(--tm-fg); border-color: rgba(128,128,128,.4); background: transparent; }
.tm-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tm-body { max-width: 36em; margin: 0 auto; padding: 32px 22px 96px; font-family: var(--serif); font-size: 21px; line-height: 1.6; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.textmode[data-size="s"] .tm-body { font-size: 18px; }
.textmode[data-size="l"] .tm-body { font-size: 24px; }
.textmode[data-size="xl"] .tm-body { font-size: 28px; }
.tm-body p { margin: 0; text-indent: 1.4em; }
.tm-body p.ni { text-indent: 0; }
.tm-body p.a-c { text-align: center; text-indent: 0; }
.tm-body p.a-r { text-align: right; text-indent: 0; }
.tm-body p.a-l { text-align: left; }
.tm-body p.in-1 { margin: 0 2em; } .tm-body p.in-2 { margin: 0 4em; } .tm-body p.in-3 { margin: 0 5em; }
.tm-body h2, .tm-body h3, .tm-body h4 { font-weight: 400; text-align: center; line-height: 1.25; margin: 2.2em 0 1.2em; }
.tm-body .bold { font-weight: 600; }
.tm-body .ruled { margin-left: 10%; margin-right: 10%; padding: .5em 0; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; }
.tm-body h2 { font-size: 1.55em; } .tm-body h3 { font-size: 1.25em; } .tm-body h4 { font-size: 1.1em; }
.tm-body > :first-child { margin-top: .6em; }
.tm-body .tm-break { text-align: center; text-indent: 0; margin: 1em 0; letter-spacing: .6em; }
.tm-body .tm-space { height: 1.6em; }
.tm-body img { display: block; max-width: 100%; height: auto; margin: 1em auto; }
.tm-body img.small { max-width: 50%; }
.tm-body .sc { font-variant: small-caps; }
.tm-body sup, .tm-body sub { font-size: .65em; line-height: 0; }

.toast {
  position: fixed; left: 50%; bottom: max(80px, calc(env(safe-area-inset-bottom) + 80px)); transform: translateX(-50%);
  z-index: 60; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; max-width: min(92vw, 520px); text-align: center;
}
.toast[hidden] { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .toolbar { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .toolbar .brand, .toolbar .spacer { display: none; }
  .toolbar select { flex: 1 1 calc(50% - 3px); min-width: 0; max-width: none; }
  .pager { order: 10; flex: 1 1 0%; min-width: 0; justify-content: space-between; }
  #page-label { flex: 1; min-width: 0; max-width: none; font-size: 15px; }
  #btn-settings, #btn-help { order: 11; }
  .hide-mobile { display: none !important; }
}
}
@media (min-width: 761px) {
  .only-mobile { display: none !important; }
}

/* ── Fallback (no WebGL / no JS) ─────────────────────────────────────────── */
.fallback { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.fallback a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .loading, .loading .line, .progress > span, .offline .bar > span, .btn { transition: none; animation: none; }
}
