/* BlackjackGuide - エレクトリック・ドリーム 改良版 */

/* CSS Custom Properties (変数定義) */
:root {
  /* === エレクトリック・ドリーム テーマ === */
  /* 背景（モノクロ1色） */
  --bg-base: #FFFFFF;
  
  /* 差し色グラデーション（1色ベース） */
  --accent-primary: #6C63FF;
  --accent-secondary: #FF6B9D;
  
  /* 枠線（1色） */
  --border-base: #E5E7EB;
  
  /* 表背景（2色） */
  --table-bg-primary: #FAFAFA;
  --table-bg-secondary: #F5F5F5;

  /* === 自動生成色（基本色から派生） === */
  --bg-primary: var(--bg-base);
  --bg-secondary: color-mix(in srgb, var(--bg-base) 95%, var(--accent-primary) 5%);
  --bg-tertiary: color-mix(in srgb, var(--bg-base) 90%, var(--accent-primary) 10%);
  --text-primary: #2C2F36;
  --text-secondary: #6B7280;
  --border-color: var(--border-base);
  --border-light: color-mix(in srgb, var(--border-base) 70%, transparent 30%);

  /* サイズ・スペーシング */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;

  /* タイポグラフィ */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* スムーズアニメーション */
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index レイヤー */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal: 1040;
  --z-popover: 1060;
  --z-tooltip: 1080;

  /* シャドウ */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 2px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

/* === ダークモード（目に優しい改良版） === */
@media (prefers-color-scheme: dark) {
  :root {
    /* 背景（モノクロ1色） */
    --bg-base: #1A1A2E;
    
    /* 枠線（1色） */
    --border-base: #373D5C;
    
    /* 表背景（2色） */
    --table-bg-primary: #212542;
    --table-bg-secondary: #2A2F54;

    /* 目に優しいテキスト色（真っ白を避ける） */
    --text-primary: #E2E8F0;        /* ソフトホワイト */
    --text-secondary: #A0A9C0;       /* 柔らかいグレー */
    
    /* ダークモードシャドウ */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 16px rgba(0,0,0,0.5);
  }
}

/* === 手動テーマ切り替え === */
[data-theme="dark"] {
  --bg-base: #1A1A2E;
  --border-base: #373D5C;
  --table-bg-primary: #212542;
  --table-bg-secondary: #2A2F54;
  --text-primary: #E2E8F0;
  --text-secondary: #A0A9C0;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 16px rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg-base: #FFFFFF;
  --border-base: #E5E7EB;
  --table-bg-primary: #FAFAFA;
  --table-bg-secondary: #F5F5F5;
  --text-primary: #2C2F36;
  --text-secondary: #6B7280;
}

/* リセットCSS */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont,
    'Helvetica Neue', Arial, sans-serif;
  font-size: var(--font-size-base);
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: background-color var(--transition-slow),
    color var(--transition-slow);
  overflow-x: hidden;
}

/* スクロールバーのスタイリング */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent-primary) 80%, black 20%);
}

/* デバイス幅対応コンテナ */
.container {
  width: 100%;
  max-width: min(95vw, 800px);
  margin: 0 auto;
  padding: var(--space-sm);
  position: relative;
}

/* ダークモード切り替えボタン（グラデーション適用） */
.theme-toggle {
  position: fixed;
  top: var(--space-sm);
  right: var(--space-sm);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: 1px solid var(--border-color);
  color: white;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  z-index: var(--z-fixed);
  transition: all var(--transition-normal);
  user-select: none;
  touch-action: manipulation;
  box-shadow: var(--shadow-md);
}

.theme-toggle:hover {
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
  transform: translateY(-2px) scale(1.02);
  box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
  transform: translateY(-1px) scale(1.01);
}

/* ヘッダー（タイトルにグラデーション適用） */
.header {
  text-align: center;
  margin-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: var(--space-sm);
}

.header h1 {
  font-size: clamp(1.2rem, 4vw, var(--font-size-2xl));
  font-weight: var(--font-weight-bold);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-xs);
  letter-spacing: -0.025em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: clamp(var(--font-size-sm), 2.5vw, var(--font-size-base));
  font-weight: var(--font-weight-normal);
}

/* メインコンテンツ */
.main-content {
  display: grid;
  gap: var(--space-md);
}

/* セクション共通スタイル */
section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

section:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

section h2 {
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  font-size: clamp(var(--font-size-base), 3vw, var(--font-size-xl));
  font-weight: var(--font-weight-bold);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: var(--space-xs);
  position: relative;
}

section h2::before {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 40px;
  height: 2px;
  background: var(--accent-primary);
  border-radius: 1px;
}

/* 資金管理セクション */
.money-section {
  background: var(--bg-secondary);
}

.money-controls {
  display: grid;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

/* フォーム要素 */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.input-group label {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  font-size: clamp(var(--font-size-sm), 2.5vw, var(--font-size-base));
}

.input-group input {
  padding: var(--space-sm);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: clamp(var(--font-size-sm), 2.5vw, var(--font-size-base));
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 100%;
  transition: all var(--transition-normal);
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 20%, transparent 80%);
  transform: translateY(-1px);
}

.input-group input:hover:not(:focus) {
  border-color: color-mix(in srgb, var(--accent-primary) 50%, var(--border-color) 50%);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  font-size: clamp(var(--font-size-sm), 2.5vw, var(--font-size-base));
  cursor: pointer;
  user-select: none;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

.checkbox-group label {
  cursor: pointer;
  font-weight: var(--font-weight-medium);
}

/* 残高表示パネル */
.balance-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.balance-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-primary);
}

.balance-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-sm);
}

.balance-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--border-light);
  font-size: clamp(var(--font-size-sm), 2.5vw, var(--font-size-base));
  transition: all var(--transition-fast);
}

.balance-item:last-child {
  border-bottom: none;
}

.balance-item:hover {
  background: color-mix(in srgb, var(--accent-primary) 5%, transparent 95%);
  margin: 0 calc(-1 * var(--space-xs));
  padding-left: var(--space-xs);
  padding-right: var(--space-xs);
  border-radius: var(--radius-sm);
  transform: translateX(2px);
}

.balance-item .label {
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
}

.balance-item .value {
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  font-feature-settings: "tnum";
  letter-spacing: 0.025em;
}

.balance-item .value.bet {
  color: var(--accent-primary);
  font-size: clamp(var(--font-size-base), 3vw, var(--font-size-lg));
}

/* ボタン共通スタイル */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: clamp(var(--space-xs), 2vw, var(--space-sm)) clamp(var(--space-sm), 2.5vw, var(--space-md));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  font-size: clamp(var(--font-size-sm), 2.2vw, var(--font-size-base));
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
  min-height: clamp(36px, 8vw, 44px);
  width: 100%;
  user-select: none;
  touch-action: manipulation;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn:not(:disabled):hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}

.btn:not(:disabled):active {
  transform: translateY(-1px) scale(1.005);
}

/* 主要ボタンにのみグラデーション適用 */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  border-color: transparent;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
  border-color: transparent;
  transform: translateY(-3px) scale(1.02);
}

.btn-win {
  background: var(--accent-primary);
  color: white;
  border-color: transparent;
}

.btn-push {
  background: color-mix(in srgb, var(--accent-primary) 70%, orange 30%);
  color: white;
  border-color: transparent;
}

.btn-lose {
  background: color-mix(in srgb, var(--accent-secondary) 70%, red 30%);
  color: white;
  border-color: transparent;
}

.btn-danger {
  background: var(--accent-secondary);
  color: white;
  border-color: transparent;
}

/* セッション制御 */
.session-controls {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

/* ゲームボタン - 常時1行配置 */
.game-buttons {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: clamp(var(--space-xs), 1.5vw, var(--space-sm));
}

/* 戦略表セクション */
.strategy-section {
  background: var(--bg-secondary);
}

.strategy-container {
  overflow: hidden;
}

.strategy-table-wrap {
  /* 動的サイズ調整 */
  --cell-size: clamp(10px, 2vw, 16px);
  --header-width: clamp(24px, 5vw, 36px);
  --cell-height: clamp(18px, 3.2vw, 26px);
  transform-origin: top left;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--table-bg-primary);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-sm);
  position: relative;
  /* スムーススクロール */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-primary) var(--table-bg-primary);
}

.strategy-table {
  width: 100%;
  min-width: max(320px, 100%);
  border-collapse: collapse;
  font-size: clamp(7px, 1.4vw, 9px);
  position: relative;
  user-select: none;
  font-weight: var(--font-weight-bold);
}

.strategy-table[data-highlight-mode="active"] {
  cursor: crosshair;
}

.strategy-table th,
.strategy-table td {
  padding: 0;
  text-align: center;
  font-weight: var(--font-weight-bold);
  line-height: var(--cell-height);
  border: 1px solid var(--border-light);
  position: relative;
  transition: all var(--transition-fast);
  height: var(--cell-height);
}

/* プレイヤー列（左端）- コントラスト改善 */
.strategy-table thead th:first-child,
.strategy-table .player {
  width: var(--header-width) !important;
  min-width: var(--header-width) !important;
  max-width: var(--header-width) !important;
  height: var(--cell-height) !important;
  background: var(--accent-primary);
  color: white;
  font-size: clamp(5px, 1.2vw, 8px) !important;
  position: sticky;
  left: 0;
  z-index: var(--z-sticky);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* 通常のセル */
.strategy-table th:not(:first-child),
.strategy-table td {
  width: var(--cell-size) !important;
  min-width: var(--cell-size) !important;
  max-width: var(--cell-size) !important;
  height: var(--cell-height) !important;
  font-size: clamp(8px, 1.3vw, 11px) !important;
}

/* ディーラー列見出し - コントラスト改善 */
.strategy-table thead th:not(:first-child) {
  background: color-mix(in srgb, var(--accent-primary) 80%, var(--accent-secondary) 20%);
  color: white;
  position: sticky;
  top: 0;
  z-index: calc(var(--z-sticky) - 1);
  height: var(--cell-height) !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* コーナーセル */
.strategy-table thead th:first-child {
  z-index: calc(var(--z-sticky) + 1);
  background: color-mix(in srgb, var(--accent-primary) 60%, var(--accent-secondary) 40%);
}

/* セクションヘッダー */
.strategy-table .section-header td {
  background: var(--accent-primary);
  color: white;
  font-size: clamp(5px, 1.1vw, 7px) !important;
  height: calc(var(--cell-height) * 0.8) !important;
  font-weight: var(--font-weight-bold);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Hit/Stand/Pair セル - ダークモード対応改善 */
.strategy-table td.h {
  background: #374151;                 /* 暗すぎないグレー */
  color: #F3F4F6;                     /* 柔らかい白 */
  position: relative;
}

.strategy-table td.s {
  background: var(--table-bg-secondary);
  color: var(--text-primary);
  position: relative;
  font-weight: var(--font-weight-bold);
}

/* Pair分割用のスタイル */
.strategy-table td.p {
  background: var(--accent-secondary);
  color: white;
  position: relative;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ホバー効果 - タッチデバイス考慮 */
@media (hover: hover) and (pointer: fine) {
  .strategy-table tbody tr:hover td:first-child,
  .strategy-table tbody td:hover {
    background: var(--accent-primary) !important;
    color: white !important;
    font-weight: var(--font-weight-bold);
    transform: scale(1.05);
    z-index: var(--z-dropdown);
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    box-shadow: 0 2px 8px rgba(108, 99, 255, 0.3);
  }

  .strategy-table tbody tr:hover {
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent 90%);
  }
}

/* 凡例 */
.legend {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
  border: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: var(--font-weight-semibold);
  font-size: clamp(var(--font-size-xs), 2vw, var(--font-size-sm));
}

.legend-color {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  color: white;
  font-weight: var(--font-weight-bold);
  min-width: 24px;
  font-size: clamp(var(--font-size-xs), 1.8vw, var(--font-size-sm));
  text-align: center;
}

.legend-color.h {
  background: #374151;
  color: #F3F4F6;
}

.legend-color.s {
  background: var(--table-bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.legend-color.p {
  background: var(--accent-secondary);
}

/* 履歴セクション */
.history-section details {
  border: none;
}

.history-section summary {
  cursor: pointer;
  outline: none;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: var(--space-xs);
  margin-bottom: var(--space-sm);
  transition: all var(--transition-normal);
  user-select: none;
}

.history-section summary:hover {
  color: var(--accent-primary);
  transform: translateX(2px);
}

.history-section summary h2 {
  display: inline;
  border: none;
  padding: 0;
  margin: 0;
}

.history-section summary::marker {
  content: '▶ ';
  color: var(--accent-primary);
  font-weight: var(--font-weight-bold);
}

.history-section details[open] summary::marker {
  content: '▼ ';
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.history-table {
  width: 100%;
  min-width: max(500px, 100%);
  border-collapse: collapse;
  font-size: clamp(var(--font-size-xs), 2vw, var(--font-size-sm));
  background: var(--bg-primary);
}

.history-table th,
.history-table td {
  border: 1px solid var(--border-color);
  padding: var(--space-xs) var(--space-sm);
  text-align: center;
  white-space: nowrap;
}

.history-table th {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  font-size: clamp(var(--font-size-xs), 1.8vw, var(--font-size-sm));
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.history-table tbody tr {
  transition: all var(--transition-fast);
}

.history-table tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

.history-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent-primary) 5%, transparent 95%);
  transform: translateX(1px);
}

/* タイマー */
.timer {
  position: fixed;
  bottom: var(--space-sm);
  right: var(--space-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', 'Courier New', monospace;
  font-weight: var(--font-weight-bold);
  font-size: clamp(var(--font-size-sm), 2vw, var(--font-size-base));
  z-index: var(--z-fixed);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
}

.timer:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.timer-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: clamp(var(--font-size-xs), 1.8vw, var(--font-size-sm));
  transition: all var(--transition-normal);
  min-width: 24px;
  text-align: center;
  user-select: none;
  touch-action: manipulation;
}

.timer-btn:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

/* レスポンシブ対応 */
@media (min-width: 480px) {
  .money-controls {
    grid-template-columns: 2fr 1fr;
  }
  .balance-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 400px) {
  .balance-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 600px) {
  .balance-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 768px) {
  .container {
    max-width: min(90vw, 700px);
    padding: var(--space-md);
  }
  .balance-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
  .main-content {
    gap: var(--space-lg);
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: min(85vw, 800px);
    padding: var(--space-lg);
  }
  .strategy-table-wrap {
    --cell-size: 18px;
    --header-width: 40px;
    --cell-height: 28px;
  }
  .game-buttons {
    gap: var(--space-md);
  }
}

/* モバイル最適化 */
@media (max-width: 480px) {
  .container {
    padding: var(--space-xs);
  }
  section {
    padding: var(--space-sm);
  }
  .strategy-table-wrap {
    --cell-size: 8px;
    --header-width: 20px;
    --cell-height: 16px;
  }
  .game-buttons {
    gap: var(--space-xs);
  }
}

@media (max-width: 360px) {
  .balance-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: var(--space-xs) 0;
  }
  .strategy-table-wrap {
    --cell-size: 7px;
    --header-width: 18px;
    --cell-height: 14px;
  }
  .legend {
    gap: var(--space-sm);
  }
  .legend-item {
    gap: var(--space-xs);
  }
}

@media (max-width: 320px) {
  .strategy-table-wrap {
    --cell-size: 6px;
    --header-width: 16px;
    --cell-height: 12px;
  }
  .strategy-table {
    min-width: 280px;
  }
}

/* 縦向きモバイル専用最適化 */
@media (max-width: 480px) and (orientation: portrait) {
  .strategy-container {
    margin: 0 calc(-1 * var(--space-sm));
  }
  .strategy-table-wrap {
    border-radius: 0;
    border-left: none;
    border-right: none;
    --cell-height: 18px;
  }
}

/* 横向きモバイル対応 */
@media (max-height: 500px) and (orientation: landscape) {
  .header {
    margin-bottom: var(--space-sm);
  }
  .header h1 {
    font-size: 1.2rem;
  }
  .subtitle {
    font-size: var(--font-size-sm);
  }
  .strategy-table-wrap {
    --cell-height: 12px;
  }
  .timer {
    bottom: var(--space-xs);
    right: var(--space-xs);
    font-size: var(--font-size-xs);
  }
}

/* 超小型デバイス対応 */
@media (max-width: 280px) {
  .strategy-table {
    min-width: 250px;
  }
  .history-table {
    min-width: 350px;
  }
  .legend {
    flex-direction: column;
    gap: var(--space-xs);
  }
}

/* 印刷対応 */
@media print {
  .timer,
  .session-controls,
  .game-section,
  .theme-toggle {
    display: none !important;
  }
  .container {
    max-width: none;
    padding: 0;
  }
  .strategy-table-wrap {
    --cell-size: 12px;
    --header-width: 28px;
    --cell-height: 16px;
    box-shadow: none;
    border: 1px solid #000;
  }
  .table-wrapper {
    overflow: visible;
  }
  section {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .balance-panel {
    border: 1px solid #000;
  }
}

/* アクセシビリティ */
.btn:focus-visible,
.theme-toggle:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* 高コントラストモード */
@media (prefers-contrast: high) {
  :root {
    --border-color: var(--accent-primary);
  }
  .strategy-table th,
  .strategy-table td {
    border-width: 2px;
  }
  .btn {
    border: 2px solid currentColor;
  }
}

/* アニメーション削減 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .btn:hover,
  .strategy-table tbody td:hover {
    transform: none;
  }
}

/* スクリーンリーダー用 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* カスタムスクロールバー（Webkit系） */
.strategy-table-wrap::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar {
  height: 4px;
}

.strategy-table-wrap::-webkit-scrollbar-track,
.table-wrapper::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.strategy-table-wrap::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: 2px;
}

.strategy-table-wrap::-webkit-scrollbar-thumb:hover,
.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent-primary) 80%, black 20%);
}

/* 選択不可テキスト */
.strategy-table,
.legend,
.timer {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* スムーズなロード時のアニメーション */
@keyframes fadeInSmooth {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

section {
  animation: fadeInSmooth 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

section:nth-child(1) { animation-delay: 0.1s; }
section:nth-child(2) { animation-delay: 0.15s; }
section:nth-child(3) { animation-delay: 0.2s; }
section:nth-child(4) { animation-delay: 0.25s; }

/* パフォーマンス最適化 */
.strategy-table,
.history-table {
  contain: layout style paint;
}

.timer {
  will-change: transform;
}

/* 最終調整 */
html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  position: relative;
}
