:root {
  --ink: #1a1a1a;
  --cyan: #28b9e6;
  --yellow: #ffd23b;
  --red: #ef3e2e;
  --pink: #ff6fb0;
  --magenta: #d63aa8;
  --bg: #eef0f3;
  /* 統一トークン */
  --bd: 4px; /* 枠線の太さ */
  --shadow: 4px 4px 0 var(--ink); /* コミック調ドロップシャドウ（統一） */
  --shadow-press: 2px 2px 0 var(--ink); /* 押下時 */
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation; /* iOSのダブルタップズームを無効化 */
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #d9dde2;
  font-family: "Mochiy Pop One", sans-serif;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  max-width: 560px; /* デスクトップでも縦長で表示 */
  background: var(--bg);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-pill {
  background: #fff;
  border: var(--bd) solid var(--ink);
  border-radius: 16px;
  padding: 6px 14px 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 84px;
}

.hud-label {
  font-family: "Bungee", sans-serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink);
  line-height: 1;
}

.hud-value {
  font-family: "Bungee", sans-serif;
  font-size: 26px;
  line-height: 1.05;
  color: var(--ink);
}

/* スコアは中央（TIMEは左、ミュートは右上に分離して重なり回避） */
#hud-score {
  position: absolute;
  left: 50%;
  top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
}
#hud-time .hud-value {
  color: var(--red);
}
#hud-score .hud-value {
  color: var(--cyan);
}

#hud-time.warn .hud-value {
  animation: blink 0.5s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

/* ---------- Mute button (always visible) ---------- */
/* right だとロゴの overflow で位置が崩れるため、#app基準の left で右上に固定 */
.mute-btn {
  position: absolute;
  left: calc(100% - 60px); /* #app の右端付近 */
  top: max(12px, env(safe-area-inset-top));
  z-index: 30;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: #fff;
  border: var(--bd) solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.mute-btn:active {
  transform: translate(2px, 2px);
}
.mute-btn.muted {
  background: #d7dbe0;
  opacity: 0.85;
}

/* ---------- SHAKE button ---------- */
.shake-btn {
  position: absolute;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Bungee", sans-serif;
  font-size: 18px;
  letter-spacing: 1px;
  color: #fff;
  background: var(--magenta);
  border: var(--bd) solid var(--ink);
  border-radius: 999px;
  padding: 10px 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.shake-btn:active {
  transform: translateX(-50%) translate(2px, 2px);
  box-shadow: var(--shadow-press);
}
.shake-btn .shake-ico {
  font-size: 18px;
}

/* ---------- Countdown ---------- */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 16;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.countdown span {
  font-family: "Luckiest Guy", "Bungee", cursive;
  font-size: clamp(120px, 42vw, 240px);
  line-height: 1;
  color: var(--yellow);
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(8px 8px 0 var(--ink));
}
.countdown span.go {
  font-size: clamp(80px, 30vw, 170px);
  color: var(--red);
}
.countdown span.pop {
  animation: cdPop 0.6s cubic-bezier(0.2, 1.5, 0.35, 1) both;
}
@keyframes cdPop {
  0% {
    transform: scale(2.6) rotate(-8deg);
    opacity: 0;
  }
  55% {
    opacity: 1;
  }
  70% {
    transform: scale(0.9) rotate(3deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(255, 255, 255, 0.55),
    rgba(210, 215, 222, 0.85)
  );
  text-align: center;
}

/* タイトルは背景の落下ツムを見せたいので薄い膜だけ */
#start-screen {
  background: rgba(238, 240, 243, 0.28);
}

/* リザルト: ロゴは上、結果表示部は中央、RETRYは下固定 */
#over-screen {
  justify-content: center;
  gap: 14px;
}
#over-screen .result-title {
  position: absolute;
  top: 5vh;
  left: 50%;
  transform: translateX(-50%) rotate(-3deg);
  margin: 0;
}
/* ロゴとボタンの間。多すぎる時だけこの領域内でスクロール（ボタンと被らない） */
.result-mid {
  position: absolute;
  left: 0;
  right: 0;
  top: 14vh;
  bottom: 96px; /* ボタンぶんだけ空ける（できるだけ広く） */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow-y: auto;
  padding: 0 20px;
  -webkit-overflow-scrolling: touch;
}
.result-actions {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom)); /* ボタンを下げる */
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.result-actions .pop-btn {
  padding: 13px 26px; /* 2つ横並びのため少し詰める */
}
.result-actions .share-btn {
  background: #1d9bf0; /* X っぽいブルー（.pop-btn の赤を上書き） */
  white-space: nowrap;
}

.burst-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: rotate(-4deg);
  filter: drop-shadow(6px 6px 0 var(--ink));
}
.burst-title .line1,
.burst-title .line2 {
  font-family: "Luckiest Guy", "Bungee", cursive;
  line-height: 0.92;
  letter-spacing: 2px;
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
}
.burst-title .line1 {
  font-size: 64px;
  color: var(--yellow);
}
.burst-title .line2 {
  font-size: 84px;
  color: var(--cyan);
}
.burst-title.small .line1 {
  font-size: 48px;
  color: var(--yellow);
}
.burst-title.small .line2 {
  font-size: 64px;
  color: var(--red);
}
.burst-title .solo {
  font-family: "Luckiest Guy", "Bungee", cursive;
  font-size: clamp(60px, 21vw, 96px); /* 狭い画面でも収まるように */
  line-height: 0.92;
  letter-spacing: 4px;
  color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  display: inline-block;
  transform-origin: center;
  animation: logoBeat 0.5s ease-in-out infinite; /* BPM≒120でビート */
}
.burst-title.result-title {
  transform: rotate(-3deg);
}
.burst-title.result-title .solo {
  font-size: clamp(56px, 20vw, 92px);
  letter-spacing: 3px;
  color: var(--cyan);
  /* リザルトは控えめでクラシックなビート（タイトルとは別） */
  animation: logoBeatSoft 1.6s ease-in-out infinite;
}
@keyframes logoBeatSoft {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.035);
  }
}
@keyframes logoBeat {
  0% {
    transform: scale(1);
  }
  12% {
    transform: scale(1.16) rotate(-2deg);
  }
  28% {
    transform: scale(0.97);
  }
  46% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* ---------- TIME UP banner ---------- */
.timeup-banner {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  overflow: hidden;
}
.timeup-banner .tu-burst {
  position: absolute;
  width: 150vw;
  height: 46vh;
  background: repeating-conic-gradient(
    from 0deg,
    var(--yellow) 0deg 9deg,
    #ffe88a 9deg 18deg
  );
  transform: rotate(-6deg);
  animation: tuBurstIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  opacity: 0.96;
  border-top: 6px solid var(--ink);
  border-bottom: 6px solid var(--ink);
}
.timeup-banner .tu-text {
  position: relative;
  font-family: "Luckiest Guy", "Bungee", cursive;
  font-size: clamp(72px, 26vw, 150px);
  line-height: 0.82;
  text-align: center;
  color: var(--red);
  -webkit-text-stroke: 9px var(--ink);
  paint-order: stroke fill;
  transform: rotate(-6deg);
  filter: drop-shadow(9px 9px 0 var(--ink));
  animation: tuSlam 0.55s cubic-bezier(0.2, 1.5, 0.35, 1) both,
    tuWobble 1.6s ease-in-out 0.55s infinite;
}
@keyframes tuSlam {
  0% {
    transform: rotate(-6deg) scale(3.4);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  75% {
    transform: rotate(-6deg) scale(0.9);
  }
  100% {
    transform: rotate(-6deg) scale(1);
    opacity: 1;
  }
}
@keyframes tuBurstIn {
  0% {
    transform: rotate(-6deg) scaleY(0);
    opacity: 0;
  }
  100% {
    transform: rotate(-6deg) scaleY(1);
    opacity: 0.96;
  }
}
@keyframes tuWobble {
  50% {
    transform: rotate(-3deg) scale(1.04);
  }
}

.subtitle {
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 16px;
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(2deg);
}

.hint {
  font-size: 13px;
  color: #555;
  line-height: 1.7;
}

/* 主要アクションボタン（START / RETRY / X POST）共通 */
.pop-btn {
  font-family: "Bungee", sans-serif;
  font-size: 24px;
  letter-spacing: 1.5px;
  color: #fff;
  background: var(--red);
  border: var(--bd) solid var(--ink);
  border-radius: 16px;
  padding: 13px 32px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.05s, box-shadow 0.05s;
}
.pop-btn:active {
  transform: translate(2px, 2px);
  box-shadow: var(--shadow-press);
}

/* ---------- Sound dialog ---------- */
#sound-screen .burst-title {
  display: none; /* 最初の質問時はロゴ非表示 */
}
.dialog-q {
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 18px;
  color: var(--ink);
  background: #fff;
  border: var(--bd) solid var(--ink);
  border-radius: 16px;
  padding: 10px 22px;
  box-shadow: var(--shadow);
}
.dialog-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
/* ダイアログの選択肢は日本語なので Mochiy、サイズは控えめに */
.dialog-actions .pop-btn {
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 18px;
  padding: 11px 30px;
}
.pop-btn.ghost {
  background: #fff;
  color: var(--ink);
}

/* ---------- Corner buttons (skip / howto) ---------- */
.corner-btn {
  position: absolute;
  z-index: 22;
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: var(--bd) solid var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.corner-btn:active {
  transform: translate(2px, 2px);
  box-shadow: var(--shadow-press);
}
/* スキップはチュートリアル中、下の端に */
.skip-btn {
  bottom: max(20px, env(safe-area-inset-bottom));
  left: calc(100% - 132px); /* 右端寄せ（right だと崩れるため left 基準） */
  z-index: 30;
}
/* あそびかたはタイトル左上 */
.howto-btn {
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
}

/* ---------- Tutorial hint ---------- */
.tutorial-hint {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 14;
  display: flex;
  justify-content: center;
  pointer-events: none; /* 操作の邪魔をしない */
  padding: 0 16px;
}
.tut-bubble {
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 20px;
  line-height: 1.4;
  text-align: center;
  color: var(--ink);
  background: var(--yellow);
  border: var(--bd) solid var(--ink);
  border-radius: 16px;
  padding: 12px 22px;
  box-shadow: var(--shadow);
  transform: rotate(-2deg);
}
.tut-bubble .tut-sub {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: #555;
}

/* ---------- Result ---------- */
.result {
  background: #fff;
  border: var(--bd) solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 28px;
  min-width: 260px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 24px;
  font-family: "Bungee", sans-serif;
  font-size: 22px;
  color: var(--ink);
  padding: 4px 0;
}
.result-row .r-label {
  letter-spacing: 1px;
}
.result-row span:last-child {
  color: var(--yellow);
  font-size: 34px;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
}

/* 広告枠 */
.result-ad {
  width: min(90%, 320px);
  min-height: 60px;
}

/* ---------- Word breakdown ---------- */
.word-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(82%, 320px);
}
.wl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border: var(--bd) solid var(--ink); /* 色は JS から border-color を上書き */
  border-radius: 12px;
  padding: 5px 16px;
}
.wl-word {
  font-family: "Bungee", "Luckiest Guy", sans-serif;
  font-size: 20px;
  letter-spacing: 0.5px;
}
.wl-x {
  font-family: "Bungee", sans-serif;
  font-size: 20px;
  color: var(--ink);
}
.wl-empty {
  font-family: "Mochiy Pop One", sans-serif;
  font-size: 14px;
  color: #777;
}
