/* 待合室。名札と物の札は白い札に黒い字。2 文字の欄は青い点線の札で、つまんで動かせる。 */
:root {
  --ink: #2a2a2e;
  --dim: #8a857b;
  --paper: #efe9de;
  --wall: #e4dccd;
  --floor: #cdbfa6;
  --card: #fff;
  --soft: #d4cbbb;
  --pre: #2f6fb0;
  --red: #c9463d;
}

* { box-sizing: border-box; }
/* 文言は文節で折る（docs/game-guidelines.md「文言」） */
.base, .talk .line, .result h2, .toast, .poster { word-break: auto-phrase; text-wrap: pretty; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; background: var(--paper); touch-action: manipulation; }

body {
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button, input { font-family: inherit; color: inherit; touch-action: manipulation; }

#app {
  position: relative;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--app-top, 0px));
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}
@media (min-width: 520px) { #app { border-left: 1px solid var(--soft); border-right: 1px solid var(--soft); } }

/* --- 名札（帯の題名も同じ形） --- */
.plate {
  display: inline-flex; align-items: center; justify-content: center; background: var(--card); border: 1.5px solid var(--ink); border-radius: 4px;
  padding: 1px 8px; white-space: nowrap; letter-spacing: 1px; font-weight: 700;
}
.plate .sg { transition: color .4s, opacity .4s; }
.plate .sg.h.off { color: var(--soft); text-decoration: line-through; }
.plate .sg.pre { color: var(--pre); }

/* --- 帯 --- */
.band { flex: 0 0 auto; padding: 6px 12px 7px; border-bottom: 1.5px solid var(--ink); background: var(--paper); position: relative; z-index: 5; }
.r { display: flex; align-items: center; gap: 10px; }
.title { margin: 0; font-size: 17px; font-weight: 700; }
.tplate { font-size: 16px; padding: 2px 8px; }
.tplate.wob { animation: wob .5s; }
.tplate.away { animation: tAway .7s ease-in forwards; }
@keyframes tAway { 30% { transform: rotate(-8deg); } 100% { transform: translateY(6px) rotate(0); } }
.dots { display: flex; gap: 4px; margin-right: auto; }
.dots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); }
.dots i.on { background: var(--ink); }
.tools { display: flex; gap: 6px; }
.tool {
  font-size: 12px; height: 26px; padding: 0 8px; border: 1.5px solid var(--ink); border-radius: 3px;
  background: var(--card); cursor: pointer; position: relative; white-space: nowrap;
}
.tool:active { transform: translateY(1px); }
.tool.snd { width: 28px; padding: 0; line-height: 1; }
.tool.snd.off::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; border-top: 1.5px solid var(--ink); transform: rotate(-40deg); }

/* --- 本編 --- */
#main { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.play { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.room {
  position: relative; flex: 1 1 auto; min-height: 200px;
  background: linear-gradient(var(--wall) 0 72%, var(--floor) 72% 100%); border-bottom: 1.5px solid var(--ink); overflow: hidden;
}
.wall { position: absolute; left: 0; right: 0; top: 8px; display: flex; justify-content: space-between; align-items: flex-start; padding: 0 12px; gap: 10px; }
.poster {
  background: #fffdf6; border: 1.5px solid var(--ink); padding: 5px 9px; font-size: 12.5px; line-height: 1.45; transform: rotate(-1.5deg);
  box-shadow: 2px 2px 0 rgba(0,0,0,.08);
}
.poster b { font-size: 14px; }
.poster.drop { animation: drop .5s ease-out; }
.poster.glow { animation: glow .9s; }
@keyframes drop { from { transform: translateY(-80px) rotate(-6deg); } to { transform: translateY(0) rotate(-1.5deg); } }
@keyframes glow { 0%, 100% { background: #fffdf6; } 30%, 60% { background: #fff1b8; } }
.slip { margin-left: auto; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 3px; white-space: nowrap; }

.bench { position: absolute; left: 6px; right: 6px; bottom: 16%; top: 46%; display: flex; justify-content: space-around; align-items: flex-end; }
.seat { position: absolute; left: 4px; right: 4px; bottom: calc(16% - 10px); height: 12px; background: #8a6a48; border: 1.5px solid var(--ink); border-radius: 3px; z-index: 0; }
.p { position: relative; flex: 0 0 24%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; transition: transform .6s ease, opacity .6s ease; z-index: 1; }
.p .fig { position: relative; width: 100%; max-width: 112px; display: flex; justify-content: center; }
.p .pfig { width: 100%; height: auto; max-height: min(160px, calc(var(--app-h, 100dvh) - 520px)); min-height: 90px; display: block; }
.p .plate { position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%) scaleX(var(--sx, 1)); font-size: 13px; padding: 1px 5px; letter-spacing: 0; }
.p .mark { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); color: var(--red); font-size: 18px; line-height: 1; animation: bob 1s ease-in-out infinite; }
.p .say {
  position: absolute; top: -30px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 3px 7px; font-size: 12px; white-space: nowrap; z-index: 3; animation: pop .25s ease-out;
}
.p.l .say { left: 0; transform: none; }
.p.rr .say { left: auto; right: 0; transform: none; }
.p.up { transform: translateY(-10px); }
.p.wob .pfig { animation: wob .5s; }
.p.leave { transform: translateY(-40px) scale(.9); opacity: 0; }
.p.enter { animation: enter .6s ease-out; }
.p.fall { animation: fall .7s cubic-bezier(.3, 0, .6, 1); }
@keyframes enter { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fall { from { transform: translateY(-300px); } 70% { transform: translateY(8px); } to { transform: none; } }
@keyframes bob { 50% { transform: translate(-50%, 4px); } }
@keyframes pop { from { scale: .6; opacity: 0; } }
.empty { position: absolute; left: 0; right: 0; bottom: 34%; text-align: center; color: var(--dim); font-size: 13px; }

.talk { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 12px; min-height: 46px; border-bottom: 1px dashed var(--soft); }
.talk .who { flex: 0 0 auto; font-size: 11px; color: var(--dim); border: 1.5px solid var(--ink); border-radius: 3px; padding: 2px 5px; background: var(--card); }
.talk .line { font-size: 16px; font-weight: 700; }
.talk .line .pre { color: var(--pre); }
.talk .line .sf { color: var(--dim); }
.talk .line.say { animation: pop2 .25s ease-out; }
@keyframes pop2 { from { opacity: 0; transform: translateY(4px); } }

.caller { flex: 0 0 auto; padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; background: var(--paper); }
.pres { display: flex; gap: 4px; }
.pres button {
  flex: 1 1 0; min-width: 0; height: 34px; font-size: 12px; border: 1.5px solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; padding: 0 2px; white-space: nowrap;
}
.pres button.on { background: var(--pre); color: #fff; border-color: var(--pre); }
.pres button:active { transform: translateY(1px); }
.row { display: flex; align-items: center; gap: 6px; margin: 0; }
.pfx { flex: 0 0 auto; color: var(--pre); font-weight: 700; font-size: 16px; }
.pfx:empty { display: none; }
.name {
  flex: 1 1 auto; min-width: 0; height: 46px; font-size: 18px; padding: 0 10px; border: 2px solid var(--ink); border-radius: 4px; background: var(--card);
  -webkit-user-select: text; user-select: text; outline: none;
}
.name:focus { border-color: var(--pre); }
.sfx { flex: 0 0 auto; font-size: 16px; color: var(--dim); font-weight: 700; }
.call { flex: 0 0 auto; height: 46px; padding: 0 16px; font-size: 16px; font-weight: 700; border: 2px solid var(--ink); border-radius: 4px; background: var(--ink); color: #fff; cursor: pointer; }
.call:active { transform: translateY(2px); }
.call.wait { opacity: .45; }


@keyframes wob { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* --- タイトル画面 --- */
.top { padding: 40px 22px 18px; display: flex; flex-direction: column; gap: 22px; align-items: flex-start; }
.big { margin: 8px 0 0; font-size: 36px; }
.big .plate { padding: 6px 16px; border-width: 2.5px; letter-spacing: 3px; }
.base { margin: 0; font-size: 17px; line-height: 1.8; }
.go { align-self: stretch; height: 52px; font-size: 17px; font-weight: 700; border: 2px solid var(--ink); border-radius: 4px; background: var(--ink); color: #fff; cursor: pointer; }
.go:active { transform: translateY(2px); }
.tfoot { align-self: stretch; font-size: 12px; text-align: center; color: var(--dim); }

/* --- 結果 --- */
.result { padding: 16px 14px 18px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.result h2 { margin: 0; font-size: 22px; }
.result details { border: 1.5px solid var(--ink); border-radius: 4px; background: var(--card); padding: 8px 10px; font-size: 14px; }
.result summary { cursor: pointer; font-weight: 700; }
.result ol { margin: 8px 0 0; padding-left: 22px; line-height: 1.7; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; height: 48px; font-size: 16px; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer;
}
.btn.x { background: var(--ink); color: #fff; }
.xlogo { width: 18px; height: 18px; }
.btn:active { transform: translateY(2px); }

#foot { padding: 6px 14px 16px; font-size: 12px; text-align: center; color: var(--dim); }
.play:not([hidden]) ~ #foot { display: none; }

.toast {
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 4px; font-size: 14px; z-index: 50; transition: opacity .5s;
}
.toast.out { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .p .mark { animation: none; } }

/* --- フタモジ --- */
.room { min-height: 300px; }
.thing { position: absolute; z-index: 2; }
.thing .say, .p .say { z-index: 6; }
.thing .say {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 3px 7px; font-size: 12px; white-space: nowrap; animation: pop .25s ease-out;
}
.thing .mark { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); color: var(--red); font-size: 18px; line-height: 1; animation: bob 1s ease-in-out infinite; z-index: 5; }
.thing.wob > svg { animation: wob .5s; }
.fujiw { left: 12px; top: 30px; width: 34%; max-width: 140px; }
.fuji { display: block; width: 100%; }
.fuji .face { opacity: 0; transition: opacity .3s; }
.fujiw.on .fuji .face { opacity: 1; }
.clockw { right: 16px; top: 18px; width: 22%; max-width: 86px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.clock { display: block; width: 100%; }
.clock .bird { transform: translateY(8px); opacity: 0; transition: transform .3s, opacity .2s; }
.clock .door { transform-origin: 33px 21px; transition: transform .25s; }
.clockw.on .clock .bird { transform: translate(0, -12px); opacity: 1; }
.clockw.on .clock .door { transform: scaleX(.15); }
.clockw .mark { top: -16px; }
/* 時計は部屋の上の端にあり、上に出すと帯の下で切れる。左に出す */
.clockw .say { top: 24%; left: auto; right: calc(100% + 6px); transform: none; }
.spkw { left: 55%; top: 26px; transform: translateX(-50%); width: 34%; max-width: 140px; }
.spkw .spk { display: block; width: 100%; }
.spkw.on .arcs { animation: blast .5s 3; }
@keyframes blast { 50% { transform: scale(1.15); } }
.spkw .arcs { transform-origin: 30% 50%; }

/* 札（欄の置き場） */
.anc { display: inline-flex; align-items: center; gap: 2px; flex: none; white-space: nowrap; }
.clockw .anc { background: var(--card); border: 1.5px solid var(--ink); border-radius: 4px; padding: 1px 5px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.anc .slot { display: inline-flex; }
/* 札の前の置き場は、ふだんは閉じている。欄を近づける（.hot）と欄（小）の大きさに開いて札がよけ、置いた後はその大きさのまま。
   離すと閉じる。開いてから入るので、置いた瞬間に周りが跳ねない。大きさは main.js の sizeSlots が測る */
.anc:not(.callbar) .slot { width: 0; height: 0; transition: width .18s ease, height .18s ease; }
.anc:not(.callbar).hot .slot, .anc:not(.callbar) .slot:not(:empty) { width: var(--slot-w-s, auto); height: var(--slot-h-s, auto); }
.anc.hot { outline: 2px dashed var(--pre); outline-offset: 3px; border-radius: 4px; }

.chip { display: inline-flex; align-items: center; border: 2px dashed var(--pre); border-radius: 5px; background: var(--card); touch-action: none; }
.chip .grip { width: 24px; justify-content: center; color: var(--pre); font-size: 15px; cursor: grab; letter-spacing: -3px; position: relative; z-index: 1; touch-action: none; align-self: stretch; display: flex; align-items: center; }
.chip .box { width: 2.7em; height: 40px; font-size: 18px; border: 0; outline: none; background: transparent; padding: 0 4px; font-weight: 700; -webkit-user-select: text; user-select: text; }
.chip.small .box { height: 28px; font-size: 15px; width: 2.6em; }
.chip.fly { position: fixed; z-index: 60; pointer-events: none; opacity: .9; transform: translate(-12px, -50%); }

.caller { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 12px; margin: 0; background: var(--paper); flex-direction: row; }
.callbar { font-size: 20px; font-weight: 700; }
.callbar .slot:empty::before { content: ""; display: inline-block; box-sizing: border-box; width: var(--slot-w, 64px); height: var(--slot-h, 40px); border: 2px dashed var(--soft); border-radius: 5px; }
.callbar .lab { margin-left: 4px; }

/* 設定の板 */
.panel { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 8; background: var(--card); border: 2px solid var(--ink); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 3px 3px 0 rgba(0,0,0,.12); }
.ph { margin: 0; font-size: 13px; color: var(--dim); }
.prow { display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 700; }
.slider { position: relative; flex: 1 1 auto; height: 30px; touch-action: none; }
.slider .track { position: absolute; left: 0; right: 0; top: 13px; height: 4px; background: var(--soft); border-radius: 2px; }
.slider .fill { position: absolute; left: 0; top: 13px; height: 4px; background: var(--pre); border-radius: 2px; }
.slider .knob { position: absolute; top: 4px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink); transition: left .25s; }
.slider.drag .knob { transition: none; }
.pnote { margin: 0; font-size: 12px; color: var(--red); min-height: 1em; }
.pclose { align-self: flex-end; height: 30px; padding: 0 12px; font-size: 13px; border: 1.5px solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; }

/* 終わり：みんな帰って がらん とした部屋。▼ は部屋そのもの */
.loop { left: 20%; right: 20%; top: 40%; height: 60px; display: flex; align-items: center; justify-content: center; }
.loop .empty { position: static; color: var(--dim); font-size: 14px; }
.loop .mark { top: -14px; }
.loop .say { top: -34px; }
.room.nofuji .fujiw .fuji .mt { opacity: 0; }
.room.nohato .clock .bird { display: none; }
.room.nohato .clock .door { transform: scaleX(.15); }

/* フタモジ v2：絵の下のローマ字の札・貼り紙・設定の 2 項目 */
.room { --fs: 1; }
.capw { left: 12px; top: calc(36px + min(34vw, 140px) * .7); width: 34%; max-width: 140px; display: flex; justify-content: center; }
.capw .cap { font-size: calc(14px * var(--fs)); letter-spacing: 1px; font-family: ui-monospace, "Courier New", monospace; }
.capw .mark { top: -20px; }
.capw.pop .cap { animation: pop .45s; }
.room .poster { position: absolute; left: 12px; top: calc(70px + min(34vw, 140px) * .7); z-index: 1; font-size: calc(12px * var(--fs)); max-width: 42%; }
.room .poster { white-space: nowrap; }
.clockw .plate, .clockw .anc { font-size: calc(13px * var(--fs)); }
.p .plate { font-size: calc(13px * var(--fs)); }
.prow { position: relative; }
.prow .mark { position: absolute; top: -18px; left: 14px; color: var(--red); font-size: 18px; line-height: 1; animation: bob 1s ease-in-out infinite; }
.prow .say { position: absolute; top: -28px; right: 0; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 3px 7px; font-size: 12px; white-space: nowrap; animation: pop2 .25s ease-out; z-index: 3; }
.prow.blast .slider .fill { background: var(--red); }
.prow.blast .slider .knob { animation: wob .5s 3; }
.prow.wob { animation: wob .5s; }
.vanish { animation: vanish .6s ease-in forwards; }
@keyframes vanish { to { opacity: 0; transform: scale(.85); } }
.capw.vanish, .clockw.vanish, .fujiw.vanish { animation: vanish .6s ease-in forwards; }
.tool:disabled { opacity: .35; }
.panel { left: auto; right: 8px; bottom: auto; top: calc(84px + min(34vw, 140px) * .7); width: max-content; min-width: 54%; max-width: calc(100% - 16px); padding: 6px 10px 8px; gap: 8px; }
.panel .prow { gap: 8px; font-size: 14px; }
.panel .ph { font-size: 11px; }
.capF { position: relative; display: inline-block; }
.capF[hidden] { display: none !important; }
.cap .anc { display: inline-flex; }
.callbar.nosan .lab { display: none; }
.capF .mark { position: absolute; top: -24px; left: 50%; transform: translateX(-50%); color: var(--red); font-size: 18px; line-height: 1; animation: bob 1s ease-in-out infinite; z-index: 5; font-family: inherit; }
.capF .say { position: absolute; top: -30px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 3px 7px; font-size: 12px; white-space: nowrap; z-index: 6; font-family: inherit; animation: pop2 .25s ease-out; }
.capF.pop { animation: pop .45s; }
.capw > .mark { display: none; }
.volset { display: flex; flex-direction: column; gap: 8px; }
.volset[hidden] { display: none !important; }
.gauge { flex: 1 1 auto; height: 10px; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--card); overflow: hidden; }
.gauge i { display: block; height: 100%; background: var(--pre); }
.gl { flex: 0 0 auto; font-size: 12px; color: var(--dim); width: 1.2em; }
.prow.blast .gauge i { background: var(--red); }
.panel { padding-left: 22px; }
.panel .prow .mark { top: 50%; left: -18px; transform: translateY(-50%) rotate(-90deg); animation: none; }
.ph { position: relative; }
.ph .pt { font-family: ui-monospace, "Courier New", monospace; font-size: 13px; color: var(--ink); letter-spacing: 1px; }
.ph .mark { position: absolute; top: 50%; left: -18px; transform: translateY(-50%) rotate(-90deg); color: var(--red); font-size: 18px; line-height: 1; }
.ph .say { position: absolute; top: -26px; left: 40px; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 3px 7px; font-size: 12px; white-space: nowrap; z-index: 3; animation: pop2 .25s ease-out; }
.ph.pop .pt { animation: pop .45s; display: inline-block; }
.toggle { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 4px; overflow: hidden; }
.toggle button { height: 30px; min-width: 44px; font-size: 14px; border: 0; background: var(--card); cursor: pointer; }
.toggle button + button { border-left: 1.5px solid var(--ink); }
.toggle button.on { background: var(--pre); color: #fff; }
.room .poster[hidden] { display: none !important; }
.poster.vanish { animation: vanish .6s ease-in forwards; }
.panel.vanish { animation: vanish .7s ease-in forwards; }
/* --- 最後の段：帯の題名「フタモジ」に ▼（左向き）・係の一言の 文字 --- */
.title { position: relative; }
.title:has(.mark) { margin-right: 16px; }
.title .mark { position: absolute; top: 50%; right: -18px; transform: translateY(-50%) rotate(90deg); color: var(--red); font-size: 18px; line-height: 1; }
.title .say { position: absolute; top: calc(100% + 6px); left: 0; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; padding: 3px 7px; font-size: 12px; font-weight: 400; white-space: nowrap; z-index: 7; animation: pop2 .25s ease-out; }
.title.pop .plate { animation: pop .45s; display: inline-block; }
.talk .line .lanc { display: inline; }
.talk .line .lanc .slot { vertical-align: middle; }
.talk .line .lanc .lab { font-weight: 700; }
.appear { animation: appear .45s ease-out; }
@keyframes appear { from { opacity: 0; } }
