/* Rituel du d20 : fenêtre de temple (katōmado), torii, bambous, shimenawa et ensō.
   Le dé est en 3D (de3d.js). Les durées des animations sont regroupées ici. */
:root {
  --r-encre: 0.7s;     /* apparition du cadre */
  --r-bambou: 0.9s;
  --r-enso: 1.1s;
}

.rituel { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at 50% 45%, rgba(16, 30, 22, 0.78), rgba(6, 9, 7, 0.95));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: r-fondu .6s ease-out; transition: opacity .6s; }
.rituel.sortie { opacity: 0; }
@keyframes r-fondu { from { opacity: 0; } }

.rituel-scene { position: relative; width: min(400px, 100%, max(260px, calc((100vh - 250px) * 0.8))); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.rituel-tete { text-align: center; }
.rituel-tete .surtitre { margin-bottom: .2rem; color: var(--or); }
.rituel-tete h2 { font-family: var(--f-nom); font-size-adjust: none; font-size: clamp(1.8rem, 5vw, 2.4rem); font-weight: 400; color: var(--blanc); }
.rituel-tete h2 em { font-style: normal; color: #e2c27a; }

/* Le cadre */
.katomado { position: relative; width: 100%; aspect-ratio: 400 / 500; margin-top: 44px;
  animation: r-encre var(--r-encre) cubic-bezier(.3,.7,.2,1) both; }
@keyframes r-encre { from { clip-path: circle(0% at 50% 55%); filter: blur(6px); } to { clip-path: circle(80% at 50% 55%); filter: none; } }
.katomado .cadre { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 24px 40px rgba(0,0,0,.55)); }
.torii { position: absolute; left: 50%; bottom: 3%; width: 86%; height: auto; transform: translateX(-50%); z-index: 0;
  filter: drop-shadow(0 14px 18px rgba(0,0,0,.6)) brightness(.92); animation: r-torii .9s .35s cubic-bezier(.2,.8,.3,1) both; pointer-events: none; }
@keyframes r-torii { from { opacity: 0; transform: translate(-50%, 18px) scale(.96); } }
.bambou { position: absolute; bottom: -6px; height: 88%; width: 15%; z-index: 0; transform-origin: bottom; animation: r-pousse var(--r-bambou) .25s cubic-bezier(.2,.7,.2,1) both; }
.bambou.gauche { left: -11%; }
.bambou.droite { right: -11%; transform: scaleX(-1); animation-name: r-pousse-d; }
@keyframes r-pousse { from { transform: scaleY(0); } }
@keyframes r-pousse-d { from { transform: scaleX(-1) scaleY(0); } to { transform: scaleX(-1) scaleY(1); } }

.katomado-contenu { position: absolute; inset: 15% 6% 4%; display: flex; flex-direction: column; align-items: center; text-align: center; z-index: 1; }
.fortune { font-size: .58rem; letter-spacing: .24em; text-transform: uppercase; color: var(--or); opacity: .85; }
.fortune .jp { font-family: var(--f-jp); font-size-adjust: none; letter-spacing: .1em; margin-right: .3em; }
.valeur { font-family: var(--f-titre); font-size-adjust: none; font-size: clamp(1.7rem, 6vw, 2.3rem); line-height: 1.15; color: #f3e3b5; min-height: 1.2em; }
.valeur .jp { font-family: var(--f-jp); font-size-adjust: none; }
.valeur.revele { animation: r-valeur .6s ease-out; text-shadow: 0 0 18px rgba(226, 194, 122, .45); }
@keyframes r-valeur { from { opacity: 0; transform: scale(.85); letter-spacing: .2em; } }
.hanko { position: absolute; right: 8%; top: 4%; width: 44px; height: 44px; display: grid; place-items: center; background: #b8432f; color: #f4e7d2;
  font-family: var(--f-jp); font-size-adjust: none; font-size: .9rem; line-height: 1; writing-mode: vertical-rl; border-radius: 4px; transform: rotate(8deg) scale(0); opacity: 0;
  box-shadow: inset 0 0 0 2px rgba(244, 231, 210, .5); }
.hanko.tampon { animation: r-tampon .45s cubic-bezier(.3,1.6,.5,1) forwards; }
@keyframes r-tampon { 0% { transform: rotate(8deg) scale(2.2); opacity: 0; } 100% { transform: rotate(8deg) scale(1); opacity: .95; } }

.shimenawa { width: 100%; height: auto; margin-top: 4px; position: relative; z-index: 3; filter: drop-shadow(0 4px 4px rgba(0,0,0,.4)); }

.de-zone { position: relative; flex: 1; width: 100%; min-height: 0; margin-top: -16px; display: grid; place-items: center; }
.enso { position: absolute; width: 84%; aspect-ratio: 1; opacity: .55; }
.enso path { stroke-dasharray: 100; stroke-dashoffset: 100; animation: r-enso var(--r-enso) .6s ease-out forwards; }
@keyframes r-enso { to { stroke-dashoffset: 6; } }
#de-canvas { position: relative; width: 70%; aspect-ratio: 1; max-height: 100%; cursor: pointer; }
.de-repli { display: none; }
.rituel.sans-3d #de-canvas { display: none; }
.rituel.sans-3d .de-repli { display: grid; place-items: center; position: relative; width: 130px; height: 130px; border: 1px solid var(--or); background: #12261b;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); color: #f3e3b5; font-family: var(--f-titre); font-size-adjust: none; font-size: 2.4rem; cursor: pointer; }

.legende { font-size: .72rem; color: #cfd3c2; border: 1px solid rgba(201, 164, 92, .35); background: rgba(8, 16, 11, .6); padding: 5px 16px; margin-top: 2px; }
.legende em { color: #e2c27a; }

/* Éclats dorés sur un 20 */
.eclats { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.eclats i { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #f3d48a; box-shadow: 0 0 6px 2px rgba(243, 212, 138, .6);
  animation: r-eclat 1.8s ease-out forwards; }
@keyframes r-eclat { from { opacity: 1; transform: translate(0, 0); } to { opacity: 0; transform: translate(var(--dx), var(--dy)); } }

/* Plaque ema du résultat */
.ema.cache { visibility: hidden; animation: none; }
.ema { width: min(440px, calc(100vw - 32px)); min-height: 74px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 16px; align-items: center; padding: 14px 18px;
  background: linear-gradient(180deg, #3a2a1c, #2a1d13); border: 1px solid rgba(201, 164, 92, .55);
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%, 0 12px);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.25); animation: r-ema .55s cubic-bezier(.2,.8,.3,1) both; }
@keyframes r-ema { from { opacity: 0; transform: translateY(14px); } }
.ema-kanji { grid-row: span 2; text-align: center; font-family: var(--f-jp); font-size-adjust: none; font-size: 2rem; line-height: 1; color: #e2c27a; }
.ema-kanji small { display: block; font-family: var(--f-texte); font-size: .48rem; letter-spacing: .2em; text-transform: uppercase; color: #c8b48a; margin-top: 4px; }
.ema-texte b { display: block; font-size: .62rem; font-weight: 500; letter-spacing: .16em; text-transform: uppercase; color: #f3e3b5; }
.ema-texte p { font-size: .74rem; line-height: 1.55; color: #d9cfb8; margin-top: 2px; }
.ema-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.bouton-sceau { font: inherit; font-size: .6rem; letter-spacing: .16em; text-transform: uppercase; color: #f4e7d2; background: #9b3626; border: 1px solid #d0745f; padding: 7px 12px; cursor: pointer; transition: background .2s; }
.bouton-sceau:hover { background: #b8432f; }
.ema .lien { background: none; border: 0; border-bottom: 1px solid rgba(201,164,92,.4); color: #c8b48a; cursor: pointer; font: inherit; font-size: .6rem; letter-spacing: .14em; text-transform: uppercase; padding: 0 0 2px; }
.rituel-passer { position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); background: none; border: 0; color: var(--gris); font: inherit; font-size: .62rem; letter-spacing: .16em; text-transform: uppercase; cursor: pointer; padding: 4px; }
.rituel-passer:hover { color: var(--blanc); }

/* Omamori suspendu en haut à droite */
.omamori { position: fixed; top: 0; right: max(28px, calc(env(safe-area-inset-right, 0px) + 20px)); z-index: 70; width: 64px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; transform-origin: 50% 0; animation: o-chute 1.1s cubic-bezier(.3,1.4,.5,1) both, o-balance 4.5s 1.1s ease-in-out infinite; }
.omamori-corde { width: 2px; height: 72px; background: linear-gradient(#7a1d14, #b8432f); }
.omamori-sachet { width: 64px; height: auto; margin-top: -10px; filter: drop-shadow(0 10px 14px rgba(0,0,0,.5)); transition: filter .3s; }
.omamori:hover .omamori-sachet, .omamori:focus-visible .omamori-sachet { filter: drop-shadow(0 0 14px rgba(226,194,122,.7)) drop-shadow(0 10px 14px rgba(0,0,0,.5)); }
@keyframes o-chute { from { transform: translateY(-110%); } }
@keyframes o-balance { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.omamori-bulle { position: absolute; top: 96px; right: calc(100% + 12px); width: 250px; padding: 12px 14px; text-align: left; color: var(--gris);
  background: linear-gradient(180deg, rgba(28, 40, 30, .97), rgba(14, 22, 16, .97)); border: 1px solid var(--or-doux);
  font-size: .68rem; line-height: 1.55; opacity: 0; transform: translateX(6px); pointer-events: none; transition: opacity .25s, transform .25s; }
.omamori:hover .omamori-bulle, .omamori:focus-visible .omamori-bulle { opacity: 1; transform: none; }
.omamori-bulle small { display: block; font-size: .52rem; letter-spacing: .18em; text-transform: uppercase; color: var(--or); }
.omamori-bulle b { display: block; font-family: var(--f-titre); font-size-adjust: none; font-size: 1.05rem; font-weight: 400; color: var(--blanc); margin: 2px 0 4px; }
.omamori-bulle .touches { display: block; margin-top: 8px; color: var(--gris-doux); }
kbd { font-family: var(--f-texte); font-size: .6rem; padding: 1px 5px; border: 1px solid var(--or-doux); border-bottom-width: 2px; color: var(--creme); }

@media (max-width: 767px) {
  .omamori { width: 48px; right: 14px; }
  .omamori-corde { height: 52px; }
  .omamori-sachet { width: 48px; }
  .omamori-bulle { display: none; }
  .katomado { margin-top: 36px; }
  .ema { grid-template-columns: 1fr; text-align: center; }
  .ema-kanji { grid-row: auto; }
  .ema-actions { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .rituel, .katomado, .torii, .bambou, .enso path, .ema, .omamori, .hanko.tampon { animation: none !important; }
  .enso path { stroke-dashoffset: 6; }
  .hanko.tampon { transform: rotate(8deg); opacity: .95; }
}

/* L'omamori suspendu est retiré de l'écran : le bouton reste en coulisse, le d20 de la barre s'en sert pour relancer */
.omamori { display: none !important; }

/* ---------- Popup du d20 façon torii (d'après le design de Sarah) ----------
   Toit à pignon et lune, bannière de parchemin avec shide, étiquette rouge, dé dans un anneau doré,
   et en bas la plaque de parchemin encadrée de bambou (cadres.js). */
.rituel-tete { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.rituel-scene { width: min(440px, 100%, max(280px, calc((100vh - 200px) / 1.4))); gap: 22px; }
.katomado { aspect-ratio: 400 / 560; margin-top: 0; }
.portique { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 24px 40px rgba(0,0,0,.55)); }
.p-pompon { transform-box: fill-box; transform-origin: 50% 0; animation: pompon-balance 5s ease-in-out infinite; }
.p-pompon.p2 { animation-duration: 6s; animation-delay: -2s; }
.p-pompon.p3 { animation-duration: 5.5s; animation-delay: -1s; }
.p-pompon.p4 { animation-duration: 4.6s; animation-delay: -3s; }
.p-anneau { stroke-dasharray: 100; stroke-dashoffset: 100; animation: r-enso 1.4s .5s ease-out forwards; }
@keyframes r-enso { to { stroke-dashoffset: 0; } }

/* bannière de parchemin suspendue à la shimenawa */
.banniere { position: absolute; left: 21%; right: 21%; top: 23%; height: 19%; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center;
  background: radial-gradient(ellipse at 50% 40%, #f3e9cf, #e2d3ac 70%, #c9b483); color: #2a2016;
  clip-path: polygon(0 0, 100% 0, 99% 30%, 100% 62%, 98% 100%, 72% 97%, 50% 100%, 24% 97%, 2% 100%, 0 64%, 1% 30%);
  box-shadow: inset 0 0 30px rgba(120, 90, 40, .35); animation: r-banniere .8s .2s cubic-bezier(.2,.8,.3,1) both; transform-origin: 50% 0; }
@keyframes r-banniere { from { transform: scaleY(.2); opacity: 0; } }
.banniere .fortune { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #3a2c1c; opacity: 1; font-size: .56rem; letter-spacing: .26em; font-weight: 600; }
.banniere .fortune .jp { font-size: 1.15rem; letter-spacing: .12em; color: #241a10; margin: 0; }
.banniere .valeur { font-family: var(--f-titre); font-size-adjust: none; font-weight: 500; color: #1f170e; font-size: clamp(1.6rem, 6vw, 2.2rem); }
.banniere .valeur.revele { text-shadow: 0 0 14px rgba(201, 164, 92, .55); }
.shide { position: absolute; width: 16px; height: 48px; fill: #f4efe2; stroke: #bfb59a; stroke-width: .6; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.banniere { overflow: visible; }
.shide.g { left: 2%; top: -8px; } .shide.d { right: 2%; top: -8px; }
.shide.bg { left: 18%; bottom: -40px; } .shide.bd { right: 18%; bottom: -40px; }
.banniere .shide { display: none; }   /* clip-path de la bannière : les shide sont redessinés à côté */
.katomado::before, .katomado::after { content: ""; position: absolute; z-index: 3; width: 4.5%; height: 9%; top: 22%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 60'%3E%3Cpath d='M2 0 h14 l-5 12 h9 l-5 12 h9 l-5 12 h9 l-5 12 h-14 l5 -12 h-9 l5 -12 h-9 l5 -12 h-9 z' fill='%23f4efe2' stroke='%23bfb59a' stroke-width='.6'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); animation: shide-vent 4s ease-in-out infinite; transform-origin: 50% 0; }
.katomado::before { left: 18%; } .katomado::after { right: 18%; animation-delay: -1.6s; }
@keyframes shide-vent { 0%, 100% { transform: rotate(3deg); } 50% { transform: rotate(-4deg); } }

/* étiquette rouge suspendue au pilier droit */
.hanko { left: auto; right: 3%; top: 24%; width: 11%; height: auto; aspect-ratio: 46 / 74; border-radius: 2px; background: linear-gradient(180deg, #a3231a, #7c140e);
  box-shadow: inset 0 0 0 2px #7c140e, inset 0 0 0 3px #d6b45e, 0 6px 12px rgba(0,0,0,.45); color: #e9cd84; font-size: 1.3rem; writing-mode: vertical-rl; z-index: 3;
  transform: rotate(0deg) scale(0); }
@keyframes r-tampon { 0% { transform: rotate(-8deg) scale(1.8); opacity: 0; } 100% { transform: rotate(0deg) scale(1); opacity: 1; } }

/* le dé au centre de l'anneau */
.katomado-contenu { inset: 40% 18% 13%; justify-content: center; }
.de-zone { margin-top: 0; flex: 1; }
#de-canvas { width: 92%; }
.legende { font-size: .82rem; color: #e8dcc0; border-color: rgba(201,164,92,.45); background: rgba(8,16,11,.72); }

/* plaque de résultat : parchemin entre deux bambous */
.rituel .ema { width: min(480px, calc(100vw - 48px)); clip-path: none; border: 0; padding: 18px 20px; margin-top: 8px;
  background: radial-gradient(ellipse at 40% 30%, #f3e9cf, #e0cfa4 75%, #cbb588); color: #2a2016; box-shadow: inset 0 0 26px rgba(120,90,40,.35), 0 18px 30px rgba(0,0,0,.45);
  grid-template-columns: auto 1px minmax(0, 1fr); gap: 6px 16px; }
.rituel .ema::before { content: ""; grid-row: span 2; grid-column: 2; align-self: stretch; background: rgba(90, 60, 30, .35); }
.rituel .ema-kanji { grid-column: 1; color: #1f170e; font-size: 2.6rem; }
.rituel .ema-kanji small { color: #3a2c1c; font-weight: 600; }
.rituel .ema-texte, .rituel .ema-actions { grid-column: 3; }
.rituel .ema-texte b { color: #7c1d12; font-weight: 600; letter-spacing: .2em; }
.rituel .ema-texte p { color: #2e2418; font-size: .86rem; font-weight: 500; }
.rituel .bouton-sceau { position: relative; background: linear-gradient(180deg, #a52a1d, #7f170f); border: 1px solid #d6b45e; box-shadow: inset 0 0 0 2px #7f170f, inset 0 0 0 3px rgba(214,180,94,.6);
  color: #f3e3b5; padding: 9px 16px; font-size: .62rem; font-weight: 600; letter-spacing: .2em; }
.rituel .bouton-sceau:hover { background: linear-gradient(180deg, #bb3324, #8f1c12); }
.rituel .ema .lien { color: #e9dcc0; background: linear-gradient(180deg, #1f3324, #122017); border: 1px solid #c9a45c; box-shadow: inset 0 0 0 2px #122017, inset 0 0 0 3px rgba(201,164,92,.45);
  padding: 9px 14px; font-size: .62rem; font-weight: 600; letter-spacing: .16em; }
.rituel .ema .lien:hover { color: #fff; }
.rituel .ema.encadre { overflow: visible; }
.rituel .ema { position: relative; z-index: 2; margin-top: -46px; }
.rituel .ema-actions { flex-wrap: nowrap; gap: 10px; }
.rituel .ema-actions button { white-space: nowrap; }

@media (max-width: 767px) {
  .rituel .ema { grid-template-columns: auto 1px minmax(0, 1fr); text-align: left; }
  .rituel .ema-kanji { grid-row: span 2; }
  .rituel .ema-actions { justify-content: flex-start; }
  .banniere .fortune { font-size: .48rem; }
  .rituel .ema { padding: 14px 14px; gap: 4px 12px; }
  .rituel .ema-kanji { font-size: 1.9rem; }
  .rituel .ema-texte p { font-size: .78rem; }
  .rituel .ema-actions { gap: 8px; flex-wrap: wrap; }
  .rituel .bouton-sceau, .rituel .ema .lien { padding: 7px 10px; font-size: .56rem; letter-spacing: .12em; }
  .hanko { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .p-pompon, .banniere, .p-anneau, .katomado::before, .katomado::after { animation: none !important; }
  .p-anneau { stroke-dashoffset: 0; }
}
