:root {
  --bg: #140f22; --bg2: #1f1833; --card: #261e3d; --line: #3d3260; --text: #ece6ff; --sub: #a99fcb;
  --gold: #f2c35a; --accent: #a46bff; --red: #ff5d73; --green: #5fe0a0;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: calc(env(safe-area-inset-top, 0px) * 1.6);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: "M PLUS Rounded 1c", system-ui, sans-serif; font-size: 15px; overscroll-behavior: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }
#boot { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; color: var(--sub); }
.screen { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.screen[hidden] { display: none; }
.scroll { flex: 1; overflow-y: auto; padding: 12px 14px calc(16px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.note { font-size: 12px; color: var(--sub); line-height: 1.6; }
.label { font-size: 12px; color: var(--sub); letter-spacing: 1px; margin-bottom: 6px; }

.btn { display: block; width: 100%; height: 48px; border-radius: 24px; border: 1px solid var(--line); background: var(--card); font-size: 16px; font-weight: 700; margin: 8px 0; }
.btn.primary { background: linear-gradient(180deg, #b884ff, #7a46d8); border: 0; box-shadow: 0 3px 0 #4a2a8a; }
.btn.ghost { background: none; }
.btn.small { height: 38px; font-size: 14px; width: auto; padding: 0 16px; margin: 0; }
.btn:disabled { opacity: .4; }
.icon-btn { width: 38px; height: 38px; border-radius: 19px; border: 1px solid var(--line); background: var(--card); font-size: 20px; line-height: 1; }

/* タイトル */
#title { background: radial-gradient(ellipse at 50% 0%, #3a2470 0%, var(--bg) 70%); overflow-y: auto; }
.title-box { padding: calc(40px + var(--safe-t)) 24px 30px; text-align: center; }
.kicker { font-size: 12px; letter-spacing: 3px; color: var(--sub); }
h1 { font-family: "DotGothic16", sans-serif; font-size: 44px; margin: 10px 0 6px; color: var(--gold); text-shadow: 0 3px 0 #6a3a10, 0 0 24px rgba(242, 195, 90, .35); letter-spacing: 2px; }
h1 span { color: #fff; }
.lead { font-size: 14px; line-height: 1.9; color: #d7cff2; margin: 8px 0 22px; }
.brain { text-align: left; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.brain label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-radius: 10px; }
.brain label span { display: flex; flex-direction: column; gap: 2px; }
.brain small { font-size: 12px; color: var(--sub); }
.brain input[type=radio] { margin-top: 4px; accent-color: var(--accent); }
.brain.disabled-pc #ai-pc { opacity: .4; }
#ollama-opts { font-size: 12px; color: var(--sub); margin-top: 4px; }
#ollama-opts input { width: 130px; margin-left: 4px; background: #0e0a18; border: 1px solid var(--line); color: #fff; border-radius: 6px; padding: 3px 6px; font-size: 16px; }
.ver { font-size: 11px; color: #6c628f; margin-top: 18px; }

/* 上のバー */
.bar { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.bar-mid { flex: 1; min-width: 0; }
.bar-title { font-family: "DotGothic16", sans-serif; font-size: 18px; color: var(--gold); }
.bar-sub { font-size: 12px; color: var(--sub); }
.day { font-size: 12px; color: var(--sub); }

/* 玉座 */
.progress { display: flex; gap: 6px; align-items: center; margin: 4px 0 12px; }
.progress .dot { flex: 1; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--sub); }
.progress .dot.done { background: #2d4a3c; color: var(--green); border-color: #3f7a5e; }
.progress .dot.now { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.next-row { display: flex; gap: 12px; align-items: center; }
.next-row .mini { flex: none; width: 110px; height: 110px; background: radial-gradient(circle, #2e2550, #1a1430); border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.next-row .info { flex: 1; min-width: 0; font-size: 13px; line-height: 1.7; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { margin: 0; height: 44px; font-size: 15px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; height: 36px; border-radius: 18px; border: 1px solid var(--line); background: none; font-size: 14px; color: var(--sub); }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pc { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px; text-align: center; position: relative; }
.pc img { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--c); object-fit: cover; background: #fff1; }
.pc .nm { font-size: 13px; font-weight: 700; }
.pc .lv { font-size: 11px; color: var(--sub); }
.pc .role { font-size: 10px; color: var(--sub); line-height: 1.3; }
.pc .tag { position: absolute; top: 6px; right: 6px; font-size: 10px; background: var(--red); color: #fff; border-radius: 8px; padding: 1px 6px; }
.tired { display: inline-flex; gap: 2px; vertical-align: middle; }
.tired i { width: 6px; height: 6px; border-radius: 3px; background: #4a4068; }
.tired i.on { background: #ffa04a; }
.book-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; line-height: 1.7; }
.book-item b { font-size: 14px; }
.eff { display: inline-block; padding: 1px 8px; border-radius: 10px; margin: 2px 3px 2px 0; font-size: 12px; background: #3a3058; }
.eff.good { background: #2e5a44; color: #b8ffd8; }
.eff.bad { background: #5a2e3a; color: #ffc8d0; }
.eff.fact::after { content: ' ✓'; font-size: 10px; }
.log-item { font-size: 13px; padding: 8px 2px; border-bottom: 1px solid var(--line); line-height: 1.6; }
.win { color: var(--green); } .lose { color: var(--red); }

/* モンスター作り */
.ed-top { display: flex; gap: 12px; align-items: center; position: sticky; top: -12px; z-index: 2; background: var(--bg); padding: 8px 0; }
.ed-preview { width: 130px; height: 130px; flex: none; background: radial-gradient(circle, #2e2550, #1a1430); border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.ed-cost { flex: 1; }
#ed-cost-text { font-size: 15px; font-weight: 700; }
.meter { height: 10px; background: #0e0a18; border-radius: 5px; overflow: hidden; margin: 6px 0; border: 1px solid var(--line); }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, #7a46d8, #f2c35a); width: 0; transition: width .15s; }
.meter.over i { background: var(--red); }
.ed-row { margin: 12px 0; }
.ed-row input { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: #fff; padding: 0 12px; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.chips button.on { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.chips .sw { display: inline-block; width: 10px; height: 10px; border-radius: 5px; margin-right: 6px; }
.ed-sec { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; margin: 12px 0; }
.ed-sec summary { font-weight: 700; padding: 6px 0; }
.sl { display: grid; grid-template-columns: 62px 32px 1fr 32px 70px; align-items: center; gap: 6px; margin: 8px 0; font-size: 13px; }
.sl .pm { width: 32px; height: 32px; border-radius: 16px; border: 1px solid var(--line); background: #1a1430; font-size: 18px; line-height: 1; padding: 0; touch-action: manipulation; }
.sl .pm:active { background: var(--accent); }
.sl input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; margin: 0; touch-action: pan-y; }
.sl .v { text-align: right; font-size: 11px; color: var(--sub); white-space: nowrap; }
.sl .v.good { color: #ff9aa8; } .sl .v.bad { color: #9affc8; }
.trait { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.trait:last-child { border: 0; }
.trait input { width: 20px; height: 20px; accent-color: var(--accent); }
.trait small { display: block; color: var(--sub); font-size: 11px; }
.foot { display: flex; gap: 10px; align-items: center; padding: 10px 14px calc(10px + var(--safe-b)); background: var(--bg2); border-top: 1px solid var(--line); }
.foot .btn.primary { flex: 1; margin: 0; }

/* 戦闘 */
#scene { background: var(--bg); }
.stage-area { position: relative; height: 34vh; min-height: 200px; background: radial-gradient(ellipse at 50% 80%, #3e6b3a 0%, #23402a 40%, #151a24 100%); overflow: hidden; padding-top: var(--safe-t); }
.sc-mon { position: absolute; left: 0; right: 0; top: calc(6px + var(--safe-t)); bottom: 40px; display: flex; align-items: center; justify-content: center; }
.sc-mon svg { width: auto; height: 100%; max-height: 220px; }
.sc-mon.shake { animation: shake .3s; }
.sc-mon.dead { opacity: .15; transition: opacity 1s; filter: grayscale(1); }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
.sc-mon-info { position: absolute; left: 12px; right: 12px; bottom: 8px; font-size: 12px; display: flex; align-items: center; gap: 8px; text-shadow: 0 1px 2px #000; }
.sc-mon-info .hp { flex: 1; height: 8px; background: #0008; border-radius: 4px; overflow: hidden; }
.sc-mon-info .hp i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff5d73, #ffa04a); transition: width .3s; }
.sc-mon-info .num { min-width: 64px; text-align: right; }
.sc-cut { position: absolute; right: 10px; bottom: 30px; width: 34%; max-width: 170px; height: 64%; border-radius: 14px; border: 3px solid var(--c, #fff); overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0) 70%), var(--c, #555); box-shadow: 0 4px 16px #0009;
  opacity: 0; transform: translateX(24px); transition: opacity .2s, transform .2s; pointer-events: none; }
.sc-cut.on { opacity: 1; transform: none; }
.sc-cut img { width: 100%; height: 100%; object-fit: cover; object-position: center top; display: block; }
.sc-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; }
.ev { font-size: 14px; line-height: 1.6; animation: fade .25s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.ev.narr { color: #d7cff2; }
.ev.round { text-align: center; font-size: 11px; color: #6c628f; letter-spacing: 2px; }
.ev.mon { color: #ffb0b8; }
.ev.hit .d { color: var(--gold); font-weight: 700; }
.ev.think { color: #9d93c4; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.ev.think img { width: 20px; height: 20px; border-radius: 50%; opacity: .8; }
.ev.say { display: flex; gap: 8px; align-items: flex-start; }
.ev.say img { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--c); flex: none; object-fit: cover; }
.ev.say .bub { background: var(--card); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 6px 10px; }
.ev.say .who { font-size: 11px; color: var(--c); font-weight: 700; }
.ev.banner { text-align: center; font-weight: 800; padding: 8px; border-radius: 10px; }
.ev.banner.win { background: #2e5a44; color: #c8ffe0; }
.ev.banner.lose { background: #4a2a36; color: #ffd0d8; }
.ev.team { background: #2a2346; border-radius: 10px; padding: 6px 10px; font-size: 13px; color: var(--gold); }
.ev.lvup { font-size: 12px; color: var(--green); }
.sc-party { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px 10px; background: var(--bg2); border-top: 1px solid var(--line); }
.sp { text-align: center; font-size: 11px; position: relative; }
.sp img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; }
.sp.down img { filter: grayscale(1); opacity: .45; }
.sp.hit img { animation: shake .3s; }
.sp .hp { height: 5px; background: #0008; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.sp .hp i { display: block; height: 100%; background: var(--green); transition: width .3s; }
.sp .hp i.low { background: var(--red); }
.sc-ctrl { display: flex; gap: 8px; align-items: center; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--bg2); }
.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 19px; overflow: hidden; }
.seg button { flex: 1; height: 36px; border: 0; background: none; font-size: 13px; color: var(--sub); }
.seg button.on { background: var(--accent); color: #fff; }

/* 下から出る詳細 */
.sheet { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: #0009; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-body { position: relative; width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto; background: var(--bg2); border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-x { position: absolute; right: 12px; top: 12px; }
.det-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.det-head img { width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--c); object-fit: cover; }
.bars { display: grid; grid-template-columns: 58px 1fr 34px; gap: 4px 8px; align-items: center; font-size: 12px; margin: 6px 0 12px; }
.bars .b { height: 8px; background: #0e0a18; border-radius: 4px; overflow: hidden; }
.bars .b i { display: block; height: 100%; background: var(--accent); }
.bars .b i.m { background: var(--gold); }
.sheet h4 { margin: 12px 0 4px; font-size: 13px; color: var(--sub); }
.help p { font-size: 14px; line-height: 1.8; }
.toast { position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translateX(-50%); background: #000c; color: #fff; padding: 8px 16px; border-radius: 18px; font-size: 13px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 99; max-width: 90%; }
.toast.on { opacity: 1; }
.btn[hidden] { display: none; }
.seg button { white-space: nowrap; font-size: 12px; }

button { touch-action: manipulation; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; }
.name-row .btn { flex: none; height: 40px; }
.upd { margin: 14px auto 0; display: block; }
