/* 灯火の迷宮（試作） */
:root {
  --bg: #0d0b0a; --panel: #1a1512; --panel2: #241d18; --line: #3a2f26;
  --gold: #d8b46a; --gold2: #f3dca0; --text: #ece3d2; --dim: #9c8f7c;
  --red: #e0604a; --blue: #6ec3ff; --green: #86d99a;
  --serif: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: #050404; color: var(--text); overscroll-behavior: none; }
body { font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; font-size: 14px; line-height: 1.5;
  -webkit-user-select: none; user-select: none; touch-action: manipulation; overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 480px; margin: 0 auto;
  background: var(--bg); padding-bottom: env(safe-area-inset-bottom); overflow: hidden; }

/* ---- 上部 ---- */
#top { display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px 10px; background: linear-gradient(#1d1713, #130f0d); border-bottom: 1px solid var(--line); flex: none; }
#goalBox { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; }
#goalBox .lbl { flex: none; font-size: 10px; letter-spacing: .1em; color: #1a130c; background: var(--gold); border-radius: 3px; padding: 1px 5px; font-weight: 700; }
#goal { font-family: var(--serif); font-size: 13.5px; color: var(--gold2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stat { flex: none; font-size: 12px; color: var(--dim); white-space: nowrap; }
#stat b { color: var(--text); } #stat .g { color: var(--gold); }
#btnMenu { flex: none; width: 38px; height: 34px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); display: grid; place-items: center; }
svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#btnMenu svg { width: 20px; height: 20px; }

/* ---- 一人称視点 ---- */
#view { position: relative; flex: 100 1 auto; min-height: 220px; max-height: min(118vw, 566px); background: #000; overflow: hidden; touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#dim { position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, rgba(0,0,0,.15), rgba(0,0,0,.6)); opacity: 0; transition: opacity .3s; pointer-events: none; }
.in-battle #dim { opacity: 1; }
.chip { position: absolute; pointer-events: none; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: rgba(10,8,7,.66); border: 1px solid rgba(216,180,106,.3); color: var(--gold2); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
#sense { left: 8px; top: 8px; display: flex; align-items: center; gap: 6px; transition: color .3s, border-color .3s; }
#sense i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px currentColor; color: var(--green); }
#sense.s1 { color: #ffd98a; border-color: rgba(255,200,90,.55); } #sense.s1 i { background: #ffc24a; color: #ffc24a; }
#sense.s2 { color: #ffb0a0; border-color: rgba(255,110,90,.7); } #sense.s2 i { background: var(--red); color: var(--red); animation: pulse .7s infinite; }
#compass { left: 50%; top: 8px; transform: translateX(-50%); font-family: var(--serif); letter-spacing: .2em; padding-left: 12px; }
#mini { position: absolute; right: 8px; top: 8px; width: 108px; height: 108px; border-radius: 10px; background: rgba(10,8,7,.62); border: 1px solid rgba(216,180,106,.4); backdrop-filter: blur(2px); }
#hint { left: 50%; bottom: 10px; transform: translateX(-50%); font-size: 13px; padding: 5px 14px; color: #fff3d0; border-color: rgba(255,214,130,.65); background: rgba(28,20,10,.78); white-space: nowrap; opacity: 0; transition: opacity .15s; }
#hint.on { opacity: 1; animation: bobhint 1.4s ease-in-out infinite; }
.in-battle #sense, .in-battle #compass, .in-battle #mini, .in-battle #hint { display: none; }
#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
#flash.red { background: #c22; animation: flash .35s; } #flash.white { background: #fff3d0; animation: flash .5s; }
#flash.blue { background: #5ac0ff; animation: flash .6s; } #flash.gold { background: #ffd067; animation: flash .9s; }
#banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-family: var(--serif); font-size: 30px; font-weight: 700; letter-spacing: .14em; color: #fff3d0;
  text-shadow: 0 0 18px rgba(255,170,60,.9), 0 2px 4px #000; pointer-events: none; opacity: 0; }
#banner.go { animation: banner 1.5s ease-out; } #banner.danger { color: #ffd0c4; text-shadow: 0 0 18px rgba(255,60,40,.9), 0 2px 4px #000; }
#banner small { display: block; font-size: 13px; letter-spacing: .2em; font-weight: 400; margin-top: 4px; }

/* ---- 敵 ---- */
#foes { position: absolute; left: 0; right: 0; bottom: 9%; display: flex; justify-content: center; align-items: flex-end; gap: 2%; padding: 0 3%; pointer-events: none; }
.foe { position: relative; width: 33%; max-width: 180px; pointer-events: auto; text-align: center; transition: opacity .45s, transform .45s, filter .45s; }
.foe.boss { width: 68%; max-width: 320px; }
.foe img { width: 100%; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.7)); animation: idle 2.6s ease-in-out infinite; }
.foe:nth-child(2) img { animation-delay: -.9s; } .foe:nth-child(3) img { animation-delay: -1.7s; }
.foe .fname { font-size: 11px; color: #fff; text-shadow: 0 1px 3px #000, 0 0 6px #000; white-space: nowrap; }
.foe .bar { width: 76%; margin: 2px auto 0; }
.foe.appear { animation: appear .45s cubic-bezier(.2,1.4,.5,1); }
.foe.hit img { animation: foehit .3s; } .foe.miss img { animation: dodge .35s; }
.foe.dead { opacity: 0; transform: translateY(14%) scale(.86); filter: brightness(3) saturate(0); pointer-events: none; }
.foe.pick::after { content: ""; position: absolute; inset: 12% 4% 0; border: 2px solid #ffe28a; border-radius: 14px; box-shadow: 0 0 14px rgba(255,214,110,.8); animation: pulse .8s infinite; }
.foe.charging img { filter: drop-shadow(0 0 16px #ff7a2e) brightness(1.25); animation: chargeup .35s infinite; }
.dmg { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); font-family: var(--serif); font-weight: 700; font-size: 26px; color: #fff; text-shadow: 0 0 6px #000, 0 2px 0 #000; pointer-events: none; animation: dmg .8s ease-out forwards; white-space: nowrap; }
.dmg.crit { color: #ffd84a; font-size: 34px; } .dmg.magic { color: #ffb070; } .dmg.missed { color: #cfd8ff; font-size: 18px; }

/* ---- ログ ---- */
#log { flex: 1 1 54px; min-height: 54px; display: flex; flex-direction: column; justify-content: flex-end; padding: 5px 12px; overflow: hidden; background: #110d0b; border-top: 1px solid var(--line); font-size: 12.5px; line-height: 1.42; }
#log div { color: #7d7264; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; }
#log div:last-child { color: var(--text); white-space: normal; } #log div:nth-last-child(2) { color: #b3a792; }
#log .warn:last-child, #log .warn:nth-last-child(2) { color: #ff9c88; } #log .good:last-child, #log .good:nth-last-child(2) { color: #ffe08a; }
#log .note:last-child, #log .note:nth-last-child(2) { color: #a8e6ff; }

/* ---- 仲間 ---- */
#party { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px 8px; background: #110d0b; }
.pc { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px 7px 6px; transition: border-color .15s, box-shadow .15s; }
.pc .pn { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; } .pc .pn span { font-size: 10px; color: var(--dim); }
.pc.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 12px rgba(216,180,106,.35); }
.pc.down { opacity: .45; } .pc.down b { color: var(--red); }
.pc.pick { border-color: var(--green); box-shadow: 0 0 0 1px var(--green), 0 0 12px rgba(134,217,154,.5); animation: pulse .8s infinite; }
.pc.hurt { animation: cardhit .3s; } .pc.healed { animation: cardheal .5s; }
.pc .psn { position: absolute; right: 5px; top: -7px; font-size: 9px; background: #6b3fa0; color: #fff; border-radius: 4px; padding: 0 4px; }
.bar { position: relative; height: 7px; border-radius: 4px; background: #000; overflow: hidden; border: 1px solid rgba(255,255,255,.08); }
.bar i { display: block; height: 100%; border-radius: 3px; transition: width .3s; }
.bar.hp i { background: linear-gradient(#ff8f6e, #d43d2a); } .bar.mp i { background: linear-gradient(#8fd2ff, #2f7fd0); }
.pc .row { display: flex; align-items: center; gap: 5px; margin-top: 3px; } .pc .row .bar { flex: 1; }
.pc .row em { font-style: normal; font-size: 10.5px; color: #cfc4b0; min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- 操作パッド ---- */
#pad, #cmd { flex: none; padding: 4px 8px 10px; background: #110d0b; }
#pad { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 7px; }
#pad button { height: 58px; border-radius: 13px; background: linear-gradient(#2c231c, #1c1612); border: 1px solid #4a3c30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--gold2); box-shadow: 0 2px 0 #060504; }
#pad button svg { width: 24px; height: 24px; } #pad button span { font-size: 10.5px; color: var(--dim); }
#pad button.main { background: linear-gradient(#5a4322, #33260f); border-color: var(--gold); color: #fff3d0; } #pad button.main svg { width: 28px; height: 28px; stroke-width: 2.6; }
#pad button.sub { background: #171210; color: #cdbf9f; }
#pad button:active, #pad button.held { transform: translateY(2px); box-shadow: none; filter: brightness(1.35); }

/* ---- 戦闘コマンド ---- */
#cmd { height: 137px; overflow: hidden; }
.cmd-head { display: flex; align-items: center; justify-content: space-between; height: 25px; font-size: 13px; color: var(--gold2); font-family: var(--serif); }
.cmd-head .tog { font-family: inherit; font-size: 11px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim); background: var(--panel); }
.cmd-head .tog.on { color: #1a130c; background: var(--gold); border-color: var(--gold); font-weight: 700; }
.cmd-row { display: grid; gap: 6px; margin-top: 5px; }
.cmd-row.sk { grid-auto-flow: column; grid-auto-columns: 1fr; } .cmd-row.base { grid-template-columns: 1.4fr 1fr 1fr 1fr; }
.cmd-row button { height: 44px; border-radius: 11px; background: linear-gradient(#2c231c, #1c1612); border: 1px solid #4a3c30; color: var(--text); font-size: 14px; line-height: 1.15; box-shadow: 0 2px 0 #060504; padding: 0 3px; }
.cmd-row button small { display: block; font-size: 9.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-row.sk button { border-color: #5a4a7a; background: linear-gradient(#2d2540, #1b1626); } .cmd-row.sk button b { color: #e3d6ff; font-weight: 600; }
.cmd-row button.atk { background: linear-gradient(#5a4322, #33260f); border-color: var(--gold); color: #fff3d0; font-weight: 700; }
.cmd-row button:disabled { opacity: .35; } .cmd-row button:active { transform: translateY(2px); box-shadow: none; filter: brightness(1.3); }
.cmd-wait { height: 93px; display: grid; place-items: center; color: var(--dim); font-size: 13px; }

/* ---- モーダル ---- */
#modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(0,0,0,.72); animation: fade .18s; }
.card { width: 100%; max-width: 380px; max-height: 92vh; overflow: auto; background: linear-gradient(#241c16, #16110e); border: 1px solid var(--gold); border-radius: 16px; padding: 18px 16px 14px; text-align: center; box-shadow: 0 10px 40px #000, inset 0 0 30px rgba(216,180,106,.06); animation: pop .22s cubic-bezier(.2,1.3,.5,1); }
.card h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 19px; color: var(--gold2); letter-spacing: .08em; }
.card p { margin: 6px 0; color: #d7ccb8; font-size: 13.5px; } .card p.warn { color: #ff9c88; } .card p.quote { font-family: var(--serif); font-size: 15px; line-height: 1.9; color: #c9f4ff; margin: 12px 0; }
.card .btns { display: grid; gap: 8px; margin-top: 14px; } .card .btns.two { grid-template-columns: 1fr 1fr; }
.card .btns button { min-height: 46px; border-radius: 11px; background: linear-gradient(#2c231c, #1c1612); border: 1px solid #4a3c30; font-size: 14.5px; padding: 6px 8px; }
.card .btns button.pri { background: linear-gradient(#5a4322, #33260f); border-color: var(--gold); color: #fff3d0; font-weight: 700; }
.card .btns button:disabled { opacity: .4; } .card .btns button small { display: block; font-size: 11px; color: var(--dim); font-weight: 400; }
.chest-img { width: 132px; height: 132px; display: block; margin: -6px auto 2px; filter: drop-shadow(0 0 18px rgba(255,200,90,.35)); }
.chest-img.shake { animation: chestshake .5s; } .chest-img.open { animation: pop .35s cubic-bezier(.2,1.5,.5,1); filter: drop-shadow(0 0 26px rgba(255,210,110,.8)); }
.loot { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.loot li { padding: 7px 10px; border-radius: 9px; background: rgba(0,0,0,.35); border: 1px solid var(--line); font-size: 13.5px; opacity: 0; animation: lootin .4s forwards; }
.loot li:nth-child(2) { animation-delay: .18s; } .loot li:nth-child(3) { animation-delay: .36s; } .loot li:nth-child(4) { animation-delay: .54s; }
.loot li.rare { border-color: var(--gold); color: #ffe9a8; background: rgba(216,180,106,.12); font-family: var(--serif); font-size: 14.5px; }
#bigmap { width: 100%; aspect-ratio: 1; display: block; background: #0c0908; border-radius: 10px; border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 11px; color: var(--dim); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 2px; vertical-align: -1px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0 4px; text-align: left; }
.stats div { background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; font-size: 11px; color: var(--dim); }
.stats b { display: block; font-size: 17px; color: var(--text); font-family: var(--serif); }
.rank { font-family: var(--serif); font-size: 22px; color: #ffe08a; margin: 8px 0 0; text-shadow: 0 0 14px rgba(255,180,60,.6); }
.help { text-align: left; font-size: 13px; color: #d7ccb8; padding-left: 18px; margin: 6px 0; } .help li { margin: 5px 0; }

/* ---- タイトル ---- */
#title { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; text-align: center; background: radial-gradient(circle at 50% 38%, rgba(40,26,12,.72), rgba(6,5,4,.95) 70%); transition: opacity .5s; }
#title.out { opacity: 0; pointer-events: none; }
.t-icon { width: 84px; height: 84px; stroke: none; animation: glow 2.4s ease-in-out infinite; }
#title h1 { margin: 6px 0 0; font-family: var(--serif); font-size: 38px; letter-spacing: .16em; color: #fff0c8; text-shadow: 0 0 24px rgba(255,170,60,.6); }
.t-sub { margin: 2px 0 20px; font-size: 11px; letter-spacing: .32em; color: var(--gold); }
.t-text { font-family: var(--serif); font-size: 15px; line-height: 2; color: #d9cdb6; margin: 0 0 22px; }
#titleBtns { display: grid; gap: 10px; width: min(280px, 80vw); margin: 0 auto; }
#titleBtns button { height: 54px; border-radius: 14px; font-size: 17px; font-family: var(--serif); letter-spacing: .12em; background: linear-gradient(#6a4e24, #3a2a10); border: 1px solid var(--gold); color: #fff3d0; box-shadow: 0 0 24px rgba(255,170,60,.25); }
#titleBtns button.sec { height: 44px; font-size: 14px; background: var(--panel); border-color: var(--line); color: var(--dim); box-shadow: none; }
.t-note { margin-top: 18px; font-size: 10.5px; color: #6f6456; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.9); } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes flash { from { opacity: .55; } to { opacity: 0; } }
@keyframes banner { 0% { opacity: 0; transform: scale(1.5); } 14% { opacity: 1; transform: scale(1); } 72% { opacity: 1; } 100% { opacity: 0; transform: translateY(-12px); } }
@keyframes bobhint { 50% { transform: translateX(-50%) translateY(-3px); } }
@keyframes idle { 50% { transform: translateY(-2.5%); } }
@keyframes appear { from { opacity: 0; transform: scale(.5) translateY(20%); } }
@keyframes foehit { 0% { transform: translateX(0); filter: brightness(4); } 30% { transform: translateX(-7%); } 60% { transform: translateX(6%); } 100% { transform: translateX(0); } }
@keyframes dodge { 40% { transform: translateX(16%); opacity: .4; } }
@keyframes chargeup { 50% { transform: translateY(-1.5%) scale(1.02); } }
@keyframes dmg { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.6); } 18% { opacity: 1; transform: translate(-50%, -8px) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -46px) scale(1); } }
@keyframes cardhit { 0% { background: #a12; transform: translateX(0); } 30% { transform: translateX(-4px); } 60% { transform: translateX(4px); } 100% { transform: translateX(0); } }
@keyframes cardheal { 0% { background: #2a6; } }
@keyframes chestshake { 20% { transform: rotate(-5deg); } 40% { transform: rotate(5deg); } 60% { transform: rotate(-3deg); } 80% { transform: rotate(3deg); } }
@keyframes lootin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }
@keyframes glow { 50% { filter: brightness(1.25); transform: scale(1.04); } }

@media (max-height: 640px) {
  #pad button { height: 50px; } #pad button span { display: none; }
  .cmd-row button { height: 36px; } #cmd { height: 121px; } .cmd-wait { height: 77px; }
  #log { flex-basis: 40px; min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) { .foe img, #hint.on, .t-icon { animation: none; } }
