/* 端末の「見えている高さ」に収める。44pxの操作を縮小したり、下端を隠して解決しない。 */
#app { height: 100dvh; max-height: 100dvh; min-height: 0; border: 0; border-radius: 0; overflow: auto; }
#app[data-screen="home"] { --home-height: 100dvh; }
#app[data-screen="home"] .topbar { position: absolute; inset: 0 0 auto; height: 0; padding: 0; }
#app[data-screen="home"] .settings-button { position: absolute; top: var(--back-top); right: calc(14px + env(safe-area-inset-right)); }
#app[data-screen="home"] .masthead-home { top: calc(env(safe-area-inset-top) + 60px); left: 15%; right: auto; width: 70%; height: clamp(66px,11dvh,104px); transform: none; }
#app[data-screen="home"] main { height: 100%; min-height: 0; }
#app .home { height: 100%; min-height: 0; padding: calc(env(safe-area-inset-top) + 62px) max(12px,4%) max(8px,env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) auto auto auto; gap: 6px; align-content: stretch; }
#app .home__intro { grid-area: 1 / 1; padding: 0; min-height: 0; }
#app .home-art { inset: 0; min-height: 0; height: 100%; }
#app .home-art img { object-fit: cover; object-position: center 60%; }
#app .home__tagline { position: absolute; top: calc(env(safe-area-inset-top) + clamp(134px,23dvh,170px)); left: 8%; width: 84%; margin: 0; font-size: clamp(.875rem,4cqw,1.1rem); line-height: 1.3; text-wrap: balance; text-shadow: 0 1px 3px #fff8e4,0 0 8px #fff8e4,0 0 12px #fff8e4; }
/* スタートは難易度札・回答方法と釣り合う幅に絞り、中央へ置く。 */
#app .home-start { grid-area: 2 / 1; width: min(66%, 17.5rem); min-width: min(100%, 12rem); justify-self: center; margin: 0; }
#app .menu__item--mint { min-height: 56px; height: 56px; padding: 5px 18px; gap: 8px; justify-content: center; border-radius: 999px; }
#app .menu__item--mint .menu__body strong { font-size: clamp(1.2rem,5.2cqw,1.7rem); line-height: 1.15; }
#app .menu__paw { width: 24px; height: 24px; flex: none; margin: 0; }
#app .home-options { grid-area: 3 / 1; margin: 0; gap: 5px; }
#app .home-options .difficulty-options,
#app .home-options .difficulty-options:has([data-difficulty="oni"]),
html:is(:lang(en),:lang(fr),:lang(es),:lang(de),:lang(pt)) #app .home-options .difficulty-options[data-count] { grid-template-columns: repeat(var(--visible-difficulties,1),minmax(0,1fr)); gap: 4px; padding: 3px; border-radius: 14px; }
/* 解放済みの札だけを並べる。1〜3枚でも1枚を全幅へ伸ばさず、4枚時と同じ札幅で中央に置く。 */
#app .home-options .difficulty-options { width: min(100%, max(8.5rem, calc(var(--visible-difficulties,4) * 25%))); margin-inline: auto; }
#app .home-options .difficulty-options button { min-height: 44px; height: 44px; padding: 3px 2px 12px; border-radius: 10px; }
#app .home-options .difficulty-options button::after { bottom: 3px; width: 6px; height: 6px; left: calc(50% - 3px); }
#app .home-options .difficulty-options strong,
#app .home-options .difficulty-options:has([data-difficulty="oni"]) strong,
html:is(:lang(en),:lang(fr),:lang(es),:lang(de),:lang(pt)) #app .home-options .difficulty-options strong { font-size: .8125rem; line-height: 1.15; overflow-wrap: normal; word-break: normal; }
#app .home-unlock-hint { margin: 3px 0 0; font-size: .75rem; line-height: 1.25; }
#app .home-options .answer-style .tabs,
html:is(:lang(en),:lang(fr),:lang(es),:lang(de),:lang(pt)) #app .home-options .answer-style .tabs { width: 100%; padding: 2px; }
#app .home-options .tabs button,
html:is(:lang(en),:lang(fr),:lang(es),:lang(de),:lang(pt)) #app .home-options .tabs button { min-height: 44px; padding: 4px; font-size: .8125rem; }
#app .home__setup { grid-area: 4 / 1; margin: 0; padding: 0; min-height: 0; }
#app .menu { gap: 6px; }
#app .menu__item--howto, #app .menu__item--highscore { min-height: 44px; padding: 4px 5px; gap: 4px; }
#app .menu__item--howto .menu__body strong, #app .menu__item--highscore .menu__body strong { font-size: .8125rem; line-height: 1.15; overflow-wrap: normal; }
#app .menu__item--howto .menu__icon, #app .menu__item--highscore .menu__icon { width: 19px; height: 19px; flex: none; }
#app .home__slogan { margin: 4px 0 0; font-size: .75rem; line-height: 1.3; }

/* ゲームはHUD、観察窓、回答の3段。回答の高さを固定して正誤で襖を動かさない。 */
#app[data-screen="game"] { height: 100dvh; max-height: 100dvh; display: grid; grid-template-rows: calc(100px + env(safe-area-inset-top)) minmax(0,1fr); padding: 0 0 env(safe-area-inset-bottom); overflow: auto; }
#app[data-screen="game"] .topbar { height: 100%; border-bottom-width: 5px; }
#app[data-screen="game"] .sound-game-toggle { grid-area: auto; position: absolute; top: var(--back-top); right: calc(14px + env(safe-area-inset-right)); }
#app[data-screen="game"] .masthead-home { top: calc(env(safe-area-inset-top) + 50px); left: 50%; right: auto; width: calc(52% - 20px); height: 44px; transform: translateX(-50%); }
#app[data-screen="game"] .hud { inset: calc(env(safe-area-inset-top) + 56px) 12px 3px; grid-template-columns: minmax(60px,24%) minmax(0,1fr) minmax(60px,24%); }
#app .hud__score, #app .hud__lives { padding: 2px 3px; }
#app .hud__score span, #app #lives-label { font-size: .625rem; }
#app .hud__score output { font-size: clamp(1rem,4.7cqw,1.4rem); }
#app .hud__count { top: -39px; left: 60px; right: 60px; }
#app[data-screen="game"] main, #app[data-screen="game"] .game { min-height: 0; height: 100%; }
#app[data-screen="game"] .game { grid-template-rows: 0 minmax(150px,1fr) auto; }
#app .scanner { min-height: 0; grid-template-rows: minmax(0,1fr) 22px; padding: 0 7px; }
#app .scanner__prompt { font-size: .75rem; }
#app .answer { min-height: 0; padding: 8px 10px; gap: 6px; border-top-width: 5px; grid-template-rows: 34px auto 2.7rem; }
#app .answer-clock { min-height: 34px; height: 34px; margin: 0; padding: 3px 7px; }
#app .answer-clock svg { height: 22px; width: 20px; }
#app .answer__timer { font-size: .9375rem; }
#app .choices { height: clamp(112px,16dvh,152px); grid-template-rows: repeat(2,minmax(52px,1fr)); gap: 8px; }
#app .choice { min-height: 44px; padding: 4px; }
#app .choice__name { font-size: clamp(.875rem,4cqw,1.2rem); line-height: 1.16; }
#app .choice .object-icon { height: 100%; width: calc(100% - 44px); max-height: 100%; max-width: 100%; object-fit: contain; }
#app .game-status { height: 3.6em; min-height: 0; margin: 0; font-size: .75rem; line-height: 1.2; }
#app .scanner__feedback, #app .scanner__feedback:has(img) { top: 36%; }
#app .next-round-button { top: auto; bottom: 10px; width: 56%; min-width: 160px; max-width: 220px; height: 44px; min-height: 44px; padding: 4px 8px; font-size: clamp(.875rem,4cqw,1rem); line-height: 1.2; transform: translateX(-50%); }
#app .next-round-button:active { transform: translate(-50%,2px); }

/* 設定は2項目と出典。通常表示はスクロール不要、拡大文字は安全にスクロール可。 */
#app dialog { max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px); padding: 14px; }
#app .dialog__head, #app .howto-dialog__head { margin-bottom: 8px; }
#app .sound-setting { margin-top: 8px; padding-block: 8px; }
#app .sound-setting > div { flex: 1 1 auto; min-width: 0; }
#app .sound-toggle { flex: 0 0 auto; min-width: max-content; max-width: none; }
#app .sound-toggle > span:last-child { white-space: nowrap; }
#app .audio-credits { margin-top: 4px; font-size: .75rem; }
#app .audio-credits p { margin: 6px 0; line-height: 1.35; }

@media (orientation: landscape) {
  #app[data-screen="home"] .masthead-home { top: calc(env(safe-area-inset-top) + 64px); left: 7%; width: 35%; height: clamp(62px,24dvh,112px); }
  #app .home { padding: calc(env(safe-area-inset-top) + 62px) calc(env(safe-area-inset-right) + 14px) max(8px,env(safe-area-inset-bottom)) calc(env(safe-area-inset-left) + 14px); grid-template-columns: minmax(0,.9fr) minmax(0,1.1fr); grid-template-rows: 50px auto auto; gap: 5px 5%; align-content: center; }
  #app .home__intro { grid-area: 1 / 1 / 4 / 2; align-self: stretch; }
  #app .home-art { right: 53%; height: 100%; }
  #app .home-art img { object-position: center 60%; }
  #app .home__tagline { top: calc(env(safe-area-inset-top) + clamp(137px,47dvh,188px)); left: 5%; width: 39%; font-size: .875rem; }
  #app .home-start { grid-area: 1 / 2; width: min(70%, 17.5rem); justify-self: center; }
  #app .home-options { grid-area: 2 / 2; }
  #app .home__setup { grid-area: 3 / 2; }
  #app .home-unlock-hint { font-size: .75rem; }
  #app .home__slogan { font-size: .75rem; }
  #app[data-screen="game"] { grid-template-rows: calc(84px + env(safe-area-inset-top)) minmax(0,1fr); }
  #app[data-screen="game"] .masthead-home { top: calc(env(safe-area-inset-top) + 36px); width: 30%; height: 44px; }
  #app[data-screen="game"] .hud { inset: calc(env(safe-area-inset-top) + 40px) 18% 3px; }
  #app .hud__count { top: -32px; left: 70px; right: 70px; }
  #app[data-screen="game"] .game { grid-template-columns: minmax(0,1.1fr) minmax(240px,1fr); grid-template-rows: minmax(0,1fr); }
  #app .scanner { grid-area: 1 / 1; min-height: 0; }
  #app .answer { grid-area: 1 / 2; grid-template-rows: 30px minmax(96px,1fr) 3em; padding: 5px 8px; gap: 5px; }
  #app .answer-clock { height: 30px; min-height: 30px; }
  #app .choices { height: 100%; min-height: 96px; grid-template-rows: repeat(2,minmax(44px,1fr)); gap: 7px; }
  #app .choice__name { font-size: clamp(.875rem,2cqw,1.2rem); }
  #app .game-status { height: 3em; font-size: .75rem; }
  #app .scanner__feedback, #app .scanner__feedback:has(img) { top: 33%; }
  #app .next-round-button { bottom: 8px; }
  #app #settings-dialog { width: min(calc(100% - 28px),40rem); }
  #app #settings-dialog[open] { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  #app #settings-dialog .dialog__head, #app #settings-dialog .audio-credits { grid-column: 1 / -1; }
  #app #settings-dialog .sound-setting { margin: 0; border: 0; padding: 0; }
  #app #settings-dialog .audio-credits[open] { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  #app #settings-dialog .audio-credits summary { grid-column: 1 / -1; }
}

@media (orientation: landscape) and (max-height: 420px) {
  #app .home { grid-template-rows: 50px auto; }
  #app .home__intro { grid-area: 1 / 1 / 3 / 2; }
  /* 元絵の両取手からコーギーの足元までを等比で切り出す。細い縦帯にしない。 */
  #app .home-art { top: calc(env(safe-area-inset-top) + 90px); bottom: auto; right: auto; left: 23%; width: calc((100dvh - 180px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.30606); max-width: 40%; height: auto; aspect-ratio: 862 / 660; transform: translateX(-50%); border-radius: 12px; background: #eddbb6; }
  #app .home-art img { position: absolute; top: 0; left: 50%; width: auto; height: 276.36364%; min-height: 0; max-width: none; object-fit: contain; transform: translate(-50%,-31.79825%); }
  #app[data-screen="home"] .masthead-home { top: calc(env(safe-area-inset-top) + 12px); left: 9%; width: 34%; height: 44px; }
  #app .home__tagline { top: calc(env(safe-area-inset-top) + 62px); }
  #app .home__setup { grid-area: auto; position: absolute; left: calc(env(safe-area-inset-left) + 14px); right: auto; top: auto; bottom: max(8px,env(safe-area-inset-bottom)); width: 40%; }
}

@media (orientation: portrait) and (max-height: 590px) {
  #app .scanner__feedback, #app .scanner__feedback:has(img) { min-height: 80px; padding-block: 8px; gap: 4px; }
  #app .round-feedback__heading { font-size: 1.5rem; }
  #app .round-feedback__heading[data-long="true"] { font-size: 19px; }
  #app .round-feedback__label { font-size: .875rem; line-height: 1.15; }
}

/* 極端な拡大や極小ウィンドウでも操作を切らず、例外的に自然なスクロールを許可する。 */
@media (orientation: portrait) and (max-height: 479px) {
  #app .home { min-height: 480px; }
  #app[data-screen="game"] .game { min-height: 370px; }
}

/* 日本語の複数文は文ごとに改行し（文言の\n）、対応ブラウザでは文節単位で折り返す。 */
#app .result-details p, #app .game-status, #app .scanner__feedback, #app .howto-dialog__rule, #app .asset-preload p { white-space: pre-line; }
html:lang(ja) #app :is(.result-details p, .game-status, .howto-dialog__rule, .howto-steps li, .home__tagline, .home-unlock-hint, .answer-style__note, .result-scene__cheer, #result-subtitle) { word-break: auto-phrase; overflow-wrap: break-word; text-wrap: pretty; }

/* 秒読み: 3・2・1は縁取りした大きな数字を淡いクリームの丸印に、「ゴー！」はスタートと同じ黄色の札にする。
   JSが毎秒 data-count（3/2/1/go）を付け直し、そのたびに弾むように現れる。 */
#app .scanner__count {
  display: grid;
  place-items: center;
  width: clamp(6.5rem, 30cqw, 8.5rem);
  min-width: 0;
  max-width: none;
  height: clamp(6.5rem, 30cqw, 8.5rem);
  padding: 0;
  border: 3px solid #fff7e2;
  border-radius: 50%;
  outline: 2px dashed #d7a64a;
  outline-offset: -10px;
  background: radial-gradient(circle at 50% 40%, #fffaf0f2, #fbe9c6e8 70%);
  box-shadow: 0 0 0 2px #a8773f, 0 6px 18px #4a2c1440;
  color: #fff8e6;
  font-family: ui-rounded, system-ui, sans-serif;
  font-size: clamp(3.4rem, 17cqw, 4.6rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  -webkit-text-stroke: 7px #5a331a;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #5a331a55;
  animation: sukimatch-count-pop 420ms cubic-bezier(.2, .9, .3, 1.35) both;
}
#app .scanner__count[data-count="go"] {
  width: auto;
  height: auto;
  min-height: 4.5rem;
  padding: .35rem 1.6rem .45rem;
  border: 3px solid #8f5426;
  border-radius: 999px;
  outline: 0;
  background: linear-gradient(#ffe67e, #ffd04e 60%, #ffc338);
  box-shadow: inset 0 3px 0 #fff6ba, 0 4px 0 #8f5426, 0 8px 18px #4a2c1440;
  color: #fffdf3;
  font-size: clamp(2.4rem, 12cqw, 3.2rem);
  white-space: nowrap;
  -webkit-text-stroke: 6px #6a3814;
  /* 「ゴー！」は280msだけ出るので、その間に弾み終える。 */
  animation-name: sukimatch-go-pop;
  animation-duration: 240ms;
}
@keyframes sukimatch-count-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(.94); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes sukimatch-go-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6) rotate(-6deg); }
  65% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(2deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  #app .scanner__count, #app .scanner__count[data-count="go"] { animation: none; }
}

/* 次へ/再挑戦は正誤札の直下（JSで測った位置）。測定前は札の下の既定位置。 */
#app .next-round-button, #app .next-round-button:active { top: var(--next-round-top, 62%); bottom: auto; }

/* 初回の画像先読みは全画面の読み込み画面。生成イラストと進捗をDOMで重ね、完了でホームを見せる。 */
#app .asset-preload { position: fixed; z-index: 30; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 24px) calc(env(safe-area-inset-right) + 24px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 24px); color: #4a2c17; text-align: center; background: radial-gradient(circle at 50% 42%, #fffaf0 0, #fbefd8 48%, #efd9b4 100%); transition: opacity .35s ease, visibility 0s linear .35s; }
#app .asset-preload__art { width: min(62vw, 34dvh, 260px); height: auto; aspect-ratio: 480 / 457; animation: asset-preload-hop .9s ease-in-out infinite; }
#app .asset-preload__title { margin: 4px 0 0; font-size: clamp(1.35rem, 6vw, 1.8rem); font-weight: 900; letter-spacing: .04em; }
#app .asset-preload progress { width: min(72vw, 17rem); height: 10px; accent-color: #5f884c; }
#app .asset-preload p { margin: 0; }
#app #asset-progress-label { max-width: 20rem; font-size: .8125rem; line-height: 1.45; color: #6a4a30; }
#app .asset-preload .link-button { min-height: 44px; padding: 8px 18px; border: 1px solid #95714c; border-radius: 12px; background: #fff4de; color: #4a2c17; font-weight: 800; }
#app .asset-preload[data-state="error"] .asset-preload__art { animation: none; }
#app .asset-preload[data-state="ready"] { opacity: 0; visibility: hidden; pointer-events: none; }
@keyframes asset-preload-hop { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { #app .asset-preload__art { animation: none; } }
@media (orientation: landscape) and (max-height: 500px) {
  #app .asset-preload { gap: 6px; }
  #app .asset-preload__art { width: min(40dvh, 200px); }
  #app .asset-preload__title { font-size: 1.25rem; }
}
