/* ==========================================
   SLIME SMASH 3D — ポップ＆ぷにぷにUI（スコア中央配置）
   ========================================== */
:root {
  --ui-font: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Arial Rounded MT Bold', 'BIZ UDPGothic',
    'Yu Gothic UI', 'Meiryo', sans-serif;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-edge: #ffffff;
  --ink: #1e293b;
  --ink-soft: #64748b;
  --slime: #22c55e;
  --slime-dark: #14532d;
  --drop: 0 5px 0 rgba(15, 23, 42, 0.35), 0 12px 24px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #111622;
  font-family: var(--ui-font);
  color: #ffffff;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

[hidden] {
  display: none !important;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  cursor: grab;
  /* タッチ操作でのスクロール・ピンチ拡大を止め、ドラッグをゲームに渡す */
  touch-action: none;
}

#canvas-container.grabbing {
  cursor: grabbing;
}

#ui-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

/* ---------- 上段: ロゴ / スコア / 記録 ---------- */
.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
}

.brand-badge {
  justify-self: start;
  margin-left: 52px; /* 左上の文字ON/OFFボタンの分あける */
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  border-radius: 999px;
  padding: 6px 16px 6px 10px;
  box-shadow: var(--drop);
}

.slime-icon {
  font-size: 22px;
  filter: drop-shadow(0 2px 0 rgba(20, 83, 45, 0.5));
}

.brand-badge h1 {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #16a34a;
  white-space: nowrap;
}

.score-center {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.score-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #ffffff;
  text-shadow: 0 2px 0 rgba(15, 23, 42, 0.7);
  margin-bottom: 4px;
}

.score-value {
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
  font-weight: 800;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(15, 23, 42, 0.55), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.score-value.bump {
  animation: scoreBump 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scoreBump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.1);
    color: #fde047;
  }
  100% {
    transform: scale(1);
  }
}

.stats-bar {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 8px;
}

.stat-card {
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  border-radius: 18px;
  padding: 5px 12px 6px;
  min-width: 84px;
  text-align: center;
  box-shadow: var(--drop);
}

.stat-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 900;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
}

.stat-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.stat-value.accent {
  color: #f59e0b;
  text-shadow: 0 2px 0 #92400e;
}

.combo-card.hot {
  background: linear-gradient(#fff7d6, #ffe08a);
  animation: comboWiggle 0.5s ease-in-out infinite alternate;
}

@keyframes comboWiggle {
  from {
    transform: rotate(-3deg) scale(1.03);
  }
  to {
    transform: rotate(3deg) scale(1.08);
  }
}

/* ---------- タイムアタックの残り時間 ---------- */
.timer-pill {
  margin-top: 6px;
  background: var(--panel);
  color: var(--ink);
  border: 3px solid var(--panel-edge);
  border-radius: 999px;
  padding: 2px 14px 3px;
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--drop);
  min-width: 64px;
  text-align: center;
}

.timer-pill::before {
  content: '⏱ ';
  font-size: 0.85em;
}

.timer-pill.hurry {
  background: linear-gradient(#fecaca, #f87171);
  color: #7f1d1d;
}

/* ---------- 文字ON/OFFボタン ---------- */
.text-toggle {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  z-index: 12;
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--drop);
}

.text-toggle[aria-pressed='true'] {
  opacity: 0.55;
  text-decoration: line-through;
}

/* 文字OFF: スコアと残り時間・アイコンだけ残し、説明や演出の文字を消す */
body.text-off .brand-badge,
body.text-off .stats-bar,
body.text-off .score-label,
body.text-off #feedback-container,
body.text-off #center-banner,
body.text-off .hint-bubble,
body.text-off .meter-label,
body.text-off .type-name,
body.text-off .action-btn span {
  display: none !important;
}

/* ---------- 着弾ポップアップ ---------- */
#feedback-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 15;
}

.smash-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(15, 23, 42, 0.7), 0 4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  animation: popFloat 0.95s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  white-space: nowrap;
}

@keyframes popFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.4) rotate(-8deg);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -65%) scale(1.15) rotate(3deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -150%) scale(0.95) rotate(0deg);
  }
}

/* ---------- 画面中央の大きな演出 ---------- */
#center-banner {
  position: fixed;
  left: 50%;
  top: 40%;
  z-index: 16;
  pointer-events: none;
  transform: translate(-50%, -50%);
  font-size: clamp(1.5rem, 4.5vw, 2.6rem);
  font-weight: 800;
  white-space: nowrap;
  color: var(--banner-color, #fde047);
  text-shadow: 0 3px 0 rgba(15, 23, 42, 0.75), 0 6px 18px rgba(0, 0, 0, 0.4);
  opacity: 0;
}

#center-banner.show {
  animation: bannerPop 1.1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes bannerPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-10deg);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15) rotate(3deg);
  }
  35% {
    transform: translate(-50%, -50%) scale(1) rotate(-1deg);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -55%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -70%) scale(0.9);
  }
}

/* ---------- スイングパワー ---------- */
#swing-meter-wrap {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  box-shadow: var(--drop);
  padding: 10px 7px;
  border-radius: 999px;
}

.meter-label {
  writing-mode: vertical-rl;
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}

.meter-track {
  width: 14px;
  height: 150px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  box-shadow: inset 0 2px 3px rgba(15, 23, 42, 0.25);
}

#swing-meter-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, #22c55e, #facc15, #f43f5e);
  border-radius: 999px;
  transition: height 0.06s linear;
}

/* ---------- 下段: スライム選択とボタン ---------- */
.hud-bottom {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.slime-selector,
.action-buttons {
  pointer-events: auto;
}

.slime-selector {
  background: var(--panel);
  border: 3px solid var(--panel-edge);
  border-radius: 999px;
  padding: 6px;
  box-shadow: var(--drop);
}

.color-buttons {
  display: flex;
  gap: 6px;
}

.type-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.type-btn .dot {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 46% 46% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, var(--c) 34%);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 55%, black);
}

.type-name {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.type-btn:hover .type-name {
  opacity: 1;
}

.type-btn:hover {
  transform: translateY(-3px) scale(1.08);
}

.type-btn.active {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 20%, white);
  transform: scale(1.12);
}

.type-btn:active {
  transform: scale(0.92);
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.action-btn {
  background: #ffffff;
  border: 3px solid #ffffff;
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 5px 0 #94a3b8, 0 10px 18px rgba(0, 0, 0, 0.2);
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.12s;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #94a3b8, 0 12px 20px rgba(0, 0, 0, 0.22);
}

.action-btn:active {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 1px 0 #94a3b8, 0 4px 8px rgba(0, 0, 0, 0.2);
}

.action-btn.primary {
  background: linear-gradient(#4ade80, #16a34a);
  border-color: #bbf7d0;
  color: #ffffff;
  text-shadow: 0 2px 0 var(--slime-dark);
  box-shadow: 0 5px 0 var(--slime-dark), 0 10px 18px rgba(0, 0, 0, 0.2);
}

.action-btn.primary:hover {
  box-shadow: 0 7px 0 var(--slime-dark), 0 12px 20px rgba(0, 0, 0, 0.22);
}

.action-btn.primary:active {
  box-shadow: 0 1px 0 var(--slime-dark), 0 4px 8px rgba(0, 0, 0, 0.2);
}

.action-btn.share {
  background: #0f172a;
  border-color: #334155;
  color: #ffffff;
  box-shadow: 0 5px 0 #000000, 0 10px 18px rgba(0, 0, 0, 0.2);
}

.action-btn.share:hover {
  box-shadow: 0 7px 0 #000000, 0 12px 20px rgba(0, 0, 0, 0.22);
}

.action-btn.share:active {
  box-shadow: 0 1px 0 #000000, 0 4px 8px rgba(0, 0, 0, 0.2);
}

#btn-slowmo.primary {
  background: linear-gradient(#a5b4fc, #6366f1);
  border-color: #e0e7ff;
  text-shadow: 0 2px 0 #312e81;
  box-shadow: 0 5px 0 #312e81, 0 10px 18px rgba(0, 0, 0, 0.2);
}

/* ---------- 初回の操作説明 ---------- */
.hint-bubble {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  z-index: 14;
  pointer-events: none;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 18px;
  box-shadow: var(--drop);
  white-space: nowrap;
  animation: hintBob 1.2s ease-in-out infinite alternate;
}

.hint-bubble b {
  color: var(--slime);
}

.hint-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 10px solid transparent;
  border-top-color: #ffffff;
}

@keyframes hintBob {
  from {
    transform: translate(-50%, 0);
  }
  to {
    transform: translate(-50%, -8px);
  }
}

/* ---------- タイトル画面 ---------- */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(15, 21, 34, 0.35), rgba(15, 21, 34, 0.85));
  cursor: pointer;
  transition: opacity 0.35s ease;
  touch-action: manipulation;
}

#title-screen.leaving {
  opacity: 0;
  pointer-events: none;
}

.title-card {
  text-align: center;
  padding: 16px;
}

.title-slime {
  font-size: 40px;
  animation: titleJiggle 0.9s ease-in-out infinite alternate;
  filter: drop-shadow(0 6px 0 rgba(20, 83, 45, 0.6));
}

@keyframes titleJiggle {
  from {
    transform: scale(1.08, 0.92) translateY(4px);
  }
  to {
    transform: scale(0.94, 1.08) translateY(-6px);
  }
}

.title-logo {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #4ade80;
  text-shadow: 0 3px 0 #14532d, 0 8px 24px rgba(0, 0, 0, 0.45);
  margin-top: 8px;
}

.title-sub {
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 2px 0 #0f172a;
}

.title-modes {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.title-start {
  display: inline-block;
  cursor: pointer;
  font-family: inherit;
  background: linear-gradient(#4ade80, #16a34a);
  border: 3px solid #bbf7d0;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 800;
  padding: 11px 26px;
  border-radius: 999px;
  text-shadow: 0 2px 0 var(--slime-dark);
  box-shadow: 0 6px 0 var(--slime-dark), 0 14px 26px rgba(0, 0, 0, 0.35);
  animation: startPulse 1s ease-in-out infinite alternate;
}

@keyframes startPulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.04);
  }
}

.title-free {
  cursor: pointer;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #ffffff;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 8px 22px;
  border-radius: 999px;
  box-shadow: 0 5px 0 #94a3b8, 0 10px 20px rgba(0, 0, 0, 0.3);
}

.title-best {
  margin-top: 14px;
  font-size: 0.85rem;
  font-weight: 800;
  color: #fde047;
  text-shadow: 0 2px 0 #0f172a;
}

/* ---------- 結果画面 ---------- */
#result-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 21, 34, 0.7);
  animation: resultFade 0.3s ease;
}

@keyframes resultFade {
  from {
    opacity: 0;
  }
}

.result-card {
  width: min(360px, 100%);
  text-align: center;
  background: var(--panel);
  color: var(--ink);
  border: 4px solid #ffffff;
  border-radius: 26px;
  padding: 22px 18px 20px;
  box-shadow: var(--drop);
  animation: resultPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes resultPop {
  from {
    transform: scale(0.6);
  }
}

.result-title {
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}

.result-new {
  margin-top: 6px;
  font-size: 0.9rem;
  font-weight: 900;
  color: #f59e0b;
  text-shadow: 0 2px 0 #92400e33;
}

.result-score {
  margin-top: 4px;
  font-size: 2.4rem;
  font-weight: 800;
  color: #16a34a;
  font-variant-numeric: tabular-nums;
}

.result-best,
.result-stats {
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.result-actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* 結果画面のボタンは小画面でも横並び・読める大きさに */
#result-screen .action-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  padding: 9px 16px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* PCなど広い画面: ボタン類を左の縦列に寄せ、床のスライムを隠さない */
@media (min-width: 761px) and (min-height: 501px) {
  .hud-bottom {
    position: fixed;
    left: max(20px, env(safe-area-inset-left));
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 12px;
  }
  .slime-selector {
    border-radius: 30px;
  }
  .color-buttons {
    flex-direction: column;
  }
  /* 色名の吹き出しはボタンの右に出す */
  .type-name {
    bottom: auto;
    top: 50%;
    left: calc(100% + 10px);
    transform: translateY(-50%);
  }
  .type-btn:hover {
    transform: translateX(3px) scale(1.08);
  }
  .action-buttons {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .action-btn {
    padding: 8px 14px;
    text-align: left;
  }
  .hint-bubble {
    bottom: 40px;
  }
}

/* ==========================================
   タッチ端末（スマホ・タブレット）向け
   ========================================== */
.touch-only {
  display: none;
}

@media (pointer: coarse) {
  .mouse-only {
    display: none;
  }
  .touch-only {
    display: inline;
  }
  .type-btn:hover,
  .action-btn:hover {
    transform: none;
  }
  .type-btn:hover .type-name {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-slime,
  .title-start,
  .hint-bubble,
  .combo-card.hot {
    animation: none;
  }
}

/* 小さい画面（スマホ縦・横） */
@media (max-width: 760px), (max-height: 500px) {
  #ui-layer {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .brand-badge {
    display: none;
  }

  .text-toggle {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    width: 36px;
    height: 36px;
    font-size: 0.75rem;
  }

  .timer-pill {
    font-size: 0.95rem;
    margin-top: 4px;
  }

  .stat-card {
    min-width: 0;
    padding: 3px 9px 4px;
    border-radius: 14px;
    border-width: 2px;
  }
  .stat-label {
    font-size: 0.5rem;
  }
  .stat-value {
    font-size: 0.95rem;
  }

  .hud-bottom {
    gap: 8px;
  }

  .type-btn {
    width: 40px;
    height: 40px;
  }
  .type-btn .dot {
    width: 26px;
    height: 26px;
  }

  .action-btn {
    padding: 9px 10px;
    font-size: 0.75rem;
    border-radius: 14px;
  }

  #swing-meter-wrap {
    right: max(6px, env(safe-area-inset-right));
    padding: 7px 5px;
  }
  .meter-label {
    display: none;
  }
  .meter-track {
    width: 9px;
    height: 100px;
  }

  .hint-bubble {
    bottom: 150px;
    font-size: 0.9rem;
  }

  .smash-popup {
    white-space: normal;
    max-width: 90vw;
    text-align: center;
  }
}

/* スマホ縦持ち: スコアを最上段中央、その下に記録を一列に */
@media (max-width: 760px) and (orientation: portrait) {
  .hud-top {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 6px;
  }
  .score-center,
  .stats-bar {
    grid-column: 1;
    justify-self: center;
  }
  .hud-bottom {
    flex-direction: column;
    align-items: center;
  }
  .action-buttons {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    width: 100%;
  }
  /* 縦持ちは6つのボタンを横一列に。アイコンの下に文字を置いて幅を節約する */
  .action-btn {
    min-width: 0;
    padding: 6px 0;
    font-size: 0.62rem;
    line-height: 1.25;
    white-space: normal;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
  }
}

/* スマホ横持ち: 高さが足りないので下段を1行に詰める */
@media (max-height: 500px) and (orientation: landscape) {
  .score-value {
    font-size: 1.6rem;
  }
  /* 横持ちは幅が足りないのでボタンはアイコンだけにする */
  .action-btn span {
    display: none;
  }
  .action-btn {
    padding: 8px 11px;
    font-size: 0.85rem;
  }
  .hud-bottom {
    flex-wrap: nowrap;
  }
  .hint-bubble {
    bottom: 80px;
  }
  .meter-track {
    height: 80px;
  }
}
