/* =============================================================
   style.css ― まほうのプログラミング・ダンジョン ver2 の見た目
   -------------------------------------------------------------
   目次
     0. フォント・色などの共通設定（CSS変数）
     1. Kenney UI Pack の部品（ボタン・パネル・チェック）
     2. 画面の土台と切り替え
     3. スタート画面（タイトル・主人公/難易度カード）
     4. プレイ画面 HUD
     5. バトルシーン（背景・主人公・モンスター）
     6. 演出（魔法・パーティクル・文字ポップ・帯）
     7. お題の単語とキーボードガイド
     8. 結果画面
     9. モンスター図鑑
    10. 画面が狭いとき（スマホ・ブログの細いカラム）

   UI Pack の画像は「9スライス（border-image）」で使っている。
   画像の四隅はそのまま、辺と中央だけを伸ばすので、ボタンの大きさが
   変わっても角の丸みや立体感（下側の影）が崩れない。
     border-image-slice : 画像の端から何px を「角・辺」とみなすか
     border-width       : 画面上でその部分を何px で描くか
   ============================================================= */

/* ---------- 0. 共通設定 ---------- */
:root {
  --ink: #3b2f5c;          /* 基本の文字色（こい紫） */
  --ink-soft: #7a7199;
  --paper: #fffaf0;        /* 画面の地の色 */
  --navy: #2d3561;
  --green: #2dbb6a;
  --blue: #1ea7e1;
  --yellow: #ffc21a;
  --red: #e8584d;
  --font-jp: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'BIZ UDPGothic', 'Meiryo', sans-serif;
  --font-num: var(--font-jp);   /* 数字・英字も「Q と O」「5 と S」が見分けやすい丸ゴシックで表示 */
}

html, body { margin: 0; padding: 0; }
body {
  background: #1f2744;
  font-family: var(--font-jp);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font-family: inherit; }
.num { font-family: var(--font-num); font-weight: 900; letter-spacing: 0.02em; }

/* ---------- 1. Kenney UI Pack の部品 ---------- */

/* 立体ボタン（192×64 の画像を 9スライス） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 3em;
  padding: 0 0.9em;
  border-style: solid;
  border-width: 10px 12px 16px;
  border-image-slice: 12 12 16 12 fill;
  border-image-source: url('../assets/kenney/ui-pack/Green/button_rectangle_depth_gradient.svg');
  background: none;
  color: #fff;
  font-weight: 900;
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.08s, filter 0.12s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(3px); filter: brightness(0.95); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn-blue { border-image-source: url('../assets/kenney/ui-pack/Blue/button_rectangle_depth_gradient.svg'); }
.btn-yellow { border-image-source: url('../assets/kenney/ui-pack/Yellow/button_rectangle_depth_gradient.svg'); color: var(--ink); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); }
.btn-dark { border-image-source: url('../assets/kenney/ui-pack/Grey/button_rectangle_depth_gradient.svg'); color: var(--ink); text-shadow: none; }
.btn-big { font-size: 1.3rem; min-height: 3.3em; padding: 0 1.6em; }
.btn-icon { width: 0.9em; height: auto; }

/* まるボタン（HUD のサウンド・やめる） */
.round-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  padding: 0 0 4px;
  background: url('../assets/kenney/ui-pack/Blue/button_round_depth_gradient.svg') center / 100% 100% no-repeat;
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}
.round-btn:active { transform: translateY(2px); }

/* チェックボックス（UI Pack のチェック画像を切り替え） */
.check-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.35em 0.6em;
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}
.check-box {
  width: 28px;
  height: 28px;
  background: url('../assets/kenney/ui-pack/Grey/check_square_grey.svg') center / contain no-repeat;
}
.check-btn[aria-pressed='true'] .check-box {
  background-image: url('../assets/kenney/ui-pack/Blue/check_square_color_checkmark.svg');
}

/* ---------- 2. 画面の土台 ---------- */
.mpd {
  container-type: inline-size;   /* 中の文字や部品を「ゲーム枠の幅」基準で伸縮させる */
  position: relative;
  max-width: 980px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  border-radius: 18px;
  box-shadow: 0 10px 0 #151b33, 0 18px 40px rgba(0, 0, 0, 0.35);
}
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in 0.35s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 見出しの「①」番号 */
.step-title {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 1.1em 0 0.6em;
  font-size: 1.15rem;
  font-weight: 900;
}
.step-num {
  display: inline-grid;
  place-items: center;
  width: 1.8em;
  height: 1.8em;
  padding-bottom: 3px;
  box-sizing: border-box;
  background: url('../assets/kenney/ui-pack/Blue/button_round_depth_flat.svg') center / 100% 100% no-repeat;
  color: #fff;
  font-family: var(--font-num);
  font-size: 0.9em;
}

/* ---------- 3. スタート画面 ---------- */

/* タイトルの景色（背景の描き方は 5. バトルシーンと共通） */
.title-scene {
  position: relative;
  height: clamp(210px, 36cqw, 330px);
  overflow: hidden;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
}
.title-logo {
  position: relative;
  z-index: 3;
  padding-top: clamp(14px, 3.5cqw, 34px);
  text-align: center;
}
.title-sub {
  display: inline-block;
  margin: 0 0 0.4em;
  padding: 0.25em 1em 0.35em;
  background: var(--navy);
  border-radius: 999px;
  color: #fff;
  font-size: clamp(0.75rem, 1.8cqw, 1rem);
  font-weight: 800;
}
.title-main {
  margin: 0;
  line-height: 1.05;
  font-weight: 900;
  -webkit-text-stroke: 0.22em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.12em 0 var(--ink);
}
.title-line1 { display: block; color: #fff; font-size: clamp(1.3rem, 4.2cqw, 2.4rem); }
.title-line2 { display: block; color: #ffd23f; font-size: clamp(1.7rem, 6.4cqw, 3.7rem); letter-spacing: 0.02em; }

/* タイトルを歩くモンスターたち */
.parade { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.parade-mon {
  position: absolute;
  bottom: calc(var(--u) * 26);
  left: 0;
  width: calc(var(--u) * 62);
  animation: parade-walk 16s linear infinite;
}
.parade-mon svg { display: block; width: 100%; height: auto; animation: bob 0.5s ease-in-out infinite alternate; }
@keyframes parade-walk { from { transform: translateX(-120%); } to { transform: translateX(calc(100cqw + 20%)); } }

.start-body { padding: 0.2em clamp(14px, 3.5cqw, 36px) 1.6em; }

/* 選択カード（主人公・難易度） */
.card-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 1.6cqw, 16px); }
/* 主人公は5人: 広い画面では横1列、狭い画面では 3人＋2人 を中央ぞろえで並べる */
.hero-list { display: flex; flex-wrap: wrap; justify-content: center; }
.hero-list .card { flex: 0 1 calc((100% - 4 * clamp(8px, 1.6cqw, 16px)) / 5); box-sizing: border-box; min-width: 0; }
.hero-list .card-hero-stage { width: clamp(60px, 11cqw, 104px); height: clamp(66px, 12cqw, 112px); }
.hero-list .card-hero-sprite { height: clamp(52px, 9.5cqw, 92px); }
.hero-list .card-sub { font-size: clamp(0.62rem, 1.35cqw, 0.8rem); }
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  padding: 0.5em 0.4em 0.7em;
  border-style: solid;
  border-width: 10px 10px 14px;
  border-image: url('../assets/kenney/ui-pack/Grey/button_square_depth_line.svg') 10 10 14 10 fill / 10px 10px 14px;
  background: none;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s;
}
.card:hover { transform: translateY(-3px); }
.card.is-selected {
  border-image-source: url('../assets/kenney/ui-pack/Yellow/button_square_depth_border.svg');
  transform: translateY(-3px);
}
.card-check {
  position: absolute;
  top: -14px;
  right: -12px;
  width: 30px;
  opacity: 0;
  transform: scale(0.4);
  transition: 0.18s;
}
.card.is-selected .card-check { opacity: 1; transform: scale(1); }
.card-title { font-size: clamp(0.95rem, 2.3cqw, 1.2rem); font-weight: 900; line-height: 1.3; }
.card-title rt { font-size: 0.5em; font-weight: 700; color: var(--ink-soft); }
.card-sub { font-size: clamp(0.72rem, 1.7cqw, 0.9rem); font-weight: 700; color: var(--ink-soft); }
.card-tag {
  margin-top: 0.25em;
  padding: 0.15em 0.7em 0.2em;
  border-radius: 999px;
  background: var(--tag-color);
  color: #fff;
  font-size: clamp(0.68rem, 1.6cqw, 0.85rem);
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.card-hero-stage {
  display: grid;
  place-items: end center;
  width: clamp(70px, 14cqw, 120px);
  height: clamp(80px, 16cqw, 136px);
  border-radius: 50% 50% 14px 14px;
  background: radial-gradient(circle at 50% 70%, color-mix(in srgb, var(--hero-color) 45%, #fff), #fff 72%);
}
.card-hero-sprite { height: clamp(68px, 13.6cqw, 116px); width: auto; transform-origin: bottom; }
.card-hero-sprite { position: relative; }
.card.is-selected .card-hero-sprite { animation: hop 0.6s ease-in-out infinite alternate; }
.card-stars { display: flex; gap: 2px; }
.card-stars .star { width: clamp(18px, 3.4cqw, 28px); }

.option-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.4em 1.4em; margin-top: 1em; }
.start-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 0.8em; }
.bestiary-count { font-family: var(--font-num); font-size: 0.85em; }

/* ---------- 4. プレイ画面 HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: clamp(5px, 1cqw, 10px);
  padding: 8px clamp(8px, 1.4cqw, 14px);
  background: var(--navy);
}
.hud-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: clamp(56px, 10cqw, 96px);
  padding: 0 0.3em;
  border-style: solid;
  border-width: 6px 8px 8px;
  border-image: url('../assets/kenney/ui-pack/Extra/input_rectangle.svg') 8 fill / 6px 8px 8px;
  line-height: 1.1;
}
.hud-label { font-size: clamp(0.6rem, 1.4cqw, 0.75rem); font-weight: 800; color: var(--ink-soft); }
.hud-value { font-size: clamp(1rem, 2.6cqw, 1.45rem); color: var(--ink); }
.hud-combo { border-image-source: url('../assets/kenney/ui-pack/Yellow/button_rectangle_depth_flat.svg'); border-width: 5px 8px 9px; }
.hud-combo .hud-value { color: var(--ink); }
.hud-combo.is-pop { animation: pop 0.25s ease-out; }
.hud-time { flex: 1; min-width: 0; color: #fff; }
.hud-time-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-weight: 800; font-size: clamp(0.66rem, 1.6cqw, 0.9rem); }
.hud-stage { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; opacity: 0.9; }
.hud-sec { white-space: nowrap; }
.hud-sec .num { font-size: 1.5em; margin-right: 2px; }
.timer-track {
  height: 16px;
  margin-top: 3px;
  box-sizing: border-box;
  border-style: solid;
  border-width: 0 8px;
  border-image: url('../assets/kenney/ui-pack/Grey/slide_horizontal_grey.svg') 0 8 fill / 0 8px;
  position: relative;
}
.timer-fill {
  position: absolute;
  left: -8px;
  top: 0;
  bottom: 0;
  min-width: 16px;
  box-sizing: border-box;
  border-style: solid;
  border-width: 0 8px;
  border-image: url('../assets/kenney/ui-pack/Green/slide_horizontal_color.svg') 0 8 fill / 0 8px;
  transition: width 0.4s linear;
}
.timer-fill.is-warn {
  border-image-source: url('../assets/kenney/ui-pack/Red/slide_horizontal_color.svg');
  animation: blink 0.5s steps(2) infinite;
}

/* ---------- 5. バトルシーン ---------- */
.battle {
  position: relative;
  height: clamp(230px, 44cqw, 420px);
  overflow: hidden;
  background: linear-gradient(var(--sky-top, #6fd3ff), var(--sky-bottom, #c9f1ff));
  transition: background 0.6s;
}
.battle-sky { position: absolute; inset: 0; }
/* 溶岩ステージは空をほんのり明滅させる */
.battle[data-stage='lava'] .battle-sky { background: radial-gradient(ellipse at 50% 100%, rgba(255, 120, 40, 0.45), transparent 70%); animation: glow 2s ease-in-out infinite alternate; }
.battle[data-stage='castle'] .battle-sky { background: radial-gradient(circle at 82% 22%, #fff7c2 0 4%, transparent 4.5%); }

/* 雲（CSSだけで描いた白い丸の集まり） */
.battle-clouds span {
  position: absolute;
  width: calc(var(--u) * 46);
  height: calc(var(--u) * 14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  animation: cloud 40s linear infinite;
}
.battle-clouds span::before, .battle-clouds span::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: inherit;
}
.battle-clouds span::before { width: 45%; height: 170%; left: 14%; bottom: 20%; }
.battle-clouds span::after { width: 34%; height: 130%; left: 50%; bottom: 25%; }
.battle-clouds span:nth-child(1) { top: 12%; animation-delay: -6s; }
.battle-clouds span:nth-child(2) { top: 26%; animation-duration: 55s; animation-delay: -30s; transform: scale(0.7); }
.battle-clouds span:nth-child(3) { top: 6%; animation-duration: 48s; animation-delay: -18s; }
.battle[data-stage='castle'] .battle-clouds span, .battle[data-stage='lava'] .battle-clouds span { background: rgba(60, 40, 80, 0.45); }
@keyframes cloud { from { left: -30%; } to { left: 110%; } }

/* 奥の飾り（木・岩・お城など。Block Pack） */
.battle-props { position: absolute; inset: 0; }
.prop {
  position: absolute;
  bottom: calc(var(--u) * 44);
  width: auto;
  filter: saturate(0.85) brightness(0.97);
}

/* 地面（Block Pack のタイルを横に敷き詰める） */
.battle-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--u) * 52);
  background-repeat: repeat-x, repeat;
  background-size: calc(var(--u) * 48) auto, calc(var(--u) * 48) auto;
  background-position: 0 0, 0 calc(var(--u) * 40);
}

/* 主人公とモンスター共通 */
.actor { position: absolute; z-index: 2; }
.nameplate {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.1em 0.7em 0.2em;
  border-radius: 999px;
  background: rgba(45, 53, 97, 0.88);
  color: #fff;
  font-size: clamp(0.66rem, 1.6cqw, 0.9rem);
  font-weight: 900;
  white-space: nowrap;
  text-align: center;
}

.hero {
  left: 9%;
  bottom: calc(var(--u) * 26);
  width: calc(var(--u) * 72);   /* Tiny Dungeon のキャラは正方形なので横幅を広めに */
}
.hero-plate { top: calc(var(--u) * -22); }
.hero-sprite {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  transform-origin: bottom center;
  animation: breathe 1.4s ease-in-out infinite alternate;
}
.hero.is-hurt .hero-sprite { animation: hurt 0.5s ease-out; }
/* 足元の影（画像に filter をかけると拡大時にぼやけるので、別要素で描く） */
.hero::after { content: ''; position: absolute; left: 10%; right: 10%; bottom: calc(var(--u) * -2); height: calc(var(--u) * 7); border-radius: 50%; background: rgba(0, 0, 0, 0.18); z-index: -1; }

/* 魔力チャージのオーブ（--charge: 0〜1 で大きさと光り方が変わる） */
.charge {
  --charge: 0;
  position: absolute;
  right: calc(var(--u) * -18);
  top: calc(var(--u) * 6);
  width: calc(var(--u) * (8 + 20 * var(--charge)));
  aspect-ratio: 1;
  transform: translate(50%, -50%);
  opacity: 0;
  transition: width 0.12s, opacity 0.2s;
}
.charge.is-active { opacity: 1; }
.charge-orb {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 18%, var(--hero-color, #ff7a2f) 55%, transparent 72%);
  box-shadow: 0 0 calc(var(--u) * 10 * var(--charge)) var(--hero-color, #ff7a2f);
  animation: spin-glow 0.8s linear infinite;
}

.monster {
  --approach: 0;
  right: calc(7% + var(--approach) * 34%);
  bottom: calc(var(--u) * 24);
  width: calc(var(--u) * 118);
  transition: right 0.25s ease-out;
}
.monster.is-boss { width: calc(var(--u) * 138); }
.monster-plate { top: calc(var(--u) * 2); display: flex; flex-direction: column; align-items: center; gap: 3px; padding-bottom: 5px; }
.approach { width: calc(var(--u) * 44); height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.approach-fill { width: 0; height: 100%; background: #ffd23f; transition: width 0.2s; }
.approach-fill.is-danger { background: #ff5a4e; }
.monster.is-defeated .monster-plate { opacity: 0; transition: opacity 0.2s; }
.monster-body svg { display: block; width: 100%; height: auto; overflow: visible; }
.monster-body .mon-svg { animation: bob 0.9s ease-in-out infinite alternate; }
.monster-body.is-hit .mon-svg { animation: hit-flash 0.3s steps(2) 2; }
/* 腕をゆらゆら（monsters.js が付けた class。原点=肩の位置で回転する） */
.mon-arm-r { animation: arm-sway 1.1s ease-in-out infinite alternate; }
.mon-arm-l { animation: arm-sway 1.1s ease-in-out infinite alternate-reverse; }
.mon-shadow { fill: rgba(0, 0, 0, 0.18); }

/* ---------- 6. 演出 ---------- */
.fx-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.fx { position: absolute; will-change: transform, opacity; }
.spell-fire { width: calc(var(--u) * 40); }
.spell-ice { width: calc(var(--u) * 46); }
.spell-thunder { width: calc(var(--u) * 26); top: 0; transform-origin: top; filter: drop-shadow(0 0 8px #fff27a); }
.spell-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spell-wind { width: calc(var(--u) * 36); filter: drop-shadow(0 0 8px rgba(80, 220, 140, 0.9)); }
.spell-star { width: calc(var(--u) * 22); filter: drop-shadow(0 0 8px rgba(255, 215, 80, 0.95)); }
.spell-fire .spell-svg, .spell-ice .spell-svg, .spell-wind .spell-svg, .spell-star .spell-svg { height: auto; }
.spell-fire { filter: drop-shadow(0 0 10px rgba(255, 140, 40, 0.8)); }
.spell-ice { filter: drop-shadow(0 0 8px rgba(120, 220, 255, 0.9)); }
.particle { width: calc(var(--u) * 7); height: calc(var(--u) * 7); border-radius: 50%; }
.ring { width: calc(var(--u) * 44); height: calc(var(--u) * 44); border: 5px solid; border-radius: 50%; box-sizing: border-box; }
.fx-star img { display: block; width: calc(var(--u) * 16); }
.puff { width: calc(var(--u) * 24); height: calc(var(--u) * 24); border-radius: 50%; background: rgba(255, 255, 255, 0.9); }
.screen-flash { left: 0 !important; top: 0 !important; width: 100%; background: #fffbe0; }
.pop-text {
  z-index: 6;
  font-family: var(--font-num);
  font-size: clamp(1rem, 3.2cqw, 1.8rem);
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  -webkit-text-stroke: 0.2em var(--ink);
  paint-order: stroke fill;
}
.pop-text.is-score { color: #ffd23f; font-size: clamp(1.3rem, 4.2cqw, 2.4rem); }
.pop-text.is-damage { color: #ff6b5e; font-family: var(--font-jp); }
.pop-text.is-combo { color: #ff9a3c; font-family: var(--font-jp); }
.pop-text.is-warn { font-family: var(--font-jp); font-size: clamp(0.9rem, 2.6cqw, 1.3rem); }

.banner { position: absolute; left: 0; right: 0; top: 30%; z-index: 7; pointer-events: none; }
.banner-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35em 0 0.5em;
  background: linear-gradient(90deg, transparent, rgba(45, 53, 97, 0.92) 18%, rgba(45, 53, 97, 0.92) 82%, transparent);
  border-top: 3px solid #ffd23f;
  border-bottom: 3px solid #ffd23f;
}
.banner-main {
  color: #ffd23f;
  font-size: clamp(1.6rem, 6cqw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  -webkit-text-stroke: 0.16em var(--ink);
  paint-order: stroke fill;
}
.banner-sub { color: #fff; font-weight: 800; font-size: clamp(0.8rem, 2.2cqw, 1.1rem); }
.banner-sub:empty { display: none; }

/* ---------- 7. お題の単語とキーボード ---------- */
.word-panel {
  position: relative;
  z-index: 3;
  margin: calc(-1 * clamp(18px, 3cqw, 30px)) clamp(10px, 4cqw, 60px) 0;
  padding: 0.35em 0.8em 0.55em;
  border-style: solid;
  border-width: 10px 12px 16px;
  border-image: url('../assets/kenney/ui-pack/Grey/button_rectangle_depth_line.svg') 12 12 16 12 fill / 10px 12px 16px;
  text-align: center;
}
.word-kana { min-height: 1.3em; font-size: clamp(0.8rem, 2cqw, 1rem); font-weight: 700; color: var(--ink-soft); letter-spacing: 0.08em; }
.word-display { min-height: 1.3em; font-size: clamp(1.5rem, 4.8cqw, 2.6rem); font-weight: 900; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; }
.word-romaji {
  min-height: 1.4em;
  margin-top: 0.15em;
  font-family: var(--font-num);
  font-size: clamp(1.05rem, 3.2cqw, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
}
.r-done { color: var(--green); }
.r-next {
  display: inline-block;
  min-width: 0.7em;
  padding: 0 0.12em;
  border-radius: 6px;
  background: #ffd23f;
  color: var(--ink);
  box-shadow: 0 3px 0 #d9a300;
  animation: next-bounce 0.7s ease-in-out infinite alternate;
}
.r-next:empty { display: none; }
.r-rest { color: #aaa3c2; }
.word-romaji.is-miss { animation: miss-shake 0.3s; }
.word-romaji.is-miss .r-next { background: #ff6b5e; box-shadow: 0 3px 0 #b8342b; color: #fff; }

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 0.6cqw, 6px);
  padding: clamp(10px, 2cqw, 18px) 8px clamp(12px, 2.2cqw, 20px);
}
.key-row { display: flex; gap: clamp(3px, 0.6cqw, 6px); }
.key-row-2 { margin-left: 2.5%; }
.key-row-3 { margin-left: 6%; }
.key {
  display: grid;
  place-items: center;
  width: clamp(24px, 6.2cqw, 50px);
  height: clamp(26px, 6.2cqw, 50px);
  box-sizing: border-box;
  padding-bottom: 3px;
  border-style: solid;
  border-width: 6px 6px 9px;
  border-image: url('../assets/kenney/ui-pack/Grey/button_square_depth_flat.svg') 8 8 12 8 fill / 6px 6px 9px;
  font-family: var(--font-num);
  font-size: clamp(0.7rem, 2cqw, 1.1rem);
  font-weight: 900;
  text-transform: uppercase;   /* 本物のキーボードの刻印と同じ大文字で表示 */
  color: var(--ink);
  user-select: none;
}
.key.is-next {
  border-image-source: url('../assets/kenney/ui-pack/Yellow/button_square_depth_gradient.svg');
  animation: key-glow 0.8s ease-in-out infinite alternate;
}
.key.is-ok { animation: key-ok 0.25s ease-out; }
.key.is-miss { border-image-source: url('../assets/kenney/ui-pack/Red/button_square_depth_gradient.svg'); color: #fff; animation: key-miss 0.35s ease-out forwards; }

/* ---------- 8. 結果画面 ---------- */
.screen-result { padding: 0 clamp(12px, 3.5cqw, 36px) 1.6em; background: radial-gradient(circle at 50% 0, #fff3c4, var(--paper) 55%); }
.result-ribbon {
  width: fit-content;
  margin: 0 auto;
  padding: 0.35em 2.2em 0.5em;
  background: var(--blue);
  clip-path: polygon(0 0, 100% 0, 94% 50%, 100% 100%, 0 100%, 6% 50%);
  color: #fff;
  font-size: clamp(1.1rem, 3cqw, 1.5rem);
  font-weight: 900;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.15);
}
.result-main { display: flex; justify-content: center; align-items: center; gap: clamp(12px, 4cqw, 40px); margin-top: 0.8em; }
.result-hero {
  display: grid;
  place-items: end center;
  width: clamp(90px, 18cqw, 160px);
  height: clamp(110px, 22cqw, 190px);
  border-radius: 50% 50% 16px 16px;
  background: radial-gradient(circle at 50% 75%, #ffe58a, transparent 70%);
}
.result-hero img { position: relative; height: clamp(96px, 19cqw, 168px); width: auto; animation: hop 0.5s ease-in-out infinite alternate; }
.result-summary { text-align: center; }
.result-stars { display: flex; justify-content: center; gap: 4px; }
.result-stars .star { width: clamp(38px, 8cqw, 64px); animation: star-pop 0.5s cubic-bezier(.2, .9, .3, 1.4) backwards; }
.result-stars .star:nth-child(2) { animation-delay: 0.15s; transform: translateY(-10px); }
.result-stars .star:nth-child(3) { animation-delay: 0.3s; }
.result-rank { margin: 0.2em 0 0; font-size: clamp(1.1rem, 3.2cqw, 1.6rem); font-weight: 900; }
.result-score { margin: 0; line-height: 1; }
.result-score .num { font-size: clamp(2.4rem, 9cqw, 4.4rem); color: var(--ink); text-shadow: 0 4px 0 #ffd23f; }
.result-score small { margin-left: 4px; font-weight: 900; }
.result-best { margin: 0.4em 0 0; font-weight: 900; color: #e8584d; animation: pop 0.6s ease-in-out infinite alternate; }

.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 1em 0 0; }
.result-stats > div {
  padding: 0.2em 0.2em 0.4em;
  border-style: solid;
  border-width: 8px 8px 12px;
  border-image: url('../assets/kenney/ui-pack/Blue/button_square_depth_border.svg') 10 10 14 10 fill / 8px 8px 12px;
  text-align: center;
}
.result-stats dt { font-size: clamp(0.66rem, 1.6cqw, 0.85rem); font-weight: 800; color: var(--ink-soft); }
.result-stats dd { margin: 0; font-weight: 900; }
.result-stats dd .num { font-size: clamp(1.2rem, 3.4cqw, 1.8rem); }

.result-defeated h3 { margin: 1em 0 0.3em; font-size: 1rem; text-align: center; }
.defeated-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.defeated-item { position: relative; width: clamp(76px, 13cqw, 110px); }
.defeated-item svg { display: block; width: 100%; height: auto; }
.defeated-count { position: absolute; right: 0; bottom: 0; padding: 0 5px; border-radius: 8px; background: var(--navy); color: #fff; font-family: var(--font-num); font-size: 0.75rem; }
.defeated-empty { margin: 0; color: var(--ink-soft); font-weight: 700; }

.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 1em; }
.result-actions .btn { font-size: clamp(0.8rem, 2cqw, 1rem); }

/* シェア欄（X / Threads / インスタ / リンクをコピー） */
.share-row { margin-top: 1.2em; text-align: center; }
.share-title { margin: 0 0 0.4em; font-weight: 900; font-size: 1rem; }
.share-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.share-buttons .btn { font-size: clamp(0.78rem, 1.9cqw, 0.95rem); }
.share-note { margin: 0.5em 0 0; color: var(--ink-soft); font-size: 0.78rem; font-weight: 700; }

.share-url {
  margin: 0.6em 0 0;
  padding: 0.4em 0.6em;
  border-radius: 8px;
  background: #fff;
  border: 2px dashed var(--ink-soft);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  user-select: all;   /* タップ1回で全部選べるようにする */
  white-space: pre-wrap;   /* インスタ用の文章は改行入りなので、そのまま表示する */
  overflow-wrap: anywhere;
}

.cta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 1.2em; }
.cta {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.4em 0.6em 0.5em;
  border-style: solid;
  border-width: 10px 12px 16px;
  border-image: url('../assets/kenney/ui-pack/Blue/button_rectangle_depth_border.svg') 12 12 16 12 fill / 10px 12px 16px;
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.12s;
}
.cta:hover { transform: translateY(-2px); }
.cta-icon { font-size: 1.8rem; }
.cta-text { flex: 1; display: flex; flex-direction: column; line-height: 1.35; }
.cta-text strong { font-size: 0.92rem; }
.cta-text small { color: var(--blue); font-weight: 800; }
.cta-arrow { width: 22px; }

/* ---------- 9. モンスター図鑑 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(20, 24, 48, 0.72);
}
.overlay-panel {
  width: min(900px, 100%);
  max-height: 92vh;
  overflow: auto;
  box-sizing: border-box;
  padding: 1em 1.2em 1.4em;
  border-radius: 18px;
  background: var(--paper);
  text-align: center;
}
.overlay-title { margin: 0; font-weight: 900; }
.overlay-note { margin: 0.3em 0 0.8em; color: var(--ink-soft); font-weight: 700; font-size: 0.9rem; }
.bestiary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 1em; }
.bestiary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 6px 10px;
  border-style: solid;
  border-width: 8px 8px 12px;
  border-image: url('../assets/kenney/ui-pack/Grey/button_square_depth_line.svg') 10 10 14 10 fill / 8px 8px 12px;
}
.bestiary-item svg { width: 100%; max-width: 150px; height: auto; }
.bestiary-no { align-self: flex-start; font-size: 0.7rem; color: var(--ink-soft); }
.bestiary-name { font-weight: 900; }
.bestiary-desc { font-size: 0.75rem; color: var(--ink-soft); font-weight: 700; line-height: 1.4; }
.bestiary-item.is-unknown svg { filter: brightness(0) opacity(0.28); }
.debug-gallery { padding: 16px; }
.debug-gallery .bestiary-item { background: #bfe9ff; }

/* ---------- アニメーション定義 ---------- */
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-3%); } }
/* 主人公（SVG の img）は transform で動かすと Chrome で絵がぼやけるため、top で上下させている */
@keyframes breathe { from { top: 0; } to { top: calc(var(--u) * -1.5); } }
@keyframes hop { from { top: 0; } to { top: -8px; } }
@keyframes arm-sway { from { transform: rotate(-5deg); } to { transform: rotate(7deg); } }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes blink { 50% { opacity: 0.55; } }
@keyframes glow { from { opacity: 0.6; } to { opacity: 1; } }
@keyframes spin-glow { to { filter: hue-rotate(25deg) brightness(1.15); } }
@keyframes hit-flash { 50% { filter: brightness(3) saturate(0); } }
@keyframes hurt { 0%, 100% { left: 0; filter: none; } 20% { left: -12%; filter: sepia(1) saturate(6) hue-rotate(-40deg); } 60% { left: 4%; filter: none; } }
@keyframes next-bounce { from { transform: translateY(0); } to { transform: translateY(-3px); } }
@keyframes miss-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes key-glow { from { transform: translateY(0); } to { transform: translateY(-3px); } }
@keyframes key-ok { 50% { transform: scale(0.88) translateY(2px); } }
@keyframes key-miss { 0%, 60% { transform: translateX(-2px); } 30% { transform: translateX(2px); } 100% { border-image-source: url('../assets/kenney/ui-pack/Grey/button_square_depth_flat.svg'); color: var(--ink); } }
@keyframes star-pop { from { transform: scale(0) rotate(-90deg); opacity: 0; } }

/* 動きを減らす設定の人には、ずっと動くアニメーションを止める */
@media (prefers-reduced-motion: reduce) {
  .parade-mon, .parade-mon svg, .hero-sprite, .monster-body .mon-svg, .mon-arm, .battle-clouds span, .r-next, .key.is-next { animation: none; }
}

/* ---------- 10. 画面が狭いとき ---------- */
@container (max-width: 600px) {
  .hud { flex-wrap: wrap; }
  .hud-time { order: 5; flex-basis: 100%; }
  .card-hero-stage { width: 64px; height: 74px; }
  .card-hero-sprite { height: 62px; }
  .hero-list .card { flex-basis: calc((100% - 2 * clamp(8px, 1.6cqw, 16px)) / 3); }
  .hero-list .card-hero-stage { width: 64px; height: 70px; }
  .hero-list .card-hero-sprite { height: 56px; }
  .card { border-width: 8px 6px 12px; padding: 0.3em 0.1em 0.5em; }
  .card-tag { padding: 0.1em 0.4em; }
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  .cta-row { grid-template-columns: 1fr; }
  .result-main { gap: 10px; }
}
