:root {
  --ink: #0b0d22;
  --panel: rgba(13, 15, 38, 0.74);
  --panel2: rgba(22, 25, 58, 0.86);
  --line: rgba(232, 199, 122, 0.55);
  --gold: #e8c77a;
  --gold2: #fff0c2;
  --text: #f4f1ff;
  --sub: #b9b6d8;
  --accent: #ffd600;
  --danger: #ff5a6e;
  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  --deco: "Cinzel Decorative", "Times New Roman", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; }
#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- 背景 ---------- */
#bg { position: absolute; inset: 0; z-index: 0; }
.bg-layer { position: absolute; inset: -2%; background-size: cover; background-position: center; opacity: 0; transition: opacity 0.9s ease;
  animation: bgdrift 40s ease-in-out infinite alternate; }
.bg-layer.on { opacity: 1; }
@keyframes bgdrift { from { transform: scale(1.02) translateX(-0.6%); } to { transform: scale(1.05) translateX(0.6%); } }
.bg-shade { position: absolute; inset: 0; background: radial-gradient(ellipse at 60% 50%, rgba(8, 9, 26, 0.15), rgba(8, 9, 26, 0.65)); transition: background 0.6s; }
#app[data-shade="puzzle"] .bg-shade { background: linear-gradient(90deg, rgba(8,9,26,0.2) 0%, rgba(8,9,26,0.55) 40%, rgba(8,9,26,0.72) 100%); }
#app[data-shade="dark"] .bg-shade { background: rgba(6, 7, 20, 0.78); }
#app[data-shade="light"] .bg-shade { background: linear-gradient(180deg, rgba(8,9,26,0) 50%, rgba(8,9,26,0.55)); }

#screen { position: absolute; inset: 0; z-index: 2; }
#fade { position: absolute; inset: 0; z-index: 50; background: #05060f; opacity: 0; pointer-events: none; transition: opacity 0.35s ease; }
#fade.on { opacity: 1; pointer-events: auto; }
#fade.white { background: #fffaf0; }

#toast { position: absolute; left: 50%; top: 18px; transform: translate(-50%, -20px); z-index: 60; padding: 10px 22px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); font-weight: 700; opacity: 0; transition: 0.3s; pointer-events: none; white-space: nowrap; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 起動 ---------- */
#boot { position: absolute; inset: 0; z-index: 100; display: grid; place-content: center; gap: 18px; text-align: center; background: radial-gradient(circle at 50% 45%, #1b1d48, #05060f 70%); transition: opacity 0.6s; }
#boot.hide { opacity: 0; pointer-events: none; }
.boot-logo { font-family: var(--deco); font-size: clamp(28px, 6vw, 56px); letter-spacing: 0.12em; color: var(--gold2); text-shadow: 0 0 18px rgba(255, 214, 120, 0.6); }
.boot-bar { width: min(320px, 70vw); height: 4px; border-radius: 4px; background: rgba(255,255,255,0.12); margin: 0 auto; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd36b, #fff); box-shadow: 0 0 10px #ffd36b; transition: width 0.2s; }
.boot-msg { color: var(--sub); font-size: 13px; letter-spacing: 0.1em; }

/* ---------- 共通部品 ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(12px) saturate(1.2); -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 18px 50px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08); position: relative; }
.panel::before, .panel::after { content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid var(--gold); pointer-events: none; }
.panel::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.panel::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }

.btn { --c: var(--gold); appearance: none; border: 1px solid color-mix(in srgb, var(--c) 70%, transparent); background: linear-gradient(180deg, rgba(40,44,92,0.9), rgba(18,20,48,0.92));
  color: var(--text); font-weight: 700; font-size: 16px; padding: 12px 26px; border-radius: 999px; cursor: pointer; letter-spacing: 0.06em;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.15); transition: transform 0.12s, box-shadow 0.2s, border-color 0.2s; position: relative; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,0,0,0.45), 0 0 16px color-mix(in srgb, var(--c) 45%, transparent); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: linear-gradient(180deg, #ffe7a3, #e7b75a 55%, #c98f2c); color: #2a1a05; border-color: #fff0c2; text-shadow: 0 1px 0 rgba(255,255,255,0.5); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.icon-btn { appearance: none; display: inline-flex; flex-direction: column; align-items: center; gap: 2px; min-width: clamp(64px, 7vh, 88px); padding: 8px 10px; border-radius: 14px;
  border: 1px solid rgba(232,199,122,0.4); background: rgba(16,18,44,0.82); color: var(--text); font-size: 11px; font-weight: 700; cursor: pointer; transition: 0.15s; }
.icon-btn svg { width: clamp(24px, 2.6vh, 30px); height: clamp(24px, 2.6vh, 30px); }
.icon-btn span { font-size: clamp(11px, 1.25vh, 14px); }
.icon-btn:hover { border-color: var(--gold); background: rgba(34,38,84,0.9); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn .badge { position: absolute; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: clamp(12px, 1.35vh, 15px); font-weight: 700; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18); cursor: pointer; }
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- タイトル ---------- */
.title-screen { position: absolute; inset: 0; }
.title-girls { position: absolute; inset: 0; pointer-events: none; }
.title-screen::before { content: ""; position: absolute; inset: 0 0 0 45%; background: linear-gradient(90deg, transparent, rgba(8,9,26,0.55) 35%, rgba(8,9,26,0.7)); pointer-events: none; }
.title-girls img { position: absolute; bottom: -8%; height: 100%; filter: drop-shadow(0 10px 30px rgba(0,0,0,0.5)); opacity: 0; animation: girlin 0.9s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes girlin { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
.title-logo { position: absolute; right: 3%; top: 12%; text-align: center; width: 44%; }
.title-logo .en { font-family: var(--deco); font-size: clamp(36px, 5.6vw, 92px); line-height: 1; letter-spacing: 0.06em; color: #fff7dc;
  background: linear-gradient(180deg, #fffdf4 10%, #ffe59a 50%, #e2a83e 90%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 210, 110, 0.65)) drop-shadow(0 4px 0 rgba(60, 30, 0, 0.6)); }
.title-logo .ja { margin-top: 10px; font-weight: 900; font-size: clamp(13px, 1.5vw, 22px); letter-spacing: 0.25em; color: #fff; text-shadow: 0 0 10px rgba(120, 160, 255, 0.9), 0 2px 4px #000; }
.title-logo .line { height: 2px; width: min(560px, 70%); margin: 12px auto 0; background: linear-gradient(90deg, transparent, #ffe59a, #fff, #ffe59a, transparent); box-shadow: 0 0 12px #ffd36b; }
.title-menu { position: absolute; right: calc(25% - min(160px, 40vw)); bottom: calc(8% + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(320px, 80vw); }
.title-menu .btn { font-size: 18px; padding: 14px 20px; }
.title-foot { position: absolute; right: 14px; bottom: calc(8px + var(--safe-b)); font-size: 11px; color: rgba(255,255,255,0.5); }

/* ---------- 依頼ボード（章えらび） ---------- */
.map-screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 18px clamp(12px, 3vw, 40px) calc(14px + var(--safe-b)); gap: 14px; }
.topbar { display: flex; align-items: center; gap: 12px; }
.topbar h2 { margin: 0; font-size: clamp(18px, 2.4vw, 28px); letter-spacing: 0.12em; font-weight: 900; text-shadow: 0 2px 8px #000; }
.topbar .spacer { flex: 1; }
.topbar .stars-total { font-weight: 900; color: var(--gold2); }
.cards { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); gap: clamp(8px, 1.4vw, 18px); min-height: 0; }
.card { position: relative; border-radius: 16px; overflow: hidden; cursor: pointer; border: 1px solid rgba(255,255,255,0.18); background: #15183a;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45); transition: transform 0.18s, box-shadow 0.18s; min-height: 0; }
.card:hover { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(0,0,0,0.55), 0 0 0 2px var(--c); }
.card .art { position: absolute; inset: 0; background-size: cover; background-position: 50% 8%; transition: transform 0.4s; }
.card:hover .art { transform: scale(1.04); }
.card .grad { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 45%, rgba(8,9,26,0.92) 85%); }
.card .no { position: absolute; left: 10px; top: 8px; font-family: var(--font); font-weight: 900; font-size: 22px; color: #fff; text-shadow: 0 2px 6px #000, 0 0 10px var(--c); }
.card .info { position: absolute; left: 12px; right: 12px; bottom: 10px; }
.card .nm { font-weight: 900; font-size: clamp(14px, 1.5vw, 19px); text-shadow: 0 2px 6px #000; }
.card .gm { font-size: 11px; color: var(--c); font-weight: 700; margin-top: 2px; text-shadow: 0 1px 3px #000; }
.card .st { font-size: 12px; color: var(--gold2); margin-top: 4px; }
.card.locked { cursor: default; }
.card.locked .art { filter: brightness(0.12) saturate(0); }
.card.locked .lock { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: rgba(255,255,255,0.6); font-weight: 700; font-size: 13px; gap: 6px; }
.card.locked .lock svg { width: 34px; height: 34px; margin: 0 auto; opacity: 0.7; }
.card .newmark { position: absolute; right: 8px; top: 8px; background: var(--c); color: #111; font-weight: 900; font-size: 11px; padding: 3px 8px; border-radius: 999px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.1); } }

/* ---------- ステージえらび ---------- */
.stages-screen { position: absolute; inset: 0; display: flex; padding: 18px clamp(12px, 3vw, 40px) calc(14px + var(--safe-b)); gap: 20px; }
.stages-screen .side { position: relative; flex: 0 0 38%; }
.stages-screen .side img { position: absolute; left: -10%; bottom: -18px; height: 108%; max-width: none; filter: drop-shadow(0 10px 30px rgba(0,0,0,0.6)); }
.stages-screen .main { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.stage-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: clamp(6px, 1.2vh, 12px); }
.stage-btn { position: relative; min-height: 0; overflow: hidden; border-radius: 14px; border: 1px solid rgba(255,255,255,0.2); background: linear-gradient(160deg, rgba(36,40,86,0.92), rgba(14,16,40,0.92));
  cursor: pointer; color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; transition: 0.15s; }
.stage-btn:hover { border-color: var(--c); box-shadow: 0 0 16px color-mix(in srgb, var(--c) 50%, transparent); }
.stage-btn .n { font-family: var(--font); font-weight: 900; font-size: clamp(16px, 2vw, 24px); letter-spacing: 0.04em; }
.stage-btn .t { font-size: 11px; color: var(--sub); text-align: center; line-height: 1.25; }
.stage-btn .s { font-size: 14px; letter-spacing: 2px; }
.stage-btn.boss { border-color: var(--c); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 35%, #20234a), #12142e); }
.stage-btn.ex { border-style: dashed; }
.stage-btn.locked { cursor: default; background: rgba(8,9,24,0.9); color: rgba(255,255,255,0.45); }
.stage-btn.locked .n { opacity: 0.6; }
.stage-btn canvas.thumb { flex: 1; width: 100%; min-height: 0; }
.stage-btn .row1 { display: flex; align-items: baseline; gap: 8px; }
.stars .on { color: #ffd84d; text-shadow: 0 0 8px rgba(255, 210, 80, 0.8); }
.stars .off { color: rgba(255,255,255,0.22); }
.chapter-desc { padding: 14px 18px; }
.chapter-desc h3 { margin: 0 0 6px; font-size: 20px; }
.chapter-desc p { margin: 0; color: var(--sub); font-size: 13px; line-height: 1.6; }

/* ---------- 会話 ---------- */
.talk-screen { position: absolute; inset: 0; cursor: pointer; }
.talk-chars { position: absolute; inset: 0; pointer-events: none; }
.talk-chars .ch { position: absolute; bottom: -6%; height: 104%; left: 50%; transform: translateX(-50%); transition: opacity 0.35s, transform 0.45s cubic-bezier(.2,.8,.2,1), filter 0.35s; filter: drop-shadow(0 10px 30px rgba(0,0,0,0.5)); }
.talk-chars .ch img { height: 100%; display: block; }
.talk-chars .ch .face { position: absolute; inset: 0; opacity: 0; transition: opacity 0.18s; }
.talk-chars .ch .face.on { opacity: 1; }
.talk-chars .ch.dim { filter: brightness(0.55) drop-shadow(0 10px 30px rgba(0,0,0,0.5)); }
.talk-chars .ch.hop { animation: hop 0.35s ease; }
@keyframes hop { 40% { margin-bottom: 14px; } }
.talk-box { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); width: min(1080px, 94vw); min-height: 150px; padding: 26px 34px 22px; }
.talk-name { position: absolute; left: 26px; top: -18px; padding: 6px 22px; border-radius: 999px; font-weight: 900; font-size: 17px; background: var(--c, #555); color: #14102a;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4); letter-spacing: 0.08em; }
.talk-name.narr { display: none; }
.talk-text { font-size: clamp(16px, 1.75vw, 21px); line-height: 1.75; min-height: 3.5em; text-shadow: 0 1px 2px rgba(0,0,0,0.5); font-weight: 500; }
.talk-next { position: absolute; right: 24px; bottom: 14px; width: 14px; height: 14px; border-right: 3px solid var(--gold); border-bottom: 3px solid var(--gold); transform: rotate(45deg); animation: nexty 0.9s infinite; opacity: 0; }
.talk-next.on { opacity: 1; }
@keyframes nexty { 50% { translate: 0 5px; } }
.talk-tools { position: absolute; right: 16px; top: 14px; display: flex; gap: 8px; z-index: 3; }
.talk-tools .chip { background: rgba(10,12,30,0.7); }
.talk-tools .chip.on { border-color: var(--gold); color: var(--gold2); }

/* ---------- パズル ---------- */
.puzzle-screen { position: absolute; inset: 0; }
.pz-girl { position: absolute; left: -2%; bottom: -8%; height: 112%; width: 42%; pointer-events: none; }
.pz-girl .ch { position: absolute; bottom: 0; left: 50%; height: 100%; transform: translateX(-50%); transition: transform 0.4s; filter: drop-shadow(0 10px 30px rgba(0,0,0,0.6)); }
.pz-girl .ch img { height: 100%; display: block; }
.pz-girl .ch .face { position: absolute; inset: 0; opacity: 0; transition: opacity 0.2s; }
.pz-girl .ch .face.on { opacity: 1; }
.pz-girl .ch.hop { animation: hop 0.4s ease; }
.pz-girl .ch.shake { animation: shake 0.4s ease; }
@keyframes shake { 20% { translate: -8px 0; } 40% { translate: 7px 0; } 60% { translate: -5px 0; } 80% { translate: 3px 0; } }
.bubble { position: absolute; left: 2%; bottom: calc(3% + var(--safe-b)); width: min(420px, 34vw); padding: 14px 18px; border-radius: 18px; background: rgba(255,255,255,0.96); color: #1b1834; font-weight: 700;
  font-size: clamp(14px, 1.3vw, 17px); line-height: 1.55; box-shadow: 0 10px 30px rgba(0,0,0,0.4); transform-origin: 30% 0%; transition: opacity 0.2s, transform 0.25s cubic-bezier(.2,1.4,.4,1); z-index: 4; border: 3px solid var(--c); }
.bubble::after { content: ""; position: absolute; left: 46%; top: -14px; border: 10px solid transparent; border-bottom: 12px solid var(--c); border-top: 0; }
.bubble.hide { opacity: 0; transform: scale(0.85); }
.bubble .who { display: block; font-size: clamp(11px, 1.3vh, 14px); color: var(--c); letter-spacing: 0.1em; margin-bottom: 2px; filter: brightness(0.75); }
.pz-main { position: absolute; left: 38%; right: 2%; top: 2%; bottom: calc(2% + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.pz-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.pz-head .lv { font-family: var(--font); font-weight: 900; font-size: 22px; color: var(--c); text-shadow: 0 0 10px color-mix(in srgb, var(--c) 60%, transparent); }
.pz-head .nm { font-weight: 900; font-size: clamp(15px, 2.2vh, 24px); }
.pz-head .spacer { flex: 1; }
.pz-head .timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--sub); }
.pz-head .timer.over { color: #ff9aa6; }
.pz-head .goals { display: flex; gap: 10px; font-size: clamp(12px, 1.4vh, 16px); color: var(--sub); }
.pz-head .goals b { color: #ffd84d; }
.pz-head .goals .lost { opacity: 0.35; text-decoration: line-through; }
.pz-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.pz-board { flex: 1; position: relative; min-height: 0; border-radius: 22px; }
.pz-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pz-board .glass { position: absolute; inset: 0; border-radius: 22px; background: radial-gradient(circle at 50% 40%, rgba(40, 46, 110, 0.55), rgba(10, 12, 32, 0.78)); border: 1px solid rgba(232,199,122,0.35);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5), 0 20px 50px rgba(0,0,0,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); overflow: hidden; }
.pz-board .glass::before { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,0.08) 1px, transparent 1.2px); background-size: 26px 26px; }
.pz-board .msg { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 13px; color: var(--sub); pointer-events: none; text-shadow: 0 1px 3px #000; white-space: nowrap; transition: opacity 0.3s; }
.pz-tools { display: flex; gap: 10px; justify-content: center; }
.pz-tools .icon-btn { position: relative; }
.pz-tools .icon-btn .cnt { position: absolute; right: -4px; top: -6px; background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; }

/* ギミック説明カード */
.modal-wrap { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(4,5,16,0.55); animation: fadein 0.25s; }
@keyframes fadein { from { opacity: 0; } }
.modal { width: min(560px, 92vw); padding: 26px 28px 22px; text-align: center; animation: popin 0.35s cubic-bezier(.2,1.3,.4,1); }
@keyframes popin { from { transform: scale(0.85); opacity: 0; } }
.modal .tag { font-family: var(--deco); color: var(--c, var(--gold)); letter-spacing: 0.2em; font-size: 13px; }
.modal h3 { margin: 6px 0 12px; font-size: 24px; font-weight: 900; }
.modal p { margin: 0 0 18px; line-height: 1.75; color: #e6e3ff; font-size: 15px; text-align: left; }
.modal .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal canvas.demo { width: 100%; height: 150px; display: block; margin: 0 0 14px; border-radius: 12px; background: rgba(0,0,0,0.25); }

/* リザルト */
.result { width: min(460px, 92vw); padding: 24px 26px 22px; text-align: center; }
.result .big { font-family: var(--deco); font-size: clamp(30px, 5vw, 46px); color: var(--gold2); text-shadow: 0 0 16px rgba(255, 210, 110, 0.8); letter-spacing: 0.08em; }
.result .rstars { font-size: 46px; letter-spacing: 8px; margin: 6px 0 4px; }
.result .rstars span { display: inline-block; opacity: 0; transform: scale(2.2) rotate(-30deg); }
.result .rstars span.in { animation: starin 0.45s cubic-bezier(.2,1.5,.4,1) forwards; }
@keyframes starin { to { opacity: 1; transform: none; } }
.result ul { list-style: none; padding: 0; margin: 8px 0 16px; text-align: left; font-size: 14px; }
.result li { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px dashed rgba(255,255,255,0.12); color: var(--sub); }
.result li b { color: var(--text); }
.result li.ok b { color: #ffd84d; }

/* ---------- 仕上げの一筆 ---------- */
.reward-screen { position: absolute; inset: 0; display: grid; place-items: center; background: #05060f; }
.reward-frame { position: relative; margin-top: 44px; width: min(96vw, calc((100vh - 64px) * 1.5)); aspect-ratio: 3 / 2; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 1px rgba(232,199,122,0.5), 0 30px 80px rgba(0,0,0,0.7); }
.reward-frame img, .reward-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; touch-action: none; }
.reward-frame .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 20px; text-align: center; font-weight: 900; background: linear-gradient(transparent, rgba(0,0,0,0.6)); pointer-events: none; transition: opacity 0.5s; }
.reward-title { position: absolute; top: 18px; left: 0; right: 0; text-align: center; font-family: var(--deco); color: var(--gold2); letter-spacing: 0.2em; text-shadow: 0 0 12px rgba(255,200,100,0.8); pointer-events: none; z-index: 3; }
.reward-done { position: absolute; right: 20px; bottom: calc(20px + var(--safe-b)); z-index: 4; }

/* ---------- ギャラリー ---------- */
.gallery-screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 18px clamp(12px, 3vw, 40px) calc(14px + var(--safe-b)); gap: 14px; }
.gal-body { flex: 1; display: flex; gap: 18px; min-height: 0; }
.gal-list { flex: 0 0 min(260px, 32%); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 4px; }
.gal-item { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.12); background: rgba(16,18,44,0.75); cursor: pointer; }
.gal-item.on { border-color: var(--c); box-shadow: 0 0 12px color-mix(in srgb, var(--c) 50%, transparent); }
.gal-item img { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; object-position: 50% 10%; background: #222; }
.gal-item.locked img { filter: brightness(0.1); }
.gal-item .nm { font-weight: 700; font-size: 14px; }
.gal-item .sub { font-size: 11px; color: var(--sub); }
.gal-view { flex: 1; position: relative; display: flex; gap: 16px; min-width: 0; }
.gal-stand { position: relative; flex: 0 0 40%; }
.gal-stand img { position: absolute; left: 50%; bottom: -14px; height: 104%; transform: translateX(-50%); max-width: none; filter: drop-shadow(0 10px 30px rgba(0,0,0,0.6)); }
.gal-prof { flex: 1; padding: 20px 22px; overflow-y: auto; min-width: 0; }
.gal-prof h3 { margin: 0; font-size: 26px; font-weight: 900; }
.gal-prof .rd { color: var(--sub); font-size: 13px; }
.gal-prof .role { color: var(--c); font-weight: 700; margin: 6px 0 10px; }
.gal-prof p { line-height: 1.8; font-size: 14px; color: #e6e3ff; }
.gal-prof dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.gal-prof dt { color: var(--sub); }
.gal-prof .faces { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.gal-prof .cgthumb { margin-top: 12px; width: 100%; aspect-ratio: 3/2; border-radius: 12px; background-size: cover; background-position: center; cursor: zoom-in; border: 1px solid var(--line); position: relative; }
.gal-prof .cgthumb.locked { filter: brightness(0.15); cursor: default; }
.cg-full { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,0.92); display: grid; place-items: center; cursor: zoom-out; animation: fadein 0.25s; }
.cg-full img { max-width: 98vw; max-height: 96vh; box-shadow: 0 0 60px rgba(0,0,0,0.8); }

/* ---------- 設定 ---------- */
.settings { width: min(520px, 92vw); padding: 24px 26px; }
.settings h3 { margin: 0 0 14px; }
.settings label { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 10px; margin: 12px 0; font-weight: 700; }
.settings input[type=range] { width: 100%; accent-color: var(--gold); }
.settings .credit { font-size: 12px; color: var(--sub); line-height: 1.7; margin-top: 14px; max-height: 30vh; overflow: auto; }

/* ---------- エンディング ---------- */
.ending-screen { position: absolute; inset: 0; background: #000; overflow: hidden; }
.ending-screen .cg { position: absolute; inset: 0; background-repeat: no-repeat; background-size: cover; background-position: center; opacity: 0; transition: opacity 2.5s; }
.ending-screen .cg.on { opacity: 1; }
.ending-screen .roll { position: absolute; left: 60%; right: 2%; top: 100%; text-align: center; font-size: 16px; line-height: 2.2; text-shadow: 0 2px 6px #000; }
.ending-screen .roll h4 { font-family: var(--deco); color: var(--gold2); margin: 30px 0 4px; letter-spacing: 0.2em; }
.ending-screen .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,0) 45%, rgba(0,0,0,0.82) 62%); }
@media (max-aspect-ratio: 1/1) { .ending-screen .roll { left: 4%; right: 4%; } .ending-screen .shade { background: rgba(0,0,0,0.55); } .ending-screen .cg { background-position: 30% center; } }

/* ---------- スマホ縦 ---------- */
@media (max-aspect-ratio: 1/1) {
  .cards { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
  .stages-screen { flex-direction: column; }
  .stages-screen .side { flex: 0 0 28%; overflow: hidden; border-radius: 16px; }
  .stages-screen .side img { left: 50%; transform: translateX(-50%); top: -4%; bottom: auto; height: 260%; }
  .stage-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stage-btn { padding-top: 6px; padding-bottom: 6px; }
  .pz-girl { left: -4%; top: 0; bottom: auto; width: 56%; height: 70vh; overflow: hidden; mask-image: linear-gradient(180deg, #000 18vh, transparent 27vh); -webkit-mask-image: linear-gradient(180deg, #000 18vh, transparent 27vh); }
  .pz-girl .ch { bottom: auto; top: 1vh; height: 70vh; }
  .bubble { left: 46%; right: 3%; top: 4.5vh; bottom: auto; width: auto; max-width: none; font-size: 13px; padding: 10px 12px; transform-origin: 0% 50%; }
  .bubble::after { left: -12px; bottom: auto; top: 18px; border: 8px solid transparent; border-right: 12px solid var(--c); border-left: 0; }
  .pz-main { left: 2%; right: 2%; top: 22vh; gap: 8px; }
  .pz-head { padding: 8px 12px; gap: 8px; }
  .pz-head .lv { font-size: 18px; }
  .pz-tools .icon-btn { min-width: 0; flex: 1; }
  .talk-chars .ch { height: 88%; bottom: 14%; }
  .talk-box { padding: 22px 18px 16px; min-height: 130px; }
  .gal-body { flex-direction: column; }
  .gal-list { flex: 0 0 auto; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .gal-item { flex: 0 0 auto; }
  .gal-item .nm, .gal-item .sub { display: none; }
  .gal-view { flex-direction: column; overflow-y: auto; }
  .gal-stand { flex: 0 0 46vh; overflow: hidden; }
  .gal-stand img { height: 150%; top: 0; bottom: auto; }
  .title-girls img { height: 74%; bottom: -6%; }
  .title-screen::before { inset: 0; background: linear-gradient(180deg, rgba(8,9,26,0.55), transparent 30%, transparent 55%, rgba(8,9,26,0.8)); }
  .title-logo { left: 4%; right: 4%; width: auto; top: 5%; }
  .title-logo .en { font-size: clamp(34px, 11vw, 64px); }
  .title-menu { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(4% + var(--safe-b)); }
}
@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  .pz-head { padding: 6px 12px; }
  .icon-btn { padding: 4px 8px; }
  .talk-box { min-height: 110px; padding: 18px 24px 14px; }
}

/* ---------- QA 後の追加 ---------- */
.talk-text.narr { color: #d9d4ff; padding-left: 1em; border-left: 3px solid rgba(232,199,122,0.5); }
.chapter-card { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: linear-gradient(90deg, rgba(4,5,16,0.85), rgba(4,5,16,0.55) 60%, rgba(4,5,16,0.85)); overflow: hidden; animation: fadein 0.3s; }
.chapter-card .cc-girl { position: absolute; right: 4%; bottom: -10%; height: 112%; filter: drop-shadow(0 0 30px color-mix(in srgb, var(--c) 50%, transparent)); animation: ccslide 0.9s cubic-bezier(.2,.8,.2,1); }
@keyframes ccslide { from { transform: translateX(60px); opacity: 0; } }
.chapter-card .cc-text { position: relative; z-index: 1; text-align: center; padding: 22px 40px; border-radius: 18px; background: radial-gradient(ellipse at center, rgba(6,7,20,0.85) 40%, rgba(6,7,20,0) 75%); margin-right: 18vw; animation: popin 0.6s cubic-bezier(.2,1.2,.4,1) 0.15s both; }
.chapter-card .cc-rule { width: min(420px, 70vw); height: 2px; margin: 10px auto 12px; background: linear-gradient(90deg, transparent, var(--c), transparent); box-shadow: 0 0 10px var(--c); }
@media (max-aspect-ratio: 1/1) { .chapter-card .cc-girl { right: -20%; height: 80%; opacity: 0.55; } .chapter-card .cc-text { margin-right: 0; padding: 18px 16px; } }
.deny-pill { position: absolute; transform: translate(-50%, -50%) scale(0.8); padding: 7px 14px; border-radius: 999px; background: rgba(20, 8, 20, 0.92); border: 1.5px solid #ff8fa0; color: #ffe3e8;
  font-size: 13px; font-weight: 700; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity 0.18s, transform 0.25s cubic-bezier(.2,1.4,.4,1); z-index: 5; box-shadow: 0 6px 18px rgba(0,0,0,0.5); }
.deny-pill.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.chip .glyph { font-weight: 900; font-size: 13px; min-width: 14px; text-align: center; }
.chip .q { opacity: 0.5; font-size: 10px; }
.num { font-family: var(--font); font-weight: 900; }

/* ---------- スマホ QA（2回目）での調整 ---------- */
.gal-item .face { flex: 0 0 46px; width: 46px; height: 46px; border-radius: 10px; background-color: #222; background-size: 300% auto; background-position: 50% 3%; }
.gal-item.locked .face { filter: brightness(0.1); }
.ending-screen .roll-clip { position: absolute; inset: 0; overflow: hidden; }
.modal-wrap > .panel { max-height: calc(100dvh - 16px); overflow-y: auto; }
.topbar h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .stars-total, .icon-btn span { white-space: nowrap; }
.pz-head .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
/* 段数が足りないときは潰さずにスクロールさせる */
.stages-screen .main { overflow-y: auto; }
.stage-grid { min-height: auto; grid-template-rows: repeat(3, minmax(84px, 1fr)); }
@media (max-aspect-ratio: 1/1) {
  .topbar h2 { font-size: clamp(15px, 4.6vw, 28px); letter-spacing: 0.04em; }
  .card .nm { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* 見出し: 1行目に番号・名前・タイム、2行目に目標 */
  .pz-head .goals { order: 9; flex-basis: 100%; }
  .gal-stand { flex: 0 0 36vh; }
  .gal-prof { flex: none; overflow: visible; }
  .reward-frame { overflow: visible; }
  .reward-frame .cap { top: 100%; bottom: auto; background: none; padding: 12px 8px; text-wrap: balance; }
  .chapter-card { place-items: end center; padding-bottom: 14vh; }
  .chapter-card .cc-text { width: 100%; border-radius: 0; background: linear-gradient(90deg, rgba(6,7,20,0.3), rgba(6,7,20,0.88) 20%, rgba(6,7,20,0.88) 80%, rgba(6,7,20,0.3)); }
  .ending-screen .cg { background-size: contain; background-position: center 6vh; }
  .ending-screen .shade { background: linear-gradient(180deg, transparent 0, transparent 34vh, rgba(0,0,0,0.85) 42vh); }
  .ending-screen .roll-clip { top: 40vh; -webkit-mask-image: linear-gradient(180deg, transparent, #000 10%); mask-image: linear-gradient(180deg, transparent, #000 10%); }
}
/* スマホ横（高さが足りない横長画面） */
@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  .title-logo { top: 4%; }
  .title-logo .en { font-size: clamp(28px, 10vh, 48px); }
  .title-logo .ja { margin-top: 4px; font-size: 13px; }
  .title-menu { gap: 8px; bottom: calc(5% + var(--safe-b)); }
  .title-menu .btn { padding: 8px 16px; font-size: 15px; }
  .stages-screen { padding-top: 10px; gap: 12px; }
  .stages-screen .side { flex-basis: 24%; }
  .chapter-desc { padding: 8px 14px; }
  .chapter-desc h3 { margin: 0; font-size: 16px; }
  .chapter-desc p { display: none; }
  .stage-grid { grid-template-rows: repeat(3, minmax(72px, 1fr)); }
  .stage-btn .t { display: none; }
  .pz-girl { width: 30%; }
  .bubble { width: 27vw; font-size: 12px; padding: 8px 10px; }
  .pz-main { left: 27%; right: 78px; top: 8px; bottom: calc(8px + var(--safe-b)); gap: 6px; }
  .pz-head { flex-wrap: nowrap; padding: 4px 12px; }
  .pz-head .lv { font-size: 18px; }
  .pz-head .goals { display: none; }
  .pz-legend .chip { padding: 2px 8px; font-size: 11px; }
  .pz-tools { position: absolute; right: -72px; top: 0; bottom: 0; flex-direction: column; justify-content: center; gap: 6px; }
  .pz-tools .icon-btn { min-width: 62px; }
  .modal { padding: 16px 20px 14px; }
  .modal h3 { margin: 4px 0 8px; font-size: 20px; }
  .modal p { margin-bottom: 10px; font-size: 14px; line-height: 1.6; }
}
