/* =====================================================================
   作り込む文字の型（『超絶怒涛のGスイング！』で塾長OKが出た版）
   - 選ぶ文字（説明・内訳・ボタン）: --font-ui のまま。読みやすさ優先
   - 作り込む文字（数字・コンボ・ハンコ・掛け声・スコア）: .fx を付ける
   - タイトルロゴ: #logo / .lt（data-t に同じ文字を入れる）
   外部フォントは読み込まない。各OSの標準から一番太い書体を選ぶ。
   ゲームに合わせて変えてよいのは色（--ink / --gloss-*）と角度・厚みだけ。
   ===================================================================== */
:root {
  --ink: #2b2140; /* 縁と厚みの色。真っ黒より濃紺・濃紫が明るい画面になじむ */
  --font-ui: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  --font-num: "Futura-CondensedExtraBold", "Futura Condensed ExtraBold", "AvenirNextCondensed-Heavy", "Avenir Next Condensed", Impact, "Arial Black", sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic StdN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  --font-fx: var(--font-num), var(--font-jp);
  /* 光沢：上半分に明るい帯、38→40%で境目をくっきり */
  --gloss-gold: linear-gradient(180deg, #fffde0 0%, #fff27a 38%, #ffc21a 40%, #ff8a1f 78%, #ff5a1f 100%);
  --gloss-pink: linear-gradient(180deg, #ffe3f4 0%, #ff8ad8 38%, #ff3c8a 40%, #c8176e 100%);
  --gloss-cyan: linear-gradient(180deg, #f0ffff 0%, #9ff3ff 38%, #3dc6ff 40%, #1a6fe0 100%);
  --gloss-white: linear-gradient(180deg, #ffffff 0%, #ffffff 40%, #dfe8ff 42%, #b6c6f0 100%);
}
html, body { font-family: var(--font-ui); }

/* ---------- 演出の文字 ---------- */
.fx {
  font-family: var(--font-fx);
  font-weight: 900;
  font-style: italic;
  color: transparent;
  /* 注意: background の一括指定は background-clip をリセットして四角く塗れる。必ず background-image */
  background-image: var(--gloss-gold);
  -webkit-background-clip: text;
  background-clip: text;
  /* 縁（4方向）＋右下へずらした厚み。transform と一緒に動くので重ねても軽い */
  filter: drop-shadow(2px 0 0 var(--ink)) drop-shadow(-2px 0 0 var(--ink)) drop-shadow(0 2px 0 var(--ink)) drop-shadow(0 -2px 0 var(--ink)) drop-shadow(2px 4px 0 var(--ink));
  padding: 0 0.12em; /* 斜体の右端が切れないように */
  white-space: nowrap;
}
.fx.jp { font-family: var(--font-jp); }          /* 日本語の掛け声 */
.fx.pink { background-image: var(--gloss-pink); } /* 最高評価・FEVER */
.fx.cyan { background-image: var(--gloss-cyan); } /* コンボ・ゴール */
.fx.white { background-image: var(--gloss-white); } /* 常時表示のスコア */
.fx.stamp { /* 画面中央のハンコ。必ず画面幅で上限を切る */
  font-size: clamp(34px, 11.5cqw, 92px);
  filter: drop-shadow(3px 0 0 var(--ink)) drop-shadow(-3px 0 0 var(--ink)) drop-shadow(0 3px 0 var(--ink)) drop-shadow(0 -3px 0 var(--ink)) drop-shadow(4px 7px 0 var(--ink)) drop-shadow(0 0 18px rgba(255, 220, 120, 0.6));
}

/* ---------- 3Dタイトルロゴ ----------
   <h1 id="logo" aria-label="正式タイトル">
     <span class="lg-burst" aria-hidden="true"></span>
     <span class="lg-top" aria-hidden="true"><span class="lt" data-t="前置き">前置き</span></span>
     <span class="lg-main" aria-hidden="true">
       <span class="lt key" data-t="G">G</span><span class="lt body" data-t="本体">本体</span><span class="lt ex" data-t="！">！</span>
     </span>
   </h1>
   - 1段目：斜めのリボンに白文字（前置き・煽り）
   - 2段目：主役の1字（大きい・別書体・別色）＋本体（金）＋「！」（傾ける）
   - 主役の1字の後ろに、題材の記号（回転なら矢印の輪 SVG）を回す */
#logo {
  position: relative; margin: 0 0 14px; padding: 0;
  font-size: clamp(44px, min(16.5cqw, 9dvh), 104px); /* 縦画面ではみ出さない上限 */
  line-height: 1; text-align: center;
  transform: perspective(700px) rotateX(12deg) rotate(-5deg);
  animation: logoin 0.7s cubic-bezier(0.2, 1.5, 0.4, 1) both, logofloat 2.6s ease-in-out 0.7s infinite;
}
@keyframes logoin { from { transform: perspective(700px) rotateX(70deg) rotate(-5deg) scale(0.4); opacity: 0; } }
@keyframes logofloat { 50% { transform: perspective(700px) rotateX(12deg) rotate(-3deg) translateY(-6px); } }

.lg-burst { /* 背後の放射光 */
  position: absolute; left: 50%; top: 58%; width: 125%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(rgba(255, 245, 160, 0.75) 0deg 9deg, rgba(255, 245, 160, 0) 9deg 22deg);
  -webkit-mask-image: radial-gradient(circle, #000 18%, transparent 62%);
  mask-image: radial-gradient(circle, #000 18%, transparent 62%);
  animation: burst 14s linear infinite; z-index: -1; pointer-events: none;
}
@keyframes burst { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* ::before = 太縁＋奥への押し出し / ::after = 光沢の表面＋白ふち＋流れる光 */
.lt { position: relative; display: inline-block; color: transparent; font-family: var(--font-jp); font-weight: 900; }
.lt::before, .lt::after { content: attr(data-t); position: absolute; left: 0; top: 0; white-space: nowrap; }
.lt::before {
  color: var(--ext, #6a1b3c);
  -webkit-text-stroke: 0.2em var(--ink);
  text-shadow:
    0.02em 0.02em 0 var(--ext, #6a1b3c), 0.04em 0.04em 0 var(--ext, #6a1b3c), 0.06em 0.06em 0 var(--ext, #6a1b3c),
    0.08em 0.08em 0 var(--ext, #6a1b3c), 0.1em 0.1em 0 var(--ink), 0.11em 0.12em 0 var(--ink),
    0.12em 0.16em 0.12em rgba(0, 0, 0, 0.35);
}
.lt::after {
  color: transparent;
  background: linear-gradient(110deg, transparent 38%, rgba(255, 255, 255, 0.95) 46%, transparent 54%) no-repeat, var(--face, var(--gloss-gold));
  background-size: 250% 100%, 100% 100%;
  background-position: 150% 0, 0 0;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-stroke: 0.035em #fff;
  animation: shine 3.2s ease-in-out 1s infinite;
}
@keyframes shine { 0% { background-position: 150% 0, 0 0; } 40%, 100% { background-position: -60% 0, 0 0; } }

.lg-top {
  display: inline-block; position: relative; margin-bottom: 0.08em;
  padding: 0.06em 0.45em 0.1em; font-size: 0.34em;
  background: linear-gradient(180deg, #ff5a5a, #d81f3a);
  border: 0.09em solid var(--ink); border-radius: 0.25em;
  box-shadow: 0.08em 0.14em 0 var(--ink);
  transform: skewX(-12deg) rotate(-3deg);
}
.lg-top .lt { --face: var(--gloss-white); --ext: #8a0f2a; letter-spacing: 0.06em; }
.lg-top .lt::before { -webkit-text-stroke-width: 0.16em; }
.lg-main { display: block; white-space: nowrap; }
.lt.key { font-family: var(--font-num); font-style: italic; font-size: 1.45em; --face: var(--gloss-pink); --ext: #5a0a3a; padding: 0 0.06em; }
.lt.body { font-size: 0.82em; --face: var(--gloss-gold); --ext: #8a3a00; letter-spacing: -0.04em; }
.lt.ex { font-size: 0.9em; --face: var(--gloss-pink); --ext: #5a0a3a; transform: rotate(10deg); }

@media (prefers-reduced-motion: reduce) {
  #logo, .lg-burst, .lt::after { animation: none !important; }
}

/* =====================================================================
   WARI RUN 固有
   色の役割：世界＝夜明けの紫と淡い空 / 主役＝白い犬 / 操作・目標＝金 /
   危険＝赤 / 左右の幕＝青（左）と赤（右）で固定（正解の色ではない）
   ===================================================================== */
:root { --bg: #2a2250; --panel: #fffaf0; --gate-l: #2d9cff; --gate-r: #ff4d6d; --gold: #ffc21a; --danger: #ff4d6d; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; touch-action: manipulation; color: var(--ink); }
#app {
  position: relative; display: flex; flex-direction: column; height: 100dvh; max-width: 520px; margin: 0 auto;
  background: #b9e4ff; box-shadow: 0 0 0 100vmax var(--bg);
  padding-top: env(safe-area-inset-top, 0px);
}
#stage { container-type: inline-size; position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---- HUD ---- */
#hud { position: absolute; inset: 0 0 auto 0; padding: 10px 14px 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
#hud[hidden] { display: none; }
#score { font-size: clamp(34px, 10vw, 54px); line-height: 1; }
#hearts { display: flex; gap: 4px; }
#hearts svg { width: clamp(20px, 6vw, 28px); height: auto; filter: drop-shadow(0 2px 0 var(--ink)); transition: transform 0.15s; }
#hearts svg.lost { opacity: 0.25; filter: none; }
#hearts svg.hit { animation: heartHit 0.35s; }
@keyframes heartHit { 30% { transform: scale(1.5) rotate(-12deg); } }
#combo { font-size: clamp(22px, 6.5vw, 32px); }
#vol {
  position: absolute; right: 10px; top: 10px; z-index: 5; font: 800 13px var(--font-ui); color: var(--ink);
  background: var(--panel); border: 3px solid var(--ink); border-radius: 999px; padding: 6px 12px; box-shadow: 0 3px 0 var(--ink);
}
#fxlayer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; left: 50%; transform: translate(-50%, 0); animation: popUp 0.9s ease-out forwards; will-change: transform, opacity; }
@keyframes popUp { 0% { transform: translate(-50%, 18px) scale(0.4); opacity: 0; } 12% { transform: translate(-50%, 0) scale(1.15); opacity: 1; } 24% { transform: translate(-50%, 0) scale(1); } 70% { transform: translate(-50%, -14px) scale(1); opacity: 1; } 100% { transform: translate(-50%, -34px) scale(1); opacity: 0; } }
.pop:not(.stamp) { font-size: clamp(28px, 9.5cqw, 46px); }
.pop.small { font-size: clamp(24px, 7.5cqw, 36px); }
.flash { position: absolute; inset: 0; opacity: 0; animation: flash 0.28s ease-out; }
@keyframes flash { 0% { opacity: 0.45; } 100% { opacity: 0; } }
.shake { animation: shake 0.3s; }
@keyframes shake { 20% { transform: translate(-5px, 2px); } 40% { transform: translate(5px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }

/* ---- 操作（下の帯）：素数ボタンはプレイヤーの下・左右タップの上 ---- */
#controls { flex: 0 0 auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(180deg, #4a3d8f, #2a2250); border-top: 4px solid var(--ink); }
#prime {
  width: 100%; height: clamp(52px, 8.5dvh, 70px); font: italic 900 clamp(28px, 8.5vw, 40px) var(--font-fx); letter-spacing: 0.04em;
  color: var(--ink); background-image: var(--gloss-gold); border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 6px 0 var(--ink);
}
#prime:disabled { filter: grayscale(0.7) brightness(0.8); }
#prime:not(:disabled):active, #prime.armed { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
#prime.armed { background-image: var(--gloss-pink); color: #fff; }
#lr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#lr button { height: clamp(72px, 14dvh, 112px); font: 900 clamp(34px, 11vw, 52px) var(--font-ui); color: #fff; border: 4px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink); }
#btnL { background: linear-gradient(180deg, #6cc0ff, var(--gate-l)); }
#btnR { background: linear-gradient(180deg, #ff8aa0, var(--gate-r)); }
#lr button:active, #lr button.on { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }

/* ---- タイトル・結果 ---- */
.card-screen {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 16px clamp(16px, 6vw, 32px); text-align: center; background: rgba(42, 34, 80, 0.62); overflow: clip; /* 放射光のはみ出しを切る */
}
.card-screen[hidden] { display: none; }
#result { background: rgba(32, 25, 66, 0.86); }
.how { list-style: none; margin: 0; padding: 12px 14px; width: 100%; max-width: 380px; background: var(--panel); border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); text-align: left; display: grid; gap: 8px; }
.how li { display: grid; grid-template-columns: 4.6em 1fr; gap: 8px; align-items: baseline; font-size: clamp(13px, 3.8vw, 16px); }
.how b { font-family: var(--font-jp); font-weight: 900; background: var(--ink); color: #fff; border-radius: 8px; padding: 2px 6px; text-align: center; }
.big-btn { font: italic 900 clamp(28px, 9vw, 40px) var(--font-fx); color: var(--ink); background-image: var(--gloss-gold); border: 4px solid var(--ink); border-radius: 22px; padding: 10px 34px; box-shadow: 0 7px 0 var(--ink); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
#retry { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.best { margin: 0; color: #fff; font-weight: 800; font-size: clamp(13px, 3.8vw, 15px); text-shadow: 0 2px 0 var(--ink); }
.err { margin: 0; max-width: 340px; padding: 10px 12px; background: #fff; border: 3px solid var(--danger); border-radius: 12px; font-size: 14px; font-weight: 700; }
#r-score { font-size: clamp(44px, 14vw, 76px); line-height: 1; }
#rank { animation: stampIn 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; font-size: clamp(64px, 22vw, 120px); }
@keyframes stampIn { from { transform: scale(3) rotate(-14deg); opacity: 0; } }
.stats { list-style: none; margin: 0; padding: 10px 14px; width: 100%; max-width: 340px; background: var(--panel); border: 4px solid var(--ink); border-radius: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: clamp(13px, 3.8vw, 15px); text-align: left; }
.stats b { float: right; }
.hint { margin: 0; max-width: 340px; padding: 8px 12px; background: #fff3b8; border: 3px solid var(--ink); border-radius: 12px; font-size: clamp(13px, 3.8vw, 15px); font-weight: 700; }
.hint::before { content: "ヒント "; font-weight: 900; color: #b25a00; }

@media (max-height: 700px) {
  .card-screen { gap: 8px; padding-block: 10px; }
  .how { padding: 8px 12px; gap: 5px; }
  .how li { font-size: 12px; }
  .big-btn { padding: 6px 28px; font-size: 26px; }
  .stats { padding: 6px 12px; font-size: 12px; }
  .hint { font-size: 12px; padding: 6px 10px; }
  #rank { font-size: 56px; }
  #r-score { font-size: 40px; }
}
@media (max-height: 620px) { .how li span { font-size: 11px; } .how li { grid-template-columns: 4.2em 1fr; } }

@media (prefers-reduced-motion: reduce) {
  .pop { animation: none !important; transform: translate(-50%, 0); opacity: 1; }
  .flash, .shake, #retry, #hearts svg.hit, #rank { animation: none !important; }
}
