/* ==========================================================================
   Sound Table Tennis (STT) - CSS Design System & Premium Stylesheet
   ========================================================================== */

/* 1. 変数定義 (カラーパレット・グリッド・トランジション) */
:root {
  --bg-primary: #0a0c10;
  --bg-secondary: rgba(18, 22, 32, 0.85);
  --bg-tertiary: rgba(30, 38, 56, 0.9);
  
  /* ネオン調のクリーンな配色 */
  --color-accent: #00f0ff;       /* サイバーシアン (Player 1 / プレイヤー) */
  --color-accent-alt: #ff007f;   /* ネオンマゼンタ (Player 2 / 対戦相手) */
  --color-success: #39ff14;      /* ネオングリーン */
  --color-danger: #ff3131;       /* ネオンレッド */
  --color-warning: #ffaa00;      /* ネオンオレンジ */
  
  --text-main: #f5f6f9;
  --text-muted: #8a99ad;
  --border-glow: rgba(0, 240, 255, 0.2);
  --font-title: 'Outfit', 'Noto Sans JP', sans-serif;
  --font-body: 'Noto Sans JP', -apple-system, sans-serif;
  
  --shadow-neon: 0 0 15px rgba(0, 240, 255, 0.4);
  --shadow-neon-alt: 0 0 15px rgba(255, 0, 127, 0.4);
  --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.6);
  
  --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* 2. リセットと基本スタイル */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(0, 240, 255, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(255, 0, 127, 0.05) 0%, transparent 40%);
  color: var(--text-main);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

/* スクリーンリーダー専用（非表示だが音声読み上げは有効） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* 3. アプリケーションレイアウト */
.app-container {
  width: 100%;
  max-width: 1140px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 90vh;
}

.game-header {
  text-align: center;
  margin-bottom: 30px;
}

.game-header h1 {
  font-family: var(--font-title);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
}

.game-header h1 .accent {
  color: var(--color-accent);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
}

.game-header .subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 5px;
  letter-spacing: 1px;
}

/* 4. ゲームカード（メインパネル） */
.game-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  transition: var(--transition-smooth);
}

.game-card h2 {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
  color: var(--text-main);
}

.game-card .description {
  text-align: center;
  color: var(--text-muted);
  max-width: 600px;
  margin-bottom: 40px;
  font-size: 1rem;
  line-height: 1.8;
}

.visitor-counter {
  max-width: 600px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--text-muted);
  color: var(--text-main);
  font-size: 1rem;
  text-align: center;
}

.visitor-counter p + p { margin-top: 4px; }
.visitor-counter strong { font-variant-numeric: tabular-nums; }

/* 5. ボタンコンポーネント */
.btn {
  font-family: var(--font-title);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  text-decoration: none;
  font-weight: 600;
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-accent) 0%, #00a8ff 100%);
  color: #000;
  padding: 16px 32px;
  font-size: 1.1rem;
  box-shadow: 0 4px 15px rgba(0, 240, 255, 0.3);
}

.btn-primary:hover, .btn-primary:focus {
  transform: translateY(-2px);
  box-shadow: var(--shadow-neon);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-large {
  padding: 24px 48px;
  border-radius: 12px;
}

.btn-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.btn-subtext {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 4px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main);
  padding: 12px 24px;
  font-size: 0.95rem;
  margin-top: 15px;
}

.btn-secondary:hover, .btn-secondary:focus {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, var(--color-danger) 0%, #b30000 100%);
  color: var(--text-main);
  padding: 12px 24px;
  font-size: 0.95rem;
  box-shadow: 0 4px 15px rgba(255, 49, 49, 0.3);
}

.btn-danger:hover, .btn-danger:focus {
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(255, 49, 49, 0.5);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* メニューのグリッド配置 */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  width: 100%;
  max-width: 700px;
  margin-bottom: 30px;
}

@media (max-width: 600px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }
}

/* 難易度選択のグリッド配置 */
.public-mode-menu {
  grid-template-columns: 1fr;
}

.public-mode-menu .mode-primary {
  border: 2px solid var(--color-accent);
}

.public-mode-menu .mode-coming-soon {
  padding: 16px 20px;
  cursor: default;
}

.public-mode-menu .mode-coming-soon .menu-icon {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.public-mode-menu .mode-coming-soon:hover {
  transform: none;
  box-shadow: none;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  width: 100%;
  max-width: 850px;
  margin-bottom: 30px;
}

@media (max-width: 768px) {
  .difficulty-grid {
    grid-template-columns: 1fr;
  }
}

.btn-diff#btn-diff-easy:hover, .btn-diff#btn-diff-easy:focus {
  border-color: var(--color-success);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.2);
}
.btn-diff#btn-diff-normal:hover, .btn-diff#btn-diff-normal:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
}
.btn-diff#btn-diff-hard:hover, .btn-diff#btn-diff-hard:focus {
  border-color: var(--color-accent-alt);
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.2);
}

.btn-menu {
  background: var(--bg-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  padding: 30px 20px;
  border-radius: 12px;
  text-align: center;
  align-items: center;
}

.btn-menu:hover, .btn-menu:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.15);
  transform: scale(1.02);
}

.btn-menu:focus {
  outline: 2px solid var(--color-accent);
}

.btn-menu .menu-icon {
  font-size: 2.2rem;
  margin-bottom: 15px;
}

.btn-menu .menu-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
}

.btn-menu .menu-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* 6. ロビーと入力フォーム */
.lobby-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.input-group label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.input-group input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--text-main);
  padding: 12px 16px;
  font-size: 1rem;
  font-family: var(--font-title);
  outline: none;
  transition: var(--transition-smooth);
}

.input-group input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

/* 7. マッチング待機状態 */
.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(0, 240, 255, 0.1);
  border-left-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pulse-text {
  font-size: 1.1rem;
  color: var(--text-main);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.highlight {
  color: var(--color-accent);
  font-weight: 700;
}

/* 8. ゲームプレイ画面 */
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  margin-bottom: 20px;
  width: 100%;
}

.score-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
  padding: 10px;
  border-radius: 10px;
}

.score-panel.player-1 {
  background: rgba(0, 240, 255, 0.05);
  border: 1px solid rgba(0, 240, 255, 0.15);
}

.score-panel.player-2 {
  background: rgba(255, 0, 127, 0.05);
  border: 1px solid rgba(255, 0, 127, 0.15);
}

.score-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-val {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 800;
}

.player-1 .score-val {
  color: var(--color-accent);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.player-2 .score-val {
  color: var(--color-accent-alt);
  text-shadow: 0 0 10px rgba(255, 0, 127, 0.3);
}

.score-divider {
  font-family: var(--font-title);
  font-size: 2rem;
  color: var(--text-muted);
  font-weight: 300;
}

/* 審判のコールテキスト */
.referee-call {
  background: rgba(0, 0, 0, 0.4);
  border-left: 4px solid var(--color-warning);
  padding: 12px 24px;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: 0 8px 8px 0;
  width: 100%;
  max-width: 600px;
  text-align: center;
  margin-bottom: 15px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.play-instructions {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 15px;
  text-align: center;
}

/* Canvas コンテナ */
.canvas-container {
  width: 100%;
  max-width: 800px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  background: #000;
  margin-bottom: 20px;
  outline: none;
}

.canvas-container:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.3);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.play-controls {
  margin-top: 10px;
}

.quit-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(5px);
}

.quit-confirm-dialog {
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  width: min(100%, 420px);
  padding: 28px;
  border: 2px solid var(--color-danger);
  border-radius: 14px;
  background: var(--bg-secondary);
  box-shadow: 0 0 28px rgba(255, 0, 127, 0.38);
  text-align: center;
}

.quit-confirm-dialog h2 {
  margin: 0 0 12px;
  color: var(--color-danger);
}

.quit-confirm-dialog p {
  margin: 0;
  font-size: 1.1rem;
}

.quit-confirm-stages {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.quit-confirm-stages .btn {
  min-height: 52px;
  width: 100%;
}

.quit-confirm-buttons {
  flex-wrap: wrap;
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}

/* 9. ヘルプとルール説明 */
.help-content {
  text-align: left;
  max-width: 650px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 15px;
  margin-bottom: 25px;
}

.help-content h3 {
  font-size: 1.15rem;
  margin: 20px 0 10px;
  color: var(--color-accent);
  border-bottom: 1px solid rgba(0, 240, 255, 0.2);
  padding-bottom: 5px;
}

.help-content ul, .help-content ol {
  padding-left: 20px;
  margin-bottom: 15px;
}

.help-content li {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.help-content p {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 15px;
}

.lobby-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--color-accent);
  padding: 12px 16px;
  border-radius: 6px;
  text-align: left;
  line-height: 1.5;
  margin-top: 15px;
  width: 100%;
  max-width: 400px;
}

/* 10. フッター */
.game-footer {
  text-align: center;
  margin-top: 30px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.game-footer a {
  color: var(--color-accent);
  text-decoration: none;
  transition: var(--transition-smooth);
}

.game-footer a:hover {
  text-decoration: underline;
  text-shadow: 0 0 5px rgba(0, 240, 255, 0.5);
}

/* 11. 表示切り替えクラス */
.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 12. スマートフォン・タブレット向けレスポンシブデザイン ＆ アクセシビリティ */

.mobile-settings-panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 20px;
  margin-top: 25px;
  width: 100%;
}

.mobile-settings-panel .checkbox-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.mobile-settings-panel input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.mobile-settings-panel label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.mobile-hint-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: left;
}

/* メディアクエリ: モバイル端末向け調整 */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .app-container {
    padding: 10px;
    min-height: 100vh;
    justify-content: flex-start;
  }

  .game-header {
    margin-bottom: 15px;
  }

  .game-header h1 {
    font-size: 1.8rem;
  }

  .game-header .subtitle {
    font-size: 0.8rem;
  }

  .game-card {
    padding: 20px 15px;
    min-height: 320px;
    border-radius: 12px;
  }

  .game-card h2 {
    font-size: 1.4rem;
    margin-bottom: 15px;
  }

  .game-card .description {
    font-size: 0.85rem;
    margin-bottom: 25px;
    line-height: 1.6;
  }

  /* ボタンのタッチターゲット拡大 (アクセシビリティ強化) */
  .btn {
    min-height: 52px;
    padding: 12px 24px;
    font-size: 1rem;
    width: 100%; /* モバイルではボタンを幅いっぱいに */
    max-width: 320px;
    margin-bottom: 10px;
  }

  .btn-large {
    min-height: 60px;
  }

  .btn-subtext {
    font-size: 0.75rem;
  }

  .menu-grid, .difficulty-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
    width: 100%;
  }

  .btn-menu {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    padding: 15px;
    min-height: 68px;
    width: 100%;
    max-width: 100%;
  }

  .btn-menu .menu-icon {
    font-size: 1.8rem;
    margin-right: 15px;
    margin-bottom: 0;
  }

  .btn-menu .menu-title {
    font-size: 1rem;
    margin-bottom: 2px;
  }

  .btn-menu .menu-desc {
    font-size: 0.75rem;
    display: block;
  }

  /* スコアボード */
  .scoreboard {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 8px;
    padding: 10px 0;
    margin-bottom: 15px;
  }

  .score-panel {
    min-width: 0;
    max-width: 100%;
    padding: 10px 4px;
    overflow-wrap: anywhere;
    text-align: center;
  }

  .score-panel > * {
    max-width: 100%;
  }

  .score-name {
    font-size: 0.75rem;
  }

  .score-val {
    font-size: 1.8rem;
  }

  /* プレイ中操作説明 */
  .play-instructions {
    font-size: 0.8rem;
    margin-bottom: 10px;
    padding: 0 10px;
  }

  /* 得点・審判コール・操作説明は、狭い画面や拡大表示でも維持する。 */
  #screen-play .referee-call,
  #screen-play .play-instructions {
    overflow-wrap: anywhere;
  }

  #screen-play #btn-calibrate-tilt {
    display: none !important;
  }

  #screen-play .play-controls {
    margin-top: 12px;
  }

  .quit-confirm-dialog {
    padding: 24px 20px;
  }

  /* ヘルプコンテンツ */
  .help-content {
    max-height: 280px;
  }

  .help-content h3 {
    font-size: 1rem;
  }

  .help-content li, .help-content p {
    font-size: 0.85rem;
  }
}

/* ==========================================================================
   13. 寸法ガイドパネルと分割レイアウト
   ========================================================================== */

.game-play-layout {
  display: flex;
  flex-direction: row;
  gap: 24px;
  width: 100%;
  align-items: flex-start;
  margin-top: 10px;
}

.game-main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dimension-guide-aside {
  width: 280px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 240, 255, 0.15);
  border-radius: 12px;
  padding: 20px;
  box-shadow: inset 0 0 15px rgba(0, 240, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex-shrink: 0;
}

.guide-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-accent);
  border-bottom: 1px solid rgba(0, 240, 255, 0.2);
  padding-bottom: 8px;
  margin: 0;
  text-align: left;
}

.guide-specs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.spec-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.spec-icon {
  font-size: 1.2rem;
  margin-top: 2px;
}

.spec-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.spec-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.spec-value {
  font-family: var(--font-title);
  font-size: 0.9rem;
  color: var(--text-main);
  font-weight: 700;
  margin-top: 1px;
}

.spec-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

.guide-diagrams {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.guide-svg {
  width: 100%;
  height: auto;
  max-width: 240px;
}

/* メディアクエリ: 画面が狭い場合およびタブレット・スマホでは縦並びにする */
@media (max-width: 992px) {
  .game-play-layout {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }
  
  .dimension-guide-aside {
    width: 100%;
    max-width: 800px;
  }
}

/* ==========================================================================
   ネットワークエラーボックス (待機画面に表示)
   ========================================================================== */
.network-error-box {
  margin: 20px 0 10px;
  padding: 18px 24px;
  border: 1.5px solid var(--color-danger);
  border-radius: 12px;
  background: rgba(255, 49, 49, 0.08);
  box-shadow: 0 0 18px rgba(255, 49, 49, 0.25), inset 0 0 10px rgba(255, 49, 49, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: errorFadeIn 0.4s ease-out;
}

.network-error-box.hidden {
  display: none;
}

@keyframes errorFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.error-icon {
  font-size: 2rem;
  line-height: 1;
}

.error-message-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #ff6b6b;
  text-align: center;
  line-height: 1.5;
}

.error-countdown-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* エラー時にスピナーをグレーアウトする */
#waiting-spinner.spinner-error {
  border-top-color: var(--color-danger);
  opacity: 0.4;
  animation-play-state: paused;
}

/* ==========================================================================
   サーバーアドレス入力欄 (ロビー画面)
   ========================================================================== */
.label-hint {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

.label-hint code {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Courier New', monospace;
  font-size: 0.85em;
  color: var(--color-accent);
}

.server-addr-detected {
  font-size: 0.82rem;
  margin-top: 6px;
  min-height: 1.2em;
  line-height: 1.5;
  transition: color 0.3s;
}

/* ==========================================================================
   Match Result Overlay
   ========================================================================== */
.match-result-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: linear-gradient(135deg, rgba(0,240,255,0.08) 0%, rgba(255,0,127,0.08) 100%);
  border: 1px solid rgba(0,240,255,0.25);
  border-radius: 16px;
  animation: fadeIn 0.5s ease-out;
}

.match-result-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--color-warning);
  text-shadow: 0 0 20px rgba(255,170,0,0.5);
  letter-spacing: 2px;
}

.match-result-winner {
  font-family: var(--font-title);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-accent);
  text-shadow: 0 0 12px rgba(0,240,255,0.5);
}

.match-result-score {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-family: var(--font-title);
  letter-spacing: 1px;
}

.match-result-next-label {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.match-result-difficulties {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 760px;
}

.match-result-difficulties .btn {
  min-height: 76px;
  padding: 12px 16px;
}

.match-result-difficulties .menu-title {
  font-size: 1rem;
}

.result-difficulty-easy:hover, .result-difficulty-easy:focus {
  border-color: var(--color-success);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.2);
}

.result-difficulty-normal:hover, .result-difficulty-normal:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
}

.result-difficulty-hard:hover, .result-difficulty-hard:focus {
  border-color: var(--color-warning);
  box-shadow: 0 0 20px rgba(255, 170, 0, 0.2);
}

.match-result-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

@media (max-width: 768px) {
  .match-result-difficulties {
    grid-template-columns: 1fr;
    max-width: 360px;
  }
}

/* Speech rate panel */
.speech-rate-panel {
  background: rgba(255,255,255,0.03);
  border: 1px dashed rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 16px 20px;
  margin-top: 15px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.speech-rate-panel label {
  font-size: 0.95rem;
  color: var(--text-main);
  font-weight: 600;
}

.speech-rate-panel input[type="range"] {
  width: 100%;
  max-width: 320px;
  accent-color: var(--color-accent);
  cursor: pointer;
  height: 6px;
}

/* Display preferences: rem-based UI text scales without changing game physics. */
.speech-rate-panel + #btn-enable-audio { margin-top: 24px; }

html[data-text-size="standard"] { font-size: 100%; }
html[data-text-size="large"] { font-size: 125%; }
html[data-text-size="extra-large"] { font-size: 150%; }
html[data-text-size="largest"] { font-size: 200%; }

.display-settings-panel {
  width: 100%;
  min-width: 0;
  max-width: 650px;
  padding: 16px;
  margin-bottom: 24px;
  border: 2px solid var(--text-muted);
  border-radius: 10px;
}

.display-settings-panel legend { padding: 0 8px; font-weight: 700; }
.display-setting { display: grid; gap: 8px; margin-bottom: 16px; }
.display-setting label { font-weight: 700; }
.display-setting select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 8px;
  font: inherit;
  color: var(--text-main);
  background: var(--bg-primary);
  border: 2px solid var(--text-muted);
  border-radius: 6px;
}
.display-settings-panel p { font-size: 1rem; overflow-wrap: anywhere; }
:is(button, select, input, a):focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

html:not([data-text-size="standard"]) .menu-grid,
html:not([data-text-size="standard"]) .difficulty-grid,
html:not([data-text-size="standard"]) .match-result-difficulties {
  grid-template-columns: 1fr;
}
html[data-text-size] .game-header,
html[data-text-size] .game-card { overflow-wrap: anywhere; }
html[data-text-size] .btn { max-width: 100%; white-space: normal; }
html[data-text-size] .score-panel { min-width: 0; overflow-wrap: anywhere; }

html[data-contrast="white-on-black"],
html[data-contrast="yellow-on-black"] {
  color-scheme: dark;
  --bg-primary: #000;
  --bg-secondary: #000;
  --bg-tertiary: #000;
  --text-main: #fff;
  --text-muted: #fff;
  --color-accent: #fff;
  --color-accent-alt: #fff;
  --color-success: #fff;
  --color-danger: #fff;
  --color-warning: #fff;
}
html[data-contrast="black-on-white"] {
  color-scheme: light;
  --bg-primary: #fff;
  --bg-secondary: #fff;
  --bg-tertiary: #fff;
  --text-main: #000;
  --text-muted: #000;
  --color-accent: #000;
  --color-accent-alt: #000;
  --color-success: #000;
  --color-danger: #000;
  --color-warning: #000;
}
html[data-contrast="yellow-on-black"] {
  --text-main: #ff0;
  --text-muted: #ff0;
  --color-accent: #ff0;
  --color-accent-alt: #ff0;
  --color-success: #ff0;
  --color-danger: #ff0;
  --color-warning: #ff0;
}

/* Override decorative and inline colors for consistent contrast throughout the UI. */
html[data-contrast]:not([data-contrast="default"]) body,
html[data-contrast]:not([data-contrast="default"]) body * {
  color: var(--text-main) !important;
  border-color: var(--text-main) !important;
  text-shadow: none !important;
  box-shadow: none !important;
  background-image: none !important;
}
html[data-contrast]:not([data-contrast="default"]) :is(
  .game-card, .btn, input, select, .score-panel, .referee-call,
  .display-settings-panel, .mobile-settings-panel, .speech-rate-panel,
  .quit-confirm-dialog, .match-result-overlay, .network-error-box, .lobby-hint
) {
  background-color: var(--bg-primary) !important;
}
html[data-contrast]:not([data-contrast="default"]) .btn {
  border: 2px solid var(--text-main);
}
html[data-contrast]:not([data-contrast="default"]) .btn-subtext { opacity: 1; }
html[data-contrast]:not([data-contrast="default"]) a { text-decoration: underline; }
html[data-contrast]:not([data-contrast="default"]) :is(.fade-in, .pulse-text) { animation: none; }
html[data-contrast="white-on-black"] #game-canvas,
html[data-contrast="yellow-on-black"] #game-canvas { filter: grayscale(1) contrast(3); }
html[data-contrast="black-on-white"] #game-canvas { filter: grayscale(1) contrast(3) invert(1); }
