/* ==========================================================================
   N-back課題 (N-Back Task) スタイルシート
   ========================================================================== */

:root {
  --bg-color: #0b0f17;
  --surface-color: #131b26;
  --surface-alt: #1a2434;
  --surface-border: #243247;
  --surface-hover: #223046;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-glow: rgba(56, 189, 248, 0.25);

  --accent-cyan: #06b6d4;
  --accent-purple: #a855f7;
  --accent-purple-glow: rgba(168, 85, 247, 0.25);
  --accent-hit: #10b981;
  --accent-hit-bg: rgba(16, 185, 129, 0.14);
  --accent-miss: #f59e0b;
  --accent-miss-bg: rgba(245, 158, 11, 0.14);
  --accent-fa: #ef4444;
  --accent-fa-bg: rgba(239, 68, 68, 0.14);
  --accent-cr: #6366f1;
  --accent-cr-bg: rgba(99, 102, 241, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.55);

  --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* 共通ユーティリティ */
.d-none { display: none !important; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-center { text-align: center; }

/* CogLab 共通トップバー */
.coglab-top-bar {
  background: #06090e;
  border-bottom: 1px solid var(--surface-border);
  font-size: 13px;
  padding: 6px 16px;
}
.coglab-bar-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.coglab-badge {
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.coglab-app-links {
  display: flex;
  align-items: center;
  gap: 8px;
}
.coglab-app-link {
  color: var(--text-dim);
  text-decoration: none;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  transition: all 0.2s ease;
  font-weight: 500;
}
.coglab-app-link:hover {
  color: var(--text-main);
  background: var(--surface-alt);
}
.coglab-app-link.active {
  color: var(--primary);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-weight: 700;
}

/* レイアウト構成 */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ヘッダー */
.app-header {
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--surface-border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-decoration: none;
}
.brand-icon {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.4));
}
.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}
.brand-badge {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  display: block;
}

/* ナビゲーションタブ */
.nav-tabs {
  display: flex;
  gap: 6px;
  background-color: var(--surface-alt);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--surface-border);
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}
.nav-btn:hover {
  color: var(--text-main);
}
.nav-btn.active {
  background-color: var(--primary);
  color: #051322;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.icon-toggle-btn {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 16px;
}
.icon-toggle-btn:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
}
.user-pill {
  font-size: 12px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}
.login-link-pill {
  font-size: 12px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--surface-border);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}
.login-link-pill:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* メインコンテナ */
.main-content {
  flex: 1;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 60px;
}
.view-panel {
  display: none;
}
.view-panel.active {
  display: block;
}

/* パネルカード共通 */
.panel-card {
  background-color: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

/* ヒーローヘッダー */
.card-hero {
  text-align: center;
  max-width: 680px;
  margin: 0 auto 32px;
}
.hero-badge {
  display: inline-block;
  background: rgba(168, 85, 247, 0.14);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.35);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: var(--radius-full);
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}
.hero-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: #ffffff;
}
.hero-desc {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* 設定グリッド */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.setting-group.full-width {
  grid-column: 1 / -1;
}
.setting-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

/* Nレベルグリッドボタン */
.n-level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.mode-opt-btn {
  background: var(--surface-alt);
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mode-opt-btn:hover {
  border-color: rgba(56, 189, 248, 0.5);
  background: var(--surface-hover);
}
.mode-opt-btn.active {
  border-color: var(--primary);
  background: rgba(56, 189, 248, 0.08);
  box-shadow: 0 0 16px var(--primary-glow);
}
.mode-opt-btn .opt-title {
  font-size: 18px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
}
.mode-opt-btn .opt-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}
.recom-tag {
  font-size: 10px;
  background: #f59e0b;
  color: #0b0f17;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
}

/* 刺激タイプ選択ボタン */
.stimulus-select-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stimulus-opt-btn {
  background: var(--surface-alt);
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stimulus-opt-btn:hover {
  border-color: rgba(168, 85, 247, 0.5);
  background: var(--surface-hover);
}
.stimulus-opt-btn.active {
  border-color: var(--accent-purple);
  background: rgba(168, 85, 247, 0.1);
  box-shadow: 0 0 16px var(--accent-purple-glow);
}
.stim-icon {
  font-size: 20px;
  margin-bottom: 2px;
}
.stim-title {
  font-size: 14px;
  font-weight: 700;
}
.stim-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ピルオプションボタン */
.sub-setting-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill-opt-btn {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.pill-opt-btn:hover {
  color: var(--text-main);
  border-color: var(--text-dim);
}
.pill-opt-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #071727;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* ガイドボックス */
.guide-box {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin-bottom: 28px;
}
.guide-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
}
.guide-keys {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.guide-key-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.k-badge {
  background: #0f172a;
  color: #38bdf8;
  border: 1px solid #38bdf8;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 0 #0284c7;
}
.k-desc {
  color: var(--text-main);
}
.guide-tip {
  font-size: 12px;
  color: var(--text-muted);
}
.guide-tip strong {
  color: var(--primary);
}

/* アクションボタン群 */
.start-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: #041220;
  border: none;
  font-size: 16px;
  font-weight: 800;
  padding: 14px 32px;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(56, 189, 248, 0.4);
  transition: all 0.2s ease;
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(56, 189, 248, 0.55);
}
.primary-btn:active {
  transform: translateY(0);
}
.primary-btn.pulse {
  animation: startPulse 2s infinite;
}
@keyframes startPulse {
  0%, 100% { box-shadow: 0 4px 18px rgba(56, 189, 248, 0.35); }
  50% { box-shadow: 0 6px 26px rgba(56, 189, 248, 0.65); }
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-alt);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
  font-size: 14px;
  font-weight: 700;
  padding: 14px 24px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}
.secondary-btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}
.btn-sm {
  padding: 8px 16px;
  font-size: 12px;
}

/* ==============================================
   タスク実行中画面
   ============================================== */
.task-card {
  padding: 24px 28px;
  position: relative;
  min-height: 540px;
  display: flex;
  flex-direction: column;
}
.task-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.hud-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.hud-badge {
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-full);
}
.hud-trial-count {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}
.hud-abort-btn {
  background: transparent;
  border: 1px solid var(--surface-border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.hud-abort-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

.task-progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 16px;
}
.task-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #a855f7);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.phase-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto 16px;
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  padding: 6px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.phase-indicator.active-judge {
  color: var(--primary);
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.08);
}

/* 刺激提示ステージ */
.stimulus-stage {
  flex: 1;
  min-height: 280px;
  background: #080d14;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

/* 注視点 */
.fixation-cross {
  font-size: 48px;
  font-weight: 300;
  color: var(--text-dim);
  line-height: 1;
}

/* 単一刺激 (文字/数字) */
.single-stimulus-display {
  display: flex;
  align-items: center;
  justify-content: center;
}
.stimulus-char {
  font-family: var(--font-mono);
  font-size: 96px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(56, 189, 248, 0.7);
  animation: popIn 0.12s ease-out;
  line-height: 1;
}
@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 3x3 グリッド (位置・Dualモード) */
.spatial-grid-container {
  position: relative;
  width: 250px;
  height: 250px;
}
.spatial-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
}
.grid-cell {
  background: var(--surface-alt);
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-md);
  transition: all 0.1s ease;
}
.grid-cell.active-spatial {
  background: #0284c7;
  border-color: #38bdf8;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.8), inset 0 0 12px rgba(255, 255, 255, 0.5);
  animation: popCell 0.12s ease-out;
}
@keyframes popCell {
  from { transform: scale(0.85); }
  to { transform: scale(1); }
}

/* Dualモード用中央文字オーバーレイ */
.dual-letter-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.dual-letter-overlay span {
  font-family: var(--font-mono);
  font-size: 52px;
  font-weight: 800;
  color: #ffffff;
  background: rgba(11, 15, 23, 0.85);
  border: 2px solid var(--accent-purple);
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 0 20px var(--accent-purple-glow);
}

/* リアルタイムフィードバックトースト */
.feedback-toast {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 13px;
  font-family: var(--font-mono);
  animation: fadeToast 0.8s forwards;
  pointer-events: none;
}
.feedback-toast.hit {
  background: var(--accent-hit-bg);
  color: var(--accent-hit);
  border: 1px solid var(--accent-hit);
}
.feedback-toast.miss {
  background: var(--accent-miss-bg);
  color: var(--accent-miss);
  border: 1px solid var(--accent-miss);
}
.feedback-toast.fa {
  background: var(--accent-fa-bg);
  color: var(--accent-fa);
  border: 1px solid var(--accent-fa);
}
.feedback-toast.cr {
  background: var(--accent-cr-bg);
  color: var(--accent-cr);
  border: 1px solid var(--accent-cr);
}
@keyframes fadeToast {
  0% { opacity: 0; transform: translateY(-6px); }
  20% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-4px); }
}

/* 操作ボタン群 */
.response-controls {
  margin-top: auto;
}
.response-single-buttons,
.response-dual-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.resp-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  position: relative;
  touch-action: manipulation;
}
.resp-btn:active {
  transform: scale(0.97);
}
.btn-k-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.btn-main-label {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}
.btn-sub-label {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 2px;
}

/* シングルボタンのカラー */
.no-match-btn {
  background: #1e293b;
  color: #94a3b8;
  border: 2px solid #334155;
}
.no-match-btn:hover {
  background: #334155;
  color: #f1f5f9;
}
.no-match-btn.active-press {
  background: #475569;
  border-color: #64748b;
}

.match-btn {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border: 2px solid #38bdf8;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4);
}
.match-btn:hover {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
}
.match-btn.active-press {
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.8);
  border-color: #ffffff;
}

/* Dualボタンのカラー */
.spatial-match-btn {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border: 2px solid #38bdf8;
}
.audio-match-btn {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  color: #ffffff;
  border: 2px solid #c084fc;
}

/* インターバルバー */
.stimulus-interval-timer {
  width: 100%;
  height: 4px;
  background: var(--surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 14px;
}
.interval-bar {
  height: 100%;
  width: 100%;
  background: var(--primary);
  transform-origin: left;
}

/* ==============================================
   リザルト画面
   ============================================== */
.result-header {
  text-align: center;
  margin-bottom: 24px;
}
.result-badge {
  display: inline-block;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: var(--radius-full);
  margin-bottom: 10px;
}
.result-title {
  font-size: 26px;
  font-weight: 800;
  color: #ffffff;
}
.result-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 総合ランクカード */
.rank-card {
  background: linear-gradient(135deg, #162032 0%, #0e1724 100%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
}
.rank-badge-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle, #38bdf8 0%, #0284c7 100%);
  color: #051322;
  font-size: 38px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.5);
  flex-shrink: 0;
}
.rank-badge-circle.rank-s {
  background: radial-gradient(circle, #f59e0b 0%, #d97706 100%);
  color: #1f1203;
  box-shadow: 0 0 28px rgba(245, 158, 11, 0.6);
}
.rank-badge-circle.rank-a {
  background: radial-gradient(circle, #38bdf8 0%, #0284c7 100%);
  color: #041220;
}
.rank-badge-circle.rank-b {
  background: radial-gradient(circle, #10b981 0%, #059669 100%);
  color: #022013;
}
.rank-badge-circle.rank-c {
  background: radial-gradient(circle, #a855f7 0%, #7c3aed 100%);
  color: #1c052e;
}
.rank-badge-circle.rank-d {
  background: radial-gradient(circle, #64748b 0%, #475569 100%);
  color: #0b0f17;
}

.rank-details {
  flex: 1;
}
.rank-title {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 4px;
}
.rank-comment {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* メトリクスグリッド */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.metric-card.highlight {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(56, 189, 248, 0.05);
}
.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.metric-value-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 4px;
}
.metric-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 800;
  color: #ffffff;
}
.metric-unit {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
}
.metric-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: auto;
}

/* Dual専用メトリクス */
.dual-metrics-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}
.dual-metric-item {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dual-metric-title {
  font-size: 13px;
  font-weight: 700;
}
.dual-metric-val {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

/* 信号検出マトリクス */
.sdt-matrix-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}
.sdt-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
}
.sdt-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.sdt-cell {
  background: #0d141f;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--surface-border);
}
.sdt-cell.hit { border-color: rgba(16, 185, 129, 0.4); }
.sdt-cell.miss { border-color: rgba(245, 158, 11, 0.4); }
.sdt-cell.fa { border-color: rgba(239, 68, 68, 0.4); }
.sdt-cell.cr { border-color: rgba(99, 102, 241, 0.4); }

.sdt-tag {
  display: block;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
}
.sdt-cell.hit .sdt-tag { color: var(--accent-hit); }
.sdt-cell.miss .sdt-tag { color: var(--accent-miss); }
.sdt-cell.fa .sdt-tag { color: var(--accent-fa); }
.sdt-cell.cr .sdt-tag { color: var(--accent-cr); }

.sdt-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
}
.sdt-note {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* チャートカード */
.chart-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}
.chart-title {
  font-size: 14px;
  font-weight: 700;
}
.chart-legend {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--text-muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot.hit { background: var(--accent-hit); }
.dot.cr { background: var(--accent-cr); }
.dot.miss { background: var(--accent-miss); }
.dot.fa { background: var(--accent-fa); }

.chart-svg-container {
  width: 100%;
  overflow-x: auto;
  min-height: 180px;
}
.timeline-svg {
  width: 100%;
  height: 180px;
}

/* アコーディオン & テーブル */
.trial-details-accordion {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  overflow: hidden;
}
.details-summary {
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}
.details-summary:hover {
  color: var(--text-main);
}
.table-responsive {
  width: 100%;
  overflow-x: auto;
}
.trial-table, .history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}
.trial-table th, .trial-table td,
.history-table th, .history-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--surface-border);
}
.trial-table th, .history-table th {
  background: #0f1724;
  color: var(--text-muted);
  font-weight: 700;
}
.trial-table td, .history-table td {
  color: var(--text-main);
  font-family: var(--font-mono);
}
.trial-table tr:last-child td,
.history-table tr:last-child td {
  border-bottom: none;
}
.badge-eval {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.badge-eval.hit { background: var(--accent-hit-bg); color: var(--accent-hit); }
.badge-eval.cr { background: var(--accent-cr-bg); color: var(--accent-cr); }
.badge-eval.miss { background: var(--accent-miss-bg); color: var(--accent-miss); }
.badge-eval.fa { background: var(--accent-fa-bg); color: var(--accent-fa); }
.badge-eval.mem { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

/* アクションボタン */
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  color: #ffffff;
  border: none;
  font-size: 14px;
  font-weight: 700;
  padding: 14px 24px;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(168, 85, 247, 0.4);
  transition: all 0.2s;
}
.share-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.6);
}

/* ==============================================
   履歴・科学解説画面
   ============================================== */
.history-header, .science-header {
  margin-bottom: 24px;
}
.section-title {
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 6px;
}
.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.history-chart-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.history-svg-container {
  width: 100%;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-placeholder {
  color: var(--text-dim);
  font-size: 13px;
}

/* 科学解説 */
.science-article {
  color: #cbd5e1;
  font-size: 15px;
  line-height: 1.8;
}
.science-article h3 {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  margin: 28px 0 12px;
  border-left: 4px solid var(--primary);
  padding-left: 12px;
}
.science-article p {
  margin-bottom: 16px;
}
.science-article ul {
  margin-left: 20px;
  margin-bottom: 20px;
}
.science-article li {
  margin-bottom: 8px;
}
.science-callout {
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 20px 0;
}
.science-callout h4 {
  color: #c084fc;
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 8px;
}
.math-formula-box {
  background: #0f172a;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--primary);
  margin: 16px 0;
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 18px;
}
.tip-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 18px;
}
.tip-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  display: block;
  margin-bottom: 6px;
}
.tip-card h4 {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 8px;
}
.tip-card p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 0;
}

/* フッター */
.app-footer {
  border-top: 1px solid var(--surface-border);
  background: #06090e;
  padding: 24px 20px;
  margin-top: auto;
}
.footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.footer-links {
  display: flex;
  gap: 16px;
}
.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.footer-links a:hover {
  color: var(--primary);
}

/* ==============================================
   レスポンシブ対応
   ============================================== */
@media (max-width: 768px) {
  .header-inner {
    padding: 10px 14px;
  }
  .brand-title {
    font-size: 17px;
  }
  .nav-btn .nav-label {
    display: none;
  }
  .nav-btn {
    padding: 6px 10px;
  }
  .main-content {
    padding: 16px 12px 40px;
  }
  .panel-card {
    padding: 20px 16px;
  }
  .hero-title {
    font-size: 22px;
  }
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .n-level-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .sdt-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .tips-grid {
    grid-template-columns: 1fr;
  }
  .rank-card {
    flex-direction: column;
    text-align: center;
  }
  .stimulus-char {
    font-size: 72px;
  }
  .spatial-grid-container {
    width: 210px;
    height: 210px;
  }
}

