:root {
  --text: #ffffff;
  --text-soft: rgba(255, 255, 255, 0.72);
  --ink: #2b2a28;
  --accent: #ffcf4d;
  --button: #fbf6ec;
  --pill-bg: rgba(24, 20, 28, 0.55);
  --pill-border: rgba(255, 255, 255, 0.35);
  --panel-shade: linear-gradient(to bottom, rgba(24, 20, 28, 0), rgba(24, 20, 28, 0.82) 38%);
  --gutter: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  color: var(--text);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #2b2333;
  /* スマホのダブルタップでの拡大と，長押ししたときの選択・メニュー・タップの色を出さない */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100dvh;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app {
  position: fixed;
  inset: 0;
}

.app canvas {
  display: block;
  touch-action: none;
}

/* ---- 遊んでいる間の表示 ---- */

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.hud button {
  pointer-events: auto;
}

.hud-count {
  position: absolute;
  top: calc(var(--gutter) + var(--safe-top));
  left: calc(var(--gutter) + var(--safe-left));
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.hud-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
}

.hud-number {
  font-size: 28px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* お渡しボタン（右下の大きなボタン） */
.present-button {
  position: absolute;
  right: calc(var(--gutter) + var(--safe-right));
  bottom: calc(var(--gutter) + var(--safe-bottom));
  min-width: 120px;
  min-height: 52px;
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  background: var(--button);
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.present-button:disabled {
  opacity: 0.45;
}

.hud-buttons,
.screen-top {
  position: absolute;
  top: calc(var(--gutter) + var(--safe-top));
  right: calc(var(--gutter) + var(--safe-right));
  display: flex;
  gap: 8px;
}

.pill-button {
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* セリフ（話す人の名札と，白い吹き出し） */
.speech {
  position: absolute;
  top: calc(var(--safe-top) + 74px);
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: max-content;
  max-width: min(80vw, 380px);
  padding: 8px 14px 10px;
  border-radius: 12px;
  background: rgba(255, 253, 247, 0.96);
  color: var(--ink);
  text-shadow: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
}

.speech.is-popping {
  animation: speechIn 0.25s ease-out;
}

.speech-label {
  padding: 1px 8px;
  border-radius: 4px;
  background: #6b5446;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.speech-text {
  font-size: 15px;
  font-weight: 700;
}

/* 「グシャ」などの浮かぶ文字 */
.popup-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.popup {
  position: absolute;
  font-size: clamp(30px, 8vw, 54px);
  font-weight: 900;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: popupRise 1.1s ease-out forwards;
}

.popup {
  color: #ffffff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 14px rgba(0, 0, 0, 0.5);
}

.hint {
  position: absolute;
  left: calc(var(--gutter) + var(--safe-left));
  right: calc(var(--gutter) * 2 + 130px + var(--safe-right));
  bottom: calc(var(--gutter) + var(--safe-bottom) + 8px);
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--pill-bg);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  animation: hintPulse 1.6s ease-in-out infinite alternate;
}

/* 結果の画面で商品に付ける札 */
/* 結果の画面の暗い重ねより上に出す（札は画面の上の方の袋に付くので，下の文字とは重ならない） */
.tag-layer {
  position: fixed;
  inset: 0;
  z-index: 11;
  pointer-events: none;
}

.tag {
  position: absolute;
  padding: 3px 9px;
  border-radius: 6px;
  background: #c94a3f;
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -100%);
  animation: tagIn 0.3s ease-out backwards;
}

/* ---- タイトル・結果・エラー（景色の下に重ねる） ---- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 var(--gutter) calc(var(--gutter) + var(--safe-bottom));
  background: var(--panel-shade);
}

.panel {
  width: min(380px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 0 4px 6px;
}

.tagline {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.title {
  margin: 0 0 10px;
  font-size: clamp(32px, 9vw, 44px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.title.is-small {
  font-size: 24px;
}

.story {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-soft);
}

.main-button,
.sub-button {
  display: block;
  width: 100%;
  min-height: 52px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.main-button {
  border: none;
  background: var(--button);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.main-button:active {
  transform: translateY(1px);
}

.sub-button {
  margin-top: 10px;
  border: 1px solid var(--pill-border);
  background: var(--pill-bg);
  color: var(--text);
}

.main-button:disabled,
.sub-button:disabled {
  opacity: 0.45;
  cursor: wait;
}

.note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-soft);
}

.note:empty {
  display: none;
}

.best {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.result-name {
  margin: 0 0 12px;
  font-size: clamp(26px, 8vw, 38px);
  font-weight: 900;
  line-height: 1.25;
}

.result-collection {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}

.result-new {
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
}

.result-comment {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

.result-comment .speech-label {
  flex-shrink: 0;
  margin-top: 3px;
}

/* ---- アニメーション ---- */

@keyframes speechIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes popupRise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  18% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  35% { transform: translate(-50%, -70%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}

@keyframes tagIn {
  from { opacity: 0; transform: translate(-50%, -60%) scale(0.7); }
  to { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}

@keyframes hintPulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

@keyframes popupFade {
  0% { opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* 横長の画面は高さが足りないので，タイトルと結果は左に寄せ，セリフは空のあたりに出す */
@media (min-aspect-ratio: 1/1) {
  .speech {
    top: calc(var(--safe-top) + var(--gutter));
  }

  .screen {
    align-items: flex-start;
    justify-content: center;
    padding-left: calc(var(--gutter) * 2 + var(--safe-left));
    background: linear-gradient(to right, rgba(24, 20, 28, 0.78), rgba(24, 20, 28, 0) 60%);
  }

  .title {
    font-size: 34px;
  }

  .story {
    margin-bottom: 12px;
  }
}

/* 動きを減らす設定では，拡大や移動をせずに表示と消去だけにする */
@media (prefers-reduced-motion: reduce) {
  .popup {
    animation-name: popupFade;
  }

  .speech.is-popping,
  .hint {
    animation: none;
  }
}

/* 共通のミニゲーム一覧へ戻る */
.arcade-back {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 14px;
  z-index: 12;
  padding: 8px 12px;
  background: rgba(24, 20, 28, 0.7);
  color: white;
  border-radius: 999px;
  font-size: 12px;
  text-decoration: none;
}
body:has(#hud:not([hidden])) .arcade-back {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
}
