:root {
  --bg: #0e0b09; --panel: #1d1712; --line: #5a4632; --ink: #f2e9dc; --dim: #a89580;
  --gold: #e8c070; --red: #d0503c; --blue: #6aa0d8; --green: #8cc060;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif; overscroll-behavior: none; }
body { display: flex; justify-content: center; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#stage { position: relative; width: 100%; max-width: 480px; height: 100vh; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); background: var(--bg); user-select: none; -webkit-user-select: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.screen.on { display: flex; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.btn { display: block; width: 100%; padding: 14px 16px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--panel); font-size: 18px; text-align: center; }
.btn small { display: block; font-size: 13px; color: var(--dim); margin-top: 2px; }
.btn.primary { background: #3a2a1a; border-color: var(--gold); color: #fff3dc; }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); filter: brightness(1.2); }
.x { background: none; border: 0; font-size: 26px; line-height: 1; padding: 4px 8px; color: var(--dim); }

/* タイトル */
#title { justify-content: flex-start; align-items: center; background: radial-gradient(circle at 50% 30%, #2a1e14, var(--bg) 70%); }
.t-cv { width: min(100%, 420px); aspect-ratio: 176 / 150; margin-top: 8px; }
.t-in { width: 100%; padding: 0 22px 16px; text-align: center; display: flex; flex-direction: column; flex: 1; }
.t-sub { color: var(--dim); font-size: 14px; letter-spacing: .1em; }
.t-name { margin: 4px 0 2px; font-size: 38px; letter-spacing: .08em; color: #fff3dc; text-shadow: 0 2px 0 #000, 0 0 18px #c0803066; }
.t-dun { color: var(--gold); font-size: 15px; margin-bottom: 16px; }
.t-btns { display: flex; flex-direction: column; gap: 10px; }
.t-font { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; color: var(--dim); margin-top: 4px; }
.fz { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: transparent; font-size: 15px; }
.fz.on { background: #3a2a1a; border-color: var(--gold); color: #fff3dc; }
.t-brand { margin-top: auto; padding-top: 12px; font-size: 13px; color: #6e5e4e; letter-spacing: .1em; }
.hint { position: absolute; top: calc(env(safe-area-inset-top) + 8px); left: 12px; right: 12px; z-index: 30;
  background: #2a3a4a; border: 1px solid #5a7a9a; border-radius: 10px; padding: 12px 40px 12px 14px; font-size: 15px; line-height: 1.6; }
.hint .x { position: absolute; right: 4px; top: 4px; color: #cde; }

/* 物語の場面 */
#scene { background: #000; justify-content: flex-start; }
.sc-cv { width: 100%; aspect-ratio: 1 / 1; max-height: 58%; object-fit: contain; }
.sc-box { position: relative; margin: 12px 16px; flex: 1; max-height: 40%; border: 2px solid var(--line); border-radius: 10px; background: #15100c; padding: 14px 16px 30px; }
.sc-who { color: var(--gold); font-size: 16px; min-height: 22px; margin-bottom: 4px; }
.sc-text { font-size: 19px; line-height: 1.75; white-space: pre-wrap; }
.sc-box.narr .sc-text { color: #e6dccd; }
.sc-next { position: absolute; right: 14px; bottom: 8px; color: var(--gold); animation: blink 1s infinite; }
.sc-skip { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 10px); background: #0008; border: 1px solid #555; border-radius: 8px; padding: 8px 12px; font-size: 14px; color: #ccc; }
@keyframes blink { 50% { opacity: .2; } }

/* 迷宮 */
#play { background: var(--bg); }
#hud { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #15100c; border-bottom: 1px solid #2e241b; font-size: 14px; }
.h-floor { font-size: 20px; font-weight: bold; color: var(--gold); min-width: 46px; text-align: center; }
.h-bars { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.bar { display: flex; align-items: center; gap: 6px; }
.bar .lab { width: 30px; color: var(--dim); font-size: 13px; }
.bar i, .luca i { flex: 1; height: 10px; background: #000; border: 1px solid #3a2e22; border-radius: 3px; overflow: hidden; display: block; }
.bar b, .luca b { display: block; height: 100%; background: var(--green); transition: width .2s; }
.bar i.br b { background: var(--blue); }
.bar .num { width: 52px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.h-side { width: 74px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.luca { display: flex; align-items: center; gap: 4px; color: #b8cde8; }
.luca i { height: 8px; } .luca b { background: #e0a060; }
#view { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #000; }
#cv { width: 100%; height: 100%; object-fit: contain; touch-action: none; }
#mini { position: absolute; right: 6px; top: 6px; width: 108px; height: 81px; opacity: .85; pointer-events: none; }
#banner { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-size: 30px; letter-spacing: .3em; color: #fff3dc; text-shadow: 0 2px 8px #000; background: linear-gradient(90deg, transparent, #000a, transparent); padding: 10px 0; pointer-events: none; }
#talk { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 10px; align-items: flex-start; background: #15100cee; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px 22px; }
#talkFace { width: 48px; height: 48px; background: #2a2018; border-radius: 6px; flex: none; }
#talk .t-body { flex: 1; }
#talk .who { color: var(--gold); font-size: 14px; }
#talk .txt { font-size: 18px; line-height: 1.6; }
#talk .nx { position: absolute; right: 10px; bottom: 4px; color: var(--gold); animation: blink 1s infinite; font-size: 13px; }
#log { height: 66px; padding: 4px 12px; font-size: 15px; line-height: 1.45; color: #d8ccbc; background: #15100c; border-top: 1px solid #2e241b; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
#log div:not(:last-child) { color: #8e7e6c; }
#ctrl { display: flex; gap: 10px; padding: 8px 12px 10px; align-items: center; justify-content: center; }
#pad { display: grid; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 56px); gap: 5px; }
#pad button { border-radius: 10px; border: 1px solid #4a3a2a; background: #241b14; font-size: 24px; touch-action: none; }
#pad button.rest { font-size: 13px; line-height: 1.15; color: var(--dim); }
#pad button:active, #pad button.press { background: #4a3626; }
#side { display: flex; flex-direction: column; gap: 6px; width: 104px; }
.sb { border-radius: 10px; border: 1px solid #4a3a2a; background: #241b14; padding: 12px 0; font-size: 18px; }
.sb small { display: block; font-size: 12px; color: var(--dim); }
.sb.small { font-size: 14px; padding: 8px 0; color: var(--dim); }

.panel { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 20; background: #1a140f; border: 2px solid var(--gold); border-radius: 12px; padding: 10px 14px 14px; max-height: 70%; display: flex; flex-direction: column; }
.p-head { display: flex; justify-content: space-between; align-items: center; font-size: 18px; color: var(--gold); margin-bottom: 6px; }
#bagList { list-style: none; margin: 0; padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#bagList li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid #2e241b; font-size: 17px; }
#bagList li canvas { width: 30px; height: 30px; flex: none; }
#bagList li small { color: var(--dim); font-size: 13px; margin-left: auto; }
#bagList li.empty { color: var(--dim); }
#imDesc, #askText { font-size: 17px; line-height: 1.6; margin: 4px 0 12px; }
.p-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.p-btns .btn { flex: 1; min-width: 40%; padding: 12px; font-size: 17px; }
.p-btns.col { flex-direction: column; } .p-btns.col .btn { width: 100%; }
#aim { position: absolute; left: 10px; right: 10px; top: 46%; z-index: 20; background: #1a140fee; border: 2px solid var(--gold); border-radius: 10px; padding: 10px 12px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
#aim button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }

/* カード（倒れた・かけら・クリア） */
#death, #frag, #clear, #gallery { background: radial-gradient(circle at 50% 30%, #241a12, #000 75%); align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-height: 100%; overflow-y: auto; background: #15100c; border: 2px solid var(--line); border-radius: 14px; padding: 20px 18px; }
.c-sub { color: var(--dim); font-size: 14px; letter-spacing: .1em; }
.card h2 { margin: 6px 0 10px; color: var(--gold); font-size: 24px; }
.card p { font-size: 17px; line-height: 1.8; margin: 0 0 16px; }
.frag .f-sec { border-left: 3px solid #6a5a4a; padding: 4px 0 4px 12px; margin: 14px 0; }
.frag .f-sec.past { border-color: var(--gold); }
.f-lab { font-size: 13px; color: var(--dim); margin-bottom: 4px; }
.frag .f-sec p { margin: 0; font-size: 18px; }
.f-note { color: var(--dim); font-size: 14px !important; }
.gal ol { padding-left: 1.6em; margin: 0; }
.gal li { font-size: 16px; line-height: 1.7; margin-bottom: 12px; }
.gal li .lk { color: #6e5e4e; }
.gal li small { display: block; color: var(--dim); font-size: 14px; }
.dun { list-style: none; padding: 0; margin: 10px 0 16px; }
.dun li { display: flex; justify-content: space-between; padding: 10px 12px; margin-bottom: 6px; border-radius: 8px; border: 1px solid #3a2e22; font-size: 17px; color: #6e5e4e; }
.dun li.done { color: var(--ink); border-color: var(--line); }
.dun li.next { color: #fff3dc; border-color: var(--gold); box-shadow: 0 0 12px #e8c07044; }
.dun li small { font-size: 13px; }
.result { font-size: 17px; line-height: 1.8; margin-bottom: 16px; padding: 10px 12px; background: #0c0907; border-radius: 8px; }

#rotate { position: fixed; inset: 0; z-index: 99; background: #000; display: flex; align-items: center; justify-content: center; font-size: 20px; padding: 20px; text-align: center; }

/* 文字の大きさ */
body.fz1 .txtbox, body.fz1 .t-btns { zoom: 1.15; }
body.fz2 .txtbox, body.fz2 .t-btns { zoom: 1.3; }
body.fz1 #hud, body.fz2 #hud { zoom: 1; }
body.fz2 #log { height: 60px; }
