3. ニセモノ見分け大作戦 ソースコード
遊ぶ一覧にもどる

HTML 1ファイルで動きます。コピーして、新しいファイル(〇〇.html)に貼ると、そのまま遊べます。このフォルダの 3_nisemono/index.html と同じ中身です。

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>ニセモノ見分け大作戦</title>
<style>
  * { box-sizing: border-box; }
  body { margin: 0; background: #0c1528; }
  #app { position: absolute; left: 0; top: 0; width: 960px; height: 540px; overflow: hidden; color: #fff;
    background: linear-gradient(#182a4a, #0c1528); user-select: none; -webkit-user-select: none; font-size: 16px; }
  #app::before { content: ""; position: absolute; inset: 0; opacity: .12;
    background-image: linear-gradient(#7fb4ff 1px, transparent 1px), linear-gradient(90deg, #7fb4ff 1px, transparent 1px);
    background-size: 40px 40px; }
  button { font: inherit; color: inherit; border: 0; cursor: pointer; }
  #fx { position: absolute; left: 0; top: 0; width: 960px; height: 540px; pointer-events: none; z-index: 60; }

  /* 上のバー */
  #top { position: absolute; left: 0; top: 0; width: 960px; height: 50px; background: rgba(5, 12, 28, .75);
    display: flex; align-items: center; padding: 0 12px; gap: 14px; }
  #lvname { font-size: 19px; font-weight: 700; width: 330px; white-space: nowrap; }
  #prog { font-size: 17px; width: 140px; color: #bcd3f5; }
  #combo { font-size: 18px; font-weight: 700; color: #ffd54f; width: 130px; text-align: right; }
  #combo.pop { animation: pop .3s; }
  #score { font-size: 24px; font-weight: 700; width: 150px; text-align: right; }
  #mute { position: absolute; right: 10px; top: 7px; width: 96px; height: 36px; border-radius: 18px; background: #2b4170; font-size: 16px; }

  /* 本物リスト */
  #ref { position: absolute; left: 10px; top: 58px; width: 244px; height: 398px; background: #f4f8ff; color: #14233f;
    border-radius: 14px; border: 3px solid #ffd54f; padding: 6px 8px; }
  #ref h2 { margin: 0 0 3px; font-size: 18px; text-align: center; color: #9a6a00; }
  .svc { padding: 3px 6px 4px; border-radius: 10px; border-top: 1px dashed #c4d2ea; }
  .svc.hit { background: #fff3bf; }
  .svc .nm { font-size: 16px; line-height: 1.5; }
  .svc .dm { font-size: 18px; font-weight: 700; line-height: 1.35; letter-spacing: .3px; white-space: nowrap; color: #0a5a2c; }
  #guide { position: absolute; left: 6px; bottom: 4px; width: 228px; height: 96px; }
  #mascot { position: absolute; left: 0; bottom: 0; }
  #mascot .m-h, #mascot .m-s { display: none; }
  #mascot.happy .m-n, #mascot.sad .m-n { display: none; }
  #mascot.happy .m-h { display: block; }
  #mascot.sad .m-s { display: block; }
  #mascot.happy { animation: hop .4s; }
  #mascot.sad { animation: shake .4s; }
  #say { position: absolute; left: 78px; top: 4px; width: 150px; height: 84px; background: #fff; border: 2px solid #3aa0ff;
    border-radius: 12px; padding: 4px 8px; font-size: 16px; line-height: 1.5; display: flex; align-items: center; }

  /* カードの場所 */
  #stage { position: absolute; left: 264px; top: 58px; width: 686px; height: 398px; }
  #stage.shake { animation: shake .4s; }
  .tbar { height: 12px; background: #06101f; border-radius: 6px; overflow: hidden; }
  .tbar i { display: block; height: 100%; width: 100%; background: #4cd787; border-radius: 6px; }
  .tbar.low i { background: #ff6b5e; }
  #holder { position: absolute; left: 0; top: 20px; width: 686px; height: 272px; }
  .card { position: absolute; inset: 0; background: #fff; color: #1c2536; border-radius: 14px; overflow: hidden;
    box-shadow: 0 6px 0 rgba(0, 0, 0, .35); animation: drop .28s ease-out; transition: transform .38s ease-in, opacity .38s; }
  .card.goL { transform: translate(-760px, 60px) rotate(-20deg); opacity: 0; }
  .card.goR { transform: translate(760px, 60px) rotate(20deg); opacity: 0; }
  .chead { height: 34px; line-height: 34px; padding: 0 14px; font-size: 16px; font-weight: 700; color: #fff; background: #4a6fa5; }
  .card.msg .chead { background: #2f9e7a; }
  .card.login .chead { background: #6b5aa8; }
  .url { font-weight: 700; letter-spacing: .6px; white-space: nowrap; }
  .bad { font-weight: inherit; border-radius: 4px; }
  .card.reveal .bad { background: #ff4d3d; color: #fff; box-shadow: 0 0 0 3px #ff4d3d; }
  .card.reveal.isreal .url { background: #c9f5d8; box-shadow: 0 0 0 3px #c9f5d8; border-radius: 4px; }
  .stamp { position: absolute; right: 16px; top: 40px; font-size: 28px; font-weight: 700; padding: 0 14px; border: 5px solid;
    border-radius: 12px; transform: rotate(-10deg) scale(0); background: rgba(255, 255, 255, .9); }
  .card.reveal .stamp { transform: rotate(-10deg) scale(1); transition: transform .18s cubic-bezier(.3, 2, .6, 1); }
  .card.login .stamp { top: 150px; right: 30px; font-size: 34px; }
  .stamp.f { color: #e0321f; } .stamp.r { color: #189a4e; }

  .mrow { padding: 6px 16px 0; font-size: 17px; white-space: nowrap; }
  .mrow span { display: inline-block; width: 64px; color: #6a7890; }
  .mrow.subj { font-size: 20px; font-weight: 700; padding-bottom: 6px; border-bottom: 2px solid #e3e8f0; }
  .mbody { padding: 8px 16px 0; font-size: 18px; line-height: 1.6; height: 72px; }
  .mlink { margin: 4px 16px 0; padding: 7px 12px; background: #eef4ff; border: 2px solid #b9cdf0; border-radius: 10px; font-size: 21px; color: #1447b8; white-space: nowrap; }
  .mlink small { font-size: 16px; color: #50607c; font-weight: 400; margin-right: 8px; }

  .who { display: flex; align-items: center; gap: 10px; padding: 10px 16px 4px; font-size: 18px; font-weight: 700; }
  .who .av { width: 40px; height: 40px; border-radius: 50%; background: #e7edf7; font-size: 24px; text-align: center; line-height: 40px; }
  .bubble { margin: 4px 16px 0 66px; padding: 10px 14px; background: #e3f6e9; border-radius: 4px 18px 18px 18px; font-size: 18px; line-height: 1.6; }
  .bubble .url { display: block; font-size: 21px; color: #1447b8; margin-top: 2px; }

  .bar { margin: 8px 12px 0; height: 42px; display: flex; align-items: center; gap: 8px; background: #e9edf3; border-radius: 21px; padding: 0 14px; font-size: 21px; white-space: nowrap; }
  .bar .lock { font-size: 17px; }
  .site { text-align: center; font-size: 21px; font-weight: 700; margin-top: 8px; }
  .fld { width: 300px; height: 32px; margin: 6px auto 0; border: 2px solid #b8c2d3; border-radius: 8px; padding: 0 10px; font-size: 16px; line-height: 28px; color: #7a8598; }
  .fbtn { width: 300px; height: 34px; margin: 8px auto 0; border-radius: 8px; color: #fff; text-align: center; line-height: 34px; font-size: 17px; font-weight: 700; }

  /* 結果の帯 */
  #banner { position: absolute; left: 0; top: 300px; width: 686px; height: 98px; border-radius: 14px; padding: 8px 14px;
    background: rgba(5, 12, 28, .6); border: 2px dashed #3d5687; }
  #banner .idle { font-size: 17px; color: #bcd3f5; line-height: 78px; text-align: center; }
  #banner.ok { background: #114d2c; border: 3px solid #4cd787; animation: pop .25s; }
  #banner.ngb { background: #5c1a16; border: 3px solid #ff8a7d; animation: pop .25s; }
  #bt { font-size: 21px; font-weight: 700; white-space: nowrap; }
  #bw { font-size: 17px; line-height: 1.45; margin-top: 2px; width: 520px; }
  #banner.ok #bw { width: 650px; }
  #next { position: absolute; right: 12px; top: 20px; width: 128px; height: 54px; border-radius: 12px; background: #ffd54f; color: #3b2a00; font-size: 17px; font-weight: 700; line-height: 1.25; box-shadow: 0 4px 0 #a47d00; }

  /* 答えのボタン */
  .ans { position: absolute; top: 464px; width: 330px; height: 66px; border-radius: 16px; font-size: 26px; font-weight: 700; }
  #bF { left: 14px; background: #e0432f; box-shadow: 0 5px 0 #8c1d10; }
  #bR { left: 616px; background: #1fa757; box-shadow: 0 5px 0 #0c6030; }
  .ans:active { transform: translateY(3px); }
  .ans.off { opacity: .35; }
  .ans small { font-size: 17px; font-weight: 400; margin: 0 8px; }

  /* ボス */
  #boss { position: absolute; left: 264px; top: 58px; width: 686px; height: 474px; display: none; }
  #bossHead { position: relative; height: 104px; background: rgba(5, 12, 28, .6); border-radius: 14px; padding: 8px 14px; }
  #bossQ { font-size: 20px; line-height: 1.5; width: 520px; }
  #bossQ b { color: #ffd54f; font-size: 23px; }
  #bossHp { font-size: 20px; margin-top: 4px; color: #ff8fa0; letter-spacing: 3px; }
  #nisemon { position: absolute; right: 22px; top: 4px; width: 96px; height: 96px; animation: float 2s ease-in-out infinite; }
  #nisemon.hit { animation: hit .5s; }
  #nisemon.dead { transition: transform 1s, opacity 1s; transform: translateY(-80px) rotate(540deg) scale(.1); opacity: 0; }
  #boss .tbar { margin-top: 10px; }
  #opts { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .opt { height: 64px; border-radius: 12px; background: #fff; color: #1c2536; font-size: 20px; text-align: left; padding: 0 10px; white-space: nowrap; box-shadow: 0 4px 0 rgba(0, 0, 0, .4); display: flex; align-items: center; gap: 8px; }
  .opt .no { width: 30px; height: 30px; border-radius: 50%; background: #2b4170; color: #fff; text-align: center; line-height: 30px; font-size: 17px; flex: none; }
  .opt.x { background: #ffd2cc; animation: shake .35s; }
  .opt.x .bad, .opt.dim .bad { background: #ff4d3d; color: #fff; box-shadow: 0 0 0 3px #ff4d3d; }
  .opt.o { background: #b9f5cf; box-shadow: 0 0 0 4px #4cd787; }
  .opt.dim { opacity: .75; }
  #bossMsg { margin-top: 12px; height: 60px; font-size: 19px; line-height: 1.5; text-align: center; padding-top: 4px; }

  /* 重ねる画面(タイトル・説明・結果) */
  #ov { position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; }
  #ov.dimmed { background: rgba(6, 12, 26, .93); }
  #ov.solid { background: linear-gradient(#1c3360, #0c1528); }
  .big { font-size: 26px; font-weight: 700; padding: 14px 44px; border-radius: 18px; background: #ffb300; color: #3b2a00; box-shadow: 0 6px 0 #a06a00; }
  .big:active { transform: translateY(3px); }
  .ttl { font-size: 54px; font-weight: 700; margin-top: 52px; color: #ffd54f; text-shadow: 0 4px 0 #6b3d00; letter-spacing: 2px; }
  .sub { font-size: 20px; line-height: 1.7; text-align: center; margin-top: 10px; }
  .note { font-size: 17px; color: #ffe9a8; margin-top: 12px; }
  .pair { display: flex; align-items: center; gap: 30px; margin-top: 20px; }
  .lvdone { font-size: 22px; color: #7ee2a8; font-weight: 700; margin-top: 46px; height: 32px; }
  .lvttl { font-size: 40px; font-weight: 700; margin-top: 6px; color: #ffd54f; }
  .tip { font-size: 21px; line-height: 1.7; text-align: center; margin-top: 16px; background: rgba(255, 255, 255, .1); border-radius: 14px; padding: 12px 26px; width: 760px; }
  .tip b { color: #ffd54f; }
  .keys { display: flex; gap: 40px; margin-top: 16px; font-size: 20px; font-weight: 700; }
  .keys span { padding: 8px 22px; border-radius: 12px; }
  .keys .kf { background: #e0432f; } .keys .kr { background: #1fa757; }
  .gap { flex: 1; }

  #res { position: absolute; inset: 0; }
  #res h1 { position: absolute; left: 30px; top: 16px; margin: 0; font-size: 34px; color: #ffd54f; }
  #resL { position: absolute; left: 30px; top: 70px; width: 380px; }
  #stars { font-size: 50px; letter-spacing: 6px; color: #ffd54f; height: 64px; }
  #stars i { font-style: normal; color: #3a4c6e; }
  #rscore { font-size: 60px; font-weight: 700; line-height: 1.1; }
  #rscore small { font-size: 24px; }
  #rank { font-size: 22px; font-weight: 700; color: #7ee2a8; margin-top: 4px; }
  #rstat { font-size: 18px; line-height: 1.7; margin-top: 8px; color: #dbe7fb; }
  #resR { position: absolute; left: 430px; top: 22px; width: 506px; background: #f4f8ff; color: #14233f; border-radius: 16px; padding: 10px 16px 12px; }
  #resR h2 { margin: 0 0 4px; font-size: 20px; color: #9a6a00; }
  #resR li { font-size: 17px; line-height: 1.5; margin-bottom: 5px; }
  #resR ol { margin: 0; padding-left: 26px; }
  #resR b { color: #c2291a; }
  #again { position: absolute; left: 676px; top: 458px; width: 260px; height: 62px; padding: 0; font-size: 24px; }
  #hero { position: absolute; left: 34px; top: 356px; width: 88px; height: 97px; animation: float 2s ease-in-out infinite; }
  .herosay { position: absolute; left: 136px; top: 372px; width: 270px; background: #fff; color: #14233f; border-radius: 14px; padding: 8px 12px; font-size: 17px; line-height: 1.5; }
  #only { position: absolute; left: 30px; top: 474px; width: 560px; font-size: 16px; line-height: 1.5; color: #ffe9a8; }

  .plus { position: absolute; z-index: 61; font-size: 30px; font-weight: 700; color: #ffb300; text-shadow: 0 2px 0 #3b2a00, 0 -1px 0 #3b2a00, 2px 0 0 #3b2a00, -2px 0 0 #3b2a00; pointer-events: none; animation: rise .9s forwards; }

  @keyframes drop { from { transform: translateY(-60px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-12px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-7px); } 80% { transform: translateX(5px); } }
  @keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
  @keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
  @keyframes hit { 0% { transform: scale(1); } 30% { transform: scale(.7) rotate(-25deg); filter: brightness(3); } 100% { transform: scale(1); } }
  @keyframes rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-70px); opacity: 0; } }

  /* どの画面の大きさでも、960×540 のゲーム全体を縮めて真ん中に表示する */
  #fitbox { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; }
</style>
</head>
<body>
<div id="fitbox">
<div id="app">
  <div id="top">
    <div id="lvname"></div>
    <div id="prog"></div>
    <div id="combo"></div>
    <div id="score">0 点</div>
    <button id="mute" type="button">🔊 音オン</button>
  </div>

  <div id="ref">
    <h2>★ 本物リスト ★</h2>
    <div id="svcs"></div>
    <div id="guide">
      <svg id="mascot" viewBox="0 0 100 110" width="74" height="82" aria-label="まもるん">
        <path d="M50 4 L92 18 V56 C92 82 72 98 50 106 C28 98 8 82 8 56 V18 Z" fill="#3aa0ff" stroke="#14233f" stroke-width="4"/>
        <path d="M50 15 L82 26 V56 C82 75 67 87 50 94 C33 87 18 75 18 56 V26 Z" fill="#8fd0ff"/>
        <circle cx="36" cy="48" r="7" fill="#12233f"/><circle cx="64" cy="48" r="7" fill="#12233f"/>
        <circle cx="38" cy="46" r="2.5" fill="#fff"/><circle cx="66" cy="46" r="2.5" fill="#fff"/>
        <path class="m-n" d="M39 66 Q50 75 61 66" fill="none" stroke="#12233f" stroke-width="4" stroke-linecap="round"/>
        <path class="m-h" d="M36 63 Q50 86 64 63 Z" fill="#12233f"/>
        <path class="m-s" d="M39 73 Q50 63 61 73" fill="none" stroke="#12233f" stroke-width="4" stroke-linecap="round"/>
      </svg>
      <div id="say"></div>
    </div>
  </div>

  <div id="stage">
    <div class="tbar" id="tbar"><i></i></div>
    <div id="holder"></div>
    <div id="banner">
      <div class="idle" id="bidle">← → キーでも選べます</div>
      <div id="bt"></div>
      <div id="bw"></div>
      <button id="next" type="button">次へ<br>(スペース)</button>
    </div>
  </div>
  <button class="ans" id="bF" type="button">← ニセモノ</button>
  <button class="ans" id="bR" type="button">本物 →</button>

  <div id="boss">
    <div id="bossHead">
      <div id="bossQ"></div>
      <div id="bossHp"></div>
      <div id="nisemon"></div>
    </div>
    <div class="tbar" id="btbar"><i></i></div>
    <div id="opts"></div>
    <div id="bossMsg"></div>
  </div>

  <div id="ov"></div>
  <canvas id="fx" width="960" height="540"></canvas>
</div>

</div>
<script>
(() => {
  // 画面の大きさ(480×360 など)に合わせて、960×540 のゲーム全体を縮めて真ん中に表示する
  const box = document.getElementById("fitbox");
  const fit = () => {
    const w = document.documentElement.clientWidth || window.innerWidth;
    const h = document.documentElement.clientHeight || window.innerHeight;
    const s = Math.min(w / 960, h / 540);
    box.style.transform = "translate(" + ((w - 960 * s) / 2) + "px, " + ((h - 540 * s) / 2) + "px) scale(" + s + ")";
  };
  window.addEventListener("resize", fit);
  fit();
})();
</script>
<script>
(() => {
  "use strict";
  const $ = (id) => document.getElementById(id);
  const el = (tag, cls, text) => {
    const e = document.createElement(tag);
    if (cls) e.className = cls;
    if (text != null) e.textContent = text;
    return e;
  };

  // ===== データ(会社・サービス・URL は全部つくりもの) =====
  const SVC = {
    bank: { name: "モグモグ銀行", icon: "🏦", dom: "mogmog-bank.jp", color: "#e08a2c" },
    ship: { name: "くじら便", icon: "🐳", dom: "kujira-bin.jp", color: "#2c8ae0" },
    game: { name: "ピコルランド", icon: "🎮", dom: "picol-land.jp", color: "#9b4de0" },
    school: { name: "みどり山小学校", icon: "🏫", dom: "midoriyama-sho.ed.jp", color: "#2fae6b" }
  };
  const REAL_WHY = "URL が本物リストとぴったり同じです。";

  // t: mail / msg / login、s: サービス、real: 本物か、url と body の [ ] の中があやしい部分
  const LEVELS = [
    {
      name: "レベル1 ウォーミングアップ", time: 20,
      tip: "左の<b>本物リスト</b>と URL を見くらべます。<br>急がせる文、パスワードを聞く文もあやしいです。",
      cards: [
        { t: "mail", s: "school", real: true, subj: "来週の時間わりについて", body: "来週の時間わりを、学校のページにのせました。", url: "https://midoriyama-sho.ed.jp/" },
        { t: "msg", s: "game", real: false, body: "おめでとう!レアアイテムが100こ当たりました!今すぐここを開いて受け取ろう!", url: "https://[present-get.xyz]/", why: "知らないドメインです。「当たりました」でさそうのは、よくある手口です。" },
        { t: "mail", s: "bank", real: false, subj: "【重要】口座が止まります", body: "30分以内に手続きをしないと、口座が使えなくなります。", url: "https://[bank-kakunin.net]/", why: "URL が本物とちがいます。「30分以内」と急がせておどすのも、あやしいサインです。" },
        { t: "msg", s: "ship", real: true, body: "お荷物を本日お届けします。配達の時間はこちらで見られます。", url: "https://kujira-bin.jp/" },
        { t: "msg", s: "game", real: false, body: "ピコルランド運営です。調査のため、あなたの[パスワードを返信]してください。", why: "本物の運営は、パスワードを聞きません。聞かれたらニセモノです。" },
        { t: "login", s: "bank", real: false, url: "https://[mogmog-ginko-login.com]/", why: "画面はそっくりでも、URL が本物リストとちがいます。カギのマークはニセモノにも付きます。" },
        { t: "login", s: "game", real: true, url: "https://picol-land.jp/login" },
        { t: "mail", s: "ship", real: false, subj: "お荷物をお預かりしています", body: "住所が分からず、お届けできません。24時間以内に住所と電話番号を入力してください。", url: "https://[kujira.saihaitatsu-form.info]/", why: "URL が本物とちがいます。急がせて個人情報を入力させるのは、ニセモノの手口です。" }
      ]
    },
    {
      name: "レベル2 そっくりドメイン", time: 18,
      tip: "文は本物と同じでも、<b>URL がちがえばニセモノ</b>です。<br>https:// のあと、最初の「 / 」の前を見ます。",
      cards: [
        { t: "mail", s: "bank", real: false, subj: "ご利用明細のお知らせ", body: "今月のご利用明細ができました。こちらから見られます。", url: "https://mogmog-bank[.net]/meisai", why: "最後が .jp ではなく .net です。文がふつうでも、URL がちがえばニセモノです。" },
        { t: "mail", s: "bank", real: true, subj: "ご利用明細のお知らせ", body: "今月のご利用明細ができました。こちらから見られます。", url: "https://mogmog-bank.jp/meisai" },
        { t: "msg", s: "ship", real: false, body: "不在のため、お荷物を持ち帰りました。再配達はこちらから。", url: "https://kujir[ab]in.jp/saihai", why: "ハイフン(-)がぬけています。本物は kujira-bin.jp です。" },
        { t: "msg", s: "ship", real: true, body: "不在のため、お荷物を持ち帰りました。再配達はこちらから。", url: "https://kujira-bin.jp/saihai" },
        { t: "login", s: "game", real: false, url: "https://picol-land.jp[.game-login.com]/", why: "本物の名前のあとに、まだ続きがあります。最初の「 / 」のすぐ前が本当のドメインです。" },
        { t: "mail", s: "school", real: false, subj: "遠足の持ち物について", body: "来月の遠足の持ち物を、学校のページにのせました。", url: "https://midoriyama-[syo].ed.jp/ensoku", why: "sho が syo になっています。1文字ちがえば、別のサイトです。" },
        { t: "mail", s: "school", real: true, subj: "音楽会のお知らせ", body: "音楽会の日時を、学校のページにのせました。", url: "https://midoriyama-sho.ed.jp/ongaku" },
        { t: "msg", s: "game", real: false, body: "期間限定イベントが始まりました!くわしくはこちら。", url: "https://picol-[r]and.jp/event", why: "land が rand になっています。" },
        { t: "login", s: "bank", real: true, url: "https://mogmog-bank.jp/login" },
        { t: "login", s: "ship", real: false, url: "https://kujira-bin[-jp.com]/login", why: ".jp ではなく -jp.com です。点(.)とハイフン(-)のちがいに注意します。" }
      ]
    },
    {
      name: "レベル3 1文字のワナ", time: 16,
      tip: "<b>0(ゼロ)と o</b>、<b>1(いち)と l(エル)</b>、<b>rn と m</b>。<br>ニセモンの得意わざです。1文字ずつ見ます。",
      cards: [
        { t: "mail", s: "bank", real: false, subj: "ご利用明細のお知らせ", body: "今月のご利用明細ができました。こちらから見られます。", url: "https://m[0]gmog-bank.jp/meisai", why: "o(オー)が 0(ゼロ)になっています。" },
        { t: "login", s: "game", real: false, url: "https://pico[1]-land.jp/login", why: "l(エル)が 1(いち)になっています。" },
        { t: "msg", s: "game", real: true, body: "期間限定イベントが始まりました!今すぐ遊ぼう!", url: "https://picol-land.jp/event", why: "元気な文ですが、URL は本物リストとぴったり同じです。" },
        { t: "mail", s: "school", real: false, subj: "音楽会のお知らせ", body: "音楽会の日時を、学校のページにのせました。", url: "https://midoriya[rn]a-sho.ed.jp/ongaku", why: "m が r と n になっています。ならべると m に見えます。" },
        { t: "msg", s: "ship", real: false, body: "お荷物を本日お届けします。配達の時間はこちらで見られます。", url: "https://kuj[l]ra-bin.jp/", why: "i(アイ)が l(エル)になっています。" },
        { t: "mail", s: "bank", real: true, subj: "アプリが新しくなりました", body: "モグモグ銀行アプリの新しい使い方を、のせました。", url: "https://mogmog-bank.jp/news" },
        { t: "login", s: "bank", real: false, url: "https://mogmog-ba[m]k.jp/login", why: "bank が bamk になっています。" },
        { t: "msg", s: "game", real: false, body: "新しいステージができました。こちらから遊べます。", url: "https://[login-check.xyz]/picol-land.jp", why: "本物の名前が「 / 」のうしろにあります。ドメインは「 / 」の前の login-check.xyz です。" },
        { t: "login", s: "school", real: true, url: "https://midoriyama-sho.ed.jp/login" },
        { t: "mail", s: "ship", real: false, subj: "お届け予定のお知らせ", body: "お荷物のお届け予定日が決まりました。", url: "https://ku[ij]ra-bin.jp/yotei", why: "j と i の順番が入れかわっています。" },
        { t: "login", s: "school", real: false, url: "https://midoriyama-sh[0].ed.jp/login", why: "o(オー)が 0(ゼロ)になっています。" },
        { t: "msg", s: "ship", real: true, body: "お荷物を本日お届けします。配達の時間はこちらで見られます。", url: "https://kujira-bin.jp/" }
      ]
    }
  ];

  const BOSS = [
    { s: "bank", opts: [
      { u: "mogmog-bank.jp", real: true },
      { u: "m[0]gmog-bank.jp", why: "o が 0(ゼロ)です。" },
      { u: "mogmog-bank[.net]", why: "最後が .net です。" },
      { u: "mogmo[gb]ank.jp", why: "ハイフン(-)がありません。" },
      { u: "mog[rn]og-bank.jp", why: "m が r と n です。" },
      { u: "mogmog-bank.jp[.info-x.com]", why: "うしろに続きがあります。" }
    ] },
    { s: "game", opts: [
      { u: "picol-land.jp", real: true },
      { u: "pico[1]-land.jp", why: "l(エル)が 1(いち)です。" },
      { u: "picol-[1]and.jp", why: "l(エル)が 1(いち)です。" },
      { u: "picol-land[.com]", why: "最後が .com です。" },
      { u: "pico[ll]-land.jp", why: "l が2つあります。" },
      { u: "picol[_]land.jp", why: "ハイフン(-)ではなく _ です。" }
    ] },
    { s: "school", opts: [
      { u: "midoriyama-sho.ed.jp", real: true },
      { u: "midoriya[rn]a-sho.ed.jp", why: "m が r と n です。" },
      { u: "midoriyama-sh[0].ed.jp", why: "o が 0(ゼロ)です。" },
      { u: "midoriyama-sho.e[b].jp", why: "d が b です。" },
      { u: "[rn]idoriyama-sho.ed.jp", why: "最初の m が r と n です。" },
      { u: "midoriyama-sh[o.j]p", why: ".ed がありません。" }
    ] }
  ];
  const BOSS_TIME = 30;
  const BOSS_TIP = "6つの URL のうち、<b>本物は1つだけ</b>。<br>早く見つけるほど高得点です。数字キーでも選べます。";
  const TOTAL_Q = LEVELS.reduce((n, l) => n + l.cards.length, 0) + BOSS.length;

  const NISEMON = '<svg viewBox="0 0 120 120" width="100%" height="100%" aria-label="ニセモン">' +
    '<path d="M20 112 V55 C20 25 40 8 60 8 C80 8 100 25 100 55 V112 L87 99 L73 112 L60 99 L47 112 L33 99 Z" fill="#8e5bd6" stroke="#fff" stroke-width="4" stroke-linejoin="round"/>' +
    '<rect x="26" y="38" width="68" height="24" rx="12" fill="#1b1030"/>' +
    '<circle cx="45" cy="50" r="6" fill="#ffe14d"/><circle cx="75" cy="50" r="6" fill="#ffe14d"/>' +
    '<path d="M42 76 Q60 94 78 76 Z" fill="#1b1030"/></svg>';
  const MAMORUN_BIG = '<svg viewBox="0 0 100 110" width="100%" height="100%" aria-label="まもるん">' +
    '<path d="M50 4 L92 18 V56 C92 82 72 98 50 106 C28 98 8 82 8 56 V18 Z" fill="#3aa0ff" stroke="#fff" stroke-width="4"/>' +
    '<path d="M50 15 L82 26 V56 C82 75 67 87 50 94 C33 87 18 75 18 56 V26 Z" fill="#8fd0ff"/>' +
    '<circle cx="36" cy="48" r="7" fill="#12233f"/><circle cx="64" cy="48" r="7" fill="#12233f"/>' +
    '<circle cx="38" cy="46" r="2.5" fill="#fff"/><circle cx="66" cy="46" r="2.5" fill="#fff"/>' +
    '<path d="M36 63 Q50 86 64 63 Z" fill="#12233f"/></svg>';

  // ===== 音(Web Audio で合成。鳴らなくてもゲームは止めない) =====
  let ac = null, muted = false;
  const initAudio = () => {
    if (ac) return;
    try {
      const AC = window.AudioContext || window.webkitAudioContext;
      ac = new AC();
      const p = ac.resume && ac.resume();
      if (p && p.catch) p.catch(() => {});
    } catch (e) { ac = null; }
  };
  const tone = (f, t0, d, type, v, f2) => {
    if (!ac || muted) return;
    try {
      const o = ac.createOscillator(), g = ac.createGain(), t = ac.currentTime + t0;
      o.type = type || "square";
      o.frequency.setValueAtTime(f, t);
      if (f2) o.frequency.exponentialRampToValueAtTime(f2, t + d);
      g.gain.setValueAtTime(0.0001, t);
      g.gain.exponentialRampToValueAtTime(v || 0.1, t + 0.01);
      g.gain.exponentialRampToValueAtTime(0.0001, t + d);
      o.connect(g); g.connect(ac.destination);
      o.start(t); o.stop(t + d + 0.03);
    } catch (e) { /* 音が出なくても続ける */ }
  };
  const sfx = {
    ok: (combo) => { const b = 660 * Math.pow(1.06, Math.min(combo, 10)); tone(b, 0, 0.09); tone(b * 1.5, 0.08, 0.2); },
    ng: () => { tone(200, 0, 0.3, "sawtooth", 0.12, 90); tone(150, 0.12, 0.3, "sawtooth", 0.1, 70); },
    card: () => tone(420, 0, 0.07, "triangle", 0.08, 760),
    tick: () => tone(1100, 0, 0.04, "square", 0.05),
    click: () => tone(520, 0, 0.06, "triangle", 0.1),
    clear: () => { [523, 659, 784, 1047].forEach((f, i) => tone(f, i * 0.11, 0.2, "square", 0.09)); },
    hit: () => { tone(880, 0, 0.25, "sawtooth", 0.1, 110); },
    win: () => { [523, 659, 784, 659, 784, 1047, 1319].forEach((f, i) => tone(f, i * 0.12, 0.24, "square", 0.09)); }
  };

  // ===== 光のつぶ =====
  const fx = $("fx").getContext("2d");
  let parts = [];
  const burst = (x, y, n, colors) => {
    for (let i = 0; i < n; i++) {
      const a = Math.random() * Math.PI * 2, s = 120 + Math.random() * 320;
      parts.push({ x, y, vx: Math.cos(a) * s, vy: Math.sin(a) * s - 160, life: 0.6 + Math.random() * 0.6, t: 0,
        c: colors[i % colors.length], r: 4 + Math.random() * 5 });
    }
  };
  const GOOD = ["#ffe14d", "#7ee2a8", "#8fd0ff", "#ffffff", "#ff9ecb"];
  const drawParts = (dt) => {
    fx.clearRect(0, 0, 960, 540);
    if (!parts.length) return;
    parts = parts.filter((p) => p.t < p.life);
    parts.forEach((p) => {
      p.t += dt; p.vy += 900 * dt; p.x += p.vx * dt; p.y += p.vy * dt;
      fx.globalAlpha = Math.max(0, 1 - p.t / p.life);
      fx.fillStyle = p.c;
      fx.fillRect(p.x - p.r / 2, p.y - p.r / 2, p.r, p.r);
    });
    fx.globalAlpha = 1;
  };

  // ===== 状態 =====
  let mode = "title", started = false;
  let score = 0, shown = 0, combo = 0, maxCombo = 0, correct = 0, lvCorrect = 0;
  let lv = 0, deck = [], idx = 0, cur = null, cardEl = null;
  let tLeft = 0, tMax = 1, lastSec = 0, modeT = 0;
  let round = 0, bossMiss = 0, bossOpts = [], bossClear = 0;
  let pendingIntro = 0, resTarget = 0, resShown = 0;
  let timers = [];
  const after = (sec, fn) => timers.push({ t: sec, fn });

  const shuffle = (arr) => {
    const a = arr.slice();
    for (let i = a.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      const tmp = a[i]; a[i] = a[j]; a[j] = tmp;
    }
    return a;
  };
  // [ ] でかこんだ部分を <b class="bad"> にする
  const marked = (str, cls) => {
    const s = el("span", cls);
    str.split(/[\[\]]/).forEach((p, i) => {
      if (!p) return;
      s.appendChild(i % 2 ? el("b", "bad", p) : document.createTextNode(p));
    });
    return s;
  };

  const say = (text, face) => {
    $("say").textContent = text;
    const m = $("mascot");
    m.setAttribute("class", "");
    if (face) { void m.getBoundingClientRect(); m.setAttribute("class", face); }
  };
  const setScore = () => { $("score").textContent = Math.round(shown) + " 点"; };
  const setCombo = () => {
    const c = $("combo");
    c.textContent = combo >= 2 ? combo + " コンボ!" : "";
    if (combo >= 2) { c.className = ""; void c.offsetWidth; c.className = "pop"; }
  };
  const plus = (text, x, y) => {
    const p = el("div", "plus", text);
    p.style.left = x + "px"; p.style.top = y + "px";
    $("app").appendChild(p);
    after(1, () => p.remove());
  };
  const hitSvc = (key) => {
    document.querySelectorAll(".svc").forEach((n) => n.classList.toggle("hit", n.dataset.k === key));
  };

  // 本物リスト
  Object.keys(SVC).forEach((k) => {
    const v = SVC[k], row = el("div", "svc");
    row.dataset.k = k;
    row.appendChild(el("div", "nm", v.icon + " " + v.name));
    row.appendChild(el("div", "dm", v.dom));
    $("svcs").appendChild(row);
  });

  // ===== カードを作る =====
  const buildCard = (c) => {
    const v = SVC[c.s], card = el("div", "card " + c.t + (c.real ? " isreal" : ""));
    if (c.t === "mail") {
      card.appendChild(el("div", "chead", "📧 メールがとどきました"));
      const r1 = el("div", "mrow"); r1.appendChild(el("span", "", "送り主")); r1.appendChild(document.createTextNode(v.icon + " " + v.name));
      const r2 = el("div", "mrow subj"); r2.appendChild(el("span", "", "件名")); r2.appendChild(document.createTextNode(c.subj));
      card.appendChild(r1); card.appendChild(r2);
      card.appendChild(marked(c.body, "mbody")).style.display = "block";
      const link = el("div", "mlink"); link.appendChild(el("small", "", "リンク")); link.appendChild(marked(c.url, "url"));
      card.appendChild(link);
    } else if (c.t === "msg") {
      card.appendChild(el("div", "chead", "💬 メッセージがとどきました"));
      const who = el("div", "who"); who.appendChild(el("div", "av", v.icon)); who.appendChild(document.createTextNode(v.name));
      card.appendChild(who);
      const b = el("div", "bubble"); b.appendChild(marked(c.body, ""));
      if (c.url) b.appendChild(marked(c.url, "url"));
      card.appendChild(b);
    } else {
      card.appendChild(el("div", "chead", "🖥 ログイン画面が開きました"));
      const bar = el("div", "bar"); bar.appendChild(el("span", "lock", "🔒")); bar.appendChild(marked(c.url, "url"));
      card.appendChild(bar);
      card.appendChild(el("div", "site", v.icon + " " + v.name + " ログイン"));
      card.appendChild(el("div", "fld", "ID"));
      card.appendChild(el("div", "fld", "パスワード"));
      const fb = el("div", "fbtn", "ログイン"); fb.style.background = v.color;
      card.appendChild(fb);
    }
    card.appendChild(el("div", "stamp " + (c.real ? "r" : "f"), c.real ? "本物" : "ニセモノ"));
    return card;
  };

  const banner = (kind, title, why) => {
    const b = $("banner");
    b.className = "";
    void b.offsetWidth;
    b.className = kind === "ok" ? "ok" : kind === "ng" ? "ngb" : "";
    $("bidle").style.display = kind ? "none" : "block";
    $("bt").textContent = title || "";
    $("bw").textContent = why || "";
    $("next").style.display = kind === "ng" ? "block" : "none";
  };
  const ansOff = (off) => { $("bF").classList.toggle("off", off); $("bR").classList.toggle("off", off); };
  const setBar = (id) => {
    const bar = $(id);
    bar.firstElementChild.style.width = Math.max(0, tLeft / tMax * 100) + "%";
    bar.classList.toggle("low", tLeft < 5);
  };
  const showPlay = (boss) => {
    $("stage").style.display = boss ? "none" : "block";
    $("bF").style.display = $("bR").style.display = boss ? "none" : "block";
    $("boss").style.display = boss ? "block" : "none";
  };

  // ===== レベルの流れ =====
  const startLevel = (i) => {
    lv = i; deck = shuffle(LEVELS[i].cards); idx = 0; lvCorrect = 0;
    $("lvname").textContent = LEVELS[i].name;
    showPlay(false);
    nextCard();
  };
  const nextCard = () => {
    if (idx >= deck.length) { showIntro(lv + 1); return; }
    cur = deck[idx];
    $("holder").textContent = "";
    cardEl = buildCard(cur);
    $("holder").appendChild(cardEl);
    $("prog").textContent = "カード " + (idx + 1) + " / " + deck.length;
    hitSvc(cur.s);
    banner("");
    ansOff(false);
    tMax = LEVELS[lv].time; tLeft = tMax; lastSec = 99;
    setBar("tbar");
    say("ニセモノか本物か、見分けてください。");
    sfx.card();
    mode = "play"; modeT = 0;
  };
  const answer = (guessReal, timeout) => {
    if (mode !== "play") return;
    const ok = !timeout && guessReal === cur.real;
    const why = cur.why || REAL_WHY;
    const kind = cur.real ? "本物" : "ニセモノ";
    cardEl.classList.add("reveal");
    ansOff(true);
    if (ok) {
      combo++; correct++; lvCorrect++;
      maxCombo = Math.max(maxCombo, combo);
      const pts = 100 + Math.round(5 * tLeft / tMax) * 10 + Math.min(combo - 1, 10) * 10;
      score += pts;
      banner("ok", "○ 正解! " + kind + "です +" + pts + "点", why);
      plus("+" + pts, guessReal ? 760 : 380, 250);
      burst(guessReal ? 780 : 430, 300, 26 + Math.min(combo, 10) * 4, GOOD);
      sfx.ok(combo);
      say(combo >= 3 ? combo + "連続です!すごい!" : ["ナイスです!", "その調子です!", "見破りました!"][idx % 3], "happy");
      mode = "fbok"; modeT = 0;
      const mine = cur;
      after(cur.real ? 1.2 : 1.9, () => { if (cur === mine && mode === "fbok") proceed(); });
    } else {
      combo = 0;
      banner("ng", (timeout ? "⏰ 時間切れ! これは" : "× ざんねん! これは") + kind + "でした", why);
      sfx.ng();
      const st = $("stage"); st.classList.remove("shake"); void st.offsetWidth; st.classList.add("shake");
      say(timeout ? "時間切れです…" : cur.real ? "本物を捨ててしまいました…" : "だまされました…", "sad");
      mode = "fbwait"; modeT = 0;
    }
    setCombo();
  };
  const proceed = () => {
    if (mode !== "fbok" && mode !== "fbwait") return;
    mode = "fly";
    cardEl.classList.add(cur.real ? "goR" : "goL");
    idx++;
    after(0.32, nextCard);
  };

  // ===== ボス =====
  const startBoss = () => {
    round = 0; bossClear = 0;
    $("lvname").textContent = "ボス ニセモンとの対決";
    $("nisemon").innerHTML = NISEMON;
    $("nisemon").className = "";
    showPlay(true);
    hitSvc("");
    nextRound();
  };
  const nextRound = () => {
    if (round >= BOSS.length) { showResult(); return; }
    const r = BOSS[round], v = SVC[r.s];
    bossMiss = 0;
    $("prog").textContent = "対決 " + (round + 1) + " / " + BOSS.length;
    const q = $("bossQ");
    q.textContent = "";
    q.appendChild(el("b", "", v.icon + " " + v.name));
    q.appendChild(document.createTextNode(" の"));
    q.appendChild(el("br"));
    q.appendChild(document.createTextNode("本物の URL を1つ選んでください。"));
    $("bossHp").textContent = "ニセモン " + "♥".repeat(BOSS.length - round) + "♡".repeat(round);
    $("bossMsg").textContent = "";
    hitSvc(r.s);
    const box = $("opts");
    box.textContent = "";
    bossOpts = shuffle(r.opts);
    bossOpts.forEach((o, i) => {
      const b = el("button", "opt");
      b.type = "button";
      b.appendChild(el("span", "no", String(i + 1)));
      b.appendChild(marked(o.u, "url"));
      b.addEventListener("click", () => { b.blur(); pick(i); });
      box.appendChild(b);
    });
    tMax = BOSS_TIME; tLeft = tMax; lastSec = 99;
    setBar("btbar");
    say("本物は1つだけです。1文字ずつ見ます。");
    sfx.card();
    mode = "boss"; modeT = 0;
  };
  const pick = (i, timeout) => {
    if (mode !== "boss") return;
    const btns = $("opts").children;
    if (!timeout) {
      const o = bossOpts[i], b = btns[i];
      if (!o || b.classList.contains("x")) return;
      if (!o.real) {
        bossMiss++; combo = 0; setCombo();
        b.classList.add("x");
        $("bossMsg").textContent = "× それはニセモノです。" + o.why;
        sfx.ng();
        say("それはニセモノです…", "sad");
        return;
      }
    }
    // 正解、または時間切れ:答えを見せる
    bossOpts.forEach((o, k) => btns[k].classList.add(o.real ? "o" : "dim"));
    if (!timeout) {
      const pts = Math.max(50, 300 + Math.round(20 * tLeft / tMax) * 10 - bossMiss * 100);
      score += pts; bossClear++;
      if (bossMiss === 0) { combo++; correct++; maxCombo = Math.max(maxCombo, combo); setCombo(); }
      $("bossMsg").textContent = "○ 正解! ニセモンにダメージ! +" + pts + "点";
      plus("+" + pts, 560, 300);
      burst(880, 110, 50, ["#c9a4ff", "#ffe14d", "#ffffff"]);
      sfx.ok(combo); sfx.hit();
      const n = $("nisemon"); n.className = ""; void n.offsetWidth; n.className = "hit";
      $("bossHp").textContent = "ニセモン " + "♥".repeat(BOSS.length - round - 1) + "♡".repeat(round + 1);
      say("見つけました!", "happy");
      if (round === BOSS.length - 1) after(0.6, () => { $("nisemon").className = "dead"; sfx.win(); burst(880, 110, 80, GOOD); });
    } else {
      combo = 0; setCombo();
      $("bossMsg").textContent = "⏰ 時間切れ! 緑色の URL が本物でした。";
      sfx.ng();
      say("時間切れです…", "sad");
    }
    mode = "bossfb"; modeT = 0;
    round++;
    after(round >= BOSS.length ? 2.6 : 2.2, nextRound);
  };

  // ===== 重ねる画面 =====
  const ov = $("ov");
  const openOv = (cls) => { ov.textContent = ""; ov.className = cls; ov.style.display = "flex"; };
  const closeOv = () => { ov.style.display = "none"; ov.textContent = ""; };

  const showTitle = () => {
    mode = "title";
    openOv("solid");
    ov.appendChild(el("div", "ttl", "ニセモノ見分け大作戦"));
    const pair = el("div", "pair");
    const a = el("div"); a.style.width = "110px"; a.style.height = "120px"; a.innerHTML = MAMORUN_BIG;
    const t = el("div", "sub");
    t.innerHTML = "いたずらおばけの<b>ニセモン</b>が、町じゅうに<br>ニセのメールやログイン画面をばらまいています。<br>見習いホワイトハッカーのきみが、<br>本物とニセモノを仕分けてください!";
    const b = el("div"); b.style.width = "120px"; b.style.height = "120px"; b.style.animation = "float 2s ease-in-out infinite"; b.innerHTML = NISEMON;
    pair.appendChild(a); pair.appendChild(t); pair.appendChild(b);
    ov.appendChild(pair);
    ov.appendChild(el("div", "note", "※ ホワイトハッカーは、守るために手口を知る人。ためしてよいのは、このゲームの中だけです。"));
    const go = el("button", "big", "▶ はじめる");
    go.type = "button"; go.style.marginTop = "26px";
    go.addEventListener("click", () => {
      go.blur();
      initAudio();
      started = true;
      sfx.click();
      newGame();
    });
    ov.appendChild(go);
  };

  const newGame = () => {
    timers = []; parts = [];
    score = 0; shown = 0; combo = 0; maxCombo = 0; correct = 0;
    setScore(); setCombo();
    $("holder").textContent = "";
    $("prog").textContent = "";
    showPlay(false);
    banner(""); ansOff(true);
    showIntro(0);
  };

  // i: 0〜2 はレベルの前、3 はボスの前
  const showIntro = (i) => {
    mode = "intro"; modeT = 0; pendingIntro = i;
    openOv("dimmed");
    const done = el("div", "lvdone");
    if (i > 0) {
      done.textContent = "レベル" + i + " クリア! 正解 " + lvCorrect + " / " + LEVELS[i - 1].cards.length;
      sfx.clear(); burst(480, 150, 60, GOOD);
    }
    ov.appendChild(done);
    ov.appendChild(el("div", "lvttl", i < LEVELS.length ? LEVELS[i].name : "ボス ニセモンとの対決"));
    const tip = el("div", "tip");
    tip.innerHTML = i < LEVELS.length ? LEVELS[i].tip : BOSS_TIP;
    ov.appendChild(tip);
    if (i === 0) {
      const keys = el("div", "keys");
      keys.appendChild(el("span", "kf", "← キー:ニセモノ"));
      keys.appendChild(el("span", "kr", "本物:→ キー"));
      ov.appendChild(keys);
    }
    const go = el("button", "big", "スタート(スペース)");
    go.type = "button"; go.style.marginTop = "22px";
    go.addEventListener("click", () => { go.blur(); introGo(); });
    ov.appendChild(go);
  };
  const introGo = () => {
    if (mode !== "intro") return;
    sfx.click();
    closeOv();
    if (pendingIntro < LEVELS.length) startLevel(pendingIntro); else startBoss();
  };

  const showResult = () => {
    mode = "result"; modeT = 0;
    const stars = correct >= TOTAL_Q - 3 ? 3 : correct >= TOTAL_Q - 9 ? 2 : 1;
    const rank = score >= 6200 ? "伝説のホワイトハッカー" : score >= 4500 ? "ホワイトハッカー" : score >= 2500 ? "ニセモノハンター" : "見習いハッカー";
    openOv("solid");
    const res = el("div"); res.id = "res";
    res.innerHTML =
      '<h1>ミッション完了!</h1>' +
      '<div id="resL"><div id="stars"></div><div id="rscore">0<small> 点</small></div><div id="rank"></div><div id="rstat"></div></div>' +
      '<div id="resR"><h2>🛡 ニセモノを見分ける5つのポイント</h2><ol>' +
      '<li><b>URL を1文字ずつ</b>、本物と見くらべる。<br>(0 と o、1 と l、rn と m、ハイフン)</li>' +
      '<li>見るのは<b>最初の「 / 」の前</b>。.jp か .net かも見る。</li>' +
      '<li><b>急がせる・おどす・「当たりました」</b>は、あやしい。</li>' +
      '<li><b>パスワードや個人情報</b>を聞かれても、教えない。</li>' +
      '<li>心配なときはリンクを押さず、<b>いつものアプリ</b>から開く。</li>' +
      '</ol></div>' +
      '<div id="only">ためしてよいのは、このゲームの中だけ。<br>覚えたコツは、自分とみんなを守るために使います。</div>';
    ov.appendChild(res);
    const st = res.querySelector("#stars");
    st.innerHTML = "★".repeat(stars) + "<i>" + "★".repeat(3 - stars) + "</i>";
    res.querySelector("#rank").textContent = "ランク:" + rank;
    res.querySelector("#rstat").innerHTML =
      "正解 " + correct + " / " + TOTAL_Q + "  最大コンボ " + maxCombo + "<br>" +
      "ニセモンに勝った回数 " + bossClear + " / " + BOSS.length;
    const again = el("button", "big", "↻ もう一度遊ぶ");
    again.type = "button"; again.id = "again";
    again.addEventListener("click", () => { again.blur(); sfx.click(); newGame(); });
    res.appendChild(again);
    const hero = el("div"); hero.id = "hero"; hero.innerHTML = MAMORUN_BIG;
    res.appendChild(hero);
    res.appendChild(el("div", "herosay", stars === 3 ? "かんぺきです!町を守りました!" : "町を守りました!もう一度で、もっと高得点をねらえます。"));
    resTarget = score; resShown = 0;
    sfx.win();
    burst(220, 200, 90, GOOD);
  };

  // ===== 入力 =====
  $("bF").addEventListener("click", () => { $("bF").blur(); answer(false); });
  $("bR").addEventListener("click", () => { $("bR").blur(); answer(true); });
  $("next").addEventListener("click", () => { $("next").blur(); proceed(); });
  $("mute").addEventListener("click", () => {
    $("mute").blur();
    muted = !muted;
    $("mute").textContent = muted ? "🔇 音オフ" : "🔊 音オン";
    if (!muted) { initAudio(); sfx.click(); }
  });
  document.addEventListener("keydown", (e) => {
    if (!started || e.repeat) return;
    const k = e.key, go = k === " " || k === "Enter";
    if (mode === "play") {
      if (k === "ArrowLeft") answer(false);
      else if (k === "ArrowRight") answer(true);
    } else if (mode === "fbok") {
      if (go && modeT > 0.3) proceed();
    } else if (mode === "fbwait") {
      if (go && modeT > 0.4) proceed();
    } else if (mode === "intro") {
      if (go && modeT > 0.5) introGo();
    } else if (mode === "boss") {
      if (k >= "1" && k <= "6") pick(Number(k) - 1);
    }
    if (go) e.preventDefault();
  });

  // ===== 毎フレーム =====
  let last = 0;
  const frame = (ts) => {
    const dt = Math.min(0.1, Math.max(0, (ts - last) / 1000)) || 0;
    last = ts;
    modeT += dt;
    if (timers.length) {
      const due = [];
      timers = timers.filter((t) => { t.t -= dt; if (t.t <= 0) { due.push(t); return false; } return true; });
      due.forEach((t) => t.fn());
    }
    if (mode === "play" || mode === "boss") {
      tLeft -= dt;
      setBar(mode === "play" ? "tbar" : "btbar");
      const sec = Math.ceil(tLeft);
      if (sec !== lastSec) { lastSec = sec; if (sec <= 5 && sec > 0) sfx.tick(); }
      if (tLeft <= 0) { if (mode === "play") answer(false, true); else pick(-1, true); }
    }
    if (shown !== score) {
      shown += (score - shown) * Math.min(1, dt * 10);
      if (Math.abs(score - shown) < 1) shown = score;
      setScore();
    }
    if (mode === "result" && resShown !== resTarget) {
      resShown += (resTarget - resShown) * Math.min(1, dt * 4);
      if (Math.abs(resTarget - resShown) < 1) resShown = resTarget;
      const rs = $("rscore");
      if (rs) rs.firstChild.textContent = String(Math.round(resShown));
    }
    drawParts(dt);
    requestAnimationFrame(frame);
  };

  showTitle();
  requestAnimationFrame(frame);
})();
</script>
</body>
</html>