:root {
  --panel: rgba(17, 19, 31, .95); --panel2: #1b1e30; --line: #d9b56a; --text: #f4f0e6; --dim: #a9a397;
  --accent: #ffd27a; --hp: #6fcf6a; --mp: #62a8ea; --atb: #f2c14e; --bad: #ff7a6a; --good: #8fe28a;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0b0a0f; overflow: hidden; overscroll-behavior: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; color: var(--text); font-size: 16px; line-height: 1.5;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

#stage { position: relative; flex: 1 1 0; min-height: 0; min-width: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---- 探索HUD ---- */
#hud { position: absolute; top: calc(8px + var(--sat)); left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
#loc { background: rgba(10, 10, 16, .7); border: 1px solid rgba(217, 181, 106, .6); border-radius: 999px; padding: 4px 14px; font-size: 14px; }
#btnMenu { pointer-events: auto; width: 52px; height: 52px; border-radius: 14px; background: var(--panel); border: 2px solid var(--line); font-size: 24px; line-height: 1; }
#btnMenu:active { transform: scale(.94); }
#banner { position: absolute; top: calc(10px + var(--sat)); left: 0; right: 0; margin: 0 auto; width: fit-content; max-width: 92%; background: rgba(10, 10, 16, .82); border: 1px solid var(--line); border-radius: 10px; padding: 6px 16px; font-size: 15px; text-align: center; pointer-events: none; white-space: pre-line; line-height: 1.4; }
#banner.warn { border-color: var(--bad); color: #ffd9d2; background: rgba(60, 12, 12, .88); }

/* ---- 会話 ---- */
#catcher { position: absolute; inset: 0; z-index: 51; }
#dialog { position: absolute; z-index: 52; left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); bottom: calc(8px + var(--sab)); min-height: 112px; max-width: 760px; margin: 0 auto;
  display: flex; gap: 12px; align-items: flex-start; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 12px 16px 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); pointer-events: none; }
#dFace { width: 72px; height: 72px; border-radius: 10px; border: 1px solid rgba(217, 181, 106, .6); object-fit: cover; flex: 0 0 auto; image-rendering: auto; }
#dBody { flex: 1; min-width: 0; }
#dName { color: var(--accent); font-weight: 700; font-size: 15px; margin-bottom: 2px; }
#dText { font-size: 17px; line-height: 1.65; white-space: pre-wrap; word-break: break-all; }
#dialog.narr #dText { color: #e2ddd0; }
#dNext { position: absolute; right: 14px; bottom: 6px; color: var(--accent); font-size: 13px; animation: bob .8s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
#choices { position: absolute; z-index: 53; left: 0; right: 0; bottom: calc(136px + var(--sab)); display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 0 16px; }
#choices button { width: min(100%, 420px); min-height: 56px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; font-size: 17px; padding: 8px 16px; }

/* ---- ボタン共通 ---- */
.btn { min-height: 52px; background: var(--panel2); border: 1.5px solid rgba(217, 181, 106, .75); border-radius: 12px; padding: 8px 12px; font-size: 16px; text-align: center; }
.btn:active:not(:disabled), #choices button:active { background: #2c3050; transform: scale(.98); }
.btn:disabled { opacity: .38; }
.btn.primary { background: #3a3350; border-color: var(--accent); font-weight: 700; }
.btn.back { background: transparent; border-style: dashed; color: var(--dim); }
button:focus-visible { outline: 3px solid #fff; outline-offset: 1px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.dim { color: var(--dim); } .small { font-size: 13px; } .good { color: var(--good); } .bad { color: var(--bad); } .gold { color: var(--accent); }

/* ---- バトル ---- */
#battleUI { flex: 0 0 auto; background: #0f1119; border-top: 2px solid var(--line); padding: 8px calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal)); display: flex; flex-direction: column; gap: 8px; }
#bParty { display: grid; gap: 4px; }
.pRow { display: grid; grid-template-columns: 5.2em 1fr 3.6em 56px; gap: 8px; align-items: center; padding: 4px 8px; border-radius: 8px; border: 1.5px solid transparent; font-size: 14px; min-height: 34px; }
.pRow.active { border-color: var(--accent); background: rgba(255, 210, 122, .1); }
.pRow.ko { opacity: .45; }
.pRow.pick { border-color: var(--good); background: rgba(143, 226, 138, .12); }
.pName { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pSt { font-size: 11px; color: var(--bad); margin-left: 4px; font-weight: 400; }
.bar { height: 7px; background: #2a2d3e; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.bar.hp > i { background: var(--hp); } .bar.mp > i { background: var(--mp); } .bar.atb > i { background: var(--atb); } .bar.lim > i { background: linear-gradient(90deg, #ffe9a8, #fff); }
.bar.atb.full > i { background: #fff; }
.pHp { font-variant-numeric: tabular-nums; } .pHp .bar { margin-top: 2px; }
.pMp { font-size: 12px; color: #9cc7f2; text-align: right; font-variant-numeric: tabular-nums; }
#bCmd { min-height: 176px; display: flex; flex-direction: column; gap: 8px; }
.cmdTitle { font-size: 16px; font-weight: 700; color: var(--accent); padding: 0 2px; display: flex; align-items: center; gap: 10px; }
.cmdTitle img { width: 44px; height: 44px; border-radius: 10px; border: 2px solid var(--accent); object-fit: cover; box-shadow: 0 0 10px rgba(255, 210, 122, .6); }
.cmdGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cmdGrid .btn { min-height: 58px; font-size: 17px; font-weight: 700; }
.cmdList { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 190px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.cmdList .btn { text-align: left; line-height: 1.3; }
.cmdList .btn small { display: block; color: var(--dim); font-size: 12px; font-weight: 400; }
.cmdInfo { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--dim); white-space: pre-line; padding: 8px; }
.result { flex: 1; display: flex; flex-direction: column; gap: 4px; justify-content: center; text-align: center; }
.result b { color: var(--accent); font-size: 30px; font-weight: 400; font-family: 'Dela Gothic One', sans-serif; letter-spacing: .08em; text-shadow: 0 0 14px rgba(255, 190, 90, .7), 0 3px 0 #3a2208; }
@media (orientation: landscape) {
  #app.battle { flex-direction: row; }
  #app.battle #battleUI { width: 46%; max-width: 520px; border-top: 0; border-left: 2px solid var(--line); justify-content: center; padding-top: calc(8px + var(--sat)); overflow-y: auto; }
  #choices { bottom: calc(128px + var(--sab)); }
}
@media (max-height: 420px) { #dialog { min-height: 92px; } #dText { font-size: 15px; } #dFace { width: 56px; height: 56px; } .pRow { min-height: 28px; padding: 2px 8px; } #bCmd { min-height: 140px; } .cmdGrid .btn { min-height: 48px; } }

/* ---- 全画面オーバーレイ（タイトル・メニュー・店） ---- */
#overlay { position: absolute; inset: 0; z-index: 40; background: rgba(8, 8, 14, .84); display: flex; justify-content: center; align-items: stretch; padding: calc(10px + var(--sat)) calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal)); }
#overlay.bare { background: transparent; }
#overlay.clear { background: linear-gradient(rgba(8, 8, 14, .35), rgba(8, 8, 14, 0) 30%, rgba(8, 8, 14, 0) 60%, rgba(8, 8, 14, .75)); }
.panel { width: 100%; max-width: 620px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.panelHead { display: flex; justify-content: space-between; align-items: center; font-size: 18px; font-weight: 700; color: var(--accent); padding: 2px 4px; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.tabs .btn { min-height: 46px; padding: 4px; font-size: 14px; }
.tabs .btn.on { background: #3a3350; border-color: var(--accent); color: var(--accent); font-weight: 700; }
.card { background: var(--panel); border: 1.5px solid rgba(217, 181, 106, .55); border-radius: 12px; padding: 10px 12px; }
.card h4 { margin: 0 0 4px; font-size: 16px; } .card h4 small { color: var(--dim); font-weight: 400; margin-left: 6px; }
.stat { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px 8px; font-size: 13px; color: var(--dim); margin-top: 6px; }
.stat b { color: var(--text); font-weight: 600; }
.bars { display: grid; grid-template-columns: 2.2em 1fr 5.5em; gap: 4px 8px; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.item { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; }
.item .grow small { display: block; color: var(--dim); font-size: 12.5px; line-height: 1.35; }
.item .cnt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips .btn { min-height: 44px; padding: 4px 14px; }
.chips .btn.on { border-color: var(--accent); color: var(--accent); background: #3a3350; }

/* ---- タイトル ---- */
.title { justify-content: flex-end; align-items: center; text-align: center; padding: 7vh 0 5vh; }
.title .grow { flex: 1; }
.logoBox { padding: 10px 18px 6px; border-radius: 16px; background: radial-gradient(closest-side, rgba(8, 8, 14, .62), rgba(8, 8, 14, 0)); }
.logo { font-family: "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif; font-size: clamp(34px, 9vw, 64px); font-weight: 700; letter-spacing: .02em; color: #fff3d6; text-shadow: 0 0 18px rgba(255, 180, 90, .75), 0 3px 0 #2a1c10; line-height: 1.1; }
.logo span { color: var(--accent); }
.sub { color: #e6dccb; letter-spacing: .3em; font-size: 14px; margin: 6px 0 0; text-shadow: 0 1px 4px #000; }
.title .btn { width: min(100%, 320px); font-size: 18px; }
.tap { animation: blink 1.4s infinite; font-size: 18px; text-shadow: 0 1px 6px #000; padding: 20px; }
@keyframes blink { 50% { opacity: .35; } }
.nameInput { width: 100%; font: inherit; font-size: 24px; text-align: center; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: #0d0f18; color: var(--text); user-select: text; -webkit-user-select: text; }
.credits { text-align: center; justify-content: center; gap: 18px; }
.credits p { margin: 0; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); }

#toast { position: absolute; z-index: 60; top: calc(72px + var(--sat)); left: 50%; transform: translateX(-50%); background: rgba(20, 22, 36, .96); border: 1.5px solid var(--accent); border-radius: 999px; padding: 8px 20px; font-size: 15px; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
#fade { position: absolute; inset: 0; z-index: 50; background: #000; opacity: 0; pointer-events: none; transition: opacity .25s linear; }

/* ---- ムービー ---- */
#overlay.movie { background: #000; padding: 0; align-items: center; }
#overlay.movie { overflow: hidden; }
#overlay.movie video { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 1; }
/* 縦長の画面：横長の動画が小さくなるので、(1) 動画を1.3倍にして左右を少し切り、(2) 上下の余白には同じ動画をぼかして敷く */
#overlay.movie video.bg { display: none; }
@media (orientation: portrait) {
  #overlay.movie video.main { position: absolute; left: 50%; top: 50%; width: 130vw; height: auto; transform: translate(-50%, -50%); }
  #overlay.movie video.bg { display: block; position: absolute; left: 50%; top: 50%; width: auto; height: 112%; min-width: 100%; transform: translate(-50%, -50%); object-fit: cover; filter: blur(22px) brightness(.45) saturate(1.1); z-index: 0; }
}
#overlay.movie .skip { position: absolute; z-index: 2; right: calc(14px + var(--sar)); bottom: calc(14px + var(--sab)); font-size: 13px; color: rgba(255, 255, 255, .45); text-shadow: 0 1px 4px #000; text-align: right; transition: color .2s; pointer-events: none; }
#overlay.movie .skip.on, #overlay.movie .skip.hint { color: #fff; }
#overlay.movie .skip b { display: block; width: 120px; height: 4px; margin-top: 6px; border-radius: 2px; background: rgba(255, 255, 255, .18); overflow: hidden; opacity: 0; transition: opacity .15s; }
#overlay.movie .skip.on b { opacity: 1; }
#overlay.movie .skip i { display: block; height: 100%; width: 0; background: #f2c877; }
#overlay.movie { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---- 移動用の丸いパッド（タッチ端末のみ表示）。押したまま指をずらした方向へ歩く ---- */
#stick { display: none; position: absolute; z-index: 20; left: calc(18px + var(--sal)); bottom: calc(26px + var(--sab)); width: 124px; height: 124px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .6); background: rgba(16, 16, 26, .32); touch-action: none; -webkit-touch-callout: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255, 255, 255, .55); box-shadow: 0 2px 8px rgba(0, 0, 0, .5); pointer-events: none; }
#stick.on { border-color: var(--accent); background: rgba(16, 16, 26, .5); } #stick.on i { background: var(--accent); }
@media (pointer: coarse) { #stick:not(.hidden) { display: block; } }
@media (max-height: 420px) { #stick { width: 104px; height: 104px; bottom: calc(14px + var(--sab)); } }

/* ---- バトル中の設定（オート・音） ---- */
#bOpts { display: flex; gap: 8px; justify-content: flex-end; }
#bOpts .btn { min-height: 40px; padding: 4px 14px; font-size: 14px; border-radius: 999px; }
#bOpts .btn.on { background: #4a3c1c; border-color: var(--accent); color: var(--accent); font-weight: 700; }

/* ---- HPバーの動き ---- */
.card .bar > i { transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.bar.rise { box-shadow: 0 0 8px rgba(143, 226, 138, .9); }
.pRow.healed { animation: healed .8s ease-out; }
@keyframes healed { 0% { background: rgba(143, 226, 138, .45); box-shadow: 0 0 14px rgba(143, 226, 138, .8); } 100% { background: transparent; box-shadow: none; } }

/* ---- タイトルロゴ：金から残り火色へのグラデーション文字。APOCALYPSE の O は「切れ目のある環」。あらわれてから、ときどき光が走る ---- */
.logoBox.fx { background: radial-gradient(closest-side, rgba(8, 8, 14, .5), rgba(8, 8, 14, 0)); padding: 14px 10px 8px; filter: drop-shadow(0 3px 0 rgba(30, 14, 6, .9)) drop-shadow(0 0 16px rgba(255, 150, 60, .45)); }
.logoTop { font-family: 'Cinzel Logo', Georgia, serif; font-weight: 900; font-size: clamp(20px, 6.2vw, 44px); letter-spacing: .62em; margin-right: -.62em; color: #f4e6c4; opacity: 0; animation: logoTop 1.4s .1s cubic-bezier(.2, .7, .2, 1) forwards; }
.logoMain { font-family: 'Cinzel Logo', Georgia, serif; font-weight: 900; font-size: clamp(34px, 11.2vw, 84px); line-height: 1.05; white-space: nowrap; letter-spacing: .02em;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0) 42%, rgba(255, 255, 255, .95) 50%, rgba(255, 255, 255, 0) 58%) 130% 0 / 260% 100% no-repeat, linear-gradient(180deg, #fff8e0 8%, #f6cf78 42%, #d9822f 68%, #7a3413 96%);
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  opacity: 0; animation: logoIn 1.7s .45s cubic-bezier(.2, .7, .2, 1) forwards, logoShine 6s 2.6s ease-in-out infinite; }
.logoMain .ringO { display: inline-block; width: .74em; height: .74em; margin: 0 .035em; vertical-align: -.03em; border-radius: 50%; border: .105em solid #f2a24a; box-sizing: border-box;
  background: none; -webkit-mask: conic-gradient(from 203deg, transparent 0 42deg, #000 0); mask: conic-gradient(from 203deg, transparent 0 42deg, #000 0);
  animation: ringSpin 2.2s .5s cubic-bezier(.2, .7, .2, 1) backwards, ringPulse 3.2s 2.6s ease-in-out infinite; }
.logoLine { height: 2px; width: min(72vw, 520px); margin: 8px auto 2px; background: linear-gradient(90deg, rgba(240, 170, 80, 0), rgba(255, 215, 140, .95) 50%, rgba(240, 170, 80, 0)); transform: scaleX(0); animation: logoLine 1.2s 1.5s ease-out forwards; }
.logoBox.fx .sub { opacity: 0; animation: logoSub 1.2s 2s ease-out forwards; }
@keyframes logoTop { from { opacity: 0; letter-spacing: 1.4em; margin-right: -1.4em; filter: blur(6px); } to { opacity: 1; letter-spacing: .62em; margin-right: -.62em; filter: blur(0); } }
@keyframes logoIn { from { opacity: 0; transform: scale(1.18); letter-spacing: .14em; filter: blur(8px); } to { opacity: 1; transform: scale(1); letter-spacing: .02em; filter: blur(0); } }
@keyframes logoShine { 0%, 55% { background-position: 130% 0, 0 0; } 80%, 100% { background-position: -30% 0, 0 0; } }
@keyframes ringSpin { from { transform: rotate(-200deg) scale(1.5); opacity: 0; } to { transform: rotate(0) scale(1); opacity: 1; } }
@keyframes ringPulse { 0%, 100% { border-color: #f2a24a; filter: drop-shadow(0 0 2px rgba(255, 140, 50, .6)); } 50% { border-color: #ffe0a0; filter: drop-shadow(0 0 10px rgba(255, 170, 70, 1)); } }
@keyframes logoLine { to { transform: scaleX(1); } }
@keyframes logoSub { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .logoTop, .logoMain, .logoMain .ringO, .logoLine, .logoBox.fx .sub { animation-duration: .01s; animation-iteration-count: 1; } }
/* タップ後：ロゴは出たまま（登場の動きをやり直さない）。光と環の脈だけ続ける */
.logoBox.still .logoTop { animation: none; opacity: 1; }
.logoBox.still .logoMain { animation: logoShine 6s 1s ease-in-out infinite; opacity: 1; }
.logoBox.still .logoMain .ringO { animation: ringPulse 3.2s ease-in-out infinite; }
.logoBox.still .logoLine { animation: none; transform: scaleX(1); }
.logoBox.still .sub { animation: none; opacity: 1; }
.titleBody { display: flex; flex-direction: column; gap: 10px; width: 100%; align-items: center; }

/* アイテムを手に入れたときの表示 */
#overlay.itemget { background: rgba(6, 6, 10, .72); align-items: center; justify-content: center; }
.igCard { position: relative; text-align: center; padding: 18px 26px 22px; min-width: 240px; max-width: 86vw; animation: igIn .35s cubic-bezier(.2, 1.4, .4, 1) both; }
.igRays { position: absolute; left: 50%; top: 92px; width: 300px; height: 300px; margin: -150px 0 0 -150px; border-radius: 50%; background: repeating-conic-gradient(rgba(255, 220, 130, .22) 0 8deg, rgba(255, 220, 130, 0) 8deg 20deg); -webkit-mask: radial-gradient(closest-side, #000 20%, transparent 100%); mask: radial-gradient(closest-side, #000 20%, transparent 100%); animation: igSpin 14s linear infinite; pointer-events: none; }
.igImg { position: relative; width: 160px; height: 160px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .7)) drop-shadow(0 0 14px rgba(255, 210, 120, .55)); animation: igFloat 2.4s ease-in-out infinite; }
.igGot { position: relative; margin-top: 6px; font-size: 13px; letter-spacing: .3em; color: #f2c877; text-shadow: 0 1px 4px #000; }
.igName { position: relative; margin-top: 4px; font-size: 24px; font-weight: 800; color: #fff; text-shadow: 0 2px 6px #000; }
.igDesc { position: relative; margin-top: 6px; font-size: 14px; color: #d8d2c4; text-shadow: 0 1px 4px #000; }
.igNote { position: relative; margin-top: 8px; font-size: 13px; color: #9fe0a8; text-shadow: 0 1px 4px #000; }
@keyframes igIn { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
@keyframes igSpin { to { transform: rotate(360deg); } }
@keyframes igFloat { 50% { transform: translateY(-6px); } }

.ver { margin-top: 6px; font-size: 11px; letter-spacing: .15em; color: rgba(230, 220, 203, .55); text-shadow: 0 1px 3px #000; }

/* 動画・最初の絵の「よみこみ中」 */
#overlay.movie .ld, #boot { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; font-size: 13px; letter-spacing: .2em; color: rgba(255, 255, 255, .7); }
#overlay.movie .ld b, #boot b { display: block; width: 180px; height: 3px; margin: 10px auto 0; border-radius: 2px; background: rgba(255, 255, 255, .15); overflow: hidden; }
#overlay.movie .ld i, #boot i { display: block; width: 0; height: 100%; background: #d9b56a; transition: width .2s; }
#boot { position: fixed; inset: 0; transform: none; z-index: 50; background: #0b0a0f; display: flex; flex-direction: column; align-items: center; justify-content: center; transition: opacity .4s; }
#boot.off { opacity: 0; pointer-events: none; }
#boot.small { background: none; pointer-events: none; }
