1. ハッカーの目 ソースコード
遊ぶ一覧にもどる

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

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>ハッカーの目</title>
<!-- 社長メモ:部屋5の「かけらC」は【55】。ここなら絶対に見つからないニャ -->
<style>
  html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #101624; }
  #stage { position: absolute; left: 0; top: 0; width: 960px; height: 540px; overflow: hidden; color: #fff; font-size: 18px; line-height: 1.5; user-select: none; -webkit-user-select: none; background: #101624; }
  button { font: inherit; font-weight: 700; cursor: pointer; border: 0; border-radius: 12px; }
  button:disabled { cursor: default; opacity: .45; }
  .hide { display: none !important; }

  /* ---- 上のバー ---- */
  #topbar { position: absolute; left: 0; top: 0; width: 960px; height: 44px; background: #182238; box-sizing: border-box; padding: 0 12px; display: flex; align-items: center; gap: 14px; font-weight: 700; }
  #roomName { flex: 1; font-size: 20px; white-space: nowrap; overflow: hidden; }
  #starsTop { color: #ffd54f; font-size: 20px; letter-spacing: 2px; }
  #timeTop, #scoreTop { font-size: 18px; min-width: 86px; text-align: right; }
  #mute { font-size: 16px; padding: 4px 12px; background: #33415f; color: #fff; }

  /* ---- 部屋 ---- */
  #scene { position: absolute; left: 0; top: 44px; width: 960px; height: 356px; overflow: hidden; touch-action: none; }
  #scene.megane { cursor: crosshair; }
  .room { position: absolute; inset: 0; display: none; }
  .room.on { display: block; }
  .wall { position: absolute; left: 0; top: 0; width: 960px; height: 270px; }
  .floor { position: absolute; left: 0; top: 270px; width: 960px; height: 86px; }
  .room > svg, .room > div.obj, .poster, .kabemoji, .memo { position: absolute; }
  #room1 .wall { background: #f6e7c1; } #room1 .floor { background: #c98f5a; }
  #room2 .wall { background: #f4f1ea; } #room2 .floor { background: #b9b3a6; }
  #room3 .wall { background: #cfe8e0; } #room3 .floor { background: #8fb7a5; }
  #room4 .wall { background: #1f2a44; } #room4 .floor { background: #141b2d; }
  #room5 .wall { background: #3b2a4d; } #room5 .floor { background: #241a30; }
  #room6 .wall { background: #6b2433; } #room6 .floor { background: #3d141d; }
  .poster { box-sizing: border-box; width: 170px; height: 130px; background: #fff; color: #333; border: 5px solid #8a5a2b; border-radius: 4px; text-align: center; font-weight: 700; font-size: 18px; padding-top: 10px; line-height: 1.6; box-shadow: 2px 3px 0 rgba(0,0,0,.2); }
  .poster b { display: block; color: #c0392b; font-size: 20px; }
  .kabemoji { font-size: 16px; font-weight: 700; white-space: nowrap; user-select: text; -webkit-user-select: text; }
  .memo { left: 478px; top: 122px; width: 150px; box-sizing: border-box; padding: 8px; background: #fff3a0; color: #222; font-weight: 700; font-size: 17px; line-height: 1.4; text-align: center; transform: rotate(-4deg); box-shadow: 2px 3px 0 rgba(0,0,0,.25); }
  .memo.pop { animation: pop .5s; }
  #slots { position: absolute; left: 286px; top: 24px; display: flex; gap: 10px; }
  #slots span { display: block; width: 104px; height: 58px; box-sizing: border-box; border: 3px solid #b99be0; border-radius: 10px; background: #24183a; color: #b99be0; text-align: center; font-weight: 700; font-size: 16px; line-height: 1.5; padding-top: 3px; }
  #slots span.got { border-color: #ffe45c; color: #ffe45c; animation: pop .5s; }
  #slots span i { display: block; font-style: normal; font-size: 20px; }
  .jsSign { position: absolute; left: 800px; top: 20px; width: 70px; height: 34px; background: #0b3; color: #012; font-weight: 700; font-size: 20px; text-align: center; border-radius: 6px; line-height: 34px; box-shadow: 0 0 14px #0f6; }

  /* ---- ドア・モニター ---- */
  #door { position: absolute; left: 770px; top: 62px; width: 130px; height: 208px; background: #3a2a1a; border-radius: 8px 8px 0 0; overflow: hidden; box-shadow: 0 0 0 6px #5b4026; }
  #doorLight { position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, #fff 0, #fff7c2 40%, #ffd54f 100%); }
  #doorPanel { position: absolute; inset: 0; background: linear-gradient(#b5793f, #94602f); transition: transform .8s cubic-bezier(.6,0,.3,1); }
  #doorPanel::before { content: ""; position: absolute; left: 14px; top: 14px; right: 14px; bottom: 60px; border: 4px solid rgba(0,0,0,.18); border-radius: 6px; }
  #doorKnob { position: absolute; left: 14px; top: 118px; width: 18px; height: 18px; border-radius: 50%; background: #ffd54f; box-shadow: 0 2px 0 rgba(0,0,0,.3); }
  #doorSign { position: absolute; left: 0; right: 0; top: 52px; text-align: center; font-size: 44px; font-weight: 700; color: rgba(255,255,255,.85); }
  #door.open #doorPanel { transform: translateY(-97%); }
  #door.shake { animation: shake .45s; }
  #scene.r4 #doorPanel { background: linear-gradient(#3d5a80, #293f5c); }
  #scene.r5 #doorPanel { background: linear-gradient(#7d5ba6, #54397a); }
  #scene.r6 #doorPanel { background: linear-gradient(#d9b44a, #a8842a); }
  #scene.r6 #door { border-radius: 14px; top: 92px; height: 178px; }
  #stamp { position: absolute; left: 765px; top: 130px; width: 140px; text-align: center; font-size: 34px; font-weight: 700; color: #ff3b3b; text-shadow: 2px 2px 0 #fff; transform: rotate(-12deg); pointer-events: none; opacity: 0; }
  #stamp.go { animation: stamp .9s; }
  #monitor { position: absolute; left: 22px; top: 16px; width: 150px; height: 108px; background: #222b3d; border: 5px solid #0d1320; border-radius: 12px; box-sizing: border-box; }
  #monitor svg { position: absolute; left: 20px; top: 6px; width: 100px; height: 84px; }
  #monitor::after { content: ""; position: absolute; left: 55px; top: 103px; width: 30px; height: 14px; background: #0d1320; }
  #catSay { position: absolute; left: 184px; top: 6px; max-width: 570px; background: #fff; color: #222; font-weight: 700; font-size: 18px; padding: 8px 14px; border-radius: 14px; border: 3px solid #f2a23a; display: none; z-index: 6; }
  #catSay.on { display: block; animation: pop .3s; }
  .cat .eL, .cat .mL { display: none; }
  .cat.laugh .eN, .cat.laugh .mN { display: none; }
  .cat.laugh .eL, .cat.laugh .mL { display: inline; }
  .cat.laugh { animation: bob .3s 4; }
  #skip { position: absolute; left: 196px; top: 296px; font-size: 18px; padding: 8px 18px; background: #33415f; color: #fff; z-index: 5; }

  /* ---- ハッカーメガネ ---- */
  #lens { position: absolute; inset: 0; display: none; pointer-events: none; z-index: 3; background-color: #06281f; background-image: linear-gradient(rgba(125,255,176,.13) 1px, transparent 1px), linear-gradient(90deg, rgba(125,255,176,.13) 1px, transparent 1px); background-size: 24px 24px; }
  #lensRing { position: absolute; width: 192px; height: 192px; margin: -96px 0 0 -96px; border-radius: 50%; box-sizing: border-box; border: 5px solid #7dffb0; box-shadow: 0 0 16px #7dffb0, inset 0 0 20px rgba(125,255,176,.4); display: none; pointer-events: none; z-index: 4; }
  #scene.megane #lens, #scene.megane #lensRing { display: block; }
  .lb { position: absolute; transform: translate(-50%, -50%); width: max-content; max-width: 176px; font-size: 16px; line-height: 1.35; font-weight: 700; color: #7dffb0; text-align: center; overflow-wrap: anywhere; }
  .lb.sec { color: #ffe45c; }
  #pins { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
  .pin { position: absolute; transform: translate(-50%, -50%); width: max-content; max-width: 230px; background: #fff3a0; color: #222; font-size: 17px; font-weight: 700; line-height: 1.35; padding: 8px 10px; border-radius: 4px; box-shadow: 2px 3px 0 rgba(0,0,0,.3); text-align: center; overflow-wrap: anywhere; animation: pop .5s; }

  /* ---- 中身パネル ---- */
  #panel { position: absolute; left: 180px; top: 12px; width: 570px; height: 332px; box-sizing: border-box; background: #0d1b2a; border: 3px solid #7dffb0; border-radius: 12px; z-index: 7; display: none; padding: 10px 14px; }
  #panel.on { display: block; animation: pop .25s; }
  #panelHead { display: flex; align-items: center; font-weight: 700; color: #7dffb0; font-size: 18px; }
  #panelHead span { flex: 1; }
  #panelClose { font-size: 16px; padding: 3px 14px; background: #33415f; color: #fff; }
  #panelBody { margin-top: 6px; height: 268px; overflow: auto; font-size: 17px; line-height: 1.55; }
  #panelBody pre { margin: 0 0 8px; font: inherit; white-space: pre-wrap; word-break: break-all; color: #e8f1ff; background: #06121e; padding: 8px 10px; border-radius: 8px; }
  #panelBody .ln { white-space: pre; color: #e8f1ff; }
  #panelBody .note { color: #ffd54f; font-size: 16px; margin-top: 6px; }
  .chip { font-size: 17px; padding: 1px 8px; border-radius: 6px; background: #ffe45c; color: #222; animation: glow 1s infinite; }
  .chip.off { text-decoration: line-through; background: #555; color: #bbb; animation: none; }

  /* ---- クリアの表示 ---- */
  #clear { position: absolute; left: 170px; top: 40px; width: 540px; box-sizing: border-box; padding: 14px 20px 16px; background: rgba(16,22,36,.95); border: 4px solid #ffd54f; border-radius: 18px; text-align: center; z-index: 8; display: none; }
  #clear.on { display: block; animation: pop .35s; }
  #clearTitle { font-size: 30px; font-weight: 700; color: #ffd54f; }
  #clearStars { font-size: 40px; color: #ffd54f; letter-spacing: 6px; line-height: 1.2; }
  #clearScore { font-size: 22px; font-weight: 700; }
  #clearLesson { font-size: 18px; margin: 6px 0 12px; background: #24304d; border-radius: 10px; padding: 8px 10px; }
  #clearNext { font-size: 22px; padding: 8px 30px; background: #2fae6b; color: #fff; }

  /* ---- 下のパネル ---- */
  #bottom { position: absolute; left: 0; top: 400px; width: 960px; height: 140px; background: #182238; }
  #pico { position: absolute; left: 8px; top: 8px; width: 90px; height: 124px; }
  #bubble { position: absolute; left: 106px; top: 10px; width: 506px; height: 120px; box-sizing: border-box; background: #fff; color: #222; border-radius: 16px; padding: 10px 16px; font-size: 18px; line-height: 1.55; font-weight: 700; }
  #bubble::before { content: ""; position: absolute; left: -12px; top: 44px; border: 8px solid transparent; border-right: 12px solid #fff; border-left: 0; }
  #bubble.new { animation: pop .3s; }
  #pw { position: absolute; left: 626px; top: 8px; width: 200px; height: 44px; box-sizing: border-box; font: inherit; font-size: 22px; font-weight: 700; padding: 0 10px; border: 3px solid #7dffb0; border-radius: 10px; background: #0d1b2a; color: #fff; }
  #pw::placeholder { color: #7f8aa3; font-size: 17px; }
  #go { position: absolute; left: 834px; top: 8px; width: 114px; height: 44px; font-size: 22px; background: #2fae6b; color: #fff; }
  #pwNote { position: absolute; left: 626px; top: 54px; width: 322px; font-size: 16px; color: #aab6d3; }
  .tool { position: absolute; top: 84px; height: 46px; font-size: 17px; color: #fff; padding: 0; }
  #tMegane { left: 626px; width: 104px; background: #1f8a5b; }
  #tPanel { left: 736px; width: 104px; background: #2b6cb0; }
  #tHint { left: 846px; width: 102px; background: #8a6d1f; }
  .tool.active { box-shadow: 0 0 0 3px #fff inset; }
  .tool.pulse { animation: glow 1s infinite; }

  /* ---- タイトル・お話・結果 ---- */
  .screen { position: absolute; inset: 0; z-index: 20; }
  #title { background: radial-gradient(circle at 50% 35%, #1d3a5c, #101624 70%); text-align: center; }
  #title h1 { margin: 26px 0 0; font-size: 64px; letter-spacing: 6px; color: #7dffb0; text-shadow: 0 0 18px rgba(125,255,176,.6); }
  #title .sub { font-size: 22px; font-weight: 700; margin-top: 2px; }
  #titleArt { position: absolute; left: 0; top: 190px; width: 960px; height: 130px; }
  #titleArt svg { position: absolute; }
  #start { position: absolute; left: 340px; top: 322px; width: 280px; height: 70px; font-size: 30px; background: #2fae6b; color: #fff; box-shadow: 0 6px 0 #1c7446; animation: bob 1.2s infinite; }
  #title .rule { position: absolute; left: 0; top: 410px; width: 960px; font-size: 18px; line-height: 1.7; color: #dbe6ff; }
  #story { background: rgba(8,12,22,.86); }
  #storyChar { position: absolute; left: 70px; top: 150px; width: 190px; height: 190px; }
  #storyChar svg { width: 100%; height: 100%; }
  #storyBox { position: absolute; left: 290px; top: 170px; width: 610px; height: 170px; box-sizing: border-box; background: #fff; color: #222; border-radius: 18px; padding: 14px 22px; font-size: 22px; font-weight: 700; line-height: 1.6; }
  #storyName { color: #c0392b; font-size: 18px; }
  #storyNext { position: absolute; left: 740px; top: 352px; width: 160px; height: 50px; font-size: 22px; background: #2fae6b; color: #fff; }
  #result { background: radial-gradient(circle at 50% 20%, #24406a, #101624 75%); }
  #result h2 { margin: 14px 0 0; text-align: center; font-size: 38px; color: #ffd54f; }
  #rank { text-align: center; font-size: 22px; font-weight: 700; }
  #resTable { position: absolute; left: 40px; top: 122px; width: 420px; font-size: 18px; font-weight: 700; border-collapse: collapse; }
  #resTable td { padding: 3px 8px; border-bottom: 1px solid #33415f; }
  #resTable td.s { color: #ffd54f; letter-spacing: 2px; }
  #resTable td.p { text-align: right; }
  #mamori { position: absolute; left: 490px; top: 122px; width: 430px; box-sizing: border-box; background: #182238; border: 3px solid #7dffb0; border-radius: 14px; padding: 10px 14px; font-size: 17px; line-height: 1.7; }
  #mamori b { color: #7dffb0; font-size: 20px; }
  #totalBox { position: absolute; left: 490px; top: 330px; width: 430px; text-align: center; }
  #total { font-size: 46px; font-weight: 700; color: #ffd54f; line-height: 1.2; }
  #resTime { font-size: 18px; }
  #bestNote { font-size: 17px; color: #7dffb0; }
  #again { position: absolute; left: 640px; top: 440px; width: 280px; height: 60px; font-size: 24px; background: #2fae6b; color: #fff; }
  #fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 15; }
  #fade.on { opacity: 1; }
  #fx { position: absolute; left: 0; top: 0; width: 960px; height: 540px; pointer-events: none; z-index: 30; }

  @keyframes pop { 0% { transform-origin: center; scale: .6; opacity: 0; } 70% { scale: 1.08; opacity: 1; } 100% { scale: 1; } }
  @keyframes shake { 0%,100% { translate: 0; } 20% { translate: -9px; } 40% { translate: 8px; } 60% { translate: -6px; } 80% { translate: 4px; } }
  @keyframes stamp { 0% { opacity: 0; scale: 2.4; } 20% { opacity: 1; scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
  @keyframes bob { 0%,100% { translate: 0 0; } 50% { translate: 0 -5px; } }
  @keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(255,228,92,.9); } 50% { box-shadow: 0 0 0 7px rgba(255,228,92,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="stage">

  <!-- ===== 上のバー ===== -->
  <div id="topbar">
    <div id="roomName"></div>
    <div id="starsTop"></div>
    <div id="timeTop">0:00</div>
    <div id="scoreTop">0点</div>
    <button id="mute" type="button">音 ON</button>
  </div>

  <!-- ===== 部屋(ここから下に、5つの部屋と金庫の中身が書いてある) ===== -->
  <div id="scene">

    <!-- 部屋1:コメントの部屋 -->
    <div class="room" id="room1">
      <div class="wall"></div><div class="floor"></div>
      <div class="poster" style="left:230px;top:50px" data-secret="comment">
        <!-- 社長メモ:パスワードは【NEKO22】 -->
        <b>社訓</b>よくねて<br>よく食べる
      </div>
      <svg style="left:470px;top:40px" width="84" height="84" viewBox="0 0 84 84" data-megane="時計:おやつの時間まで、あと少し">
        <circle cx="42" cy="42" r="38" fill="#fff" stroke="#8a5a2b" stroke-width="6"/>
        <path d="M42 42V18M42 42l16 8" stroke="#333" stroke-width="5" stroke-linecap="round"/>
      </svg>
      <svg style="left:430px;top:196px" width="110" height="80" viewBox="0 0 110 80" data-megane="&lt;div class=&quot;hako&quot;&gt; 空っぽ。社長のお気に入り">
        <path d="M8 22h94v54H8z" fill="#d9a066"/><path d="M8 22l14-16h66l14 16z" fill="#c48a4e"/><path d="M50 22h10v20H50z" fill="#f3d9b1"/>
      </svg>
      <svg style="left:620px;top:150px" width="84" height="124" viewBox="0 0 84 124" data-megane="&lt;div class=&quot;ueki&quot;&gt; ただの植木">
        <path d="M42 84C10 62 10 22 40 8c-8 32 2 54 2 76z" fill="#3fa66b"/><path d="M42 84c32-22 32-58 6-72 6 30-6 50-6 72z" fill="#2e8b57"/><path d="M22 84h40l-6 38H28z" fill="#c9773f"/>
      </svg>
    </div>

    <!-- 部屋2:まっ白な部屋 -->
    <div class="room" id="room2">
      <div class="wall"></div><div class="floor"></div>
      <div class="poster" style="left:230px;top:40px" data-megane="&lt;div class=&quot;poster&quot;&gt; 本当かニャ?">
        <b>お知らせ</b>このかべには<br>何もないニャ
      </div>
      <span class="kabemoji" style="left:470px;top:44px;color:#f4f1ea">ハズレだニャ</span>
      <span class="kabemoji" style="left:590px;top:140px;color:#f4f1ea">おなかがすいたニャ</span>
      <span class="kabemoji" style="left:216px;top:216px;color:#f4f1ea">ここにはないニャ</span>
      <span class="kabemoji" style="left:420px;top:206px;color:#f4f1ea" data-secret="text">パスワードは【SAKANA8】</span>
    </div>

    <!-- 部屋3:消えたメモの部屋 -->
    <div class="room" id="room3">
      <div class="wall"></div><div class="floor"></div>
      <svg style="left:230px;top:36px" width="150" height="120" viewBox="0 0 150 120" data-megane="&lt;div class=&quot;mado&quot;&gt; 外はいい天気">
        <rect x="4" y="4" width="142" height="112" fill="#9fd8ff" stroke="#fff" stroke-width="8"/><path d="M75 4v112M4 60h142" stroke="#fff" stroke-width="6"/><circle cx="112" cy="32" r="12" fill="#ffe45c"/>
      </svg>
      <svg style="left:430px;top:166px" width="250" height="110" viewBox="0 0 250 110">
        <rect x="0" y="0" width="250" height="18" rx="4" fill="#a8703c"/><path d="M14 18h16v90H14zM220 18h16v90h-16z" fill="#8a5a2b"/><rect x="150" y="18" width="70" height="46" fill="#96622f"/><circle cx="185" cy="41" r="5" fill="#ffd54f"/>
      </svg>
      <div class="obj" style="left:500px;top:130px;width:110px;height:36px" data-megane="??? 何かあるはず。でも画面に出ていない"></div>
      <div class="memo" id="memo3" style="display:none">社長メモ<br>パスワードは<br>【KOTATSU5】</div>
      <svg style="left:236px;top:234px" width="130" height="44" viewBox="0 0 130 44" data-megane="ざぶとん:社長の昼ね用">
        <rect x="4" y="8" width="122" height="32" rx="14" fill="#e57373"/><circle cx="65" cy="24" r="5" fill="#fff"/>
      </svg>
    </div>

    <!-- 部屋4:プログラムのドア(パスワードは下の script の door4Check の中) -->
    <div class="room" id="room4">
      <div class="wall"></div><div class="floor"></div>
      <div class="jsSign">JS</div>
      <svg style="left:226px;top:66px" width="96" height="206" viewBox="0 0 96 206" data-megane="サーバー:ピコピコ光るだけ">
        <rect x="2" y="2" width="92" height="202" rx="6" fill="#0d1320" stroke="#3d5a80" stroke-width="4"/>
        <path d="M14 24h68M14 60h68M14 96h68M14 132h68M14 168h68" stroke="#33415f" stroke-width="18"/>
        <circle cx="24" cy="24" r="5" fill="#0f6"/><circle cx="40" cy="60" r="5" fill="#fd0"/><circle cx="24" cy="96" r="5" fill="#0f6"/><circle cx="56" cy="132" r="5" fill="#f55"/><circle cx="24" cy="168" r="5" fill="#0f6"/>
      </svg>
      <svg style="left:390px;top:150px" width="170" height="124" viewBox="0 0 170 124" data-megane="金魚:あいことばは、ぼくも知らない">
        <rect x="6" y="6" width="158" height="96" rx="8" fill="#2a6f97" stroke="#bfe6ff" stroke-width="5"/><path d="M20 102h130v18H20z" fill="#33415f"/>
        <ellipse cx="78" cy="56" rx="22" ry="13" fill="#ff8a3d"/><path d="M98 56l20-14v28z" fill="#ff8a3d"/><circle cx="66" cy="52" r="3" fill="#222"/><circle cx="40" cy="30" r="4" fill="#bfe6ff"/><circle cx="50" cy="18" r="3" fill="#bfe6ff"/>
      </svg>
      <div class="poster" style="left:590px;top:50px;width:160px;height:118px;font-size:17px" data-megane="&lt;div class=&quot;poster&quot;&gt; 本当に見えないかニャ?">
        <b>安心</b>パスワードは<br>だれにも見えない
      </div>
    </div>

    <!-- 部屋5:3つのかけらの部屋(かけらBは下の script、かけらCはこのファイルの上のほう) -->
    <div class="room" id="room5">
      <div class="wall"></div><div class="floor"></div>
      <div id="slots"><span id="slotA">かけらA<i>?</i></span><span id="slotB">かけらB<i>?</i></span><span id="slotC">かけらC<i>?</i></span></div>
      <span class="kabemoji" style="left:228px;top:214px;color:#3b2a4d" data-secret="text">かけらAは【MATA】</span>
      <span class="kabemoji" style="left:590px;top:116px;color:#3b2a4d">かけらZはないニャ</span>
      <svg style="left:440px;top:150px" width="100" height="124" viewBox="0 0 100 124" data-megane="トロフィー:ねこ社長コンテスト 2位">
        <path d="M26 8h48v34a24 24 0 0 1-48 0z" fill="#ffd54f"/><path d="M26 16H10a16 16 0 0 0 18 22M74 16h16a16 16 0 0 1-18 22" fill="none" stroke="#ffd54f" stroke-width="6"/><path d="M44 64h12v26H44z" fill="#d9b44a"/><path d="M24 90h52v26H24z" fill="#8a5a2b"/>
      </svg>
    </div>

    <!-- おまけ:社長の金庫(絵の中身をよく見ると…) -->
    <div class="room" id="room6">
      <div class="wall"></div><div class="floor"></div>
      <svg id="shachoE" style="left:330px;top:30px" width="170" height="200" viewBox="0 0 170 200" data-megane="&lt;svg&gt; の中に &lt;title&gt; がある。絵の上にマウスを置いて待つと…?">
        <title>FLAG{NAKAMI_MIETA}</title>
        <rect x="5" y="5" width="160" height="190" fill="#f6e7c1" stroke="#d9b44a" stroke-width="10"/>
        <path d="M46 92L40 46l34 22zM124 92l6-46-34 22z" fill="#f2a23a"/><ellipse cx="85" cy="108" rx="50" ry="44" fill="#f7b955"/>
        <ellipse cx="66" cy="102" rx="6" ry="9" fill="#222"/><ellipse cx="104" cy="102" rx="6" ry="9" fill="#222"/><path d="M80 116h10l-5 6z" fill="#d9534f"/>
        <path d="M85 122q-9 9-16 2M85 122q9 9 16 2" stroke="#222" stroke-width="3" fill="none"/><path d="M75 158l10-8 10 8-10 12z" fill="#c0392b"/>
        <path d="M70 60h30l-6-18-9 10-9-10z" fill="#ffd54f"/>
      </svg>
      <button id="skip" type="button">金庫はあきらめて、結果を見る ▶</button>
    </div>

    <div id="monitor"></div>
    <div id="catSay"></div>
    <div id="door"><div id="doorLight"></div><div id="doorPanel"><div id="doorKnob"></div><div id="doorSign">1</div></div></div>
    <div id="stamp">ブブー!</div>
    <div id="lens"></div>
    <div id="lensRing"></div>
    <div id="pins"></div>
    <div id="panel">
      <div id="panelHead"><span>中身パネル</span><button id="panelClose" type="button">閉じる</button></div>
      <div id="panelBody"></div>
    </div>
    <div id="clear">
      <div id="clearTitle">ドアが開いた!</div>
      <div id="clearStars"></div>
      <div id="clearScore"></div>
      <div id="clearLesson"></div>
      <button id="clearNext" type="button">次の部屋へ ▶</button>
    </div>
  </div>

  <!-- ===== 下のパネル ===== -->
  <div id="bottom">
    <div id="pico"></div>
    <div id="bubble"></div>
    <input id="pw" type="text" maxlength="24" autocomplete="off" autocapitalize="characters" spellcheck="false" inputmode="latin" placeholder="ここにパスワード">
    <button id="go" type="button">開く!</button>
    <div id="pwNote">半角で。本物のパスワードは入れません</div>
    <button class="tool" id="tMegane" type="button">メガネ</button>
    <button class="tool" id="tPanel" type="button">???</button>
    <button class="tool" id="tHint" type="button">ヒント</button>
  </div>

  <div id="fade"></div>

  <!-- ===== タイトル ===== -->
  <div class="screen" id="title">
    <h1>ハッカーの目</h1>
    <div class="sub">中をのぞいて、ひみつの部屋から だっしゅつしよう</div>
    <div id="titleArt"></div>
    <button id="start" type="button">スタート</button>
    <div class="rule">画面に見えないものも、作品の中身(コード)には書いてあります。<br>約束:ためしてよいのは、このゲームの中だけです。</div>
  </div>

  <!-- ===== お話 ===== -->
  <div class="screen hide" id="story">
    <div id="storyChar"></div>
    <div id="storyBox"><div id="storyName"></div><div id="storyText"></div></div>
    <button id="storyNext" type="button">次へ ▶</button>
  </div>

  <!-- ===== 結果 ===== -->
  <div class="screen hide" id="result">
    <h2>だっしゅつ成功!</h2>
    <div id="rank"></div>
    <table id="resTable"></table>
    <div id="mamori">
      <b>ホワイトハッカーの守り方</b><br>
      ・パスワードや大事なことは、コードに書かない<br>
      ・見えなくしても、中身を見れば分かる<br>
      ・ためしてよいのは、このゲームの中だけ
    </div>
    <div id="totalBox"><div id="total"></div><div id="resTime"></div><div id="bestNote"></div></div>
    <button id="again" type="button">もう一度ちょうせん</button>
  </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);

  // ===== 部屋4:ドアのプログラム =====
  function door4Check(nyuryoku) {
    // 入力された文字が「あいことば」と同じなら、ドアが開く
    const mae = "NIKU";
    const ushiro = "KYU";
    const aikotoba = mae + ushiro;
    return nyuryoku === aikotoba;
  }

  // ===== 部屋5:ドアのプログラム =====
  const KAKERA_B = "TABI";
  function door5Check(nyuryoku) {
    // A は見えない文字、C はコードのコメントの中
    return nyuryoku === kakeraA() + KAKERA_B + kakeraC();
  }

  // ---- 中身から読み出す道具 ----
  const kakko = (s) => { const m = /【(.+?)】/.exec(s || ""); return m ? m[1] : ""; };
  // スタジオがコメントを消してしまったときの予備(1文字ずつずらしてある)
  const modosu = (s) => s.split("").map((c) => String.fromCharCode(c.charCodeAt(0) - 1)).join("");
  function findComment(root, word) {
    const w = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
    let found = "";
    while (!found && w.nextNode()) {
      if (w.currentNode.nodeValue.indexOf(word) >= 0) found = w.currentNode.nodeValue.trim();
    }
    return found;
  }
  const comment1 = () => findComment($("room1"), "パスワード") || "社長メモ:パスワードは【" + modosu("OFLP33") + "】";
  const kakeraA = () => kakko($("room5").querySelector("[data-secret]").textContent);
  const kakeraC = () => kakko(findComment(document.head, "かけらC")) || modosu("66");
  const flagText = () => norm($("shachoE").querySelector("title").textContent);
  const norm = (v) => String(v).normalize("NFKC").toUpperCase().replace(/\s+/g, "");

  // ---- キャラクターの絵 ----
  const CAT = '<svg class="cat" viewBox="0 0 120 100"><path d="M22 40L18 6l30 18zM98 40l4-34-30 18z" fill="#f2a23a"/><ellipse cx="60" cy="54" rx="44" ry="38" fill="#f7b955"/><path d="M54 18h12l-6 14z" fill="#e08a1e"/><g class="eN"><ellipse cx="42" cy="50" rx="6" ry="8" fill="#222"/><ellipse cx="78" cy="50" rx="6" ry="8" fill="#222"/></g><g class="eL"><path d="M34 54l8-9 8 9M70 54l8-9 8 9" stroke="#222" stroke-width="4" fill="none" stroke-linecap="round"/></g><path d="M56 62h8l-4 5z" fill="#d9534f"/><path class="mN" d="M60 67q-8 8-14 2M60 67q8 8 14 2" stroke="#222" stroke-width="2.5" fill="none"/><path class="mL" d="M46 68q14 22 28 0z" fill="#7a1f1f"/><path d="M20 58H6M20 66L7 71M100 58h14M100 66l13 5" stroke="#222" stroke-width="2"/><path d="M52 92l8-6 8 6-8 8z" fill="#c0392b"/></svg>';
  const PICO = '<svg viewBox="0 0 90 124"><path d="M45 20V6" stroke="#9fb3d9" stroke-width="4"/><circle cx="45" cy="6" r="6" fill="#ff5c5c"/><rect x="10" y="20" width="70" height="54" rx="14" fill="#dfe8fb" stroke="#5b6f9a" stroke-width="4"/><circle cx="32" cy="46" r="9" fill="#27c4ff"/><circle cx="58" cy="46" r="9" fill="#27c4ff"/><circle cx="34" cy="44" r="3" fill="#fff"/><circle cx="60" cy="44" r="3" fill="#fff"/><path d="M36 62q9 6 18 0" stroke="#5b6f9a" stroke-width="3" fill="none" stroke-linecap="round"/><rect x="22" y="78" width="46" height="36" rx="8" fill="#9fb3d9" stroke="#5b6f9a" stroke-width="4"/><circle cx="45" cy="96" r="7" fill="#7dffb0"/><path d="M22 86H8v16M68 86h14v16" stroke="#5b6f9a" stroke-width="5" fill="none" stroke-linecap="round"/></svg>';
  $("monitor").innerHTML = CAT;
  $("pico").innerHTML = PICO;
  $("titleArt").innerHTML = CAT.replace('<svg', '<svg style="left:150px;top:6px;width:140px;height:118px"') + PICO.replace('<svg', '<svg style="left:690px;top:0;width:96px;height:130px"') +
    '<svg style="left:380px;top:8px;width:200px;height:110px" viewBox="0 0 200 110"><circle cx="50" cy="55" r="40" fill="#06281f" stroke="#7dffb0" stroke-width="8"/><circle cx="150" cy="55" r="40" fill="#06281f" stroke="#7dffb0" stroke-width="8"/><path d="M90 50q10-10 20 0" stroke="#7dffb0" stroke-width="8" fill="none"/><ellipse cx="50" cy="55" rx="14" ry="20" fill="#7dffb0"/><ellipse cx="150" cy="55" rx="14" ry="20" fill="#7dffb0"/><circle cx="54" cy="48" r="5" fill="#fff"/><circle cx="154" cy="48" r="5" fill="#fff"/></svg>';
  const catEl = $("monitor").querySelector("svg");

  // ===== 部屋のデータ =====
  const DOOR_TXT = '<div id="door"> パスワードがないと開かない';
  const ROOMS = [
    { id: "room1", name: "コメントの部屋",
      check: (v) => v === kakko(comment1()),
      enter: "ドアを開くにはパスワードが必要です。まず「メガネ」を押して、部屋をなぞってみましょう。",
      found: "コメントを発見! 画面には出ないメモですが、中身には書いてありました。",
      hints: [() => "メガネをオンにして、あやしい物の上に動かしましょう。", () => "ポスターの中身を、メガネで見てみましょう。", () => "パスワードは " + kakko(comment1()) + " です。"],
      lesson: "コメントは画面に出ません。でも、中身(コード)を見ればだれでも読めます。", door: DOOR_TXT },
    { id: "room2", name: "まっ白な部屋",
      check: (v) => v === kakko($("room2").querySelector("[data-secret]").textContent),
      enter: "今度はポスターにメモがありません。でも、かべが少しあやしいです。メガネで調べましょう。",
      found: "かべと同じ色の文字でした! 見えないだけで、中身には書いてあります。",
      hints: [() => "メガネで、かべのすみずみまでなぞりましょう。", () => "かべの下のほう、真ん中あたりがあやしいです。", () => "パスワードは " + kakko($("room2").querySelector("[data-secret]").textContent) + " です。"],
      lesson: "かべと同じ色の文字は、見えないだけです。中身にはそのまま書いてあります。", door: DOOR_TXT },
    { id: "room3", name: "消えたメモの部屋",
      check: (v) => v === kakko($("memo3").textContent),
      enter: "メガネだけでは読めないようです。新しい道具「中身」パネルを開いてみましょう。",
      found: "メモが出てきました! 消えていたのは見た目だけでした。",
      hints: [() => "「中身」パネルを開いて、黄色いところを探しましょう。", () => "display:none は「画面に出さない」という指定です。押すと消せます。", () => "パスワードは " + kakko($("memo3").textContent) + " です。"],
      lesson: "display:none は見た目を消すだけです。中身にはちゃんと残っています。", door: DOOR_TXT },
    { id: "room4", name: "プログラムのドア",
      check: door4Check,
      enter: "このドアはプログラムで動いています。「中身」パネルで、ドアのコードを読みましょう。",
      found: "入力と何をくらべているでしょうか。「+」は文字をつなげる記号です。",
      hints: [() => "「中身」パネルを開いて、aikotoba に何が入るかを考えましょう。", () => "mae と ushiro の文字を、そのままつなげます。", () => "NIKU と KYU をつなげて、NIKUKYU です。"],
      lesson: "プログラムに書いたパスワードは、コードを読めば分かってしまいます。", door: "このドアは JavaScript というプログラムで動いている" },
    { id: "room5", name: "3つのかけらの部屋",
      check: door5Check,
      enter: "最後の部屋です。パスワードは、かけら A・B・C を順につなげたものです。今までの技で探しましょう。",
      found: "かけらAを発見! 残りも探しましょう。",
      hints: [() => "かけらAはメガネで、かけらBは「中身」パネルで見つかります。", () => "かけらCは、この作品の本物のコードの中のコメントです。「かけらC」という言葉を探しましょう。", () => "かけらCは " + kakeraC() + " です。つなげると " + kakeraA() + KAKERA_B + kakeraC() + " です。"],
      lesson: "かくし方を組み合わせても、中身を見れば全部分かってしまいます。", door: "3つのかけらをつなげると開く" },
    { id: "room6", name: "おまけ:社長の金庫", bonus: true,
      check: (v) => v === flagText() || "FLAG{" + v + "}" === flagText(),
      enter: "金庫のパスワードは、社長の絵の中身にかくれています。この作品の本物のコードを見てみましょう。",
      found: "", hints: [], lesson: "絵(SVG)の中にも、画面に出ない文字を書けます。コードを見れば読めます。", door: "金庫:FLAG{…} の形のパスワードで開く" },
  ];
  const NG_LINES = ["ニャハハ! ちがうニャ〜!", "ブブー! ねこパンチだニャ!", "おしい…くないニャ!", "それは、きのうの晩ごはんの名前ニャ", "ドアはピクリともしないニャ〜", "もっとよく中をのぞくニャ。…あっ、今のはなしニャ!"];
  const WEAK = ["1234", "0000", "1111", "123456", "PASSWORD", "ABC", "ABCD", "NEKO", "QWERTY"];

  // ===== 音(Web Audio で合成。鳴らなくてもゲームは止めない) =====
  let ac = null, muted = false;
  function tone(f, at, dur, type, vol, f2) {
    if (!ac || muted) return;
    try {
      const t = ac.currentTime + at, o = ac.createOscillator(), g = ac.createGain();
      o.type = type || "square";
      o.frequency.setValueAtTime(f, t);
      if (f2) o.frequency.exponentialRampToValueAtTime(f2, t + dur);
      g.gain.setValueAtTime(0.0001, t);
      g.gain.exponentialRampToValueAtTime(vol || 0.1, t + 0.012);
      g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
      o.connect(g); g.connect(ac.destination);
      o.start(t); o.stop(t + dur + 0.03);
    } catch (e) { /* 音が出なくても続ける */ }
  }
  const sClick = () => tone(660, 0, 0.06, "square", 0.07);
  const sFind = () => { tone(988, 0, 0.09, "square", 0.1); tone(1319, 0.09, 0.09, "square", 0.1); tone(1760, 0.18, 0.2, "square", 0.1); };
  const sPop = () => tone(300, 0, 0.18, "sine", 0.16, 900);
  const sWrong = () => { tone(196, 0, 0.16, "sawtooth", 0.1); tone(147, 0.16, 0.3, "sawtooth", 0.1); tone(700, 0.5, 0.22, "triangle", 0.12, 1100); tone(1100, 0.72, 0.3, "triangle", 0.12, 500); };
  const sOpen = () => { tone(70, 0, 0.8, "sawtooth", 0.07, 180); [523, 659, 784, 1047, 1319].forEach((f, i) => tone(f, 0.25 + i * 0.1, i === 4 ? 0.5 : 0.12, "square", 0.1)); };
  const sLens = (on) => tone(on ? 500 : 900, 0, 0.14, "sine", 0.12, on ? 1200 : 400);
  const sNew = () => [659, 784, 988, 1319].forEach((f, i) => tone(f, i * 0.08, 0.14, "triangle", 0.14));

  // ===== 状態 =====
  const S = { mode: "title", room: 0, megane: false, hints: 0, misses: 0, roomTime: 0, totalTime: 0, results: [], score: 0, stars: 0, lensItems: [], memoShown: false, bFound: false, lx: 480, ly: 150 };
  const scene = $("scene"), lens = $("lens"), ring = $("lensRing"), pw = $("pw");

  let bubbleTimer = 0;
  function pico(text) {
    const b = $("bubble");
    b.textContent = text;
    b.classList.remove("new"); void b.offsetWidth; b.classList.add("new");
  }
  let catTimer = 0;
  function catSay(text, laugh) {
    const c = $("catSay");
    c.textContent = "社長「" + text + "」";
    c.classList.remove("on"); void c.offsetWidth; c.classList.add("on");
    catEl.classList.toggle("laugh", !!laugh);
    clearTimeout(catTimer);
    catTimer = setTimeout(() => { c.classList.remove("on"); catEl.classList.remove("laugh"); }, 2800);
  }
  const fmtTime = (s) => Math.floor(s / 60) + ":" + String(Math.floor(s % 60)).padStart(2, "0");
  function updateTop() {
    $("timeTop").textContent = fmtTime(S.totalTime);
    $("scoreTop").textContent = S.score + "点";
    $("starsTop").textContent = "★".repeat(S.stars);
  }

  // ===== ハッカーメガネ =====
  function sceneXY(el) {
    const r = el.getBoundingClientRect(), s = scene.getBoundingClientRect(), k = 960 / s.width;
    return { x: (r.left + r.width / 2 - s.left) * k, y: (r.top + r.height / 2 - s.top) * k };
  }
  function buildLens() {
    const R = ROOMS[S.room], roomEl = $(R.id);
    lens.textContent = "";
    S.lensItems = [];
    const add = (el, text, secret) => {
      const p = sceneXY(el);
      const x = Math.min(860, Math.max(100, p.x)), y = Math.min(320, Math.max(34, p.y));
      const d = document.createElement("div");
      d.className = "lb" + (secret ? " sec" : "");
      d.textContent = text;
      d.style.left = x + "px"; d.style.top = y + "px";
      lens.appendChild(d);
      S.lensItems.push({ x, y, text, secret, found: false });
    };
    roomEl.querySelectorAll("[data-megane], [data-secret], .kabemoji").forEach((el) => {
      const kind = el.getAttribute("data-secret");
      if (kind === "comment") add(el, "<!-- " + comment1() + " -->", true);
      else if (el.classList.contains("kabemoji")) add(el, el.textContent.trim(), kind === "text");
      else add(el, el.getAttribute("data-megane"), false);
    });
    add($("door"), R.door, false);
    add($("monitor"), "<svg> 社長はいつも見ているニャ", false);
  }
  function moveLens(x, y) {
    S.lx = x; S.ly = y;
    lens.style.clipPath = "circle(92px at " + x + "px " + y + "px)";
    ring.style.left = x + "px"; ring.style.top = y + "px";
    if (S.mode !== "play") return;
    S.lensItems.forEach((it) => {
      if (it.secret && !it.found && Math.hypot(it.x - x, it.y - y) < 70) {
        it.found = true;
        const pin = document.createElement("div");
        pin.className = "pin"; pin.textContent = it.text;
        pin.style.left = it.x + "px"; pin.style.top = it.y + "px";
        $("pins").appendChild(pin);
        sFind();
        pico(ROOMS[S.room].found);
        if (S.room === 4) setSlot("A", kakeraA());
        $("tMegane").classList.remove("pulse");
      }
    });
  }
  function setMegane(on) {
    S.megane = on;
    scene.classList.toggle("megane", on);
    $("tMegane").classList.toggle("active", on);
    $("tMegane").textContent = on ? "メガネ ON" : "メガネ";
    if (on) { setPanel(false); moveLens(S.lx, S.ly); }
  }
  scene.addEventListener("pointermove", (e) => {
    if (!S.megane) return;
    const s = scene.getBoundingClientRect(), k = 960 / s.width;
    moveLens((e.clientX - s.left) * k, (e.clientY - s.top) * k);
  });
  scene.addEventListener("pointerdown", (e) => {
    if (!S.megane) return;
    const s = scene.getBoundingClientRect(), k = 960 / s.width;
    moveLens((e.clientX - s.left) * k, (e.clientY - s.top) * k);
  });
  $("tMegane").addEventListener("click", () => {
    if (S.mode !== "play") return;
    setMegane(!S.megane); sLens(S.megane);
    $("tMegane").classList.remove("pulse");
    if (S.megane && S.room === 0) pico("メガネの丸の中に、部屋の中身が見えます。あやしい物の上に動かしましょう。");
  });

  // ===== 中身パネル =====
  function codeText(fn) {
    const lines = fn.toString().split("\n");
    let min = 99;
    lines.slice(1).forEach((l) => { if (l.trim()) min = Math.min(min, l.length - l.trimStart().length); });
    return lines.map((l, i) => (i === 0 ? l : l.slice(Math.min(min, l.length - l.trimStart().length)))).join("\n");
  }
  function addPre(body, text) { const p = document.createElement("pre"); p.textContent = text; body.appendChild(p); }
  function addNote(body, text) { const p = document.createElement("div"); p.className = "note"; p.textContent = text; body.appendChild(p); }
  function buildPanel() {
    const body = $("panelBody");
    body.textContent = "";
    if (S.room === 2) {
      const CHIP = {};
      const rows = [['<div id="room3">'], ['  <svg class="mado"> … </svg>'], ['  <svg class="tsukue"> … </svg>'], ['  <div class="memo" style="', CHIP, '"> … </div>'], ['  <svg class="zabuton"> … </svg>'], ['</div>']];
      rows.forEach((parts) => {
        const ln = document.createElement("div"); ln.className = "ln";
        parts.forEach((p) => {
          if (p !== CHIP) { ln.appendChild(document.createTextNode(p)); return; }
          const c = document.createElement("button");
          c.type = "button"; c.className = "chip" + (S.memoShown ? " off" : ""); c.textContent = "display:none";
          c.addEventListener("click", () => {
            if (S.memoShown || S.mode !== "play") return;
            S.memoShown = true; c.classList.add("off"); sClick();
            setTimeout(() => {
              setPanel(false);
              const m = $("memo3"); m.style.display = "block"; m.classList.add("pop");
              sPop(); sFind(); pico(ROOMS[2].found);
            }, 500);
          });
          ln.appendChild(c);
        });
        body.appendChild(ln);
      });
      addNote(body, "↑ この部屋の中身です。画面にない物が1つ書いてあります。黄色いところを押すと、その指定を消せます。");
    } else if (S.room === 3) {
      addPre(body, codeText(door4Check));
      addNote(body, "↑ ドアを動かしている本物のプログラムです。nyuryoku は入力した文字のことです。");
    } else if (S.room === 4) {
      addPre(body, 'const KAKERA_B = "' + KAKERA_B + '";\n\n' + codeText(door5Check));
      addNote(body, "かけらA:この部屋の見えない文字(メガネで探す)");
      addNote(body, "かけらC:この作品の本物のコードの中のコメント");
    } else if (S.room === 5) {
      addPre(body, '<svg id="shachoE">\n  <title>(ここは本物のコードで読めます)</title>\n  <rect … /> <ellipse … />\n</svg>');
      addNote(body, "title は、絵に付ける名前や説明です。画面には出ません。");
    }
  }
  function setPanel(on) {
    $("panel").classList.toggle("on", on);
    $("tPanel").classList.toggle("active", on);
    if (on) { setMegane(false); buildPanel(); }
  }
  $("tPanel").addEventListener("click", () => {
    if (S.mode !== "play" || S.room < 2) return;
    const on = !$("panel").classList.contains("on");
    setPanel(on); sClick();
    $("tPanel").classList.remove("pulse");
    if (!on) return;
    if (S.room === 2 && !S.memoShown) pico("display:none は「画面に出さない」という指定です。黄色いところを押して、消してみましょう。");
    if (S.room === 3) pico(ROOMS[3].found);
    if (S.room === 4) {
      if (!S.bFound) { S.bFound = true; setSlot("B", KAKERA_B); sFind(); }
      pico("かけらBを発見! かけらCは、この作品の本物のコードの中です。中身(コード)を見てみましょう。");
    }
  });
  $("panelClose").addEventListener("click", () => { setPanel(false); sClick(); });
  function setSlot(k, v) {
    const el = $("slot" + k);
    el.classList.toggle("got", !!v);
    el.querySelector("i").textContent = v || "?";
  }

  // ===== ヒント =====
  function updateHintBtn() {
    const R = ROOMS[S.room], left = R.hints.length - S.hints;
    $("tHint").textContent = R.bonus ? "ヒントなし" : "ヒント ×" + left;
    $("tHint").disabled = !!R.bonus || left <= 0;
  }
  $("tHint").addEventListener("click", () => {
    const R = ROOMS[S.room];
    if (S.mode !== "play" || S.hints >= R.hints.length) return;
    const text = R.hints[S.hints]();
    S.hints++;
    if (S.room === 4 && S.hints === 3) setSlot("C", kakeraC());
    pico("ヒント" + S.hints + ":" + text);
    sClick(); updateHintBtn();
  });

  // ===== 部屋に入る =====
  function enterRoom(i) {
    S.room = i; S.hints = 0; S.misses = 0; S.roomTime = 0; S.mode = "play";
    const R = ROOMS[i];
    document.querySelectorAll(".room").forEach((r) => r.classList.remove("on"));
    $(R.id).classList.add("on");
    scene.className = "r" + (i + 1);
    const dp = $("doorPanel");
    dp.style.transition = "none";
    $("door").classList.remove("open", "shake");
    void dp.offsetWidth;
    dp.style.transition = "";
    $("doorSign").textContent = R.bonus ? "金" : String(i + 1);
    $("roomName").textContent = R.bonus ? R.name : "部屋 " + (i + 1) + "/5 " + R.name;
    $("pins").textContent = "";
    $("clear").classList.remove("on");
    $("catSay").classList.remove("on");
    setPanel(false); setMegane(false);
    S.lx = 480; S.ly = 150;
    pw.value = ""; pw.disabled = false; $("go").disabled = false;
    $("tPanel").textContent = i < 2 ? "???" : "中身";
    $("tPanel").disabled = i < 2;
    $("tMegane").classList.toggle("pulse", i < 2);
    $("tPanel").classList.toggle("pulse", i === 2 || i === 3);
    if (i === 2) sNew();
    updateHintBtn(); updateTop();
    pico(R.enter);
    buildLens();
  }

  // ===== パスワードを入れる =====
  function submit() {
    if (S.mode !== "play") return;
    const R = ROOMS[S.room], v = norm(pw.value);
    if (!v) { catSay("何か入れてニャ!", false); sClick(); return; }
    if (/[^\x21-\x7E]/.test(v)) { pico("半角の英数字で入力しましょう。(キーボードの「半角/全角」キーで切りかえます)"); sClick(); return; }
    if (R.check(v)) { clearRoom(); return; }
    S.misses++;
    let line = NG_LINES[(S.misses - 1 + S.room) % NG_LINES.length];
    if (WEAK.indexOf(v) >= 0) line = "そんな簡単なパスワードにはしないニャ!";
    for (let k = 0; k < S.room && k < 5; k++) { if (ROOMS[k].check(v)) line = "それは前の部屋のニャ! 使い回しはしないニャ!"; }
    catSay(line, true); sWrong();
    const d = $("door"), st = $("stamp");
    d.classList.remove("shake"); st.classList.remove("go"); void d.offsetWidth;
    d.classList.add("shake"); st.classList.add("go");
    pw.select();
  }
  $("go").addEventListener("click", submit);
  pw.addEventListener("keydown", (e) => {
    if (e.key !== "Enter" || e.isComposing) return;
    if (S.mode === "play") submit();
    else if (S.mode === "clear" && $("clear").classList.contains("on")) nextRoom();
  });

  function clearRoom() {
    const R = ROOMS[S.room];
    S.mode = "clear";
    setPanel(false); setMegane(false);
    pw.disabled = true; $("go").disabled = true; pw.blur();
    let pts, stars;
    if (R.bonus) { pts = 1500; stars = 0; }
    else {
      const speed = Math.max(0, 600 - Math.floor(S.roomTime) * 5);
      pts = Math.max(200, 1000 - 250 * S.hints - 50 * Math.min(S.misses, 6)) + speed;
      stars = Math.max(1, 3 - S.hints - (S.misses >= 3 ? 1 : 0));
    }
    S.results[S.room] = { pts, stars, time: S.roomTime, hints: S.hints };
    S.score += pts; S.stars += stars;
    if (S.room === 4) { setSlot("A", kakeraA()); setSlot("B", KAKERA_B); setSlot("C", kakeraC()); }
    $("door").classList.add("open");
    sOpen(); confetti(835, 200, 90);
    catSay(R.bonus ? "ニャんと、金庫まで!?" : "ニャ、ニャんで分かったニャ!?", false);
    updateTop();
    setTimeout(() => {
      $("clearTitle").textContent = R.bonus ? "金庫が開いた!" : "ドアが開いた!";
      $("clearStars").textContent = R.bonus ? "ボーナス" : "★".repeat(stars) + "☆".repeat(3 - stars);
      $("clearScore").textContent = "+" + pts + "点" + (R.bonus ? "" : "(" + fmtTime(S.roomTime) + ")");
      $("clearLesson").textContent = R.lesson;
      $("clearNext").textContent = R.bonus ? "結果を見る ▶" : S.room === 4 ? "外へ出る ▶" : "次の部屋へ ▶";
      $("clear").classList.add("on"); $("catSay").classList.remove("on");
    }, 1000);
  }
  function fadeTo(fn) {
    $("fade").classList.add("on");
    setTimeout(() => { fn(); $("fade").classList.remove("on"); }, 320);
  }
  function nextRoom() {
    if (S.mode !== "clear") return;
    S.mode = "move"; sClick();
    if (S.room < 4) fadeTo(() => enterRoom(S.room + 1));
    else if (S.room === 4) fadeTo(() => { $("clear").classList.remove("on"); story(ENDING, () => enterRoom(5)); });
    else fadeTo(showResult);
  }
  $("clearNext").addEventListener("click", nextRoom);
  $("skip").addEventListener("click", () => { if (S.mode === "play") { S.mode = "move"; sClick(); fadeTo(showResult); } });

  // ===== お話 =====
  const INTRO = [
    ["cat", "ニャン社長", "ようこそ、ゴロニャー社のひみつの部屋へ。見習いホワイトハッカーのうでを、ためしてやるニャ。"],
    ["cat", "ニャン社長", "部屋は5つ。ドアのパスワードは、完ぺきにかくしたニャ。出られるかニャ? ニャハハ!"],
    ["pico", "案内ロボのピコ", "画面に見えなくても、中身には書いてあるかもしれません。「ハッカーの目」で、中をのぞきましょう。"],
  ];
  const ENDING = [
    ["cat", "ニャン社長", "ニャんと! 完ぺきにかくしたのに、どうして全部分かったニャ!?"],
    ["pico", "案内ロボのピコ", "見えなくしても、中身(コード)を見れば全部読めます。かくしたつもりでも、丸見えです。"],
    ["pico", "案内ロボのピコ", "だから、パスワードや大事なことは、コードに書いてはいけません。"],
    ["cat", "ニャン社長", "分かったニャ…もう書かないニャ。お礼に、わしの金庫にちょうせんさせてやるニャ!"],
  ];
  let storyPages = [], storyIdx = 0, storyDone = null;
  function story(pages, done) {
    S.mode = "story"; storyPages = pages; storyIdx = 0; storyDone = done;
    $("story").classList.remove("hide");
    showPage();
  }
  function showPage() {
    const p = storyPages[storyIdx];
    $("storyChar").innerHTML = p[0] === "cat" ? CAT : PICO;
    $("storyName").textContent = p[1];
    $("storyText").textContent = p[2];
    $("storyNext").textContent = storyIdx === storyPages.length - 1 ? "OK ▶" : "次へ ▶";
  }
  $("story").addEventListener("click", () => {
    if (S.mode !== "story") return;
    sClick(); storyIdx++;
    if (storyIdx < storyPages.length) { showPage(); return; }
    $("story").classList.add("hide");
    const f = storyDone; storyDone = null; f();
  });

  // ===== 結果 =====
  function showResult() {
    S.mode = "result";
    $("clear").classList.remove("on");
    const t = $("resTable");
    t.textContent = "";
    ROOMS.forEach((R, i) => {
      const r = S.results[i], tr = document.createElement("tr");
      const cells = [R.bonus ? "金庫" : "部屋" + (i + 1), R.bonus ? (r ? "ボーナス" : "まだ") : "★".repeat(r.stars) + "☆".repeat(3 - r.stars), R.bonus ? "" : fmtTime(r.time), (r ? r.pts : 0) + "点"];
      cells.forEach((c, k) => { const td = document.createElement("td"); td.textContent = c; td.className = k === 1 ? "s" : k === 3 ? "p" : ""; tr.appendChild(td); });
      t.appendChild(tr);
    });
    const rank = S.stars >= 14 ? "スーパーホワイトハッカー" : S.stars >= 10 ? "ホワイトハッカー" : "かけ出しホワイトハッカー";
    $("rank").textContent = "★" + S.stars + "/15 ランク:" + rank;
    $("total").textContent = S.score + "点";
    $("resTime").textContent = "時間 " + fmtTime(S.totalTime);
    $("bestNote").textContent = S.results[5] ? "" : "金庫を開けると、さらに +1500点";
    $("result").classList.remove("hide");
    confetti(480, 120, 140); sNew();
  }
  $("again").addEventListener("click", () => {
    sClick();
    S.results = []; S.score = 0; S.stars = 0; S.totalTime = 0; S.memoShown = false; S.bFound = false;
    $("memo3").style.display = "none"; $("memo3").classList.remove("pop");
    setSlot("A", ""); setSlot("B", ""); setSlot("C", "");
    $("result").classList.add("hide");
    enterRoom(0);
  });

  // ===== スタート・音 =====
  $("start").addEventListener("click", () => {
    try { ac = ac || new (window.AudioContext || window.webkitAudioContext)(); if (ac.resume) ac.resume().catch(() => {}); } catch (e) { ac = null; }
    sNew();
    $("title").classList.add("hide");
    enterRoom(0);
    story(INTRO, () => { S.mode = "play"; });
  });
  $("mute").addEventListener("click", () => {
    muted = !muted;
    $("mute").textContent = muted ? "音 OFF" : "音 ON";
    if (!muted) sClick();
  });

  // ===== 紙ふぶきと時間(requestAnimationFrame) =====
  const fx = $("fx").getContext("2d");
  let parts = [];
  const COLORS = ["#ffd54f", "#7dffb0", "#ff7a7a", "#6fc3ff", "#fff", "#f7b955"];
  function confetti(x, y, n) {
    for (let i = 0; i < n; i++) {
      const a = Math.random() * Math.PI * 2, v = 120 + Math.random() * 320;
      parts.push({ x, y, vx: Math.cos(a) * v, vy: Math.sin(a) * v - 180, c: COLORS[i % COLORS.length], s: 5 + Math.random() * 6, life: 1.4 + Math.random() * 0.8, r: Math.random() * 6 });
    }
  }
  let last = 0, shownSec = -1;
  function frame(now) {
    const dt = Math.min(0.1, (now - last) / 1000 || 0);
    last = now;
    if (S.mode === "play") {
      S.roomTime += dt;
      if (!ROOMS[S.room].bonus) S.totalTime += dt;
      const sec = Math.floor(S.totalTime);
      if (sec !== shownSec) { shownSec = sec; $("timeTop").textContent = fmtTime(S.totalTime); }
    }
    if (parts.length || fx.dirty) {
      fx.clearRect(0, 0, 960, 540);
      fx.dirty = parts.length > 0;
      parts = parts.filter((p) => p.life > 0);
      parts.forEach((p) => {
        p.life -= dt; p.vy += 520 * dt; p.x += p.vx * dt; p.y += p.vy * dt; p.r += 8 * dt;
        fx.globalAlpha = Math.max(0, Math.min(1, p.life));
        fx.fillStyle = p.c;
        fx.fillRect(p.x, p.y, p.s, p.s * (0.5 + 0.5 * Math.abs(Math.sin(p.r))));
      });
      fx.globalAlpha = 1;
    }
    requestAnimationFrame(frame);
  }
  requestAnimationFrame(frame);
})();
</script>
</body>
</html>