/* ═══════════════════════════════════════════
   LangLearn — ヒアリング学習 UI v0.5.1
═══════════════════════════════════════════ */

/* ── リセット＆ベース ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
html { background: #0EA5E9; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: #0EA5E9;
  min-height: 100%;
  color: #fff;
}

#app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: linear-gradient(165deg, #1D4ED8 0%, #2563EB 38%, #0EA5E9 100%);
}

/* ── ヘッダー ── */
header {
  padding-top: max(22px, env(safe-area-inset-top, 22px));
  padding-bottom: 14px;
  padding-left: max(20px, env(safe-area-inset-left, 20px));
  padding-right: max(20px, env(safe-area-inset-right, 20px));
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
}
.header-logo { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; box-shadow: 0 2px 8px rgba(0,0,0,0.3); flex-shrink: 0; }
.header-text { flex-shrink: 0; }
.header-text h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.3px; }
.header-text p { font-size: 0.7rem; color: rgba(255,255,255,0.85); letter-spacing: 0.04em; margin-top: 1px; white-space: nowrap; }
.help-link { margin-left: auto; flex-shrink: 0; font-size: 0.7rem; font-weight: 700; color: #fff; text-decoration: none; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.28); padding: 4px 9px; border-radius: 999px; }

/* ── メイン領域 ── */
.view {
  flex: 1; overflow-y: auto;
  padding: 14px 14px 16px;
  -webkit-overflow-scrolling: touch;
}

/* ── 設定画面 ── */
.setup-card {
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 18px; padding: 18px 16px;
}
.setup-section { margin-bottom: 18px; }
.setup-label {
  display: block; font-size: 0.82rem; font-weight: 700;
  color: rgba(255,255,255,0.85); margin-bottom: 8px;
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  flex: 1; min-width: 80px; padding: 10px 6px;
  border: 1.5px solid rgba(255,255,255,0.35); border-radius: 12px;
  background: rgba(255,255,255,0.08); color: #fff;
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
  text-align: center; transition: all 0.15s;
}
.chip-btn.active {
  background: rgba(255,255,255,0.95); color: #1D4ED8;
  border-color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.theme-input {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  border: 1.5px solid rgba(255,255,255,0.30);
  background: rgba(0,0,0,0.15); color: #fff;
  font-size: 0.95rem; outline: none;
}
.theme-input::placeholder { color: rgba(255,255,255,0.45); }
.theme-input:focus { border-color: rgba(255,255,255,0.7); }

.btn-generate {
  display: block; width: 100%; padding: 14px;
  border: none; border-radius: 14px; cursor: pointer;
  font-size: 1.05rem; font-weight: 800;
  color: #0f172a; background: #38BDF8;
  box-shadow: 0 4px 16px rgba(56,189,248,0.35);
  margin-top: 6px; transition: transform 0.1s;
}
.btn-generate:active { transform: scale(0.97); }
.btn-generate:disabled { opacity: 0.5; pointer-events: none; }

/* ── プレイヤー画面 ── */
#view-player { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.player-fixed { flex-shrink: 0; padding: 14px 14px 0; }
.player-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 14px 16px; -webkit-overflow-scrolling: touch; }
.player-head { margin-bottom: 12px; }
.player-title { font-size: 1.15rem; font-weight: 800; display: block; }
.player-title-ja { font-size: 0.82rem; color: rgba(255,255,255,0.7); }
.player-meta { font-size: 0.75rem; color: rgba(255,255,255,0.6); margin-top: 4px; }

.player-controls {
  display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; margin-bottom: 12px;
}
.repeat-btn {
  display: inline-flex; align-items: center; gap: 1px;
  padding: 6px 10px; border: 1px solid rgba(253,230,138,0.4); border-radius: 10px;
  background: rgba(253,230,138,0.12); color: #FDE68A;
  font-size: 0.78rem; font-weight: 800; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; font-family: inherit;
}
.repeat-btn:active { background: rgba(253,230,138,0.25); }

.progress-bar-wrap {
  position: relative; height: 24px;
  background: rgba(0,0,0,0.2); border-radius: 12px;
  margin-bottom: 14px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%; border-radius: 12px;
  background: linear-gradient(90deg, #38BDF8, #34D399);
  transition: width 0.3s ease;
}
.progress-text {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 0.72rem; font-weight: 700; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ── 文リスト ── */
.sentence-list {
  margin-bottom: 14px;
}
.sent-row {
  padding: 10px 12px; margin-bottom: 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px; transition: all 0.2s;
}
.sent-row.active {
  background: rgba(255,255,255,0.18);
  border-color: rgba(56,189,248,0.6);
  box-shadow: 0 0 12px rgba(56,189,248,0.2);
}
.sent-row.swipe-flash {
  animation: swipeFlash 0.4s ease-out;
}
@keyframes swipeFlash {
  0%   { background: rgba(56,189,248,0.35); }
  100% { background: rgba(255,255,255,0.06); }
}
.repeat-badge {
  display: inline-block; float: right;
  font-size: 0.75rem; font-weight: 800;
  color: #FDE68A; margin-top: 2px;
}

.speaker-tag {
  display: inline-block; font-size: 0.7rem; font-weight: 800;
  padding: 2px 8px; border-radius: 8px; margin-bottom: 4px;
}
.speaker-A { background: #38BDF8; color: #0f172a; }
.speaker-B { background: #A78BFA; color: #0f172a; }

.sent-en { font-size: 0.95rem; line-height: 1.6; margin-bottom: 2px; }
.sent-ja {
  font-size: 0.82rem; color: rgba(255,255,255,0.6);
  line-height: 1.5; margin-top: 4px;
  border-top: 1px dashed rgba(255,255,255,0.15); padding-top: 4px;
}

.player-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}

/* ── クイズ画面 ── */
.quiz-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.quiz-title { font-size: 1.1rem; font-weight: 800; }

.quiz-card {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px; padding: 14px; margin-bottom: 12px;
}
.quiz-q { font-size: 0.95rem; font-weight: 700; margin-bottom: 10px; line-height: 1.6; }

.quiz-choices { display: flex; flex-direction: column; gap: 6px; }
.quiz-choice {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px; border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06); color: #fff;
  font-size: 0.9rem; cursor: pointer; transition: all 0.15s;
}
.quiz-choice.selected {
  background: rgba(56,189,248,0.25); border-color: #38BDF8;
}
.quiz-choice.correct {
  background: rgba(52,211,153,0.3); border-color: #34D399;
}
.quiz-choice.wrong {
  background: rgba(248,113,113,0.3); border-color: #F87171;
}
.quiz-choice:disabled { cursor: default; opacity: 0.85; }

.quiz-explanation {
  font-size: 0.85rem; line-height: 1.6;
  padding: 8px 10px; margin-top: 8px; border-radius: 8px;
}
.quiz-explanation.correct { background: rgba(52,211,153,0.15); color: #A7F3D0; }
.quiz-explanation.wrong   { background: rgba(248,113,113,0.15); color: #FCA5A5; }

.quiz-result { text-align: center; padding: 16px; margin-top: 12px; }
.quiz-score { font-size: 1.8rem; font-weight: 900; color: #38BDF8; }
.quiz-score-msg { font-size: 1.0rem; font-weight: 700; margin-top: 4px; }

/* ── 保存した教材 ── */
.saved-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.saved-title { font-size: 1.1rem; font-weight: 800; }

.saved-item {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
}
.saved-item-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.saved-item-meta { font-size: 0.78rem; color: rgba(255,255,255,0.6); margin-bottom: 6px; }
.saved-date { margin-left: 8px; }
.saved-item-actions { display: flex; gap: 8px; }
.saved-empty {
  text-align: center; padding: 40px 16px;
  font-size: 0.9rem; color: rgba(255,255,255,0.5); line-height: 1.8;
}

/* ── 共通ボタン ── */
.icon-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px; border: none; border-radius: 10px;
  font-size: 0.85rem; font-weight: 700; cursor: pointer;
  color: #fff; background: transparent; transition: all 0.15s;
}
.icon-btn.primary { background: #2563EB; }
.icon-btn.primary:active { background: #1D4ED8; }
.icon-btn.ghost { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25); }
.icon-btn.ghost:active { background: rgba(255,255,255,0.20); }
.icon-btn.small { padding: 6px 10px; font-size: 0.78rem; }
.icon-btn.active { background: rgba(248,113,113,0.3); border-color: #F87171; }
.icon-btn.danger { color: #FCA5A5; }
.icon-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ── 単語タップ ── */
.word {
  cursor: pointer; border-radius: 4px; padding: 1px 2px;
  transition: background 0.15s;
}
.word:active { background: rgba(255,255,255,0.25); }

/* ── 単語ポップアップ ── */
#word-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom);
  animation: fadeIn 0.15s;
}
#word-overlay.hidden { display: none; }
#word-card {
  width: 100%; max-width: 480px;
  background: #1e293b; color: #e5edff;
  border-radius: 20px 20px 0 0; padding: 18px 18px 24px;
  max-height: 60vh; overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
}
.word-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.word-term { font-size: 1.3rem; font-weight: 800; }
.word-close { background: none; border: none; color: #94a3b8; font-size: 1.3rem; cursor: pointer; padding: 4px 8px; }
.word-body { font-size: 0.92rem; line-height: 1.7; }
.word-loading { color: #94a3b8; }
.w-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.w-ipa { font-family: monospace; color: #BAE6FD; font-size: 1.0rem; }
.w-pos { background: rgba(56,189,248,0.18); color: #7DD3FC; padding: 2px 8px; border-radius: 6px; font-size: 0.78rem; font-weight: 700; }
.w-meaning { margin-bottom: 10px; }
.w-usage-label { font-size: 0.78rem; color: #94a3b8; font-weight: 700; margin-bottom: 2px; }
.w-usage { color: #cbd5e1; }

/* ── ステータスバー ── */
.status-bar {
  text-align: center; font-size: 0.82rem; color: rgba(255,255,255,0.7);
  min-height: 1.4em; padding: 4px 0;
}
.status-bar.active { color: #FDE68A; }

/* ── 下タブ ── */
#tabbar {
  display: flex; flex-shrink: 0;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.18);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 9px 0 8px; border: none; background: none; cursor: pointer;
  color: rgba(255,255,255,0.7); font-family: inherit; font-size: 1.3rem;
}
.tab-btn span { font-size: 0.66rem; font-weight: 700; }
.tab-btn.active { color: #fff; }

/* ── コピーライト ── */
.copyright {
  text-align: center; font-size: 0.62rem;
  color: rgba(255,255,255,0.35); padding: 4px 0;
}

/* ── セーフスペーサー ── */
#safe-spacer { background: #0EA5E9; height: env(safe-area-inset-bottom); }

/* ── アニメーション ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
