* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(ellipse at top, #23234a 0%, #12121f 60%, #0a0a12 100%);
  color: #fff;
  font-family: 'Courier New', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 12px;
  overflow-x: hidden;
}

.wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 520px;
}

h1 {
  font-size: 2.2rem;
  letter-spacing: 0.18em;
  color: #e0d7ff;
  text-shadow: 0 0 24px rgba(160, 60, 255, 0.7);
  display: flex;
  gap: 0.15em;
}
h1 span { color: #ff5db1; text-shadow: 0 0 24px rgba(255, 60, 160, 0.7); }

.game-area {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  width: 100%;
  justify-content: center;
}

.board-wrap {
  position: relative;
  line-height: 0;
}

#board {
  border: 2px solid #3a3a5c;
  border-radius: 6px;
  background: #0d0d1a;
  display: block;
  box-shadow: 0 0 30px rgba(90, 60, 200, 0.25);
  max-width: 100%;
  height: auto;
  touch-action: none;
}

/* ---- Overlay (pause / gameover) ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(8, 8, 20, 0.78);
  border-radius: 6px;
  backdrop-filter: blur(2px);
  transition: opacity 0.2s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-inner { text-align: center; }
#overlay-title {
  font-size: 1.8rem;
  font-weight: bold;
  letter-spacing: 0.15em;
  color: #fff;
  text-shadow: 0 0 20px rgba(255, 90, 180, 0.8);
}
#overlay-sub { margin-top: 10px; font-size: 0.9rem; color: #b8b0e0; line-height: 1.6; }

/* ---- Toast (combo / level up) ---- */
.toast {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.4rem;
  font-weight: bold;
  color: #ffe14d;
  text-shadow: 0 0 16px rgba(255, 200, 60, 0.9);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { animation: toastPop 0.9s ease-out; }
@keyframes toastPop {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.6); }
  20%  { opacity: 1; transform: translateX(-50%) scale(1.15); }
  70%  { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(0.9); }
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 140px;
  flex-shrink: 0;
}

.panel-box {
  background: rgba(13, 13, 26, 0.85);
  border: 1px solid #333356;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 8px 4px; }

.label {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: #8a86b8;
  margin-bottom: 4px;
}

.value {
  font-size: 1.25rem;
  font-weight: bold;
  color: #e0d7ff;
}

#next, #hold {
  display: block;
  margin: 0 auto;
  background: transparent;
  max-width: 100%;
}

.btn-row { display: flex; gap: 8px; }

#start-btn {
  background: linear-gradient(135deg, #5b4fcf, #8a4fff);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.95rem;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s;
  flex: 1;
}
#start-btn:hover { filter: brightness(1.15); }
#start-btn:active { transform: scale(0.97); }

.icon-btn {
  background: #2a2a44;
  color: #fff;
  border: 1px solid #444;
  border-radius: 8px;
  width: 42px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.icon-btn:hover { background: #3a3a5c; }

/* ---- Touch controls ---- */
.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
.tc {
  background: rgba(42, 42, 68, 0.9);
  color: #fff;
  border: 1px solid #4a4a6c;
  border-radius: 10px;
  padding: 16px 0;
  font-size: 1.3rem;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.tc:active { background: #5b4fcf; }

/* ---- 対戦バー（合言葉マッチング） ---- */
.is-hidden { display: none !important; }

/* ---- 相手盤面パネル（対戦中のみ表示） ---- */
.opp-panel { display: none; flex-direction: column; align-items: center; gap: 8px; }
.versus-active .opp-panel { display: flex; }
.opp-board-wrap { position: relative; line-height: 0; }
#oppBoard {
  border: 2px solid #cf4f8a;
  border-radius: 6px;
  background: #0d0d1a;
  box-shadow: 0 0 18px rgba(207, 79, 138, 0.35);
  display: block;
}
.opp-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 20, 0.72);
  color: #ff8a8a;
  font-weight: bold;
  font-size: 1rem;
  text-align: center;
  line-height: 1.3;
  border-radius: 6px;
}
.opp-stats {
  display: flex;
  gap: 8px;
  font-size: 0.62rem;
  color: #9a94c0;
}
.opp-stats b { color: #e0d7ff; }

.versus-bar {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 400px;
  flex-wrap: wrap;
  justify-content: center;
}
#passphrase {
  flex: 1;
  min-width: 140px;
  background: #0d0d1a;
  border: 1px solid #3a3a5c;
  border-radius: 8px;
  color: #e0d7ff;
  padding: 10px 12px;
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
}
#passphrase:disabled { opacity: 0.5; }
#versus-btn, #ready-btn {
  background: linear-gradient(135deg, #cf4f8a, #ff4f9a);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s;
}
#ready-btn { background: linear-gradient(135deg, #3fae5b, #4fd97a); }
#versus-btn:hover, #ready-btn:hover { filter: brightness(1.15); }
#versus-btn:active, #ready-btn:active { transform: scale(0.97); }

.net-status {
  font-size: 0.8rem;
  color: #9a94c0;
  text-align: center;
  min-height: 1.1em;
  letter-spacing: 0.03em;
}
.net-status.ok  { color: #6ee2a0; }
.net-status.err { color: #ff8a8a; }

.controls {
  font-size: 0.72rem;
  color: #6a6a8a;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.7;
}
.hint-mobile { display: none; color: #7a7aa0; }

/* ---- Responsive / mobile ---- */
@media (max-width: 480px), (pointer: coarse) {
  .touch-controls { display: grid; }
  .hint-mobile { display: block; }
}

@media (max-width: 480px) {
  h1 { font-size: 1.7rem; }
  .game-area { gap: 10px; }
  .side-panel { width: 104px; gap: 8px; }
  .value { font-size: 1rem; }
  .icon-btn { width: 36px; }
}
