/* ==========================================================================
   DictaFlow - リスニング＆ディクテーション スタイルシート
   ========================================================================== */

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.85);
  --bg-card-hover: rgba(51, 65, 85, 0.9);
  --bg-input: #0b1120;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.35);
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.3);
  --accent-red: #ef4444;
  --accent-yellow: #f59e0b;
  --accent-orange: #f97316;
  
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #06b6d4;
  
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px var(--accent-cyan-glow);
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background: radial-gradient(circle at top right, #1e1b4b 0%, #0f172a 60%, #030712 100%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 80px 20px;
  line-height: 1.6;
  overflow-y: auto;
}

/* アプリ全体のコンテナ */
.app-container {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: auto;
  height: auto;
}

/* ヘッダー */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 1.8rem;
  background: linear-gradient(135deg, #06b6d4, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, #f8fafc, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.header-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-pill strong {
  color: var(--accent-cyan);
}

/* ナビゲーションタブ */
.nav-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(59, 130, 246, 0.25));
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

.tab-badge {
  background: var(--accent-orange);
  color: white;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-weight: bold;
}

/* カテゴリ・フィルターバー */
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.category-selector, .level-filter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
}

.custom-select:focus {
  border-color: var(--accent-cyan);
}

/* メイン学習カード */
.main-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
}

/* 問題ヘッダー */
.sentence-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.meta-tags {
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-level {
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.4);
}

.badge-category {
  background: rgba(6, 182, 212, 0.2);
  color: #67e8f9;
  border: 1px solid rgba(6, 182, 212, 0.4);
}

.meta-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1rem;
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.icon-btn.active-star {
  color: #fbbf24;
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.15);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

/* オーディオプレイヤーセクション */
.audio-player-card {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(30, 41, 59, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.audio-main-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.play-controls-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-play {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  border: none;
  color: white;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.3rem;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
  transition: var(--transition);
}

.btn-play:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.6);
}

.btn-repeat {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.btn-repeat:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* オーディオ波形ビジュアライザーアニメーション */
.audio-visualizer {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 10px;
}

.wave-bar {
  width: 4px;
  height: 8px;
  background: var(--accent-cyan);
  border-radius: 2px;
  transition: height 0.15s ease;
}

.audio-visualizer.playing .wave-bar:nth-child(1) { animation: wave 0.8s infinite ease-in-out 0.1s; }
.audio-visualizer.playing .wave-bar:nth-child(2) { animation: wave 0.8s infinite ease-in-out 0.3s; }
.audio-visualizer.playing .wave-bar:nth-child(3) { animation: wave 0.8s infinite ease-in-out 0.5s; }
.audio-visualizer.playing .wave-bar:nth-child(4) { animation: wave 0.8s infinite ease-in-out 0.2s; }
.audio-visualizer.playing .wave-bar:nth-child(5) { animation: wave 0.8s infinite ease-in-out 0.4s; }

@keyframes wave {
  0%, 100% { height: 6px; }
  50% { height: 22px; background: #8b5cf6; }
}

.audio-settings-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.rate-pills {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.rate-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.rate-btn.active {
  background: var(--accent-cyan);
  color: #042f2e;
}

.accent-toggle-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.accent-toggle-btn:hover {
  border-color: var(--accent-cyan);
}

/* 日本語訳エリア */
.translation-box {
  background: rgba(15, 23, 42, 0.5);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.japanese-text {
  font-size: 1.05rem;
  color: #e2e8f0;
  font-weight: 500;
}

.japanese-text.blurred {
  filter: blur(5px);
  user-select: none;
  cursor: pointer;
}

.toggle-ja-btn {
  background: transparent;
  border: none;
  color: var(--accent-cyan);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ==========================================================================
   練習モード (Practice Mode) - 単語スロット & タイピング
   ========================================================================== */
.practice-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 10px 0;
}

.slots-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  min-height: 120px;
  align-items: center;
  justify-content: flex-start;
  cursor: text;
}

.word-slot-group {
  display: inline-flex;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: var(--transition);
  position: relative;
}

.word-slot-group.current {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

.word-slot-group.completed {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.08);
}

.char-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 36px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 2px solid var(--text-muted);
  border-radius: 4px 4px 0 0;
  font-family: "SF Mono", Consolas, Monaco, monospace;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  position: relative;
  transition: var(--transition);
}

.char-slot.active-char {
  border-bottom: 3px solid var(--accent-cyan);
  background: rgba(6, 182, 212, 0.2);
  animation: pulse-char 1s infinite alternate;
}

@keyframes pulse-char {
  from { background: rgba(6, 182, 212, 0.15); }
  to { background: rgba(6, 182, 212, 0.35); }
}

.char-slot.filled {
  border-bottom-color: var(--accent-green);
  color: #34d399;
}

.char-slot.punctuation {
  width: auto;
  padding: 0 4px;
  background: transparent;
  border-bottom: none;
  color: var(--text-secondary);
}

.char-slot.hinted {
  color: #fbbf24;
  border-bottom-color: #fbbf24;
}

.char-slot.wrong-shake {
  animation: shake 0.3s ease;
  border-bottom-color: var(--accent-red);
  background: rgba(239, 68, 68, 0.2);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* タイピング用隠し / 入力フィールド */
.hidden-typing-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  top: 0;
  left: 0;
  z-index: -1;
}

/* 練習モード コントロールバー */
.practice-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.action-btn-group {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  color: white;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
  transition: var(--transition);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
}

/* ==========================================================================
   テストモード (Test Mode) - 全文入力 & 差分採点
   ========================================================================== */
.test-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.test-textarea {
  width: 100%;
  height: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1.15rem;
  padding: 16px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: var(--transition);
}

.test-textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 15px var(--accent-cyan-glow);
}

.test-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* テスト採点結果セクション */
.test-result-box {
  margin-top: 10px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.3s ease;
}

.score-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.score-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.score-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent-green);
}

.score-grade {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

/* 差分ハイライト */
.diff-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diff-row {
  font-size: 1.1rem;
  line-height: 1.8;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}

.diff-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  font-weight: 600;
}

.diff-content {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.diff-word {
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.diff-word.correct {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.diff-word.wrong {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  text-decoration: line-through;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.diff-word.missing {
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
  border: 1px dashed rgba(245, 158, 11, 0.5);
}

/* 解説ノートカード */
.notes-card {
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.notes-icon {
  font-size: 1.2rem;
  color: #c4b5fd;
}

.notes-text {
  font-size: 0.92rem;
  color: #ddd6fe;
  line-height: 1.5;
}

/* ==========================================================================
   カスタム教材 & 復習 & 統計 ビュー
   ========================================================================== */
.view-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.text-input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.95rem;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent-cyan);
}

.custom-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.custom-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
}

.custom-item:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(30, 41, 59, 0.6);
}

.custom-item-content h4 {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.custom-item-content p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.custom-item-actions {
  display: flex;
  gap: 8px;
}

.btn-danger-sm {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger-sm:hover {
  background: var(--accent-red);
  color: white;
}

/* 統計グリッド */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
}

.stat-card-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.stat-card-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* アニメーション & ユーティリティ */
.hidden {
  display: none !important;
}

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

/* レスポンシブ */
@media (max-width: 640px) {
  body {
    padding: 10px;
  }
  
  .header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  
  .header-stats {
    width: 100%;
    justify-content: space-between;
  }
  
  .main-card {
    padding: 16px;
  }
  
  .audio-main-controls {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .char-slot {
    width: 22px;
    height: 32px;
    font-size: 1.1rem;
  }
}

/* ==========================================================================
   無料サーバー（XREA等）広告バナー（#vdbanner）自動検知 & レイアウト最適化
   ========================================================================== */

/* 広告コンテナ自体のセンタリングと安全な余白確保 */
#vdbanner,
.vdbanner,
[id*="vdbanner"] {
  width: 100% !important;
  max-width: 900px !important;
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  margin: 0 auto 16px auto !important;
  position: relative !important;
  z-index: 100 !important;
  overflow: hidden !important;
}

/* 広告要素が存在する場合の初期余白調整 */
body:has(#vdbanner),
body:has(.vdbanner),
body:has([id*="vdbanner"]) {
  padding-top: 10px;
}

/* 広告表示時でもコンテンツ全体が下に途切れずスクロールできるよう高さを自動拡張 */
body:has(#vdbanner) #hero,
body:has(.vdbanner) #hero,
body:has([id*="vdbanner"]) #hero,
body:has(#vdbanner) .app-container,
body:has(.vdbanner) .app-container,
body:has([id*="vdbanner"]) .app-container {
  height: auto !important;
  min-height: calc(100vh - 100px);
}

@media (max-width: 768px) {
  body {
    padding: 10px 10px 60px 10px;
  }

  body:has(#vdbanner) .nav-tabs,
  body:has(.vdbanner) .nav-tabs,
  body:has([id*="vdbanner"]) .nav-tabs {
    height: auto !important;
  }
}
