  :root{
    --panel: rgba(255,252,244,.88);
    --ink: #4a3f33;
    --accent: #7a9e6b;
    --radius: 16px;
  }
  *{ margin:0; padding:0; box-sizing:border-box; }
  html,body{ width:100%; height:100%; overflow:hidden; background:#0b1026;
    font-family:"Hiragino Maru Gothic ProN","BIZ UDGothic","Yu Gothic UI",'Segoe UI',sans-serif;
    color:var(--ink); -webkit-user-select:none; user-select:none; }
  #game{ display:block; position:fixed; top:0; left:0; width:100vw; height:100vh; height:100dvh; touch-action:none; }

  /* ------- HUD ------- */
  #hud{ position:fixed; top:10px; left:10px; display:flex; flex-wrap:wrap; align-items:center; gap:8px; z-index:5; max-width:76vw; }
  .chip{ background:var(--panel); border-radius:999px; padding:7px 14px; font-size:13px;
    box-shadow:0 2px 8px rgba(30,20,10,.18); white-space:nowrap; line-height:1.3; }
  .chip b{ font-weight:700; }
  /* HUDに並べたマイク/サウンド/話すボタン(チップと高さをそろえる) */
  #hud .btn{ padding:6px 12px; font-size:16px; line-height:1.2; }

  /* ------- 村ナビ(村1↔村2) ------- */
  #villageNav{ position:fixed; top:calc(8px + env(safe-area-inset-top)); left:50%; transform:translateX(-50%);
    display:none; align-items:center; gap:8px; z-index:6; }
  #villageNav button{ background:var(--panel); border:none; border-radius:999px; width:34px; height:30px;
    font-size:14px; cursor:pointer; box-shadow:0 2px 8px rgba(30,20,10,.18); color:var(--ink); font-family:inherit; }
  #villageNav button:active{ transform:scale(.94); }
  #vLabel{ background:var(--accent); color:#fff; border-radius:999px; padding:5px 14px; font-size:13px; font-weight:700;
    box-shadow:0 2px 8px rgba(30,20,10,.18); white-space:nowrap; }

  /* ------- ログ / 図鑑ボタン ------- */
  #logWrap{ position:fixed; top:10px; right:10px; z-index:5; width:230px; }
  #logBtns{ display:flex; flex-wrap:wrap; justify-content:flex-end; gap:8px; white-space:nowrap; }
  #logToggle, #bookToggle, #relToggle, #emoToggle{ background:var(--panel); border:none; border-radius:999px; padding:7px 14px;
    font-size:13px; cursor:pointer; box-shadow:0 2px 8px rgba(30,20,10,.18);
    font-family:inherit; color:var(--ink); }

  /* ------- アンビエント(スクリーンセーバー)モード:放置でUIが消え、村だけが映る ------- */
  #hud, #logWrap, #villageNav{ transition:opacity .9s ease; }
  body.ambient #hud, body.ambient #logWrap, body.ambient #villageNav{ opacity:0; pointer-events:none; }
  #log{ clear:both; margin-top:8px; background:var(--panel); border-radius:var(--radius);
    padding:10px 12px; font-size:12px; max-height:38vh; overflow-y:auto; display:none;
    box-shadow:0 2px 8px rgba(30,20,10,.18); }
  #log.open{ display:block; }
  #log div{ padding:3px 0; border-bottom:1px dashed rgba(74,63,51,.15); }
  #log div:last-child{ border-bottom:none; }
  #log .t{ color:#9a8b78; font-size:10px; margin-right:4px; }

  /* ------- 図鑑オーバーレイ ------- */
  #bookOverlay{ position:fixed; inset:0; z-index:30; display:none;
    background:rgba(20,22,42,.72); align-items:center; justify-content:center; padding:16px; }
  #bookOverlay.open{ display:flex; }
  #bookPanel{ background:var(--panel); border-radius:var(--radius); width:min(760px,94vw);
    max-height:88vh; display:flex; flex-direction:column; box-shadow:0 8px 30px rgba(20,15,10,.4);
    padding:14px 16px; }
  #bookHead, .bookHead{ display:flex; align-items:center; gap:10px; margin-bottom:10px; }
  #bookTitle, .bookTitle{ font-size:17px; font-weight:700; color:var(--ink); }
  #bookCount{ font-size:12px; color:#9a8b78; }
  #bookClose{ margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer;
    color:#9a8b78; font-family:inherit; }
  #bookTabs{ display:flex; gap:8px; margin-bottom:10px; }
  .bookTab{ border:none; border-radius:999px; padding:6px 16px; font-size:13px; cursor:pointer;
    font-family:inherit; color:var(--ink); background:rgba(74,63,51,.1); }
  .bookTab.on{ background:var(--accent); color:#fff; }
  #bookGrid{ overflow-y:auto; display:grid; gap:8px;
    grid-template-columns:repeat(auto-fill, minmax(84px,1fr)); }
  .bookCard{ background:rgba(255,255,255,.5); border-radius:12px; padding:8px 4px; text-align:center;
    box-shadow:inset 0 0 0 1px rgba(74,63,51,.12); }
  .bookCard.locked{ opacity:.6; }
  .bookCard canvas{ display:block; margin:0 auto; image-rendering:pixelated; }
  .bookCard .bid{ font-size:10px; color:#9a8b78; margin-top:3px; }
  .bookCard .bnm{ font-size:11px; color:var(--ink); font-weight:700; line-height:1.2; }
  .bookCard .bin{ font-size:9px; color:#7a9e6b; font-weight:700; }

  /* ------- つながりオーバーレイ ------- */
  #relOverlay{ position:fixed; inset:0; z-index:30; display:none;
    background:rgba(20,22,42,.72); align-items:center; justify-content:center; padding:16px; }
  #relOverlay.open{ display:flex; }
  #relPanel{ background:var(--panel); border-radius:var(--radius); width:min(760px,94vw);
    max-height:90vh; display:flex; flex-direction:column; box-shadow:0 8px 30px rgba(20,15,10,.4);
    padding:14px 16px; }
  #relLegend{ font-size:11px; color:#9a8b78; }
  #relClose{ margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer;
    color:#9a8b78; font-family:inherit; }
  #relCanvas{ display:block; margin:4px auto 0; touch-action:manipulation; }
  #relHint{ font-size:10px; color:#9a8b78; text-align:center; margin-top:6px; }

  /* ------- こびとの村パス(購入) ------- */
  #shopOverlay{ position:fixed; inset:0; z-index:31; display:none;
    background:rgba(20,22,42,.72); align-items:center; justify-content:center; padding:16px; }
  #shopOverlay.open{ display:flex; }
  /* オーバーレイの padding:16px を差し引いた実効幅で上限を切る。
     94vw や 100% だと padding と二重にかかり、狭い画面で ✕ や価格が見切れる。 */
  #shopPanel{ background:var(--panel); border-radius:var(--radius); width:min(440px, calc(100vw - 32px));
    max-height:90vh; overflow-y:auto; box-shadow:0 8px 30px rgba(20,15,10,.4); padding:16px 18px; }
  #shopClose{ margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer;
    color:#9a8b78; font-family:inherit; }
  .shopStatus{ font-size:12px; color:#7a9e6b; font-weight:700; margin-bottom:12px;
    background:rgba(122,158,107,.12); border-radius:10px; padding:8px 12px; text-align:center; }
  .shopCard{ background:rgba(255,255,255,.5); border-radius:14px; padding:14px;
    box-shadow:inset 0 0 0 1px rgba(74,63,51,.12); margin-bottom:12px; }
  .shopCardHead{ font-size:16px; font-weight:700; color:var(--ink); display:flex;
    align-items:baseline; gap:8px; margin-bottom:8px; flex-wrap:wrap; }
  .shopPrice{ font-size:13px; color:#c98a3a; font-weight:700; margin-left:auto; }
  .shopDesc{ font-size:13px; color:var(--ink); line-height:1.6; margin-bottom:12px; }
  .shopDesc b{ color:#7a9e6b; }
  .shopFeat{ list-style:none; margin:0 0 12px; padding:0; }
  .shopFeat li{ font-size:13px; color:var(--ink); line-height:1.7; padding:2px 0; }
  .shopFeat li b{ color:#7a9e6b; }
  .btn-buy{ display:block; width:100%; background:var(--accent); color:#fff; font-weight:700;
    padding:12px; font-size:15px; box-shadow:0 3px 10px rgba(122,158,107,.35); }
  .btn-buy--sub{ background:rgba(74,63,51,.12); color:var(--ink); box-shadow:none; }
  .btn-buy:disabled{ opacity:.5; cursor:default; }
  .shopNote{ font-size:11px; color:#9a8b78; line-height:1.6; margin-top:4px; }

  /* ------- 村のきもち(AI感情分析) ------- */
  #emoOverlay{ position:fixed; inset:0; z-index:31; display:none;
    background:rgba(20,22,42,.72); align-items:center; justify-content:center; padding:16px; }
  #emoOverlay.open{ display:flex; }
  #emoPanel{ background:var(--panel); border-radius:var(--radius); width:min(460px, calc(100vw - 32px));
    max-height:90vh; overflow-y:auto; box-shadow:0 8px 30px rgba(20,15,10,.4); padding:16px 18px; }
  #emoClose{ margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer;
    color:#9a8b78; font-family:inherit; }
  #emoWheel{ text-align:center; margin:2px 0 10px; }
  #emoWheel svg{ max-width:100%; height:auto; }
  #emoBars{ display:flex; flex-direction:column; gap:6px; margin-bottom:14px; }
  .emoRow{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--ink); }
  .emoRow .dot{ width:11px; height:11px; border-radius:3px; flex:none; }
  .emoRow .lbl{ width:44px; flex:none; }
  .emoRow .track{ flex:1; height:9px; border-radius:5px; background:rgba(74,63,51,.1); overflow:hidden; }
  .emoRow .fill{ height:100%; border-radius:5px; min-width:2px; }
  .emoRow .val{ width:30px; text-align:right; font-variant-numeric:tabular-nums; color:#9a8b78; }
  #emoBody .btn-buy:disabled{ opacity:.5; cursor:default; }

  /* ------- 音の設定(🔊ボタンから開く) ------- */
  #sndOverlay{ position:fixed; inset:0; z-index:31; display:none;
    background:rgba(20,22,42,.72); align-items:center; justify-content:center; padding:16px; }
  #sndOverlay.open{ display:flex; }
  #sndPanel{ background:var(--panel); border-radius:var(--radius); width:min(400px, calc(100vw - 32px));
    max-height:90vh; overflow-y:auto; box-shadow:0 8px 30px rgba(20,15,10,.4); padding:16px 18px; }
  #sndClose{ margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer;
    color:#9a8b78; font-family:inherit; }
  #sndRows{ display:flex; flex-direction:column; gap:13px; margin:14px 0; }
  /* マスターOFFのときは、スライダーを薄くして触れないようにする */
  #sndPanel.muted #sndRows{ opacity:.4; pointer-events:none; }
  .sndRow{ display:flex; align-items:center; gap:10px; font-size:13px; color:var(--ink); }
  .sndRow label{ width:74px; flex:none; }
  .sndRow input[type=range]{ flex:1; min-width:0; -webkit-appearance:none; appearance:none;
    height:6px; border-radius:3px; background:rgba(74,63,51,.15); outline:none; }
  .sndRow input[type=range]::-webkit-slider-thumb{ -webkit-appearance:none; appearance:none;
    width:22px; height:22px; border-radius:50%; background:var(--accent); cursor:pointer;
    box-shadow:0 2px 6px rgba(30,20,10,.3); }
  .sndRow input[type=range]::-moz-range-thumb{ width:22px; height:22px; border:none; border-radius:50%;
    background:var(--accent); cursor:pointer; box-shadow:0 2px 6px rgba(30,20,10,.3); }
  .sndVal{ width:32px; flex:none; text-align:right; font-size:12px; color:#9a8b78;
    font-variant-numeric:tabular-nums; }

  /* ------- コントロール(マイク/サウンド/話す:HUDに配置) ------- */
  .btn{ background:var(--panel); border:none; border-radius:999px; padding:10px 18px;
    font-size:14px; cursor:pointer; box-shadow:0 3px 10px rgba(30,20,10,.22);
    font-family:inherit; color:var(--ink); transition:transform .1s; }
  .btn:active{ transform:scale(.95); }
  .btn.on{ background:var(--accent); color:#fff; }

  /* ------- あなたの発話トースト ------- */
  #userToast{ position:fixed; bottom:70px; left:50%; transform:translateX(-50%);
    background:rgba(74,63,51,.85); color:#fff; border-radius:999px; padding:8px 18px;
    font-size:13px; z-index:6; display:none; max-width:80vw; }

  /* ------- 小人の詳細パネル ------- */
  #detail{ position:fixed; right:10px; bottom:70px; width:252px; z-index:7;
    max-height:calc(100vh - 150px); overflow-y:auto;
    background:var(--panel); border-radius:var(--radius); padding:14px;
    box-shadow:0 4px 16px rgba(30,20,10,.28); display:none; font-size:13px; }
  #detail.open{ display:block; }
  #detailClose{ position:absolute; top:8px; right:10px; border:none; background:none;
    font-size:15px; cursor:pointer; color:#9a8b78; font-family:inherit; }
  #detailBody h3{ font-size:16px; margin-bottom:6px; }
  #detailBody .row{ margin:4px 0; line-height:1.5; }
  #detailBody .lbl{ color:#9a8b78; font-size:11px; margin-right:4px; }
  .bar{ height:8px; background:rgba(74,63,51,.15); border-radius:99px; overflow:hidden; margin-top:2px; }
  .bar i{ display:block; height:100%; border-radius:99px; background:var(--accent); }
  .bar i.warn{ background:#e0925a; }
  #detailActions{ display:flex; gap:6px; margin-top:10px; }
  #detailActions .btn{ flex:1; padding:8px 2px; font-size:12px; box-shadow:0 2px 6px rgba(30,20,10,.15); }
  #dNameEdit{ border:none; background:none; cursor:pointer; font-size:13px; font-family:inherit; }
  #dNameInput{ width:95px; font-size:14px; font-family:inherit; padding:2px 6px;
    border:1px solid rgba(74,63,51,.3); border-radius:8px; background:#fff; color:var(--ink); }
  #dNameSave{ border:none; background:var(--accent); color:#fff; border-radius:8px;
    padding:4px 10px; cursor:pointer; font-family:inherit; font-size:13px; }

  /* ------- スタート画面 ------- */
  #startOverlay{ position:fixed; inset:0; z-index:20; background:#8fd0ef;
    display:flex; flex-direction:column; align-items:center; justify-content:center;
    color:#fff8ec; text-align:center; cursor:pointer; overflow:hidden; }
  #titleCanvas{ position:absolute; inset:0; width:100%; height:100%; image-rendering:pixelated; z-index:0; }
  #titleUI{ position:relative; z-index:1; display:flex; flex-direction:column; align-items:center;
    justify-content:center; gap:2.2vh; width:100%; height:100%; padding:3vh 4vw; }
  .titleLogo{ font-family:'DotGothic16','Hiragino Maru Gothic ProN',monospace; font-weight:400; font-synthesis:none;
    line-height:1; letter-spacing:.12em; font-size:clamp(30px,7vw,72px);
    text-shadow:-3px 0 #123a1e,3px 0 #123a1e,0 -3px #123a1e,0 3px #123a1e,-3px -3px #123a1e,3px -3px #123a1e,-3px 3px #123a1e,3px 3px #123a1e,6px 6px 0 #0c2513,9px 9px 0 rgba(0,0,0,.3); }
  .titleLogo .lw{ color:#fdfdf5; } .titleLogo .ly{ color:#ffd84d; }
  .titleRibbon{ margin-top:1vh; padding:6px 22px; background:linear-gradient(#8a5a34,#6b4222);
    color:#ffe9b0; font-family:'Press Start 2P',monospace; font-size:clamp(8px,1.6vw,14px); letter-spacing:.2em;
    box-shadow:0 0 0 3px #3a2414,0 0 0 6px #b98a4f,4px 6px 0 rgba(0,0,0,.28); text-shadow:2px 2px 0 #3a2414; }
  #passInput{ margin-top:2.4vh; width:min(74vw,300px); text-align:center; border:none; border-radius:10px;
    padding:12px 14px; font-size:clamp(13px,1.8vw,16px); color:#4a3f33; background:rgba(255,252,244,.94);
    font-family:'Hiragino Maru Gothic ProN',sans-serif; box-shadow:0 0 0 3px #b98a4f,3px 4px 0 rgba(0,0,0,.28); outline:none; }
  #passInput::placeholder{ color:#a99; }
  #startBtns{ display:flex; gap:12px; margin-top:1.8vh; flex-wrap:wrap; justify-content:center; }
  #btnCreate, #btnContinue, #btnPass{ background:#f2c14e; color:#4a3f33; border:none; border-radius:12px;
    padding:13px 24px; font-size:clamp(12px,1.8vw,16px); font-weight:700; cursor:pointer;
    font-family:'Hiragino Maru Gothic ProN',sans-serif; letter-spacing:.04em;
    box-shadow:0 0 0 3px #b98a4f,4px 5px 0 rgba(0,0,0,.3); }
  #btnContinue{ background:#cfe0a8; }
  #btnPass{ background:#a8cfe0; }
  #passArea{ display:flex; flex-direction:column; align-items:center; gap:1.4vh; margin-top:1.8vh; }
  #passLabel{ margin:0; }
  #passBtns{ display:flex; gap:12px; }
  #btnGo, #btnBack{ background:#f2c14e; color:#4a3f33; border:none; border-radius:12px;
    padding:12px 24px; font-size:clamp(12px,1.8vw,16px); font-weight:700; cursor:pointer;
    font-family:'Hiragino Maru Gothic ProN',sans-serif; letter-spacing:.04em;
    box-shadow:0 0 0 3px #b98a4f,4px 5px 0 rgba(0,0,0,.3); }
  #btnBack{ background:#e6ddce; }
  #btnInstall{ margin-top:1.2vh; background:#8ad0a0; color:#234; border:none; border-radius:12px;
    padding:11px 20px; font-size:clamp(11px,1.6vw,15px); font-weight:700; cursor:pointer;
    font-family:'Hiragino Maru Gothic ProN',sans-serif; letter-spacing:.03em;
    box-shadow:0 0 0 3px #5a9e73,4px 5px 0 rgba(0,0,0,.3); }
  @keyframes titlePulse{ 0%,100%{ transform:translateY(0); } 50%{ transform:translateY(-4px); } }
  .titleHint{ font-size:clamp(11px,1.6vw,14px); color:#fff; opacity:.9; text-shadow:1px 1px 0 #1a2a4a; }
  .mini{ font-size:clamp(9px,1.3vw,12px); color:#fff; opacity:.75; text-shadow:1px 1px 0 #1a2a4a; max-width:90vw; }

  /* ------- スマホ:セーフエリア(ノッチ)対応 ------- */
  #hud{ top:calc(10px + env(safe-area-inset-top)); left:calc(10px + env(safe-area-inset-left)); }
  #logWrap{ top:calc(10px + env(safe-area-inset-top)); right:calc(10px + env(safe-area-inset-right)); }
  #detail{ right:calc(10px + env(safe-area-inset-right)); bottom:calc(70px + env(safe-area-inset-bottom)); }

  /* ------- 横向きの小さな画面(スマホ横)向けの微調整 ------- */
  @media (max-height: 460px){
    /* 時刻チップと上部メニュー(村のできごと/ずかん/つながり)の文字サイズをそろえる */
    .chip, #logToggle, #bookToggle, #relToggle{ padding:5px 10px; font-size:11px; }
    .btn{ padding:8px 13px; font-size:12px; }
    #logWrap{ width:190px; }
    #detail{ width:220px; font-size:12px; padding:11px; }
  }

  /* ------- たて向きのときは「よこ向きにしてね」を表示 ------- */
  #rotateHint{ position:fixed; inset:0; z-index:99; display:none;
    flex-direction:column; align-items:center; justify-content:center; gap:14px;
    background:#0b1026; color:#fff; text-align:center; padding:24px;
    font-size:clamp(16px,5vw,24px); }
  #rotateHint .big{ font-size:clamp(40px,16vw,80px); animation:rotatePulse 1.6s ease-in-out infinite; }
  @keyframes rotatePulse{ 0%,100%{ transform:rotate(0); } 50%{ transform:rotate(-90deg); } }
  @media (orientation: portrait) and (max-width: 820px){
    #rotateHint{ display:flex; }
  }

  /* ------- PCゲート: PCで開いたらゲームを隠してスマホ誘導QRを全面表示 ------- */
  #pcGate{ display:none; }
  html.is-pc #pcGate{
    display:flex; position:fixed; inset:0; z-index:9999;
    align-items:center; justify-content:center; padding:24px;
    background:#141426; color:#e8e4da; text-align:center;
    font-family:"DotGothic16",system-ui,sans-serif; -webkit-font-smoothing:none;
  }
  html.is-pc, html.is-pc body{ overflow:hidden; }
  .pcGate-card{ max-width:420px; }
  .pcGate-title{ font-size:34px; color:#f4d98a; letter-spacing:2px;
    text-shadow:3px 3px 0 #c9532f; margin-bottom:18px; }
  .pcGate-title span{ color:#e0c078; }
  .pcGate-lead{ font-size:15px; line-height:1.9; margin:0 0 20px; }
  .pcGate-lead b{ color:#f4d98a; }
  .pcGate-qr{ display:inline-block; background:#fff; padding:14px;
    border-radius:12px; box-shadow:0 6px 24px rgba(0,0,0,.4); }
  .pcGate-qr svg{ width:200px; height:200px; display:block; }
  .pcGate-url{ font-size:13px; color:#a8a2b8; margin:16px 0 0; word-break:break-all; }
  .pcGate-note{ font-size:12px; color:#7a7590; margin:12px 0 0; }
