/* SPDX-License-Identifier: MIT */
/* Indic Library of Babel - pop-up book visuals (T9) on top of the T8 base styles.
   Parchment, charcoal ink, vignette and a decorative pop-up book whose cardstock
   layers (arches, spiral stair, silhouettes) hinge up in 3D.
   Rules:
   - Only transform and opacity are ever animated.
   - The resting style of every animated element is its final (unfolded) state;
     animations only play from the folded state, so prefers-reduced-motion simply
     switches them off and the book is shown already open.
   - Page text is never transformed and stays selectable.
   - Pure CSS; no 3D/WebGL library, no images, no third-party URLs.
   Font files are wired in by T7 (fonts/fonts.css). */

:root {
  --ink: #2a2724;          /* charcoal */
  --ink-soft: #4a443d;
  --paper: #f2e6cc;        /* parchment */
  --paper-light: #fbf4e2;
  --card: #e6d6b0;         /* cardstock */
  --card-shade: #cdb98c;
  --card-edge: #a88f60;
  --cover: #5b2f17;
  --accent: #7a3b12;
  --error: #9b1c1c;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, rgba(120, 90, 40, 0.035) 0, rgba(120, 90, 40, 0.035) 1px, transparent 1px, transparent 3px),
    repeating-linear-gradient(90deg, rgba(120, 90, 40, 0.025) 0, rgba(120, 90, 40, 0.025) 1px, transparent 1px, transparent 4px);
  font-family: 'Noto Sans', 'Noto Sans Gujarati', 'Noto Sans Devanagari', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: 1rem;
  max-width: 60rem;
  line-height: 1.5;
}

/* Vignette: fixed, behind all content, never intercepts input. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 40%, rgba(58, 40, 22, 0) 55%, rgba(58, 40, 22, 0.28) 100%);
}

h1 { font-size: 1.5rem; letter-spacing: 0.02em; }
h2 { font-size: 1.2rem; margin-top: 1.5rem; }
header { text-align: center; }

button, select, input, textarea { font: inherit; min-height: 2.75rem; color: var(--ink); }
button {
  padding: 0.25rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--ink-soft);
  border-radius: 3px;
}
button:disabled { color: var(--ink-soft); background: var(--paper); }
input, select, textarea { background: var(--paper-light); border: 1px solid var(--card-edge); }

#hex-input, textarea { width: 100%; }

fieldset { border: 1px solid var(--card-edge); }

.lang-list, .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.5rem 0;
}

.lang-option { display: flex; align-items: center; gap: 0.25rem; min-height: 2.75rem; }
.lang-english { color: #554a3a; }

.help, .note { font-size: 0.9rem; }
.note { border-left: 3px solid var(--accent); padding-left: 0.5rem; }
.error { color: var(--error); font-weight: bold; }

.address { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem; }
.address dd { margin: 0; overflow-wrap: anywhere; }

/* The page section is the open book page. Flat: no 3D, no animation. */
.book-page {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem 1rem;
  background: linear-gradient(to right, rgba(42, 39, 36, 0.05), rgba(42, 39, 36, 0) 2rem), var(--paper-light);
  border: 1px solid var(--card-edge);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(42, 39, 36, 0.18);
}

.page-text {
  overflow-x: auto;
  border: 1px solid var(--card-edge);
  background: var(--paper-light);
  color: var(--ink);
  padding: 0.75rem;
  line-height: 1.9;
  font-family: 'Noto Sans Gujarati', 'Noto Sans Devanagari', 'Noto Sans', system-ui, sans-serif;
  -webkit-user-select: text;
  user-select: text;
}
.page-text .line { white-space: pre; }

/* Glyph Inspector (T10). Flat panel; no animation. */
.inspector {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--card-edge);
  border-radius: 4px;
  background: var(--paper);
}
.inspector h3 { font-size: 1.05rem; margin: 0 0 0.25rem; }
.inspector-body { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; }
.inspector-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  min-height: 4.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 2.5rem;
  line-height: 1.4;
  white-space: pre;
  border: 1px dashed var(--card-edge);
  background: var(--paper-light);
  font-family: 'Noto Sans Gujarati', 'Noto Sans Devanagari', 'Noto Sans', system-ui, sans-serif;
}
.inspector-facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem; margin: 0; }
.inspector-facts dd { margin: 0; overflow-wrap: anywhere; }

/* Highlight of the inspected character (CSS Custom Highlight API, where supported). */
::highlight(glyph-inspector) { background-color: #f1d48a; color: #2a2724; }

.offscreen { position: absolute; left: -9999px; top: 0; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ---------- Pop-up book (decorative, aria-hidden) ---------- */

.popup-stage {
  position: relative;
  height: 15rem;
  max-width: 36rem;
  margin: 0.5rem auto 1.5rem;
  perspective: 900px;
  perspective-origin: 50% 15%;
  overflow: hidden;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.popup-stage .book {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 0.75rem;
  height: 9rem;
  transform-style: preserve-3d;
  transform-origin: 50% 100%;
  transform: rotateX(55deg);
}

.popup-stage .leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 1px solid var(--card-edge);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 10px 18px rgba(42, 39, 36, 0.3);
}
.popup-stage .leaf-left {
  left: 0;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(to right, var(--card), var(--paper-light) 80%, var(--card-shade));
}
.popup-stage .leaf-right {
  right: 0;
  border-radius: 0 6px 6px 0;
  background: linear-gradient(to left, var(--card), var(--paper-light) 80%, var(--card-shade));
}

/* Cover: hinged at the spine, swings open; its back face is hidden. */
.popup-stage .cover {
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: 50%;
  width: 50%;
  border-radius: 0 6px 6px 0;
  background: linear-gradient(to right, #3f200f, var(--cover) 12%, #6e3a1d);
  border: 1px solid #2b160a;
  transform-origin: 0 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(2px) rotateY(-180deg);
  opacity: 0;
  animation: popup-open-cover 1.1s ease-in-out 0.1s both;
}

/* Cardstock layers: hinged at their bottom edge on the spread. */
.popup-stage .layer {
  position: absolute;
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateX(-62deg);
  opacity: 1;
  animation: popup-raise-layer 1s cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
}

.popup-stage .layer-arches {
  left: 8%;
  right: 8%;
  bottom: 58%;
  height: 7rem;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  padding: 0 5%;
  background: linear-gradient(to bottom, var(--paper-light), var(--card));
  border: 1px solid var(--card-edge);
  border-radius: 10px 10px 0 0;
  box-shadow: 0 -2px 8px rgba(42, 39, 36, 0.15);
  animation-delay: 0.7s;
}
.popup-stage .arch {
  width: 22%;
  height: 75%;
  border: 2px solid var(--ink);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
  background: radial-gradient(ellipse at 50% 100%, #3a332c, #6b5e4c);
}
.popup-stage .arch-tall { height: 90%; }

.popup-stage .layer-stair {
  left: 40%;
  width: 20%;
  bottom: 34%;
  height: 8rem;
  animation-delay: 0.95s;
}
.popup-stage .column {
  position: absolute;
  left: 44%;
  width: 12%;
  top: 0;
  bottom: 0;
  border: 1px solid var(--ink);
  background: linear-gradient(to right, #6b5e4c, var(--card), #6b5e4c);
}
.popup-stage .step {
  position: absolute;
  width: 45%;
  height: 0.45rem;
  border: 1px solid var(--ink);
  background: var(--card);
}
.popup-stage .step-1 { bottom: 0; left: 50%; }
.popup-stage .step-2 { bottom: 12%; left: 30%; }
.popup-stage .step-3 { bottom: 24%; left: 5%; }
.popup-stage .step-4 { bottom: 36%; left: 30%; }
.popup-stage .step-5 { bottom: 48%; left: 50%; }
.popup-stage .step-6 { bottom: 60%; left: 30%; }
.popup-stage .step-7 { bottom: 72%; left: 5%; }
.popup-stage .step-8 { bottom: 84%; left: 30%; }

.popup-stage .layer-silhouettes {
  left: 6%;
  right: 6%;
  bottom: 6%;
  height: 4.5rem;
  animation-delay: 1.2s;
}
.popup-stage .figure {
  position: absolute;
  bottom: 0;
  width: 1.4rem;
  height: 2.8rem;
  border-radius: 0.7rem 0.7rem 0.2rem 0.2rem;
  background: var(--ink);
}
.popup-stage .figure::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -1.05rem;
  width: 0.95rem;
  height: 0.95rem;
  margin-left: -0.475rem;
  border-radius: 50%;
  background: var(--ink);
}
.popup-stage .figure-1 { left: 10%; }
.popup-stage .figure-2 { left: 46%; height: 3.2rem; }
.popup-stage .figure-3 { left: 82%; height: 2.5rem; }

@keyframes popup-open-cover {
  from { transform: translateZ(2px) rotateY(0deg); opacity: 1; }
  80% { opacity: 1; }
  to { transform: translateZ(2px) rotateY(-180deg); opacity: 0; }
}

@keyframes popup-raise-layer {
  from { transform: rotateX(0deg); opacity: 0; }
  30% { opacity: 1; }
  to { transform: rotateX(-62deg); opacity: 1; }
}

@media (max-width: 30rem) {
  .popup-stage { height: 11rem; }
  .popup-stage .book { height: 6.5rem; }
  .popup-stage .layer-arches { height: 5rem; }
  .popup-stage .layer-stair { height: 5.5rem; }
}

/* Reduced motion: no unfolding. Resting styles are already the open state. */
@media (prefers-reduced-motion: reduce) {
  .popup-stage *,
  .popup-stage *::before,
  .popup-stage *::after {
    animation: none !important;
    transition: none !important;
  }
}
