:root {
  --night: #0a1026; --ink: #1b2236; --paper: #ece5d3; --paper2: #ddd4bd; --lantern: #ff6a3d; --warm: #ffd9a0;
  --red: #c8372d; --line: rgba(255, 255, 255, .16); --text: #f6f1e4; --dim: #a9b0c6;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--text); font-family: var(--sans); touch-action: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
[hidden] { display: none !important; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#touch { position: fixed; inset: 0; }
#base { position: absolute; width: 18px; height: 18px; margin: -9px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .7); display: none; pointer-events: none; }

/* 名前と吹き出し */
.tag { position: absolute; left: 0; top: 0; font-size: 11px; font-weight: 700; padding: 1px 7px 2px; background: rgba(10, 16, 38, .82); border-left: 3px solid var(--c, #fff); white-space: nowrap; }
.tag.me { border-left-color: #9fd3ff; color: #cfe8ff; }
.bub { position: absolute; left: 0; top: 0; max-width: min(240px, 62vw); font-size: 14px; line-height: 1.45; font-weight: 700; padding: 7px 11px 8px; background: var(--paper); color: var(--ink); border-radius: 4px; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.bub::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--paper); border-bottom: 0; }
.bub b { display: block; font-size: 11px; color: var(--red); line-height: 1.3; }
.bub.far { font-size: 12px; padding: 2px 8px 4px; opacity: .8; }

/* 上の帯 */
#bar { position: fixed; left: 0; right: 0; top: 0; height: calc(46px + var(--st)); padding: var(--st) 12px 0; display: flex; align-items: center; justify-content: space-between; background: rgba(10, 16, 38, .92); border-bottom: 1px solid var(--line); }
#loop { font-size: 13px; font-weight: 700; color: var(--text); min-width: 84px; white-space: nowrap; }
#clock { font-family: var(--mono); font-weight: 600; font-size: 24px; letter-spacing: .02em; color: var(--warm); }
#bar .r { display: flex; gap: 6px; min-width: 84px; justify-content: flex-end; }
#bNote { font-size: 13px; font-weight: 700; padding: 6px 12px; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); color: var(--ink); }
#bPause { width: 34px; height: 32px; display: flex; gap: 5px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 3px; }
#bPause i { width: 4px; height: 13px; background: var(--text); }
#prog { position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: rgba(255, 255, 255, .12); }
#progFill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--lantern); }
#prog b { position: absolute; top: -2px; width: 1px; height: 7px; background: rgba(255, 255, 255, .5); }
#prog u { position: absolute; top: -3px; width: 7px; height: 7px; margin-left: -3.5px; border-radius: 50%; background: var(--paper); border: 2px solid var(--red); }
#items { position: fixed; left: 10px; top: calc(58px + var(--st)); display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#items span { font-size: 12px; font-weight: 700; padding: 3px 8px; background: rgba(10, 16, 38, .88); border-left: 3px solid var(--warm); }
#toasts { position: fixed; right: 10px; top: calc(58px + var(--st)); width: min(250px, 66vw); display: flex; flex-direction: column; gap: 5px; align-items: flex-end; pointer-events: none; }
.toast { font-size: 13px; line-height: 1.4; padding: 6px 10px; background: rgba(10, 16, 38, .92); border-right: 3px solid var(--line); animation: tin .25s ease-out; }
.toast.clue { border-right-color: var(--lantern); }
.toast.clue b { display: block; font-size: 11px; color: var(--lantern); }
@keyframes tin { from { transform: translateX(16px); opacity: 0; } }

/* 下の操作 */
#ctl { position: fixed; left: 50%; bottom: calc(18px + var(--sb)); transform: translateX(-50%); display: flex; gap: 12px; align-items: center; }
#bLeap, #bFF { width: 64px; height: 64px; border-radius: 50%; background: rgba(10, 16, 38, .9); border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#bLeap small, #bFF small { font-size: 10px; font-weight: 700; color: var(--dim); }
#bLeap { border-color: var(--warm); }
.watch { position: relative; width: 24px; height: 24px; border: 2px solid var(--warm); border-radius: 50%; }
.watch i { position: absolute; left: 50%; bottom: 50%; width: 2px; margin-left: -1px; background: var(--warm); transform-origin: 50% 100%; }
.watch i:first-child { height: 8px; }
.watch i:last-child { height: 6px; transform: rotate(-90deg); }
.ff { font-size: 15px; letter-spacing: -3px; padding-right: 3px; }
#bFF.on { background: var(--lantern); border-color: var(--lantern); }
#bFF.on small { color: #fff; }
#bAct { width: 150px; height: 64px; border-radius: 6px; background: var(--paper); color: var(--ink); font-size: 17px; font-weight: 900; box-shadow: 0 4px 0 rgba(0, 0, 0, .4); }
#bAct:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .4); }
#bAct.off { visibility: hidden; }
#hud.intro #bLeap, #hud.intro #bFF, #hud.intro #bNote { visibility: hidden; }
#hud.cut #ctl, #hud.cut #items { display: none; }

/* はじめの案内 */
#guide { position: fixed; left: 50%; bottom: calc(120px + var(--sb)); transform: translateX(-50%); text-align: center; pointer-events: none; }
#guide p { margin: 8px 0 0; font-size: 14px; font-weight: 700; padding: 4px 12px; background: rgba(10, 16, 38, .9); }
.finger { width: 34px; height: 34px; margin: 0 auto; border-radius: 50%; background: rgba(255, 255, 255, .85); animation: fg 1.6s ease-in-out infinite; }
@keyframes fg { 0%, 15% { transform: translate(-40px, 20px) scale(1.15); opacity: 0; } 30% { opacity: 1; transform: translate(-40px, 20px) scale(1); } 75% { transform: translate(40px, -20px); opacity: 1; } 100% { transform: translate(40px, -20px); opacity: 0; } }

/* 会話 */
#dlg { position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 18px calc(22px + var(--sb)); min-height: 150px; background: rgba(10, 16, 38, .96); border-top: 1px solid var(--line); }
#dlg > * { max-width: 620px; margin-left: auto; margin-right: auto; }
#dName { font-size: 13px; font-weight: 900; padding-left: 8px; border-left: 4px solid var(--c, var(--warm)); margin-bottom: 8px; }
#dName:empty { display: none; }
#dText { font-size: 17px; line-height: 1.65; margin-top: 0; margin-bottom: 0; min-height: 56px; }
#dText.narr { color: var(--warm); }
#dOpts { display: flex; flex-direction: column; gap: 8px; }
#dOpts button { text-align: left; font-size: 16px; font-weight: 700; line-height: 1.4; padding: 12px 14px; background: var(--paper); color: var(--ink); border-radius: 4px; border-left: 6px solid var(--lantern); }
#dOpts button.x { background: transparent; color: var(--dim); border: 1px solid var(--line); }
#dNext { position: absolute; right: 18px; bottom: calc(10px + var(--sb)); font-size: 12px; color: var(--warm); animation: nx 1s infinite; }
@keyframes nx { 50% { transform: translateY(4px); } }

/* 結末 */
#card { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6, 9, 22, .93); padding: 20px; animation: fade .5s; }
@keyframes fade { from { opacity: 0; } }
#card .in { width: min(440px, 100%); }
#cNo { display: inline-block; font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: .12em; padding: 3px 10px; border: 2px solid var(--red); color: #ff8a7e; transform: rotate(-2deg); }
#card.solved #cNo { border-color: var(--warm); color: var(--warm); }
#cTitle { font-size: 34px; font-weight: 900; line-height: 1.25; margin: 14px 0 4px; }
#cTime { font-family: var(--mono); font-size: 18px; color: var(--warm); }
#cText { font-size: 16px; line-height: 1.75; margin: 14px 0 18px; }
#cClues { border-top: 1px solid var(--line); margin-bottom: 22px; }
#cClues h4 { font-size: 12px; color: var(--lantern); margin: 12px 0 4px; }
#cClues p { margin: 0; font-size: 14px; line-height: 1.55; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.main { display: block; width: 100%; height: 56px; font-size: 17px; font-weight: 900; background: var(--paper); color: var(--ink); border-radius: 6px; box-shadow: 0 4px 0 rgba(0, 0, 0, .4); }
.sub { display: block; width: 100%; height: 46px; margin-top: 12px; font-size: 14px; font-weight: 700; color: var(--dim); border: 1px solid var(--line); border-radius: 6px; }

/* 手帳 */
#note { position: fixed; inset: 0; background: var(--paper); color: var(--ink); display: flex; flex-direction: column; }
#note header { display: flex; justify-content: space-between; align-items: flex-end; padding: calc(10px + var(--st)) 14px 0; border-bottom: 2px solid var(--ink); }
#note nav { display: flex; gap: 2px; }
#note nav button { font-size: 15px; font-weight: 900; padding: 9px 16px 8px; border: 2px solid var(--ink); border-bottom: 0; border-radius: 4px 4px 0 0; background: var(--paper2); color: #6a6a66; }
#note nav button.on { background: var(--ink); color: var(--paper); }
#nClose { font-size: 14px; font-weight: 700; padding: 8px 4px 10px 14px; }
#nBody { flex: 1; overflow-y: auto; padding: 14px 14px calc(30px + var(--sb)); touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#nBody > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.tl { margin-bottom: 18px; }
.tl .axis, .tl .row { display: grid; grid-template-columns: 54px 1fr; align-items: center; }
.tl .axis div { position: relative; height: 18px; font-family: var(--mono); font-size: 11px; }
.tl .axis span { position: absolute; transform: translateX(-50%); }
.tl .row { height: 30px; font-size: 13px; font-weight: 700; }
.tl .row .ln { position: relative; height: 100%; background: linear-gradient(var(--ink), var(--ink)) 0 50% / 100% 1px no-repeat; margin: 0 10px; }
.tl .row .ln::before { content: ""; position: absolute; inset: 0 0 0 0; background: repeating-linear-gradient(90deg, rgba(27, 34, 54, .25) 0 1px, transparent 1px 33.333%); }
.tl .dot { position: absolute; top: 50%; width: 22px; height: 22px; margin: -11px; border-radius: 50%; }
.tl .dot::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--red); border: 2px solid var(--paper); box-shadow: 0 0 0 1px var(--red); }
.tl .dot.sel::after { background: var(--ink); box-shadow: 0 0 0 3px var(--ink); }
.cl { display: grid; grid-template-columns: 50px 52px 1fr; gap: 6px; padding: 9px 0; border-bottom: 1px solid rgba(27, 34, 54, .25); font-size: 14px; line-height: 1.5; }
.cl.sel { background: #fff7dc; }
.cl time { font-family: var(--mono); font-size: 13px; color: var(--red); padding-top: 1px; }
.cl b { font-size: 13px; }
.rest { font-size: 13px; color: #6a6a66; padding: 12px 0; }
.cs { padding: 12px 0; border-bottom: 1px solid rgba(27, 34, 54, .25); }
.cs .no { font-family: var(--mono); font-size: 12px; color: var(--red); letter-spacing: .1em; }
.cs h4 { margin: 2px 0 4px; font-size: 18px; font-weight: 900; }
.cs p { margin: 0; font-size: 14px; line-height: 1.6; }
.cs.un h4 { color: #9a9488; }

/* 一時停止・確認 */
.sheet { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6, 9, 22, .8); padding: 20px; }
.sheet .in { width: min(340px, 100%); padding: 22px 20px; background: var(--night); border: 1px solid var(--line); border-radius: 6px; }
.sheet h3 { margin: 0 0 18px; font-size: 18px; font-weight: 900; line-height: 1.5; text-align: center; }

/* 巻き戻し */
#leapfx { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle, rgba(10, 16, 38, .2), rgba(10, 16, 38, .98) 70%); animation: fade .25s; }
#leapfx .dial { position: absolute; width: min(78vw, 420px); aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255, 217, 160, .5); background: repeating-conic-gradient(rgba(255, 217, 160, .55) 0 .6deg, transparent .6deg 30deg); -webkit-mask: radial-gradient(circle, transparent 0 62%, #000 62.5% 70%, transparent 70.5%); mask: radial-gradient(circle, transparent 0 62%, #000 62.5% 70%, transparent 70.5%); }
#leapfx .dial i { display: none; }
#leapfx .dial { animation: back 1.3s cubic-bezier(.5, 0, .2, 1); }
@keyframes back { from { transform: rotate(0); } to { transform: rotate(-540deg); } }
#leapClock { position: relative; font-family: var(--mono); font-weight: 600; font-size: min(22vw, 120px); color: var(--warm); text-shadow: 0 0 30px rgba(255, 180, 90, .6); }
#flash { position: fixed; inset: 0; background: #fff3d0; opacity: 0; pointer-events: none; }
#flash.go { animation: fl .9s ease-out; }
@keyframes fl { 0% { opacity: .95; } 100% { opacity: 0; } }

/* タイトル */
#title { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 0 20px calc(34px + var(--sb)); background: linear-gradient(rgba(10, 16, 38, .15) 30%, rgba(10, 16, 38, .95) 78%); }
.tin { width: min(360px, 100%); }
#title h1 { margin: 0; font-size: 72px; font-weight: 900; line-height: 1; letter-spacing: -.01em; text-shadow: 0 3px 0 rgba(0, 0, 0, .5); }
#title h1 span { display: block; font-family: var(--mono); font-size: 30px; font-weight: 600; color: var(--warm); margin-bottom: 8px; letter-spacing: .02em; }
#tSub { font-size: 15px; line-height: 1.6; margin: 14px 0 22px; }
#tStat { font-family: var(--mono); font-size: 12px; color: var(--dim); text-align: center; margin: 12px 0 0; min-height: 16px; }
@media (max-height: 560px) { #title h1 { font-size: 50px; } #tSub { margin: 8px 0 12px; } }
@media (prefers-reduced-motion: reduce) { .finger, #dNext { animation: none; } }

/* 地図 */
.map { display: block; width: 100%; max-height: 62vh; background: #d9cfb6; border: 2px solid var(--ink); }
.map rect.pt { fill: #b9b3a4; } .map rect.st { fill: #a9a8ad; } .map rect.sp { fill: #8e8d94; } .map rect.bd { fill: var(--ink); } .map rect.wt { fill: #6f93b8; }
.map rect.lot { fill: #b4b2ae; } .map rect.site { fill: none; stroke: #b86a10; stroke-width: .4; stroke-dasharray: 1 .6; } .map rect.tent { fill: #f6f1e4; stroke: var(--ink); stroke-width: .3; }
.map text { font: 900 2.1px var(--sans); fill: var(--ink); text-anchor: middle; } .map text.w { fill: var(--paper); }
.map .hd { fill: none; stroke: #2a62a8; stroke-width: .35; stroke-dasharray: .7 .5; }
.map .me { fill: #fff; stroke: var(--red); stroke-width: .6; }

.main:disabled { opacity: .6; }

/* 冒頭の物語：上下を帯で締めて、操作できない場面だと分かるようにする */
#intro { position: fixed; inset: 0; cursor: pointer; }
#intro::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: calc(64px + var(--st)); background: #05070f; }
#intro .cap { position: absolute; left: 0; right: 0; bottom: 0; min-height: calc(132px + var(--sb)); padding: 22px 22px calc(40px + var(--sb)); background: #05070f; }
#iText { max-width: 560px; margin: 0 auto; font-size: 17px; font-weight: 700; line-height: 1.75; color: var(--text); }
#iN { position: absolute; left: 22px; bottom: calc(14px + var(--sb)); font-family: var(--mono); font-size: 12px; color: var(--dim); }
#intro .nx { position: absolute; right: 22px; bottom: calc(12px + var(--sb)); font-size: 12px; color: var(--warm); animation: nx 1s infinite; }
#iSkip { position: absolute; right: 12px; top: calc(14px + var(--st)); height: 36px; padding: 0 14px; font-size: 13px; font-weight: 700; color: var(--dim); border: 1px solid var(--line); border-radius: 3px; }
#iFade { position: absolute; inset: 0; background: #05070f; opacity: 0; pointer-events: none; }
#iFade.go { animation: ifd .7s ease-out; }
@keyframes ifd { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #iFade.go, #intro .nx { animation: none; } }

/* 完全クリア：時計が止まる場面 */
#watch { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5, 7, 15, .9); animation: fade .5s; transition: opacity .5s; }
#watch.out { opacity: 0; }
#watch .dial, #wHand { position: absolute; width: min(78vw, 420px); aspect-ratio: 1; }
#watch .dial { border-radius: 50%; border: 2px solid rgba(255, 217, 160, .5); background: repeating-conic-gradient(rgba(255, 217, 160, .55) 0 .6deg, transparent .6deg 30deg); -webkit-mask: radial-gradient(circle, transparent 0 62%, #000 62.5% 70%, transparent 70.5%); mask: radial-gradient(circle, transparent 0 62%, #000 62.5% 70%, transparent 70.5%); transition: filter .6s; }
#wHand { transition: transform .09s cubic-bezier(.3, 1.7, .6, 1); }
#wHand::before { content: ""; position: absolute; left: 50%; top: 13%; width: 3px; height: 8%; margin-left: -1.5px; background: var(--warm); box-shadow: 0 0 12px rgba(255, 180, 90, .9); }
#watch .wc { position: relative; text-align: center; }
#watch .wc b { display: block; font-family: var(--mono); font-weight: 600; font-size: min(17vw, 92px); line-height: 1.1; color: var(--warm); }
#watch .wc span { display: block; margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--text); opacity: 0; transition: opacity .6s; }
#watch.stop .wc span { opacity: 1; }
#watch.stop .dial { filter: brightness(1.7); }
#black { position: fixed; inset: 0; background: #05070f; opacity: 0; pointer-events: none; transition: opacity .4s; }
#black.on { opacity: 1; }
body.cine #hud { display: none; }
/* 完全クリアの結果：花火が見えるよう、空は覆わず下に寄せる */
#card.solved { align-items: flex-end; background: linear-gradient(to top, rgba(6, 9, 22, .94) 0, rgba(6, 9, 22, .86) 46%, rgba(6, 9, 22, 0) 78%); padding-bottom: calc(20px + var(--sb)); animation: fade 1.2s; }
#card.solved #cTitle { font-size: 30px; margin-top: 10px; }
#card.solved #cText { font-size: 15px; line-height: 1.65; margin: 10px 0 14px; }
#card.solved #cClues { margin-bottom: 16px; }
#cStats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
#cStats div { padding: 8px 0 2px; border-top: 2px solid var(--line); transition: border-color .3s; }
#cStats div.done { border-color: var(--warm); }
#cStats span { display: block; font-size: 12px; font-weight: 700; color: var(--dim); }
#cStats b { font-family: var(--mono); font-weight: 600; font-size: 30px; line-height: 1.2; color: var(--warm); }
#cStats i { font-style: normal; font-size: 13px; font-weight: 700; color: var(--dim); margin-left: 2px; }
@media (prefers-reduced-motion: reduce) { #wHand, #watch, #black { transition: none; } }

/* 巻き戻し：会場が逆再生されるのを見せるので、中央は覆わない */
#leapfx { background: radial-gradient(circle, rgba(5, 7, 15, .3) 0 28%, rgba(5, 7, 15, .74) 82%); pointer-events: none; }
#leapfx .dial { animation: none; transition: filter .25s; }
#leapfx .hd { position: absolute; width: min(78vw, 420px); aspect-ratio: 1; }
#leapfx .hd::before { content: ""; position: absolute; left: 50%; background: var(--warm); box-shadow: 0 0 12px rgba(255, 180, 90, .9); }
#lMin::before { top: 11%; width: 3px; height: 10%; margin-left: -1.5px; }
#lHour::before { top: 14.5%; width: 7px; height: 5%; margin-left: -3.5px; }
#leapfx .lc { position: relative; text-align: center; }
#leapClock { text-shadow: 0 2px 18px rgba(0, 0, 0, .95), 0 0 30px rgba(255, 180, 90, .6); line-height: 1.1; }
#leapSub { height: 26px; font-size: 17px; font-weight: 900; color: var(--text); text-shadow: 0 2px 10px rgba(0, 0, 0, .9); opacity: 0; }
#leapfx.lock { animation: lout .35s .7s forwards; }
#leapfx.lock .dial { filter: brightness(1.9); }
#leapfx.lock #leapClock { animation: lk .45s cubic-bezier(.2, 1.5, .4, 1); }
#leapfx.lock #leapSub { opacity: 1; transition: opacity .2s .1s; }
@keyframes lk { from { transform: scale(1.24); } }
@keyframes lout { to { opacity: 0; } }
#flash.soft { animation: fl2 .5s ease-out; }
@keyframes fl2 { 0% { opacity: .4; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #leapfx.lock #leapClock { animation: none; } }
body.rw #hud, body.rw #guide { visibility: hidden; }
