:root {
  --bg: #15171c;
  --panel: #20232b;
  --text: #f3efe6;
  --muted: #a9adb8;
  --warm: #ffc15a;
  --caught: #ff7a45;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font: 14px/1.4 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.top { flex: none; height: 40px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.top h1 { margin: 0; font-size: 15px; letter-spacing: .02em; }
.tools { display: flex; gap: 4px; }
.tools button { min-width: 36px; height: 32px; padding: 0 8px; background: transparent; border: 1px solid #444a57; border-radius: 6px; font-size: 12px; }
.tools button[data-lang][aria-pressed="true"] { background: var(--text); color: var(--bg); }
#mute { display: flex; align-items: center; justify-content: center; }
#mute svg { width: 18px; height: 18px; }
#mute .cross, #mute[aria-pressed="true"] .wave { display: none; }
#mute[aria-pressed="true"] .cross { display: inline; }
#mute[aria-pressed="true"] { color: var(--muted); }

/* 写真の帯（飼い主のスマホに届く通知） */
.tray { flex: none; position: relative; height: 86px; display: flex; flex-direction: column; }
/* 枠は上に寄せ、下の 6px に飼い主のすきの線を収める */
#strip { flex: 1; min-height: 0; margin: 0; padding: 0 4px; list-style: none; display: grid; grid-template-columns: repeat(10, minmax(0, 32px)); justify-content: center; align-content: start; gap: 2px; }
#meter-legend { flex: none; height: 12px; margin: 0; padding: 0 4px; display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 10px; font-weight: 700; line-height: 12px; color: var(--muted); white-space: nowrap; }
#meter-legend > span { display: flex; align-items: center; gap: 3px; }
#meter-legend svg { width: 11px; height: 11px; }
#meter-legend .lamp-mark { color: #ffd60a; }

/* 飼い主の気づく度合い: 目（だんだん開く）、区切り、「？」の位置であやしい、右端の家と人でいっぱいになると帰宅 */
#meter { flex: none; height: 17px; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 0 6px 1px; }
.meter-eye { flex: none; width: 21px; height: 14px; }
.meter-eye .lid { transform-origin: 12px 8px; transform: scaleY(var(--open, .22)); transition: transform .4s ease .3s; }
#meter-name { flex: none; min-width: 4.6em; font-size: 11px; font-weight: 800; line-height: 1; color: var(--muted); white-space: nowrap; }
.meter-track { position: relative; flex: 0 1 230px; min-width: 0; display: flex; align-items: center; gap: 4px; }
#meter-cells { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; }
#meter-cells i { flex: 1; height: 9px; border-radius: 2px; background: #2c303a; box-shadow: inset 0 0 0 1px #565d6d; }
#meter-cells i.on { background: #f3a95f; box-shadow: none; }
/* 「ここから あやしい」の印は、遊ぶ画面の黄色いランプと同じ絵（丸、にじむ光、白い照り） */
#meter-cells em { flex: none; width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #ffd60a; }
#meter-cells em svg { width: 14px; height: 14px; }
#meter-cells i.fresh { animation: fill .55s ease-out backwards; }
.meter-home { flex: none; width: 30px; height: 17px; color: #8b92a3; }
#meter[data-level="suspicious"] #meter-name { color: #ffd60a; }
#meter[data-level="suspicious"] #meter-cells i.on { background: #ffd60a; }
#meter[data-level="suspicious"] #meter-cells em { box-shadow: 0 0 9px 2px rgba(255, 214, 10, .8); }
#meter[data-level="suspicious"] .meter-home { color: #ffd60a; }
#meter[data-level="home"] #meter-name, #meter[data-level="home"] .meter-home { color: #ff6a55; }
#meter[data-level="home"] #meter-cells i.on { background: #ff4b3a; }
#meter[data-level="home"] #meter-cells em { color: #ff4b3a; box-shadow: 0 0 9px 2px rgba(255, 75, 58, .8); }
#meter.bump .meter-eye { animation: peek .6s ease-out .3s; }
#meter-gain { position: absolute; right: 30px; top: -17px; z-index: 6; padding: 0 6px; border-radius: 999px; background: var(--caught); color: #fff; font-size: 13px; line-height: 17px; animation: gain 2.2s ease-out .3s both; }
@keyframes fill { from { background: #fff; transform: scaleY(2.3); } 45% { background: #fff; } }
@keyframes peek { 40% { transform: scale(1.6); } }
@keyframes gain { from { opacity: 0; transform: translateY(8px) scale(.5); } 15% { opacity: 1; transform: scale(1.25); } 25%, 80% { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-5px); } }
#strip li { position: relative; aspect-ratio: 5 / 8; min-width: 0; border: 1px dashed #4a505e; border-radius: 4px; }
#strip li.safe { border: 1px solid #8a90a0; }
#strip li.bad { border: 2px solid var(--caught); box-shadow: 0 0 7px rgba(255, 122, 69, .55); }
#strip canvas { display: block; width: 100%; height: 100%; border-radius: 3px; }
#strip li.waiting { border: 1px dashed #4a505e; box-shadow: none; }
#strip li.waiting > * { visibility: hidden; }
/* 届いた写真の動きは中の絵だけに掛ける（枠の下のすきの線は動かさない） */
#strip li.safe:not(.waiting) canvas { animation: arrive .35s ease-out; }
#strip li.bad:not(.waiting) canvas { animation: jitter .45s linear; }
.mark { position: absolute; right: -2px; bottom: -3px; width: 18px; height: 18px; }
#strip .mark { bottom: -1px; }
#strip li:not(.waiting) .mark { animation: pop .3s ease-out; }
.tag { position: absolute; left: -1px; top: -3px; padding: 0 2px; border-radius: 3px; background: #7fd6a0; color: #082b18; font-size: 8px; font-weight: 800; line-height: 1.35; white-space: nowrap; }
/* 帯の吹き出しは、今撮れた写真の印を隠さないよう、部屋の上端（REC と時刻の行の下）に出す。上の行 40 + 帯 86 + 40 */
#bubble { position: fixed; left: 50%; top: 166px; transform: translateX(-50%); z-index: 6; margin: 0; padding: 4px 14px; width: max-content; max-width: min(280px, calc(100% - 96px)); border-radius: 16px; background: #fff7ea; color: #2a2118; font-weight: 700; font-size: 13px; text-align: center; text-wrap: balance; box-shadow: 0 3px 12px rgba(0, 0, 0, .5); pointer-events: none; animation: pop .25s ease-out; }
.flyer { position: fixed; z-index: 5; pointer-events: none; transform-origin: 0 0; border: 3px solid #fff; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
@keyframes arrive { 40% { transform: scale(1.22); } }
@keyframes jitter { 15%, 55% { transform: translateX(-3px); } 35%, 75% { transform: translateX(3px); } }
@keyframes pop { from { scale: .2; } 70% { scale: 1.3; } }

#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#room { display: block; border-radius: 12px; box-shadow: 0 0 0 1px #343945; touch-action: none; user-select: none; -webkit-user-select: none; }

/* 読み込み中: カメラの接続のように、暗い絵に REC の点だけ */
body[data-state="loading"] #stage { position: relative; }
body[data-state="loading"] #stage::after { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px; border-radius: 50%; background: #ff3b30; box-shadow: 0 0 14px #ff3b30; animation: connect 1s ease-in-out infinite alternate; }
@keyframes connect { to { opacity: .25; } }

/* 下の台。右端は「作った話と感想」のボタンの場所 */
.dock { flex: none; height: calc(66px + env(safe-area-inset-bottom, 0px)); padding: 5px 68px calc(5px + env(safe-area-inset-bottom, 0px)) 10px; display: flex; align-items: center; }
.dock > div { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.dock p { margin: 0; }
.go { flex: none; width: 54px; height: 54px; padding: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--warm); color: #2a1a00; box-shadow: 0 0 0 0 rgba(255, 193, 90, .6); animation: beckon 1.8s ease-out infinite; }
.go svg { width: 30px; height: 30px; }
#dock-resume p { font-weight: 700; }
@keyframes beckon { 70%, 100% { box-shadow: 0 0 0 10px rgba(255, 193, 90, 0); } }
.how { flex: 1; min-width: 0; }
/* 最初の画面は、札の下に今日のすきを足した分だけ台を高くする（遊び始めたら元の高さ） */
body[data-state="ready"] .dock { height: auto; min-height: calc(66px + env(safe-area-inset-bottom, 0px)); padding-top: 2px; padding-bottom: calc(3px + env(safe-area-inset-bottom, 0px)); }
.dock #dock-start { flex-wrap: wrap; row-gap: 1px; }
/* 幅は台に合わせる。width 0 と min-width 100% で、横向きと PC の中央の列（auto 幅）を長い1行が押し広げないようにする */
.dock #start-slow { width: 0; min-width: 100%; font-size: 11px; font-weight: 700; line-height: 1.35; text-wrap: balance; word-break: auto-phrase; }
#start-slow-lost { display: inline-block; color: var(--muted); }
.how svg { display: block; width: 132px; height: 24px; margin-bottom: 2px; }
.how p { font-weight: 700; line-height: 1.25; word-break: auto-phrase; }
.said { flex: 1; min-width: 0; line-height: 1.25; }
#reaction { font-size: 14px; font-weight: 800; color: #ff9db4; }
#reaction.bad { color: var(--caught); }
#message { font-size: 13px; }
#shake { flex: none; width: 40px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; border: 1px solid #3b404c; border-radius: 8px; }
#shake svg { width: 24px; height: 24px; }
#shake[aria-pressed="false"] { opacity: .4; }

/* 上の行（名前、言語、消音）は結果の画面でも使えるよう残す */
#result { position: fixed; inset: 40px 0 0 0; z-index: 10; display: flex; flex-direction: column; background: var(--bg); }
.result-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 12px 20px; text-align: center; }
.result-body h2 { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.result-body p { margin: 6px 0; }

/* コマ送りの大きな写真 */
#player-screen { width: min(100%, calc(min(32vh, 440px) / 1.6)); width: min(100%, calc(min(32dvh, 440px) / 1.6)); margin: 0 auto; }
#player { position: relative; display: block; width: 100%; aspect-ratio: 5 / 8; padding: 0; border: 3px solid #5d6372; border-radius: 12px; background: #000; overflow: hidden; touch-action: manipulation; }
#player.bad { border-color: var(--caught); }
#player canvas { display: block; width: 100%; height: 100%; }
#player .mark { right: 4px; bottom: 4px; width: min(36px, 19%); height: auto; aspect-ratio: 1; }
.controls { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 4px; min-height: 36px; }
.controls p { margin: 0; min-width: 0; font-size: 13px; line-height: 1.25; }
.step { flex: none; width: 40px; height: 36px; padding: 0; border: 1px solid #444a57; border-radius: 8px; background: transparent; font-size: 22px; line-height: 1; }
#player-toggle::before { content: "▶"; font-size: 13px; }
#player-toggle[data-playing="true"]::before { content: "❚❚"; font-size: 11px; }
.result-body #player-hint { margin: 0 0 6px; font-size: 11px; color: var(--muted); }

/* ばれた写真の直し方: 最初の画面の絵の札と1行 */
/* 高さは2行分で固定。ばれ方で文が変わっても、コマ送りで下が動かない */
#player-fix { display: flex; align-items: center; justify-content: center; column-gap: 8px; max-width: 440px; min-height: 40px; margin: 4px auto 0; padding: 3px 8px; border: 1px solid var(--warm); border-radius: 8px; background: var(--panel); }
#player-fix.off { visibility: hidden; }
#player-fix svg { flex: none; width: 88px; height: 16px; }
.result-body #player-fix p { margin: 0; min-width: 0; font-size: 12px; font-weight: 800; line-height: 1.35; text-wrap: balance; word-break: auto-phrase; }

/* 全部の写真（5列×2段） */
#result-photos { margin: 0 auto 8px; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(5, minmax(0, 53px)); justify-content: center; gap: 8px 4px; }
#result-photos li { min-width: 0; animation: deliver .25s ease-out backwards; }
#result-photos.now li { animation: none; }
@keyframes deliver { from { opacity: 0; transform: translateY(-14px) scale(1.15); } }
#result-photos button { position: relative; display: block; width: 100%; padding: 0; border: 2px solid #3b404c; border-radius: 6px; background: transparent; }
#result-photos li.bad button { border-color: var(--caught); }
#result-photos li.on button { box-shadow: 0 0 0 2px var(--text); }
#result-photos canvas { display: block; width: 100%; height: auto; border-radius: 4px 4px 0 0; }
#result-photos span { display: block; font-size: 11px; line-height: 1.4; color: var(--muted); }
#result-photos .mark { bottom: 14px; right: 0; width: 19px; height: 19px; }
#result-photos li.closed { border: 2px solid transparent; }
#result-photos .door { display: block; width: 100%; height: auto; border-radius: 4px 4px 0 0; opacity: .85; }

/* 今日の飼い主のすき: 長い窓の後の写真の枠の下の水色の実線。点滅も動きもしない（合図の暖色、ばれの橙と分ける） */
:root { --slow: #9cc9e8; }
#strip li[data-slow]::after, #result-photos li[data-slow]::after { content: ""; position: absolute; left: -1px; right: -1px; top: calc(100% + 3px); height: 3px; border-radius: 2px; background: var(--slow); opacity: .85; pointer-events: none; }
#strip li.bad:not(.waiting)[data-slow]::after { left: -2px; right: -2px; top: calc(100% + 4px); }
#result-photos li { position: relative; }
#result-photos li[data-slow]::after { left: 0; right: 0; top: calc(100% + 2px); }
/* あやしまれたら左右から縮めて消す */
#strip li[data-slow="gone"]::after { transform: scaleX(0); transition: transform .4s ease-in; }
.slow-mark { display: inline-block; width: 18px; height: 3px; margin-right: 5px; border-radius: 2px; background: var(--slow); vertical-align: middle; }
.result-body #result-slow { max-width: 340px; margin: 2px auto 0; font-size: 12px; font-weight: 700; line-height: 1.4; text-wrap: balance; }

/* 結果の画面の上の端に、後ろの帯の光がにじまないようにする */
body[data-state="result"] .tray { visibility: hidden; }

/* 点、飼い主の一言、ばれた回数、称号は写真より上にまとめて、開いた画面に見せる */
.summary { min-width: 0; max-width: 440px; margin: 0 auto 8px; }
.summary p { margin: 4px 0; text-wrap: balance; }
#result-titles span { text-wrap: balance; }
.result-body .owner { position: relative; margin: 8px auto 4px; width: fit-content; max-width: 100%; padding: 7px 14px; background: #fff7ea; color: #2a2118; border-radius: 16px; font-size: 16px; font-weight: 800; line-height: 1.3; }
.owner::before { content: ""; position: absolute; left: 24px; top: -7px; border: 8px solid transparent; border-top: 0; border-bottom-color: #fff7ea; }
.scoreline { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; column-gap: 10px; }
.result-body .score { margin: 0; font-size: 36px; font-weight: 800; line-height: 1.15; }
.scoreline .badges { margin: 0; }
.result-body #result-home { color: var(--caught); font-weight: 800; font-size: 13px; line-height: 1.3; }
#result-caught { font-size: 13px; line-height: 1.3; }
.badges.small { column-gap: 8px; font-size: 12px; color: var(--muted); }
#result-bonus:empty, #result-missed:empty { display: none; }
#result-bonus { color: var(--warm); font-weight: 800; }
#result-missed { opacity: .75; }
.result-body #result-found { font-size: 12px; line-height: 1.3; }
/* 日本語は文節で折る（「1枚｜目」「（練｜習）」にしない。使えないブラウザは今までどおり） */
#result-found, #player-why { word-break: auto-phrase; }
#player-why { display: inline-block; }
#result-titles { display: block; width: 100%; min-height: 40px; margin-top: 4px; padding: 4px 8px; background: var(--panel); border: 1px solid var(--warm); border-radius: 8px; line-height: 1.25; }
#result-titles b { display: block; color: var(--warm); font-size: 13px; }
#result-titles span { display: block; font-size: 11.5px; color: var(--muted); }
#result-titles #result-titles-now { color: var(--text); font-weight: 800; }
#result-titles #result-titles-now[hidden] { display: none; }
.badges { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.title { padding: 3px 14px; border-radius: 999px; background: var(--warm); color: #2a1a00; font-weight: 800; font-size: 16px; }
.new { padding: 1px 8px; border-radius: 4px; background: #e8567c; color: #fff; font-size: 12px; font-weight: 800; }
/* 0点で終わった回の初めての称号は、祝いの赤い札にしない */
.new.quiet { background: transparent; border: 1px solid #555c6b; color: var(--muted); font-weight: 700; }
.result-body .perfect { display: inline-block; padding: 4px 14px; border: 2px solid var(--warm); border-radius: 8px; color: var(--warm); font-weight: 800; transform: rotate(-3deg); }
.plain { min-height: 40px; padding: 0 14px; background: transparent; border: 1px solid #555c6b; border-radius: 8px; }
.aftermath { margin: 18px auto 0; max-width: 300px; }
#result-room { width: min(100%, 240px); margin: 0 auto; }
#result-room canvas { display: block; width: 100%; height: auto; border-radius: 12px; }
.aftermath figcaption { margin-top: 8px; font-weight: 700; }

.result-bar { flex: none; display: flex; gap: 8px; padding: 8px 68px calc(8px + env(safe-area-inset-bottom, 0px)) 12px; min-height: 64px; }
.result-bar button { flex: 1 1 0; min-width: 0; min-height: 48px; padding: 4px 6px; border: 1px solid #6a7180; border-radius: 12px; background: var(--panel); font-weight: 700; font-size: 13px; line-height: 1.25; }
.result-bar #again, .result-bar .main { border: 0; background: var(--warm); color: #2a1a00; }
.result-bar #again { flex-grow: 1.2; font-size: 15px; }
/* 320 幅: 2つのボタンを同じ幅にして「画像を保存・共有」を途中で折らない */
@media (max-width: 340px) {
  .dock #dock-start { column-gap: 6px; }
  .how p { font-size: 13px; }
  .result-bar #again { flex-grow: 1; }
  .result-bar #send { font-size: 12.5px; padding: 4px 2px; white-space: nowrap; }
}
#preview .result-bar #preview-share ~ #preview-save:not([hidden]) { background: var(--panel); color: var(--text); border: 1px solid #6a7180; }
#preview .result-bar #preview-share[hidden] ~ #preview-save { background: var(--warm); color: #2a1a00; border: 0; }

/* 重ねる画面（プレビュー、称号の一覧）。上の行は残し、閉じるは右上（感想のボタンから離す） */
.sheet { position: fixed; inset: 40px 0 0 0; z-index: 12; display: flex; flex-direction: column; background: var(--bg); }
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; }
.sheet-head h2 { margin: 0; font-size: 16px; }
.preview-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 12px; }
#preview-img { display: block; max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; border-radius: 8px; box-shadow: 0 0 0 1px #3b404c; }
#preview-note { flex: none; margin: 0; padding: 6px 12px 0; min-height: 26px; text-align: center; font-size: 13px; }
#preview-text { flex: none; margin: 4px 12px 0; padding: 6px; background: var(--panel); color: var(--text); border: 1px solid #555c6b; border-radius: 8px; font: inherit; font-size: 12px; resize: none; }
/* 一覧は感想のボタンより上で切る */
.titles-body { flex: 1; min-height: 0; overflow-y: auto; margin-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); padding: 0 12px 6px; }
.titles-body > .badges { margin: 4px 0 8px; }
@media (max-height: 700px) {
  #titles-list { gap: 5px; }
  #titles-list li { padding: 5px 10px; line-height: 1.3; }
  #titles-list span { font-size: 11.5px; line-height: 1.25; }
}
#titles-list { margin: 0 auto; padding: 0; max-width: 440px; list-style: none; display: grid; gap: 8px; }
#titles-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid #3b404c; }
#titles-list li.got { border-color: var(--warm); }
#titles-list li.fresh { box-shadow: 0 0 12px rgba(255, 193, 90, .55); }
#titles-list b { flex: none; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: #333846; color: var(--muted); font-size: 18px; }
#titles-list li.got b { background: var(--warm); color: #2a1a00; }
#titles-list strong, #titles-list span { display: block; }
#titles-list span { font-size: 12px; color: var(--muted); }
#titles-open { flex: none; width: 44px; height: 44px; margin-left: auto; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; border: 1px solid #3b404c; border-radius: 8px; color: var(--warm); }
#titles-open svg { width: 26px; height: 26px; }

/* 背の低い縦の画面（360×640、320×568）: 大きな写真を左に縮め、点と一言を右に置く */
@media (max-width: 899px) and (orientation: portrait) and (max-height: 740px) {
  .result-body { display: grid; grid-template-columns: minmax(0, 42%) minmax(0, 1fr); align-content: start; column-gap: 8px; padding: 4px 8px 16px; }
  .reel { display: contents; }
  .reel h2 { display: none; }
  #player-screen { grid-column: 1; grid-row: 1; align-self: center; width: 100%; }
  .summary { grid-column: 2; grid-row: 1; align-self: center; width: 100%; margin: 0; }
  .summary p { margin: 3px 0; }
  .result-body .owner { margin-top: 2px; padding: 6px 8px; font-size: 14px; }
  .owner::before { display: none; }
  .result-body .score { flex-basis: 100%; font-size: 32px; }
  .title { font-size: 14px; padding: 2px 10px; }
  #player-fix, .controls, .result-body #player-hint, .report { grid-column: 1 / -1; min-width: 0; }
  #player-fix { justify-self: center; }
}
@media (max-width: 340px) and (max-height: 600px) {
  .result-body .owner { font-size: 13px; }
  .result-body .score { font-size: 28px; }
  #result-caught, .result-body #result-home { font-size: 12px; }
  #result-titles span { font-size: 11px; }
}

/* 幅の広い画面の結果は2列 */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) {
  .result-body { display: grid; grid-template-columns: auto minmax(0, 440px); grid-template-rows: auto 1fr; justify-content: center; align-items: start; column-gap: 32px; }
  .reel { grid-column: 1; grid-row: 1 / span 2; position: sticky; top: 0; width: 340px; }
  .summary { grid-column: 2; grid-row: 1; width: 100%; }
  .report { grid-column: 2; grid-row: 2; }
  #player-screen { width: min(100%, calc((100vh - 254px) / 1.6)); width: min(100%, calc((100dvh - 254px) / 1.6)); min-width: 130px; }
  .result-bar { justify-content: center; }
  .result-bar button { max-width: 260px; }
}
@media (prefers-reduced-motion: reduce) {
  #result-photos li { animation: none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  /* 背の低い横向き: 写真の下に積むと「左右を押すとめくれる」が下の帯に隠れるので、直し方、ボタン、その行は写真の右に置く */
  .reel { display: grid; width: min(370px, 54vw); grid-template-columns: 140px minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; column-gap: 10px; align-content: start; }
  .reel h2 { display: none; }
  #player-screen { grid-column: 1; grid-row: 1 / span 4; width: min(140px, calc((100dvh - 120px) / 1.6)); min-width: 108px; }
  #player-fix { grid-column: 2; grid-row: 1; flex-direction: column; gap: 3px; width: 100%; margin: 0; padding: 6px 2px; }
  .controls { grid-column: 2; grid-row: 2; flex-wrap: wrap; margin-top: 8px; }
  .controls p { order: -1; flex-basis: 100%; }
  .result-body #player-hint { grid-column: 2; grid-row: 3; margin-top: 8px; }
}

#boot-error { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; background: var(--bg); text-align: center; }
#boot-error button { min-height: 44px; padding: 0 16px; background: var(--panel); border: 1px solid #555c6b; border-radius: 8px; }
.noscript { padding: 24px; text-align: center; }

/* PC と横向き: 絵を高さに合わせて中央に置き、帯は右の 2列×5段 */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) {
  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: 40px minmax(0, 1fr) auto;
    background: repeating-linear-gradient(90deg, #17181c 0 70px, #1a1a1d 70px 71px, #19191d 71px 150px, #15161a 150px 152px);
  }
  .top { grid-column: 1 / -1; }
  #stage { grid-column: 2; grid-row: 2; width: min(calc((100dvh - 106px - env(safe-area-inset-bottom, 0px)) / 1.6), calc(100vw - 300px)); }
  .tray { grid-column: 3; grid-row: 2; align-self: center; justify-self: start; align-items: flex-start; height: auto; max-height: 100%; margin-left: 18px; }
  #strip { flex: none; padding: 0; grid-template-columns: repeat(2, var(--slot)); gap: 6px; --slot: min(60px, calc((100dvh - 196px) / 8)); }
  #meter { flex-wrap: wrap; justify-content: flex-start; width: 160px; height: auto; margin-top: 10px; padding: 0; row-gap: 5px; }
  .meter-track { flex-basis: 100%; }
  #meter-legend { flex-direction: column; align-items: flex-start; gap: 3px; height: auto; margin-top: 6px; padding: 0; font-size: 11px; }
  /* 部屋は画面の中央の列。上の行 40 + REC の行の下 */
  #bubble { top: 78px; max-width: min(280px, 60vw); }
  .dock { grid-column: 2; grid-row: 3; width: max(100%, 340px); justify-self: center; padding-right: 10px; }
}
/* 背の高い PC は部屋が大きいので、REC の行の下まで下げる */
@media (min-width: 900px) and (min-height: 600px) {
  #bubble { top: 108px; }
}
