/**
 * style.css - タイピング道場
 * statistics / portfolio 準拠デザイン
 * ダーク/ライトテーマ対応
 */

/* ===== リセット & ベース ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html { scroll-behavior: smooth; }
a { color: inherit; text-decoration: none; }

/* ===== CSS 変数（共通） ===== */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #3b82f6;
  --primary-bg:     #eff6ff;
  --success:        #10b981;
  --success-bg:     #ecfdf5;
  --warning-color:  #f59e0b;
  --error-color:    #ef4444;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --radius:    12px;
  --radius-sm: 8px;
  --font-mono: "Courier New", Consolas, monospace;
  --navbar-height: 60px;
}

/* ===== ダークテーマ ===== */
[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #161b22;
  --bg-card-hover: #1c2333;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-glow: rgba(88, 166, 255, 0.15);
  --correct: #3fb950;
  --miss: #f85149;
  --warning: #d29922;
  --border: #30363d;
  --border-light: #444c56;
  --navbar-bg: rgba(13, 17, 23, 0.92);
  --countdown-bg: rgba(13, 17, 23, 0.94);

  /* primary を dark 向けに上書き */
  --primary:       #58a6ff;
  --primary-dark:  #79c0ff;
  --primary-bg:    rgba(88, 166, 255, 0.12);
}

/* ===== ライトテーマ（デフォルト） ===== */
:root,
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.1);
  --correct: #10b981;
  --miss: #ef4444;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --navbar-bg: rgba(255, 255, 255, 0.95);
  --countdown-bg: rgba(248, 250, 252, 0.96);

  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-bg:    #eff6ff;
}

body {
  font-family: 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ===== ナビバー ===== */
/* ===== ナビバー（statistics 準拠） ===== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--gray-200);
    z-index: 1000;
    transition: all 0.3s;
}

.navbar.scrolled {
    box-shadow: var(--shadow-md);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 24px;
}

.nav-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
    flex-shrink: 0;
    text-decoration: none;
}

.nav-logo:hover { opacity: 0.8; }

.nav-menu {
    display: flex;
    align-items: center;
    gap: 24px;
    list-style: none;
}

.nav-menu > li > a {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--gray-600);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
    position: relative;
    transition: color 0.2s;
}

.nav-menu > li > a::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 0; height: 2px;
    background: var(--primary);
    transition: width 0.2s;
}

.nav-menu > li > a:hover,
.nav-menu > li > a.active {
    color: var(--primary);
}

.nav-menu > li > a:hover::after,
.nav-menu > li > a.active::after {
    width: 100%;
}

.nav-dropdown { position: relative; }

.nav-dropdown-toggle .fa-chevron-down {
    font-size: 0.58rem;
    transition: transform 0.2s;
}

.nav-dropdown:hover .nav-dropdown-toggle .fa-chevron-down {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%) translateY(-6px);
    min-width: 200px;
    background: #ffffff;
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 500;
    list-style: none;
}

.nav-dropdown:hover .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.nav-dropdown-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 0.87rem;
    font-weight: 500;
    color: var(--gray-700);
    border-radius: 8px;
    transition: all 0.15s;
    white-space: nowrap;
}

.nav-dropdown-menu li a::after { display: none !important; }

.nav-dropdown-menu li a:hover {
    background: var(--gray-50);
    color: var(--primary);
}

.nav-dropdown-menu li a.active {
    color: var(--primary);
    background: #eff6ff;
    font-weight: 600;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.nav-toggle span {
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    transition: all 0.3s;
}

/* ===== メインコンテンツ ===== */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: calc(var(--navbar-height) + 32px) 24px 40px;
  min-height: 100vh;
}

/* ===== ホーム画面 ===== */
.home-screen {
  width: 100%;
}

.hero {
  text-align: center;
  padding: 48px 24px 44px;
  background: var(--primary-bg);
  border-radius: 18px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

/* hero-badge: statistics スタイルのバッジ */
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 16px;
  border-radius: 20px;
  margin-bottom: 16px;
  letter-spacing: .5px;
}

.hero-title {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 900;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: 3px;
  line-height: 1.3;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.7;
}

/* hero-actions: ボタングループ */
.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ===== ボタン共通 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all .2s;
  letter-spacing: .5px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn-outline:hover {
  background: var(--accent-glow);
  transform: translateY(-2px);
}

/* ===== モードカード ===== */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

.mode-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}
.mode-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.mode-card-icon {
  width: 50px; height: 50px;
  border-radius: var(--radius-sm);
  background: var(--accent-glow);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.mode-card-body h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.mode-card-body p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.mode-card-body strong { color: var(--accent); }

.mode-card-badge {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--accent);
}

/* 遊び方 */
.how-to {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}

.how-to h2 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.how-to-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.how-to-steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.8rem;
  border-radius: 50%;
  border: 1px solid var(--accent);
  flex-shrink: 0;
}

/* ===== サウンド設定 ===== */
.sound-settings {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}
.sound-settings h2 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sound-type-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}
@media (max-width: 760px) {
  .sound-type-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  .sound-type-grid { grid-template-columns: repeat(3, 1fr); }
}

.sound-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .18s;
  color: var(--text-secondary);
  font-family: inherit;
}
.sound-type-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-primary);
  transform: translateY(-2px);
}
.sound-type-btn.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.sound-type-icon {
  font-size: 1.4rem;
  line-height: 1;
}
.sound-type-name {
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

/* タイピング中の音インジケーター */
.sound-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all .18s;
  font-family: inherit;
  flex-shrink: 0;
}
.sound-indicator:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ===== カウントダウンオーバーレイ ===== */
.countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--countdown-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: background 0.3s;
}

.countdown-number {
  font-size: 8rem;
  font-weight: 900;
  color: var(--accent);
  animation: countdownPulse 0.6s ease-out;
  font-family: var(--font-mono);
}

@keyframes countdownPulse {
  0% { transform: scale(1.5); opacity: 0; }
  50% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== スペースキー案内 ===== */
.space-prompt {
  text-align: center;
  padding: 60px 0;
}

.space-prompt-text {
  font-size: 1.2rem;
  color: var(--text-secondary);
  animation: spaceBlink 1.5s ease-in-out infinite;
}

@keyframes spaceBlink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ===== タイピングエリア ===== */
.typing-area {
  width: 100%;
}

.question-section {
  width: 100%;
}

/* プログレスバー */
.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a371f7);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  color: var(--text-secondary);
  font-size: 0.82rem;
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* 問題表示 */
.question-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 36px;
  margin-bottom: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}

.question-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-glow);
  margin-bottom: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 4px 14px;
  border-radius: 20px;
}

.question-text {
  font-size: 1.7rem;
  font-weight: 800;
  margin-bottom: 14px;
  line-height: 1.7;
  letter-spacing: 1px;
}

.kana-display {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  letter-spacing: 3px;
  line-height: 1.8;
}

/* ローマ字表示 */
.romaji-display {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  letter-spacing: 3px;
  line-height: 2;
  min-height: 50px;
  word-break: break-all;
  padding: 8px 0;
}

.char-correct {
  color: var(--correct);
  font-weight: bold;
}

.char-current {
  color: var(--text-primary);
  background: var(--accent-glow);
  border-radius: 3px;
  padding: 0 2px;
  animation: blink 0.8s ease-in-out infinite alternate;
}

.char-pending {
  color: var(--text-secondary);
}

.char-miss {
  color: var(--miss);
  text-decoration: underline;
}

@keyframes blink {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

/* ===== キーボード ===== */
.keyboard-section {
  margin-top: 16px;
  text-align: center;
}

.finger-label {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 10px;
  min-height: 24px;
  font-weight: bold;
}

.keyboard-container {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}

.keyboard-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.key {
  min-width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all 0.15s;
  flex: 1;
}

.key-active {
  transform: scale(1.1);
  box-shadow: 0 0 0 2px var(--accent);
  color: var(--accent);
  font-weight: bold;
  z-index: 1;
}

/* ===== 結果画面 ===== */
.result-screen {
  text-align: center;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 0;
}

.result-screen h2 {
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 20px;
  font-weight: 800;
}

.result-rating {
  font-size: 4rem;
  margin-bottom: 8px;
}

.result-comment {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.result-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s, border-color 0.3s;
}

.result-item .result-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.result-item .result-value {
  font-size: 1.7rem;
  font-weight: bold;
  color: var(--accent);
  font-family: var(--font-mono);
}

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.retry-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 13px 32px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: .5px;
}

.retry-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.home-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 13px 32px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: .5px;
}

.home-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
}

/* ===== 非表示ユーティリティ ===== */
.hidden {
  display: none !important;
}

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }

  .nav-menu {
    position: fixed;
    top: 60px; left: 0; right: 0;
    background: white;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
  }

  .nav-menu.active {
    max-height: 500px;
    padding: 12px 0;
  }

  .nav-menu > li { width: 100%; text-align: center; }
  .nav-menu > li > a { justify-content: center; padding: 12px 24px; width: 100%; }

  .nav-dropdown-menu {
    position: static;
    opacity: 1; visibility: visible;
    transform: none;
    box-shadow: none; border: none;
    border-top: 1px solid var(--gray-100);
    border-radius: 0;
    background: var(--gray-50);
    padding: 4px 0;
    min-width: unset;
  }

  .nav-dropdown:hover .nav-dropdown-menu { transform: none; }
  .nav-dropdown-menu li a { justify-content: center; }

  .nav-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
  .nav-toggle.active span:nth-child(2) { opacity: 0; }
  .nav-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

  .mode-grid { grid-template-columns: 1fr; }

  .hero-title {
    font-size: 1.7rem;
  }

  .question-text {
    font-size: 1.2rem;
  }

  .romaji-display {
    font-size: 1.2rem;
    letter-spacing: 2px;
  }

  .key {
    min-width: 30px;
    height: 34px;
    font-size: 0.65rem;
  }

  .keyboard-container {
    padding: 8px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .countdown-number {
    font-size: 5rem;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .hero-title {
    font-size: 1.5rem;
  }

  .how-to {
    padding: 24px 20px;
  }

  .question-box {
    padding: 16px;
  }

  .key {
    min-width: 24px;
    height: 28px;
    font-size: 0.55rem;
  }
}
