:root {
  color-scheme:dark;--ink:#172220;--pine:#192a27;--ivory:#f2ead6;--gold:#d9b77b;--edge:#6d6049;
  --sans:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --serif:Georgia,"Times New Roman",serif;
}
*{box-sizing:border-box}
[hidden]{display:none!important}
body{margin:0;background:#111b1a;color:var(--ivory);font-family:var(--sans);min-width:270px}
button{font:inherit;color:inherit;cursor:pointer;touch-action:manipulation}
button:focus-visible,a:focus-visible{outline:2px solid #ffe1a4;outline-offset:3px}
button{border:0;background:transparent}
svg{width:1.3em;height:1.3em;fill:none;stroke:currentColor;stroke-width:1.65;stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
.defs{position:absolute;width:0;height:0;overflow:hidden}
#app{width:min(100%,1450px);margin:auto;padding:clamp(8px,1.4vw,18px) clamp(12px,4vw,64px) calc(14px + var(--ad-space,0px))}
/* ボタンは共通ヘッダーに集約した。題名だけの帯は縦をとるだけなので、見た目だけ隠す（DOM には残す） */
.mast{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}
.head-tools{display:none}
.hud-tools button{display:inline-flex;gap:7px;align-items:center;justify-content:center;font:12px var(--sans);min-height:39px}
.hud-tools button:hover{color:#ffe0a0}
.poster{position:relative;isolation:isolate;display:flex;align-items:center;overflow:hidden;min-height:430px;height:clamp(456px,65svh,735px);background:#241c20}
.scenery,.shade,.print-border{position:absolute;pointer-events:none}
.scenery,.shade{inset:0;z-index:-1}
.scenery{background:url(../assets/keyart.webp?ver=20261126-5) center 44%/cover no-repeat}
.shade{background:linear-gradient(90deg,#140e13a6 0%,#190f1557 35%,transparent 62%),linear-gradient(0deg,#160f161f,transparent 22%)}
.print-border{inset:10px;border:1px solid #e9be7678;z-index:1}
.print-border i{position:absolute;width:22px;height:22px;border:solid #d6af70;border-width:2px 0 0 2px;left:-2px;top:-2px}
.print-border i::after{content:"";position:absolute;top:4px;left:4px;border:1px solid currentColor;color:#c6a367;width:4px;height:4px;transform:rotate(45deg)}
.print-border i:nth-child(2){left:auto;right:-2px;transform:rotate(90deg)}.print-border i:nth-child(3){right:-2px;bottom:-2px;left:auto;top:auto;transform:rotate(180deg)}.print-border i:nth-child(4){bottom:-2px;top:auto;transform:rotate(270deg)}
.hero-copy{position:relative;display:flex;flex-direction:column;align-items:flex-start;width:52%;margin:16px 0 16px 5.8%;text-shadow:0 2px 8px #0a080c}
h1{margin:0;width:100%;max-width:540px}
h1 img{display:block;width:100%;height:auto}
.english{display:flex;align-items:center;gap:.8em;margin:10px 0 0 4px;color:#ebcd91;font:clamp(9px,1vw,14px) Georgia,serif;letter-spacing:.23em}
.english i{width:24px;height:1px;background:#c6a977}
.premise{line-height:1.9;letter-spacing:.07em;font-family:var(--serif);font-size:clamp(13px,1.16vw,17px);margin:20px 0 22px 3px;color:#fff2d8}
.admit{position:relative;display:flex;align-items:center;gap:12px;color:#362619;background:linear-gradient(110deg,#f0dcab,#d5b477);padding:14px 19px;box-shadow:inset 0 0 0 1px #f9e4b7,inset 0 0 0 4px #ddc191,inset 0 0 0 5px #70542c8c,0 4px 20px #09070c50;min-width:207px;font:700 16px var(--serif);letter-spacing:.13em}
.admit .go{margin-left:auto;width:18px}.admit:hover{filter:brightness(1.09)}.admit:active{transform:translateY(1px)}
.fresh{padding:8px;font-size:12px;text-decoration:underline;text-underline-offset:4px}
.program{color:#3b3025;background:linear-gradient(100deg,#d9c7a3,#efe5cc 47%,#dfcfb1);display:grid;grid-template-columns:1.2fr repeat(3,1fr);align-items:center;min-height:92px;position:relative;border-top:3px double #7b6140;border-bottom:4px double #8a7452;padding:9px clamp(15px,4vw,68px);gap:10px}
.program-title small,.room small{font-family:Georgia,serif;letter-spacing:.17em;color:#69583e;display:block}
.program-title small{font-size:10px}.program-title h2{font:600 22px var(--serif);letter-spacing:.13em;margin:4px 0 0}
.room{display:flex;align-items:center;justify-content:center;gap:11px;min-height:44px;border-left:1px solid #82684466}
.room svg{width:38px;height:38px;stroke:#735c3c;stroke-width:1.3}.room b{font:600 17px var(--serif);letter-spacing:.12em}.room small{font-size:8px;margin-top:4px}
.page-foot{display:flex;justify-content:space-between;flex-wrap:wrap;gap:5px 16px;color:#abae9e;font-size:10px;line-height:1.7;margin:13px 0}
.page-foot a{color:inherit;text-underline-offset:2px}
body.playing{overflow:hidden}
body.playing #app{height:calc(100dvh - var(--sgh-top,0px) - var(--ad-space,0px));display:flex;flex-direction:column;padding-top:6px;padding-bottom:max(8px,env(safe-area-inset-bottom))}
html.has-ad-banner body.playing #app{padding-bottom:4px}
#play{flex:1;min-height:0;display:flex;flex-direction:column}
.viewport{position:relative;isolation:isolate;flex:1;min-height:0;border:1px solid #7a6a4a;background:#111715;overflow:hidden}
#world{display:block;width:100%;height:100%;touch-action:none;outline:0}
.view-vignette{position:absolute;inset:0;pointer-events:none;box-shadow:inset 0 0 42px #160c1022}
#scene-clock{position:absolute;top:12px;pointer-events:none;color:#f7e9c8;background:#14211ee3;border:1px solid #b79b644f;box-shadow:0 2px 8px #0003}
#scene-clock{right:12px;display:flex;align-items:center;gap:6px;padding:7px 10px;font:14px ui-monospace,monospace}
#scene-clock svg{width:15px;height:15px;color:var(--gold)}
#targets{position:absolute;inset:0;pointer-events:none}
.focus-target{position:absolute;transform:translate(-50%,-50%);width:28px;height:28px;opacity:0;pointer-events:none;padding:0}
.focus-target:focus-visible{opacity:1;background:#ffe7b833;border-radius:50%;outline:3px solid #ffe1a4}
.focus-target[data-action]{opacity:1}
.focus-target[data-action]::after{content:attr(data-action);position:absolute;bottom:calc(100% + 30px);left:50%;transform:translateX(-50%);padding:3px 8px;border:1px solid #b69a68;border-radius:3px;background:#182723ef;color:#f5deae;font:11px/1.5 var(--sans);white-space:nowrap;pointer-events:auto;cursor:pointer}
.turn{position:absolute;display:grid;place-items:center;width:46px;height:54px;color:#f1d8a6;background:#14201ebf;border:1px solid #c4ad7a88}
.turn:hover{background:#293d32f2}.turn svg{width:24px;height:24px}
#left,#right{top:50%;transform:translateY(-50%)}#left{left:9px}#right{right:9px}#left svg{transform:rotate(180deg)}
#back{bottom:12px;left:12px;width:48px;height:40px}#back svg{transform:rotate(90deg)}
#feedback{position:absolute;left:50%;bottom:13px;transform:translateX(-50%);width:max-content;max-width:calc(100% - 125px);text-align:center;pointer-events:none;font-size:13px;line-height:1.55;padding:8px 14px;color:#fcf0d3;background:#182723ef;border:1px solid #afa2757a;box-shadow:0 2px 10px #0003}
#feedback:empty{display:none}
#scene-failure{position:absolute;inset:25% 9% auto;background:#172924;padding:24px;border:1px solid var(--gold);text-align:center;font-size:14px}#scene-failure button{display:inline-block;margin:12px 5px 0;padding:8px;border:1px solid}
.hud{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:68px;padding:6px clamp(8px,2vw,20px);background:#1a2824;border:1px solid #766346;border-top:0}
.inventory,.inventory>span,#items,.hud-tools{display:flex;align-items:center}
.inventory{gap:12px;min-width:0}.inventory>span{gap:6px;font-size:12px;white-space:nowrap;color:#dfd3b9}.inventory>span svg{color:var(--gold)}
#items{flex-wrap:wrap;gap:5px}
.slot{display:grid;place-items:center;width:43px;height:43px;padding:2px;border:1px solid #a38b58;background:radial-gradient(ellipse at 40% 35%,#455047,#27332f);position:relative}
.slot.empty{border-color:#9b8a663f;background:#16201cc9}.slot.selected{border-color:#f6d690;box-shadow:inset 0 0 0 1px #f6d690;background:#5c4a30}.slot:hover:not(.empty){outline:1px solid #ead5a0}
.item-art{display:block;width:100%;height:100%;background:url(../assets/items.webp) no-repeat var(--tile,0%) center/800% 100%}
.item-art.shadow-slide{background-image:url(../assets/shadow-slide.webp);background-size:contain;background-position:center}
.slot .item-art{height:auto;aspect-ratio:1}
.hud-tools{gap:8px}.hud-tools button{border:1px solid #8c7a54;padding:7px 12px;white-space:nowrap}.hud-tools svg{color:#d5b97c}
.ending-view .hud,.ending-view .viewport>:not(#world){visibility:hidden}.ending-view .hud{display:none}
/* ダイアログ: 共通ヘッダーの下〜広告枠の上をおおう幕（dialog 自身）と、その中央のカード */
dialog{position:fixed;inset:var(--sgh-top,0px) 0 var(--ad-space,0px) 0;z-index:1000;width:auto;height:auto;max-width:none;max-height:none;margin:0;padding:12px;border:0;color:var(--ivory);overflow:auto;overscroll-behavior:contain;background:#09100ed6;-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}
dialog[open]{display:flex}
.dialog-card{padding:clamp(20px,4vw,32px);position:relative;min-width:0;width:min(470px,100%);margin:auto;border:1px solid #ab8c5c;background:#20302b;box-shadow:0 24px 90px #000a}.dialog-card:before{content:"";position:absolute;inset:6px;border:1px solid #af946050;pointer-events:none}
.dialog-card #code{font:11px Georgia,serif;letter-spacing:.22em;color:var(--gold)}
.dialog-card h2{font:600 25px var(--serif);letter-spacing:.07em;margin:10px 0 17px;padding-right:44px}
.dialog-card p,.dialog-card li{font-size:14px;line-height:1.8;color:#ece5d2}.dialog-card ol{padding-left:1.5em}.dialog-card li+li{margin-top:.6em}
#dialog-close{position:absolute;top:12px;right:12px;display:grid;place-items:center;width:36px;height:36px;color:#ead4ad}
#clear-buttons{display:flex;gap:8px;flex-wrap:wrap;margin-top:20px}#clear-buttons button,#dialog-body .reveal{padding:10px 15px;border:1px solid #9e8b65;font-size:13px}
#clear-buttons button:first-child{background:#ddc292;color:#26332b}.reveal{color:#efd5a8}
.entry{border-bottom:1px solid #7d795855;padding:10px 0}.entry b{font:600 16px var(--serif);color:#e6c698}.entry p{margin:4px 0 0}
.result-time{font:38px Georgia,serif;color:#f7d396}.result-row{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #7d795855;font-size:13px;gap:12px}.large-item{width:110px;height:110px;margin:0 auto}
@media(min-width:1600px){.program{min-height:108px}}
@media(max-width:740px){
#app{padding:8px 12px calc(12px + var(--ad-space,0px))}
.poster{height:clamp(450px,70svh,660px)}.hero-copy{width:56%;margin-left:5%}
.program{min-height:76px;padding:8px 14px;gap:0}.program-title h2{font-size:18px}.room{gap:6px}.room svg{width:27px;height:27px}.room b{font-size:14px}.room small{font-size:7px}.program-title small{font-size:8px}
body.playing #app{padding:4px 4px max(3px,env(safe-area-inset-bottom))}.inventory{gap:7px}.hud{gap:6px;min-height:60px;padding:5px 8px}.hud-tools{gap:5px}.hud-tools button{padding:6px 8px}
}
@media(max-width:560px) and (orientation:portrait){
#app{padding:8px 8px calc(12px + var(--ad-space,0px))}.poster{min-height:440px;height:clamp(440px,calc(100svh - var(--sgh-top,0px) - var(--ad-space,0px) - 158px),750px);align-items:flex-end}
.scenery{background-position:72% 12%;background-size:auto 93%}
.shade{background:linear-gradient(0deg,#161615 1%,#1a1319f0 24%,#21151db3 44%,transparent 65%)}
.hero-copy{margin:0 0 27px;width:100%;align-items:center;text-align:center}
h1{width:75%;max-width:322px}.english{font-size:9px;margin:5px 0 0;gap:8px}.english i{width:15px}
.premise{font-size:12px;line-height:1.75;margin:11px 0 13px}.admit{font-size:15px;min-width:195px;padding:12px 16px}
.print-border{inset:7px}.program{grid-template-columns:.9fr repeat(3,1fr);min-height:69px;padding:6px 8px}.program-title small{font-size:6px}.program-title h2{font-size:15px}.room{flex-direction:column;gap:1px;min-height:auto}.room svg{width:21px;height:21px}.room div{text-align:center}.room b{font-size:12px}.room small{font-size:6px;margin-top:1px}
.page-foot{display:block;font-size:10px;margin:9px 3px}
.hud{padding:5px;min-height:63px}.inventory{gap:4px}.inventory>span{font-size:8px;flex-direction:column;gap:2px}.inventory>span svg{width:17px;height:17px}
#items{gap:3px}.slot{width:34px;height:38px}.hud-tools button{flex-direction:column;gap:2px;font-size:10px;min-height:42px;padding:4px 6px}
#scene-clock{top:7px;right:6px;padding:5px;font-size:11px}.turn{width:33px;height:46px}#left{left:4px}#right{right:4px}
#feedback{font-size:12px;padding:6px 9px;max-width:calc(100% - 90px);bottom:12px}#back{left:5px;width:36px}
}
@media(max-height:520px) and (orientation:landscape){.hud{min-height:43px;padding:2px 8px}.slot{width:33px;height:33px}.hud-tools button{min-height:32px}#scene-clock{top:5px}.turn{height:37px}.poster{height:380px;min-height:380px}.hero-copy{max-width:390px}.hero-copy h1{max-width:310px}.premise{margin:9px 0 12px}}
@media(max-width:350px) and (orientation:portrait){#left,#right{top:62%}}
.sgr-panel,.sgr-cta{--c-panel:#1b302f;--c-text:#f1e9d8;--c-dim:#b5bdaf;--c-line:#75816f;--c-accent:#a48149;--c-accent-deep:#866535;--c-orange:#ecc788;--c-red:#f8ada0;--font-jp:var(--sans);--font-num:ui-monospace,monospace}
/* ===== 全国ランキング（共通モジュール sgr-*） ===== */
.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 12, 18, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-hidden { display: none !important; }

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-panel);
  color: var(--c-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid var(--c-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(226, 80, 42, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-orange);
}

.sgr-form { display: flex; gap: 8px; }

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid var(--c-line);
  border-radius: 8px;
  background: #fff;
  color: #192926;
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: var(--c-dim); }

.sgr-name:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 8px rgba(226, 80, 42, 0.3);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
  cursor: pointer;
}

.sgr-submit:hover { filter: brightness(1.1); }

.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-red);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-dim);
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) { background: rgba(226, 80, 42, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}

.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: bold;
  font-family: var(--font-num);
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(226, 80, 42, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: var(--c-accent); }

.sgr-cta {
  margin: 2px 0 12px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-orange);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, #f5a623, #f0741e);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(240, 116, 30, 0.4);
}

.sgr-cta-btn:hover { filter: brightness(1.08); }

.sgr-cta-link {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(30, 43, 56, 0.08);
  border: 1px solid var(--c-line);
  color: var(--c-text);
  cursor: pointer;
}

:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

#back{top:auto;bottom:12px;left:12px;transform:none;width:48px;height:42px}
#back svg{transform:rotate(90deg)}
@media(max-width:640px){#back{left:7px;bottom:7px;width:44px;height:44px}}

/* 探索中は枠（まわりの余白・ふち取り）を出さず、3D を画面の幅いっぱいに見せる（Ver. 1.2.3。人間の指示） */
body.playing #app{width:100%;max-width:none;padding:0 0 env(safe-area-inset-bottom,0px)}
html.has-ad-banner body.playing #app{padding-bottom:0}
body.playing .viewport{border:0}
body.playing .hud{border-width:1px 0 0;padding-left:max(8px,env(safe-area-inset-left,0px));padding-right:max(8px,env(safe-area-inset-right,0px))}
