/* =====================================================
   色やサイズの設定（ここを変えると全体の雰囲気が変わります）
   ===================================================== */
:root {
  --night: #1a0f2b;        /* 背景の夜空 */
  --night-light: #3a1f5c;
  --pumpkin: #f28c28;      /* ハロウィンのオレンジ */
  --gold: #ffd56b;         /* 魔法の金色 */
  --paper: #efdfb8;        /* 紙の色 */
  --paper-dark: #c9a96e;
  --ink: #2b1a12;          /* インクの色 */
  --text: #f6ecff;

  --paper-width: min(94vw, 540px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 213, 107, 0.25) 0 4%, transparent 12%),
    radial-gradient(1px 1px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 60%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 40%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 10% 70%, #fff 50%, transparent 51%),
    radial-gradient(ellipse at 50% 120%, rgba(242, 140, 40, 0.35), transparent 60%),
    linear-gradient(var(--night), var(--night-light));
  background-attachment: fixed;
  color: var(--text);
  font-family: "Yomogi", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Meiryo", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

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

/* 画面の切りかえ：is-active が付いた画面だけ表示する */
.screen {
  display: none;
}

.screen.is-active {
  display: flex;
}

/* =====================================================
   画面0：ストーリー導入（古書店の灯りと、古い魔法書のページ）
   ===================================================== */
#story-screen {
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  /* ランプの暖かい灯りと、うしろに並ぶ本棚の影 */
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 190, 110, 0.22), transparent 55%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 46px),
    linear-gradient(rgba(26, 15, 43, 0.15), rgba(26, 15, 43, 0.6));
}

.story {
  position: relative;
  width: min(100%, 520px);
  padding: 30px 22px 28px;
  color: #3a2716;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(150, 100, 40, 0.16), transparent 45%),
    radial-gradient(ellipse at 85% 90%, rgba(120, 70, 20, 0.2), transparent 50%),
    #efe1bf;
  border-radius: 6px 10px 6px 12px;
  box-shadow:
    inset 0 0 36px rgba(110, 65, 20, 0.45),
    inset 0 0 0 1px rgba(110, 65, 20, 0.35),
    0 12px 36px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(255, 170, 80, 0.12);
  animation: story-appear 1s ease-out both;
}

/* ページの内側の飾り枠 */
.story::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(120, 75, 30, 0.35);
  border-radius: 4px;
  pointer-events: none;
}

@keyframes story-appear {
  from { opacity: 0; transform: translateY(12px); }
}

.story-kicker {
  margin: 0 0 6px;
  text-align: center;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  color: #8a5a2b;
}

.story-title {
  margin: 0 0 22px;
  text-align: center;
  font-family: "Zen Old Mincho", serif;
  font-weight: 700;
  font-size: clamp(1.7rem, 8vw, 2.3rem);
  letter-spacing: 0.12em;
  color: #6b3410;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* タイトルの下の飾り線 */
.story-title::after {
  content: "";
  display: block;
  width: 60%;
  height: 1px;
  margin: 14px auto 0;
  background: linear-gradient(90deg, transparent, rgba(120, 75, 30, 0.6), transparent);
}

.story-body {
  font-family: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 1.02rem;
  line-height: 1.95;
}

.story-body p {
  margin: 0 0 1.05em;
  animation: story-line 0.9s ease-out both;
}

/* 段落を順番にふわっと出す */
.story-body > :nth-child(1) { animation-delay: 0.4s; }
.story-body > :nth-child(2) { animation-delay: 0.8s; }
.story-body > :nth-child(3) { animation-delay: 1.2s; }
.story-body > :nth-child(4) { animation-delay: 1.6s; }
.story-body > :nth-child(5) { animation-delay: 2s; }
.story-body > :nth-child(6) { animation-delay: 2.4s; }
.story-body > :nth-child(7) { animation-delay: 2.8s; }

@keyframes story-line {
  from { opacity: 0; transform: translateY(6px); }
}

.story-price strong {
  font-size: 1.15em;
  color: #9a3a0e;
}

/* 店主のセリフ */
.story-quote {
  margin: 0 0 1.05em;
  padding: 12px 14px 12px 16px;
  background: rgba(120, 75, 30, 0.1);
  border-left: 3px solid #b0782f;
  border-radius: 0 6px 6px 0;
  animation: story-line 0.9s ease-out 2s both;
}

.story-quote p {
  margin: 0;
  font-weight: 700;
  color: #4a2a10;
  animation: none;
}

.story-button {
  display: block;
  margin: 8px auto 0;
  min-width: 70%;
  padding: 14px 24px;
  font-family: "Zen Old Mincho", serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #2a1300;
  background: linear-gradient(#ffb04d, var(--pumpkin));
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 0 #a5520d, 0 0 18px rgba(242, 140, 40, 0.45);
  cursor: pointer;
  animation: story-line 0.9s ease-out 3.2s both;
}

.story-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #a5520d;
}

/* 動きを減らす設定の端末では、アニメーションを止める */
@media (prefers-reduced-motion: reduce) {
  .story,
  .story-body p,
  .story-quote,
  .story-button {
    animation: none;
  }
}

/* =====================================================
   画面1：魔法書
   ===================================================== */
#book-screen {
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.book-title {
  margin: 0;
  font-family: "Zen Old Mincho", serif;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  letter-spacing: 0.15em;
  color: var(--pumpkin);
  text-shadow: 0 0 12px rgba(242, 140, 40, 0.6);
}

/* ---------- 古びた紙 ---------- */
.paper {
  position: relative;
  width: var(--paper-width);
  padding: calc(var(--paper-width) * 0.05);
  background:
    radial-gradient(ellipse at 15% 20%, rgba(150, 100, 40, 0.18), transparent 40%),
    radial-gradient(ellipse at 85% 85%, rgba(120, 70, 20, 0.22), transparent 45%),
    radial-gradient(circle at 70% 25%, rgba(140, 90, 30, 0.12), transparent 20%),
    /* 真ん中の折り目（開いた紙） */
    linear-gradient(90deg, transparent 48.5%, rgba(90, 55, 20, 0.18) 50%, transparent 51.5%),
    var(--paper);
  color: var(--ink);
  border-radius: 6px 10px 5px 12px;
  box-shadow:
    inset 0 0 40px rgba(110, 65, 20, 0.55),
    inset 0 0 8px rgba(110, 65, 20, 0.6),
    0 10px 30px rgba(0, 0, 0, 0.55);
  transform: rotate(-0.6deg);
  animation: paper-open 0.9s ease-out both;
}

@keyframes paper-open {
  from {
    opacity: 0;
    transform: rotate(-0.6deg) scaleX(0.6);
  }
  to {
    opacity: 1;
    transform: rotate(-0.6deg) scaleX(1);
  }
}

/* ---------- 薄い参照表（11列 × 6段） ---------- */
.ref-table {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  opacity: 0.32;
}

.ref-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ref-head svg {
  width: 72%;
  height: 72%;
}

/* 方眼の線 */
.ref-grid {
  border-right: 1px solid rgba(43, 26, 18, 0.55);
  border-bottom: 1px solid rgba(43, 26, 18, 0.55);
}

/* 方眼のいちばん上と左の線 */
.ref-table > .ref-grid:nth-child(-n + 22):nth-child(n + 12) {
  border-top: 1px solid rgba(43, 26, 18, 0.55);
}

.ref-table > .ref-grid:nth-child(11n + 1) {
  border-left: 1px solid rgba(43, 26, 18, 0.55);
}

/* ワ行のイ段・ウ段・エ段（ワ・ヲ・ン 以外）は左の縦線を消す。幅がずれないよう線は透明にする */
.ref-table > .ref-grid.ref-no-left {
  border-left-color: transparent;
}

/* ワ行のイ段・ウ段の下の横線（イ段とウ段、ウ段とエ段の境目）も同じように消す */
.ref-table > .ref-grid.ref-no-bottom {
  border-bottom-color: transparent;
}

.ref-swatch {
  width: 55%;
  height: 55%;
  border-radius: 50%;
  border: 1px solid var(--ink);
}

/* ---------- 謎の記号文（参照表の上に重ねる） ---------- */
.cipher {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--paper-width) * 0.025);
  /* 少しずらして、傾けて書いたように見せる */
  transform: translate(-2%, 4%) rotate(-2.5deg);
  pointer-events: none;
}

.cipher-line {
  display: flex;
  align-items: center;
  gap: calc(var(--paper-width) * 0.004);
}

.cipher-sym {
  display: inline-block;
  width: calc(var(--paper-width) * 0.068);
  height: calc(var(--paper-width) * 0.068);
  filter: drop-shadow(0 1px 0 rgba(43, 26, 18, 0.35));
}

.cipher-sym svg {
  display: block;
  width: 100%;
  height: 100%;
}

.cipher-sep {
  font-size: calc(var(--paper-width) * 0.06);
  line-height: 1;
  font-weight: bold;
  color: var(--ink);
}

/* 不正解のときのゆれ */
.paper.is-shaking {
  animation: paper-shake 0.45s ease-in-out;
}

@keyframes paper-shake {
  0%, 100% { transform: rotate(-0.6deg) translateX(0); }
  20% { transform: rotate(-1.4deg) translateX(-8px); }
  40% { transform: rotate(0.4deg) translateX(7px); }
  60% { transform: rotate(-1.2deg) translateX(-5px); }
  80% { transform: rotate(-0.2deg) translateX(3px); }
}

/* 正解のときの光 */
.paper.is-glowing {
  animation: paper-glow 2.2s ease-in-out forwards;
}

@keyframes paper-glow {
  0% {
    box-shadow: inset 0 0 40px rgba(110, 65, 20, 0.55), 0 10px 30px rgba(0, 0, 0, 0.55);
  }
  50% {
    box-shadow: inset 0 0 30px rgba(255, 213, 107, 0.9), 0 0 50px 12px rgba(255, 213, 107, 0.85);
    filter: brightness(1.12);
  }
  100% {
    box-shadow: inset 0 0 30px rgba(255, 213, 107, 0.9), 0 0 80px 24px rgba(255, 213, 107, 0.9);
    filter: brightness(1.3);
    transform: rotate(-0.6deg) scale(1.03);
  }
}

.paper.is-glowing .cipher-sym {
  animation: symbol-shine 1.2s ease-in-out infinite alternate;
}

@keyframes symbol-shine {
  to {
    filter: drop-shadow(0 0 6px var(--gold)) brightness(1.2);
  }
}

.paper-sparkle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 10px 4px var(--gold);
  opacity: 0;
  animation: paper-sparkle 1.2s ease-out forwards;
  pointer-events: none;
}

@keyframes paper-sparkle {
  0% { opacity: 0; transform: scale(0.2) translateY(0); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: scale(1) translateY(-30px); }
}

/* ---------- 入力欄 ---------- */
.spell-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: var(--paper-width);
}

.spell-input {
  flex: 1 1 220px;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px; /* 16px 未満だと iPhone で自動ズームされる */
  color: var(--ink);
  background: #f8eed6;
  border: 2px solid var(--paper-dark);
  border-radius: 8px;
  outline: none;
}

.spell-input:focus {
  border-color: var(--pumpkin);
  box-shadow: 0 0 0 3px rgba(242, 140, 40, 0.35);
}

.spell-button {
  flex: 0 0 auto;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: bold;
  color: #2a1300;
  background: linear-gradient(#ffb04d, var(--pumpkin));
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 0 #a5520d, 0 0 14px rgba(242, 140, 40, 0.5);
  cursor: pointer;
}

.spell-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #a5520d;
}

.spell-button:disabled,
.spell-input:disabled {
  opacity: 0.6;
}

.spell-message {
  min-height: 1.6em;
  margin: 0;
  text-align: center;
}

.spell-message.is-wrong {
  color: #ffb3b3;
}

.spell-message.is-correct {
  color: var(--gold);
  text-shadow: 0 0 8px var(--gold);
}

/* ---------- ヒント ---------- */
.hint-open-button {
  padding: 8px 20px;
  font-family: "Zen Old Mincho", serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #f3e3c0;
  background: rgba(60, 35, 20, 0.55);
  border: 1px solid rgba(239, 223, 184, 0.55);
  border-radius: 999px;
  cursor: pointer;
}

.hint-open-button:active {
  transform: translateY(1px);
}

/* ヒントを開いている間は、うしろの画面をスクロールさせない */
body.is-hint-open {
  overflow: hidden;
}

.hint-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.hint-modal[hidden] {
  display: none;
}

.hint-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 6, 20, 0.72);
  animation: fade-in 0.25s ease-out;
}

/* 古い紙のシート */
.hint-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 480px);
  max-height: 100%;
  padding: 18px 16px 16px;
  color: #3a2716;
  background:
    radial-gradient(ellipse at 15% 10%, rgba(150, 100, 40, 0.16), transparent 45%),
    radial-gradient(ellipse at 90% 95%, rgba(120, 70, 20, 0.2), transparent 50%),
    var(--paper);
  border-radius: 6px 10px 6px 12px;
  box-shadow: inset 0 0 32px rgba(110, 65, 20, 0.45), 0 14px 40px rgba(0, 0, 0, 0.65);
  font-family: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  animation: hint-open 0.3s ease-out;
}

@keyframes hint-open {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
}

.hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(120, 75, 30, 0.35);
}

.hint-heading {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  color: #6b3410;
}

.hint-close {
  padding: 6px 14px;
  font: inherit;
  font-size: 0.9rem;
  color: #4a2a10;
  background: rgba(120, 75, 30, 0.12);
  border: 1px solid rgba(120, 75, 30, 0.4);
  border-radius: 999px;
  cursor: pointer;
}

/* ヒント1〜3のボタン（しおり風） */
.hint-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 10px;
}

.hint-tab {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  text-align: left;
  color: #3a2716;
  background: rgba(255, 250, 235, 0.55);
  border: 1px solid rgba(120, 75, 30, 0.35);
  border-left: 4px solid #b0782f;
  border-radius: 4px;
  cursor: pointer;
}

.hint-tab.is-current {
  background: rgba(176, 120, 47, 0.2);
  border-color: rgba(120, 75, 30, 0.6);
  border-left-color: #8a3f10;
}

.hint-tab:disabled {
  color: rgba(58, 39, 22, 0.45);
  background: rgba(120, 75, 30, 0.06);
  border-left-color: rgba(120, 75, 30, 0.3);
  cursor: default;
}

.hint-tab-number {
  flex: 0 0 auto;
  font-weight: 700;
  color: #8a3f10;
}

.hint-tab:disabled .hint-tab-number {
  color: inherit;
}

.hint-tab-title {
  font-size: 0.92rem;
}

/* ヒントの中身（長いときはこの部分だけスクロール） */
.hint-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px 2px;
  font-size: 0.98rem;
  line-height: 1.85;
}

.hint-content p {
  margin: 0 0 0.8em;
}

.hint-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: #6b3410;
}

.hint-guide {
  color: rgba(58, 39, 22, 0.7);
}

.hint-lead {
  font-size: 1.1rem;
  font-weight: 700;
  color: #4a2a10;
}

.hint-content strong {
  color: #8a3f10;
}

.hint-notes {
  margin: 0;
  padding: 10px 12px 10px 28px;
  background: rgba(120, 75, 30, 0.1);
  border-left: 3px solid #b0782f;
  border-radius: 0 6px 6px 0;
}

.hint-notes li + li {
  margin-top: 4px;
}

/* 答え：インクで書いたように大きく */
.hint-answer {
  padding: 12px 10px;
  text-align: center;
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.7;
  color: #2b1a12;
  background: rgba(255, 250, 235, 0.6);
  border: 1px dashed rgba(120, 75, 30, 0.6);
  border-radius: 6px;
}

/* 最後のヒントの確認（シートの上に重ねる） */
.hint-confirm {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 20px;
  text-align: center;
  background: rgba(43, 26, 18, 0.97);
  border-radius: inherit;
  color: #f6ead0;
  animation: fade-in 0.2s ease-out;
}

.hint-confirm[hidden] {
  display: none;
}

.hint-confirm-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
}

.hint-confirm-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.8;
}

.hint-confirm-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.hint-confirm-cancel,
.hint-confirm-ok {
  min-width: 128px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
}

.hint-confirm-cancel {
  color: #2a1300;
  background: linear-gradient(#ffb04d, var(--pumpkin));
  border: none;
  box-shadow: 0 3px 0 #a5520d;
}

.hint-confirm-ok {
  color: #f6ead0;
  background: transparent;
  border: 1px solid rgba(246, 234, 208, 0.6);
}

@media (prefers-reduced-motion: reduce) {
  .hint-backdrop,
  .hint-sheet,
  .hint-confirm {
    animation: none;
  }
}

/* =====================================================
   画面2：ARカメラ
   ===================================================== */
#ar-screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  animation: fade-in 0.8s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
}

.ar-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ar-video.is-mirrored {
  transform: scaleX(-1);
}

/* 3D を描くキャンバス：映像と同じ大きさで上に重ねる */
.ar-canvas,
.ar-debug {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.ar-debug {
  pointer-events: none;
}

.ar-debug-info {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  margin: 0;
  padding: 6px 8px;
  font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: #9f9;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  white-space: pre-wrap;
  pointer-events: none;
}

/* ---------- 中央のパネル（カメラ起動・エラー） ---------- */
.ar-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(86vw, 380px);
  padding: 22px 18px;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: rgba(26, 15, 43, 0.88);
  border: 1px solid rgba(255, 213, 107, 0.55);
  border-radius: 16px;
  box-shadow: 0 0 30px rgba(242, 140, 40, 0.35);
}

.ar-panel[hidden] {
  display: none;
}

.ar-panel-text {
  margin: 0;
  white-space: pre-line;
  line-height: 1.6;
}

.ar-main-button,
.ar-sub-button {
  font-weight: bold;
  border-radius: 999px;
  cursor: pointer;
}

.ar-main-button {
  min-width: 70%;
  padding: 12px 22px;
  font-size: 1.05rem;
  color: #2a1300;
  background: linear-gradient(#ffb04d, var(--pumpkin));
  border: none;
  box-shadow: 0 4px 0 #a5520d, 0 0 14px rgba(242, 140, 40, 0.5);
}

.ar-sub-button {
  padding: 8px 16px;
  font-size: 0.9rem;
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.ar-main-button[hidden],
.ar-sub-button[hidden] {
  display: none;
}

/* ---------- 小さな案内（手が見つからないとき など） ---------- */
.ar-guide {
  position: absolute;
  left: 50%;
  top: max(30%, env(safe-area-inset-top));
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 8px 14px;
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.95rem;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  pointer-events: none;
}

.ar-guide[hidden] {
  display: none;
}

/* ---------- フラッシュ ---------- */
.ar-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #fff8d8, rgba(255, 213, 107, 0.6) 40%, transparent 75%);
  opacity: 0;
  animation: ar-flash 0.9s ease-out;
  pointer-events: none;
}

@keyframes ar-flash {
  20% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- 呪文の詠唱 ---------- */
.ar-chant {
  position: absolute;
  top: max(6%, env(safe-area-inset-top));
  left: 0;
  right: 0;
  padding: 12px 16px 18px;
  /* 明るいカメラ映像の上でも読めるように、うしろをうっすら暗くする */
  background: radial-gradient(ellipse at 50% 50%, rgba(20, 10, 30, 0.55), rgba(20, 10, 30, 0) 70%);
  text-align: center;
  font-family: "Zen Old Mincho", serif;
  font-size: clamp(1.1rem, 5.5vw, 2rem);
  line-height: 1.6;
  color: #fff7d6;
  text-shadow: 0 0 6px var(--gold), 0 0 16px var(--pumpkin), 0 2px 4px #000;
  opacity: 0;
  transition: opacity 0.8s;
  pointer-events: none;
}

.ar-chant.is-visible {
  opacity: 1;
}

/* 魔法発動中：呪文が強く光る */
.ar-chant.is-shining {
  animation: chant-shine 0.7s ease-in-out infinite alternate;
}

@keyframes chant-shine {
  to {
    text-shadow: 0 0 10px #fff, 0 0 24px var(--gold), 0 0 40px var(--pumpkin), 0 2px 4px #000;
  }
}

.ar-chant span {
  display: inline-block;
  opacity: 0;
  animation: chant-char 0.5s ease-out forwards;
}

@keyframes chant-char {
  from { opacity: 0; transform: translateY(10px) scale(1.6); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

/* ---------- 案内メッセージとボタン ---------- */
.ar-message {
  position: absolute;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 64px);
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 12px 18px;
  transform: translateX(-50%);
  text-align: center;
  white-space: pre-line;
  font-size: clamp(1rem, 4.5vw, 1.3rem);
  background: rgba(26, 15, 43, 0.78);
  border: 1px solid rgba(255, 213, 107, 0.5);
  border-radius: 12px;
  pointer-events: none;
}

.ar-message.is-success {
  font-size: clamp(1.2rem, 6vw, 1.7rem);
  color: var(--gold);
  text-shadow: 0 0 10px var(--pumpkin);
  animation: fade-in 0.8s ease-out;
}

.ar-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
}

.ar-button {
  padding: 8px 14px;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(26, 15, 43, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  cursor: pointer;
}

.ar-button[hidden] {
  display: none;
}
