html,
body {
  background-color: #111111;
}
body {
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: white;
  margin: 0;
  position: fixed; /* スクロール防止 */
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

[v-cloak] {
  display: none;
}

#app {
  width: 100%;
  height: 100%;
}

.main-wrapper {
  width: 100%;
  height: 100dvh; /* スマホのバー対策 */
  display: flex;
  flex-direction: column;
  /* ★修正: 上下均等配置をやめて、中央に寄せる */
  justify-content: center;
  align-items: center;
  /* ★修正: 各要素の間隔を gap で管理（PCでも間延びしない） */
  gap: 20px;

  transition: background-color 3s ease;
  background-image: radial-gradient(
    circle at center,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(0, 0, 0, 0.4) 100%
  );

  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
}

.main-wrapper.stage-1 {
  background-color: #2c3e50;
}
.main-wrapper.stage-2 {
  background-color: #6a1b9a;
}
.main-wrapper.stage-3 {
  background-color: #922b21;
}

/* === 1. Top Area === */
.top-area {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: center;
  /* 余白調整 */
  margin-bottom: 10px;
}
.game-hud {
  width: 90%;
  max-width: 320px;
  text-align: center;
}

.turn-badge {
  display: inline-block;
  padding: 6px 20px;
  border-radius: 50px;
  font-weight: bold;
  font-size: 1rem;
  margin-bottom: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s;
  letter-spacing: 1px;
}
.my-turn-bg {
  background: #00e676;
  color: #003300;
  transform: scale(1.05);
  border: 2px solid white;
}
.enemy-turn-bg {
  background: #b0bec5;
  color: #37474f;
}

.timer-bar-container {
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.timer-bar {
  height: 100%;
  transition: width 0.3s linear;
}
.bar-active {
  background-color: #00e676;
  box-shadow: 0 0 10px #00e676;
}
.bar-inactive {
  background-color: #b0bec5;
}

/* === 2. Center Area (Board) === */
.center-area {
  flex: 0 0 auto; /* 盤面のサイズを固定的に扱う */
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
}

.emoji-container {
  /* 盤面に被らないように絶対配置をやめ、高さだけ確保 */
  height: 40px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}
.emoji-bubble {
  font-size: 3rem;
  animation: popIn 0.3s;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}
@keyframes popIn {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* 盤面 */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  /* 基本サイズ */
  width: 320px;
  height: 320px;
  /* スマホなどで画面が小さい場合の縮小処理 */
  max-width: 90vw;
  max-height: 90vw; /* 正方形を維持 */
}
.board.disabled {
  opacity: 0.6;
  pointer-events: none;
  filter: grayscale(60%);
}

.cell {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);

  /* ★修正: 縦伸び防止のキモ */
  position: relative; /* 子要素の基準点 */
  overflow: hidden; /* はみ出し防止 */
}
.cell:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.25);
}

/* ★修正: 駒（SVG）を絶対配置にして、親（セル）のサイズに影響させない */
.cell-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.svg-wrapper {
  width: 70%; /* セルに対する駒の大きさ */
  height: 70%;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.cell.own {
  color: #4fc3f7;
}
.cell.enemy {
  color: #ff5252;
}
.fading-own {
  opacity: 0.4;
  transform: scale(0.9);
}
.fading-enemy {
  opacity: 0.4;
  transform: scale(0.9);
}
.highlight-win {
  background-color: #ffeb3b !important;
  color: #3e2723 !important;
  animation: winFlash 0.5s infinite alternate;
  z-index: 10;
}
@keyframes winFlash {
  from {
    box-shadow: 0 0 10px #ffeb3b;
  }
  to {
    box-shadow: 0 0 30px #ffeb3b;
  }
}

.turn-display {
  margin-top: 10px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 10px;
}
.phase-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
}
.turn-number {
  font-size: 1.2rem;
  color: #fff;
}

/* === 3. Bottom Area === */
.bottom-area {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: center;
  /* 高さは成り行き任せ（gapで間隔確保済み） */
  padding-bottom: 10px;
}
.panel {
  width: 90%;
  max-width: 320px;
  text-align: center;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.win-text {
  font-size: 3.5rem;
  margin: 0 0 10px 0;
  color: #ffeb3b;
  text-shadow: 0 0 20px rgba(255, 235, 59, 0.6);
  font-weight: 900;
  line-height: 1;
}
.lose-text {
  font-size: 3.5rem;
  margin: 0 0 10px 0;
  color: #ff5252;
  font-weight: 900;
  line-height: 1;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

/* Stats Area */
.stats-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 8px 0;
  margin-top: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.stat-label {
  font-size: 0.7rem;
  opacity: 0.7;
  letter-spacing: 1px;
}
.stat-value {
  font-size: 1.1rem;
  font-weight: bold;
  color: #4fc3f7;
}
.stat-divider {
  width: 1px;
  height: 25px;
  background: rgba(255, 255, 255, 0.2);
}

.emoji-panel {
  margin-top: 0;
}
.emoji-picker {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.emoji-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 1.4rem;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
  min-width: 40px;
  min-height: 40px;
}
.emoji-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.3);
}
.result-emoji {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.rematch-offer {
  animation: pulse 1s infinite;
}
.offer-text {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 8px;
  color: #4fc3f7;
}
.offer-buttons {
  display: flex;
  gap: 10px;
}
.offer-buttons button {
  flex: 1;
  margin: 0;
}

.room-input {
  display: flex;
  gap: 8px;
  align-items: center; /* 縦位置中央揃え */
}
.room-input input {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 12px;
  border-radius: 8px;
  width: 100%;
  text-align: center;
  font-size: 1rem;
}

button {
  border: none;
  padding: 14px;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  touch-action: manipulation;
}
button:active {
  transform: translateY(2px);
  box-shadow: none;
}
button:disabled {
  background: #b0bec5;
  color: #78909c;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: #29b6f6;
  color: white;
}
.btn-secondary {
  background: #78909c;
  color: white;
}
.btn-small {
  background: #66bb6a;
  color: white;
  padding: 12px 20px;
}
.btn-cancel {
  background: transparent;
  border: 2px solid #ff5252;
  color: #ff5252;
  margin-top: 10px;
  box-shadow: none;
}
.btn-cancel:active {
  background: #ff5252;
  color: white;
}
.btn-disabled {
  background: #cfd8dc;
  color: #90a4ae;
}
/* シェアボタン（アイコン） */
.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0;
  width: 46px; /* 高さ(padding+font+border)に合わせる */
  height: 46px; /* room-inputの高さに合わせる */
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
  /* フレックスボックス内で縮まないように */
  flex-shrink: 0;
}
.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}
.btn-icon:active {
  background: rgba(255, 255, 255, 0.3);
}

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top: 4px solid #29b6f6;
  border-radius: 50%;
  animation: spin 1s infinite linear;
  margin: 0 auto 15px;
}
.room-id-display {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 10px 0;
  letter-spacing: 2px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
