@font-face { font-family: Keifont; src: url('./fonts/keifont.ttf') format('truetype'); font-display: swap; }
:root { color-scheme: dark; font-family: 'Yu Gothic', Meiryo, sans-serif; color: #fff3e8; background: #1d1512; --dialogue-space: clamp(150px, 23vh, 220px); --stage-pad: clamp(18px, 3vh, 32px); --motion-bleed: clamp(16px, 3vh, 42px); }
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
button, select, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.app-shell { position: relative; width: 100%; height: 100dvh; overflow: hidden; }
.stage { position: relative; height: 100%; display: grid; place-items: center; padding: var(--stage-pad) var(--stage-pad) var(--dialogue-space); background: #251b17; overflow: hidden; }
.stage:has(.dialogue[hidden]) { padding-bottom: 20px; }
.art-root { position: relative; width: min(80vw, calc((100dvh - var(--dialogue-space) - var(--stage-pad) * 2 - var(--motion-bleed)) * .75), 680px); aspect-ratio: 3 / 4; overflow: hidden; isolation: isolate; background: #fff; box-shadow: 0 24px 28px #0006; }
.stage:has(.dialogue[hidden]) .art-root { width: min(80vw, calc((100dvh - 40px) * .75), 680px); }
.art-canvas { position: absolute; pointer-events: none; }
.scene-subwindow { position: absolute; z-index: 5; border: 0; outline: 2px solid #000; outline-offset: 0; background: #fff; }
.art-layer-wrap { position: absolute; inset: 0; pointer-events: none; }
/* 差分を非表示にしても呼吸の時間を保ち、再表示時に顔からずれないようにします。 */
.art-layer-wrap[hidden] { display: block !important; visibility: hidden; }
.art-layer { position: absolute; max-width: none; object-fit: fill; }
.art-breathing { animation: character-breathing var(--period) ease-in-out var(--phase) infinite; }
.art-chest-rebound { animation: chest-rebound var(--period) ease-in-out var(--phase) infinite; }
@keyframes chest-rebound {
  0%, 50%, 72%, 100% { transform: translateY(0%) scale(1, 1); }
  54% { transform: translateY(.25%) scale(1.008, .995); }
  59% { transform: translateY(-.125%) scale(.996, 1.0025); }
  64% { transform: translateY(.06%) scale(1.002, .999); }
  68% { transform: translateY(-.025%) scale(.999, 1.0005); }
}
@keyframes character-breathing { 0%, 100% { transform: translateY(0%) scale(1, 1); } 50% { transform: translateY(var(--breath-down, 0%)) scale(var(--breath-scale-x, 1.0015), var(--breath-scale-y, 1.0035)); } }
.art-steam { animation: steam-rise var(--steam-period) linear var(--steam-delay) infinite; }
@keyframes steam-rise {
  0% { transform: translate(0, 2%); opacity: 0; }
  25% { opacity: .65; }
  65% { opacity: .65; }
  100% { transform: translate(1%, var(--steam-rise)); opacity: 0; }
}
.dialogue { position: absolute; left: clamp(18px, 4vw, 56px); right: clamp(18px, 4vw, 56px); bottom: clamp(18px, 4vh, 40px); z-index: 10; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 9px 16px; height: 180px; border: 1px solid #5f36252e; border-radius: 8px; background: #fff4e6; color: #34231d; padding: 18px 20px; box-shadow: 0 16px 46px #3b1c1338; font-family: Keifont, sans-serif; overflow: hidden; }
.speaker { grid-column: 1 / -1; margin: 0; color: #a84f3f; font-size: 15px; }
.line { min-height: 0; margin: 0; font-size: clamp(16px, 2.1vw, 22px); line-height: 1.75; white-space: pre-line; overflow-y: auto; }
.next-button { align-self: end; width: 42px; height: 42px; border: 0; border-radius: 50%; background: #a84f3f; color: #fff8ef; }
.dialogue:has(.dialogue-choices:not([hidden])) { grid-template-rows: auto minmax(0, 1fr) auto; }
.dialogue-choices { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; padding-right: 52px; }
.dialogue-choices button { flex: 1; min-height: 44px; padding: 8px 12px; border: 1px solid #a84f3f; border-radius: 8px; background: #fff8ef; color: #34231d; }
@media (max-width: 979px), (orientation: portrait) {
  .dialogue:has(.dialogue-choices:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, auto) auto;
    align-content: start;
    gap: 6px;
    padding: 12px 16px;
  }
  .dialogue:has(.dialogue-choices:not([hidden])) .speaker { grid-row: 1; }
  .dialogue:has(.dialogue-choices:not([hidden])) .line { grid-row: 2; max-height: 36px; }
  .dialogue:has(.dialogue-choices:not([hidden])) .line:empty { display: none; }
  .dialogue:has(.dialogue-choices:not([hidden])) .next-button { position: absolute; right: 14px; bottom: 14px; }
  .dialogue-choices { grid-row: 3; gap: 6px; }
  .dialogue-choices button { flex: none; min-height: 40px; padding: 6px 12px; }
}
.loading-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #251b17; z-index: 20; }
.settings-toggle { position: fixed; right: 16px; top: 16px; z-index: 40; width: 44px; height: 44px; border: 1px solid #ffffff40; border-radius: 50%; color: #fff3e8; background: #2a201c; }
.settings-panel { position: fixed; right: 12px; top: 68px; bottom: 16px; width: min(340px, calc(100vw - 24px)); overflow-y: auto; z-index: 30; padding: 20px; border: 1px solid #ffffff30; border-radius: 12px; background: #2a201cf5; }
h1 { font-family: Keifont, sans-serif; font-size: 22px; margin-top: 0; }
fieldset { border: 1px solid #ffffff30; border-radius: 8px; margin: 16px 0; }
.field { display: grid; gap: 7px; margin: 10px 0; font-size: 14px; }
select, #resetScene { width: 100%; padding: 8px; border: 1px solid #ffffff40; border-radius: 6px; background: #1d1512; color: #fff3e8; }
select:disabled { opacity: .45; }
@media (min-width: 980px) and (orientation: landscape) {
  :root { --side-dialogue-space: min(520px, 42vw); --stage-pad: 20px; --art-width: min(calc((100dvh - var(--stage-pad) * 2 - var(--motion-bleed)) * .75), calc(100vw - var(--side-dialogue-space) - var(--stage-pad) * 2)); }
  .stage { grid-template-columns: minmax(0,1fr) var(--art-width) var(--side-dialogue-space) minmax(0,1fr); grid-template-rows: 1fr; column-gap: 0; padding: var(--stage-pad); }
  .art-root, .stage:has(.dialogue[hidden]) .art-root { grid-column: 2; grid-row: 1; justify-self: end; align-self: center; width: var(--art-width); }
  .stage:has(.dialogue[hidden]) { grid-template-columns: minmax(0,1fr) var(--art-width) minmax(0,1fr); padding: var(--stage-pad); }
  .dialogue { position: relative; left: auto; right: auto; bottom: auto; grid-column: 3; grid-row: 1; align-self: end; justify-self: start; width: var(--side-dialogue-space); height: 280px; max-height: calc(100dvh - 56px); grid-template-columns: 1fr; grid-template-rows: auto minmax(0,1fr) auto; border-radius: 16px 8px 8px 16px; }
  .next-button { justify-self: end; }
}
@media (min-width: 980px) and (orientation: landscape) and (min-aspect-ratio: 21 / 9) {
  :root { --side-dialogue-space: min(480px, 32vw); }
  .stage { grid-template-columns: minmax(24px,1fr) var(--art-width) var(--side-dialogue-space) minmax(24px,1fr); }
  .dialogue { align-self: center; }
}
@media (min-width: 980px) and (orientation: landscape) and (max-height: 620px) {
  :root { --stage-pad: 14px; }
  .dialogue { height: 240px; min-height: 240px; }
  .line { font-size: clamp(15px, 1.6vw, 20px); }
}
@media (max-width: 760px) {
  :root { --dialogue-space: 190px; --stage-pad: 18px; }
  .dialogue { grid-template-columns: 1fr; grid-template-rows: auto minmax(0,1fr); height: 190px; padding: 15px 16px; }
  .line { font-size: 18px; line-height: 1.6; }
  .line { padding-right: 48px; }
  .next-button { position: absolute; right: 14px; bottom: 14px; width: 40px; height: 40px; }
}
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) { .app-shell::after { content: 'スマホでは縦画面でご覧ください'; position: fixed; inset: 0; z-index: 999; display: grid; place-items: center; padding: 24px; background: #1d1512; color: #fff3e8; font-size: 18px; font-weight: 800; line-height: 1.8; text-align: center; pointer-events: auto; } }
.settings-toggle { top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); }
.settings-panel { top: max(68px, calc(env(safe-area-inset-top) + 56px)); bottom: max(16px, env(safe-area-inset-bottom)); }
.dialogue { bottom: max(clamp(18px, 4vh, 40px), env(safe-area-inset-bottom)); }
@media (min-width: 980px) and (orientation: landscape) { .dialogue { bottom: auto; } }
@media (prefers-reduced-motion: reduce) { .art-breathing { animation-play-state: paused; } }
@media (prefers-reduced-motion: reduce) { .art-steam { animation: none; } .art-steam-secondary { display: none; } }
