/* ==========================================================================
   英検5級 単語帳 スタイルシート（ふりがな＆スマホ最適化）
   ========================================================================== */

:root {
  --bg-body: #f3f6fb;
  --bg-card: #ffffff;
  --bg-soft: #eef2ff;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --border-color: #e2e8f0;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;

  --accent-ja2en: #0ea5e9;
  --accent-ja2en-light: #e0f2fe;

  --success: #10b981;
  --success-hover: #059669;
  --success-light: #d1fae5;

  --danger: #f43f5e;
  --danger-hover: #e11d48;
  --danger-light: #ffe4e6;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 14px 36px rgba(79, 70, 229, 0.14);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

button,
select,
input {
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.flashcard:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ふりがな（ルビ）スタイル */
ruby {
  ruby-position: over;
  ruby-align: center;
}

rt {
  font-size: 0.56em;
  font-weight: 600;
  color: #475569;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.brand-badge rt,
.mode-tab.active rt,
.btn-primary rt,
.sheet-btn.active rt {
  color: rgba(255, 255, 255, 0.92);
}

.main-word rt,
.quiz-question-text rt {
  font-size: 0.42em;
  font-weight: 700;
  color: var(--primary);
}

body.hide-furigana rt {
  display: none;
}

.hidden {
  display: none !important;
}

.app-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

/* ==================== ヘッダー ==================== */
.app-header {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-badge {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 7px 12px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-soft);
  border-color: #c7d2fe;
}

/* 進捗ダッシュボード */
.progress-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.progress-item {
  background: #f8fafc;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 5px;
}

.progress-label strong {
  color: var(--text-main);
  font-size: 0.82rem;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.progress-fill.en2ja {
  background: linear-gradient(90deg, var(--primary), #818cf8);
}

.progress-fill.ja2en {
  background: linear-gradient(90deg, var(--accent-ja2en), #38bdf8);
}

body.audio-track .progress-fill.en2ja {
  background: linear-gradient(90deg, #9333ea, #c084fc);
}

body.audio-track .progress-fill.ja2en {
  background: linear-gradient(90deg, #0d9488, #2dd4bf);
}

/* 設定パネル */
.settings-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
}

.settings-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.toggle-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  user-select: none;
  min-height: 36px;
}

.toggle-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.settings-data-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
}

.settings-backup-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.settings-reset {
  margin-left: auto;
}

.settings-tip {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #475569;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.notice-banner {
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.6;
}

.notice-banner.warning {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.notice-banner.info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecdd3;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger-outline:hover {
  background: var(--danger-light);
}

/* ==================== コントロールバー ==================== */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.mode-tabs {
  display: inline-flex;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-tab .tab-icon {
  font-size: 1rem;
  line-height: 1;
}

.mode-tab:hover {
  color: var(--text-main);
}

.mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.direction-switch {
  display: inline-flex;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.dir-btn {
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.dir-btn[data-dir="en2ja"].active {
  background: var(--primary-light);
  color: var(--primary);
}

.dir-btn[data-dir="ja2en"].active {
  background: var(--accent-ja2en-light);
  color: #0284c7;
}

/* ==================== フィルターバー ==================== */
.filter-section {
  margin-bottom: 16px;
}

.filter-mobile-bar {
  display: none;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 170px;
}

.filter-group label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-sub);
}

.filter-group select {
  padding: 9px 10px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: #f8fafc;
  color: var(--text-main);
  font-size: 1rem; /* iOS自動ズーム防止のため16px */
  font-family: inherit;
  cursor: pointer;
}

.filter-group select:focus {
  outline: 2px solid var(--primary-light);
  border-color: var(--primary);
}

.filter-actions {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 9px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 20px;
  min-height: 46px;
  border-radius: var(--radius-sm);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.count-badge {
  background: var(--bg-soft);
  color: var(--primary);
  font-weight: 800;
  font-size: 0.86rem;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ==================== 共通セクション ==================== */
.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.empty-state {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.empty-icon {
  font-size: 2.6rem;
  margin-bottom: 10px;
}

.empty-title {
  font-size: 1.12rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.empty-sub {
  color: var(--text-sub);
  font-size: 0.92rem;
  margin-bottom: 18px;
}

/* ==================== 単語カードモード ==================== */
.card-stage {
  max-width: 600px;
  margin: 0 auto;
}

.card-counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 2px;
}

.card-position {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text-sub);
  white-space: nowrap;
}

.card-status-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.status-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.status-pill.unseen {
  background: #e2e8f0;
  color: #475569;
}

.status-pill.review {
  background: var(--danger-light);
  color: var(--danger);
}

.status-pill.mastered {
  background: var(--success-light);
  color: var(--success-hover);
}

.category-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--primary);
}

/* 3D フリップカード（Grid重ね合わせで中身が長くても絶対はみ出さない） */
.flashcard-wrapper {
  perspective: 1200px;
  margin-bottom: 14px;
}

.flashcard {
  display: grid;
  width: 100%;
  min-height: 300px;
  border-radius: var(--radius-lg);
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
  user-select: none;
  touch-action: pan-y; /* 縦スクロールは許可しつつ横スワイプ検知 */
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

/* iOS Safari でのカード裏面タップ貫通を防止 */
.flashcard:not(.flipped) .card-back {
  pointer-events: none;
}

.flashcard.flipped .card-front {
  pointer-events: none;
}

.card-face {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 2px solid #e2e8f0;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.card-front {
  border-top: 6px solid var(--primary);
}

body.dir-ja2en .card-front {
  border-top-color: var(--accent-ja2en);
}

body.mode-audio .card-front {
  border-top-color: #9333ea;
  background: linear-gradient(180deg, #ffffff 0%, #faf5ff 100%);
}

body.mode-audio.dir-ja2en .card-front {
  border-top-color: #0d9488;
  background: linear-gradient(180deg, #ffffff 0%, #f0fdfa 100%);
}

/* おとカード（音声だけ）オモテ面UI */
.audio-only-body {
  gap: 12px;
  padding: 16px 0;
}

.audio-big-btn {
  position: relative;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #9333ea);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(124, 58, 237, 0.34);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

body.mode-audio.dir-ja2en .audio-big-btn {
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  box-shadow: 0 10px 26px rgba(13, 148, 136, 0.34);
}

.audio-big-btn:active {
  transform: scale(0.93);
}

.audio-big-btn.speaking {
  animation: audio-pulse 1.1s infinite ease-out;
}

@keyframes audio-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.45);
  }
  70% {
    box-shadow: 0 0 0 20px rgba(124, 58, 237, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(124, 58, 237, 0);
  }
}

body.mode-audio.dir-ja2en .audio-big-btn.speaking {
  animation-name: audio-pulse-teal;
}

@keyframes audio-pulse-teal {
  0% {
    box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.45);
  }
  70% {
    box-shadow: 0 0 0 20px rgba(13, 148, 136, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(13, 148, 136, 0);
  }
}

.audio-big-icon {
  font-size: 2.3rem;
  line-height: 1;
}

.audio-big-label {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.audio-prompt-text {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-main);
}

.audio-sub-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.audio-sub-btn {
  background: #ffffff;
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 16px;
  min-height: 42px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, transform 0.1s;
}

.audio-sub-btn:hover {
  background: var(--bg-soft);
}

.audio-sub-btn:active {
  transform: scale(0.95);
}

.audio-hint-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 1.05rem;
  font-weight: 700;
  max-width: 100%;
  word-break: break-word;
}

.audio-homophone-note {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  max-width: 100%;
}

.audio-big-btn:disabled,
.audio-sub-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.word-note {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.cell-note {
  display: inline-block;
  font-size: 0.78rem;
  color: #475569;
  margin-left: 6px;
}

.dict-note {
  font-size: 0.82rem;
  color: #475569;
  background: #f8fafc;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  padding: 5px 10px;
}

.back-prompt-recall {
  font-size: 0.92rem;
  color: var(--text-sub);
  background: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 4px 12px;
  border-radius: 999px;
}

.card-back {
  transform: rotateY(180deg);
  border-top: 6px solid var(--success);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.face-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.lang-label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-sub);
}

.pos-badge {
  font-size: 0.78rem;
  font-weight: 700;
  background: #f1f5f9;
  color: #334155;
  padding: 3px 10px;
  border-radius: 6px;
}

.face-body {
  text-align: center;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.main-word {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: 0.01em;
  word-break: break-word;
  line-height: 1.55;
}

.sub-hint {
  font-size: 1rem;
  color: var(--text-sub);
  font-weight: 600;
}

.speak-btn {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  padding: 9px 18px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.speak-btn:hover {
  background: #c7d2fe;
}

.speak-btn:active {
  transform: scale(0.95);
}

.example-box {
  margin-top: 8px;
  width: 100%;
  background: #f1f5f9;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  text-align: left;
}

.example-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.example-en {
  font-weight: 700;
  font-size: 0.96rem;
  color: var(--text-main);
  word-break: break-word;
}

.example-ja {
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-top: 4px;
  line-height: 1.8;
}

.speak-mini-btn {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.speak-mini-btn:hover {
  background: var(--primary-light);
}

.speak-mini-btn:active {
  transform: scale(0.93);
}

.face-footer {
  text-align: center;
  font-size: 0.78rem;
  color: #475569;
}

.hint-mobile {
  display: none;
}

/* 判定ボタン */
.judge-actions {
  display: grid;
  grid-template-columns: 1fr 0.75fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-judge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 8px;
  min-height: 64px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}

.btn-judge:active {
  transform: scale(0.96);
}

.btn-judge .judge-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.btn-judge .judge-text {
  font-size: 0.94rem;
}

.btn-judge kbd {
  font-size: 0.7rem;
  opacity: 0.7;
  font-family: monospace;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

.btn-judge.review {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #fecdd3;
}

.btn-judge.review:hover {
  background: #fecdd3;
}

.btn-judge.flip {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
  box-shadow: var(--shadow-sm);
}

.btn-judge.flip:hover {
  background: #f8fafc;
}

.btn-judge.mastered {
  background: var(--success-light);
  color: var(--success-hover);
  border-color: #a7f3d0;
}

.btn-judge.mastered:hover {
  background: #a7f3d0;
}

/* カード下部ナビ */
.card-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 16px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: var(--bg-soft);
}

.nav-btn:active {
  transform: scale(0.97);
}

.both-status-mini {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-sub);
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
}

/* ==================== 4択テストモード ==================== */
.quiz-stage {
  max-width: 600px;
  margin: 0 auto;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.score-badge {
  background: var(--success-light);
  color: var(--success-hover);
  font-weight: 800;
  font-size: 0.88rem;
  padding: 4px 12px;
  border-radius: 999px;
}

.quiz-question-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.quiz-question-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.quiz-question-text {
  font-size: 2rem;
  font-weight: 800;
  margin-top: 4px;
  line-height: 1.55;
  word-break: break-word;
}

.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-choice-btn {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 15px 14px;
  min-height: 58px;
  font-size: 1.04rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  text-align: center;
  line-height: 1.65;
}

.quiz-choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--bg-soft);
}

.quiz-choice-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.quiz-choice-btn.correct {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success-hover);
}

.quiz-choice-btn.wrong {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.quiz-choice-btn:disabled {
  cursor: default;
}

.quiz-feedback {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.feedback-msg {
  font-weight: 800;
  font-size: 1.02rem;
  margin-bottom: 6px;
}

.feedback-msg.is-correct {
  color: var(--success-hover);
}

.feedback-msg.is-wrong {
  color: var(--danger);
}

.feedback-example {
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-bottom: 14px;
  line-height: 1.8;
}

.quiz-feedback-actions {
  display: flex;
  justify-content: flex-end;
}

.quiz-result {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.result-score {
  font-size: 2.3rem;
  font-weight: 900;
  color: var(--primary);
  margin: 10px 0;
}

.result-comment {
  color: var(--text-sub);
  margin-bottom: 22px;
  font-weight: 600;
}

.result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ==================== 一覧チェックモード ==================== */
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.search-box {
  flex: 1 1 220px;
}

.search-box input {
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  font-size: 1rem; /* iOS自動ズーム防止 */
  font-family: inherit;
}

.search-box input:focus {
  outline: 2px solid var(--primary-light);
  border-color: var(--primary);
}

.list-switch-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.list-track-switch {
  display: inline-flex;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  gap: 4px;
}

.track-btn {
  border: none;
  background: transparent;
  padding: 7px 11px;
  min-height: 36px;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-sub);
  cursor: pointer;
  white-space: nowrap;
}

.track-btn[data-track="text"].active {
  background: var(--primary);
  color: #fff;
}

.track-btn[data-track="audio"].active {
  background: #7c3aed;
  color: #fff;
}

.red-sheet-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.toolbar-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
  padding-left: 4px;
  white-space: nowrap;
}

.sheet-btn {
  border: none;
  background: transparent;
  padding: 7px 11px;
  min-height: 36px;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-sub);
  cursor: pointer;
  white-space: nowrap;
}

.sheet-btn.active {
  background: var(--danger);
  color: #fff;
}

.list-hint {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 10px;
}

.table-wrap {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.word-table th {
  background: #f8fafc;
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.word-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.word-table tr:last-child td {
  border-bottom: none;
}

.word-table tr:hover td {
  background: #f8fafc;
}

.col-speak {
  width: 56px;
  text-align: center;
}

.col-check {
  width: 86px;
  text-align: center !important;
}

.cell-en-word {
  font-weight: 800;
  font-size: 1.04rem;
  color: var(--text-main);
}

.cell-reading {
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-left: 4px;
}

.cell-pos {
  display: inline-block;
  font-size: 0.72rem;
  background: #f1f5f9;
  color: #475569;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 5px;
}

.check-dir-prefix {
  display: none;
}

/* 暗記シート（マスク） */
.masked-text {
  display: inline-block;
  border: none;
  font: inherit;
  text-align: left;
  background: #fda4af;
  color: transparent !important;
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}

.masked-text * {
  color: transparent !important;
  background: transparent !important;
}

.masked-text rt {
  color: transparent !important;
}

.masked-text.revealed {
  background: #fff1f2;
  color: var(--text-main) !important;
}

.masked-text.revealed * {
  color: inherit !important;
}

.masked-text.revealed rt {
  color: #475569 !important;
}

/* 一覧のチェック切替ボタン */
.check-cycle-btn {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 38px;
  min-width: 58px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s;
}

.check-cycle-btn:active {
  transform: scale(0.94);
}

.check-cycle-btn.unseen {
  background: #f8fafc;
  color: #475569;
}

.check-cycle-btn.mastered {
  background: var(--success-light);
  color: var(--success-hover);
  border-color: #a7f3d0;
}

.check-cycle-btn.review {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #fecdd3;
}

.app-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.8rem;
  color: #475569;
}

/* トースト通知 */
.toast-banner {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28);
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ==================== 単語帳（検索・答え表示）モード ==================== */
.dict-search-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.dict-search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.dict-search-icon {
  position: absolute;
  left: 12px;
  font-size: 1rem;
  pointer-events: none;
}

.dict-search-box input {
  width: 100%;
  padding: 11px 42px 11px 38px;
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  background: #f8fafc;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-main);
  transition: border-color 0.15s, background 0.15s;
}

.dict-search-box input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.dict-clear-btn {
  position: absolute;
  right: 6px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dict-clear-btn:hover {
  background: #cbd5e1;
}

.dict-index-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 4px;
  scrollbar-width: thin;
}

.dict-index-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border-color);
  background: #f8fafc;
  color: var(--text-sub);
  border-radius: 999px;
  padding: 5px 11px;
  min-height: 34px;
  min-width: 36px;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.12s;
}

.dict-index-chip:hover {
  background: var(--bg-soft);
  color: var(--primary);
}

.dict-index-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.dict-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-sub);
}

.dict-result-count {
  font-weight: 800;
  color: var(--primary);
}

.dict-results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.dict-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body.dir-ja2en .dict-card {
  border-left-color: var(--accent-ja2en);
}

.dict-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.dict-head-main {
  min-width: 0;
  flex: 1;
}

.dict-primary-term {
  font-size: 1.38rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.5;
  word-break: break-word;
}

.dict-reading-tag {
  display: inline-block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-left: 6px;
}

.dict-answer-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.dict-answer-label {
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

body.dir-ja2en .dict-answer-label {
  background: var(--accent-ja2en-light);
  color: #0284c7;
}

.dict-answer-text {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.6;
  word-break: break-word;
}

.dict-speak-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.dict-example {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.dict-example-en-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  color: var(--text-main);
}

.dict-example-ja {
  color: var(--text-sub);
  margin-top: 2px;
  line-height: 1.75;
}

.dict-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.dict-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.dict-open-card-btn {
  border: 1px solid #c7d2fe;
  background: var(--bg-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 34px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.dict-open-card-btn:hover {
  background: var(--primary-light);
}

/* ==========================================================================
   スマホ最適化（画面幅 640px 以下）
   ========================================================================== */
@media (max-width: 640px) {
  .app-container {
    /* 上部ノッチ（ホーム画面起動時）＋左右＆下部固定ナビバーのセーフエリアを確保 */
    padding: calc(10px + env(safe-area-inset-top, 0px))
      calc(10px + env(safe-area-inset-right, 0px))
      calc(86px + env(safe-area-inset-bottom, 0px))
      calc(10px + env(safe-area-inset-left, 0px));
  }

  .toast-banner {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  /* ヘッダーをコンパクト化 */
  .app-header {
    padding: 11px 12px;
    border-radius: 16px;
    margin-bottom: 10px;
  }

  .header-top {
    margin-bottom: 8px;
  }

  .brand-badge {
    font-size: 0.78rem;
    padding: 3px 8px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .icon-btn {
    padding: 6px 10px;
    min-height: 36px;
    font-size: 0.82rem;
  }

  .progress-dashboard {
    gap: 8px;
  }

  .progress-item {
    padding: 6px 9px;
    border-radius: 10px;
  }

  .progress-label {
    font-size: 0.74rem;
    margin-bottom: 4px;
  }

  .progress-label strong {
    font-size: 0.74rem;
  }

  .progress-track {
    height: 6px;
  }

  .settings-grid {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .settings-data-row {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-backup-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-backup-actions button {
    width: 100%;
  }

  .settings-reset {
    margin-left: 0;
    width: 100%;
    padding-top: 4px;
  }

  .btn-danger-outline {
    width: 100%;
  }

  /* モード切替タブをスマホ下部固定のボトムナビゲーションバーに！ */
  .controls-bar {
    margin-bottom: 8px;
  }

  .mode-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 5px calc(3px + env(safe-area-inset-right, 0px)) calc(5px + env(safe-area-inset-bottom, 0px)) calc(3px + env(safe-area-inset-left, 0px));
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  }

  body.keyboard-open .mode-tabs {
    display: none;
  }

  .mode-tab {
    flex-direction: column;
    gap: 1px;
    padding: 6px 2px;
    min-height: 52px;
    font-size: 0.68rem;
    border-radius: 10px;
  }

  .mode-tab .tab-icon {
    font-size: 1.12rem;
  }

  /* 出題方向スイッチは横幅いっぱいに大きく */
  .direction-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .dir-btn {
    font-size: 0.88rem;
    padding: 9px 6px;
    min-height: 44px;
    text-align: center;
  }

  /* フィルターバーをスマホは折りたたみ式にしてファーストビュー確保 */
  .filter-section {
    margin-bottom: 10px;
  }

  .filter-mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .btn-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 13px;
    min-height: 40px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
  }

  .filter-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    display: inline-block;
  }

  .filter-mobile-right {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .btn-compact {
    padding: 7px 11px;
    min-height: 40px;
    font-size: 0.84rem;
  }

  .filter-bar {
    display: none;
    margin-top: 8px;
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar.open {
    display: flex;
  }

  .filter-bar .filter-actions {
    display: none;
  }

  /* 単語カード（スマホで1画面にすっきり収まる） */
  .card-counter-row {
    margin-bottom: 8px;
  }

  .flashcard-wrapper {
    margin-bottom: 12px;
  }

  .flashcard {
    min-height: 255px;
  }

  .card-face {
    padding: 14px 16px;
    border-radius: 18px;
  }

  .face-body {
    padding: 10px 0;
  }

  .audio-big-btn {
    width: 94px;
    height: 94px;
  }

  .audio-big-icon {
    font-size: 2rem;
  }

  .audio-prompt-text {
    font-size: 0.88rem;
  }

  .main-word {
    font-size: 1.85rem;
  }

  .sub-hint {
    font-size: 0.92rem;
  }

  .hint-desktop {
    display: none;
  }

  .hint-mobile {
    display: inline;
  }

  .btn-judge {
    min-height: 60px;
    padding: 10px 6px;
  }

  .btn-judge .judge-text {
    font-size: 0.88rem;
  }

  .btn-judge kbd {
    display: none;
  }

  .judge-actions {
    gap: 8px;
    margin-bottom: 10px;
  }

  .both-status-mini {
    font-size: 0.72rem;
    padding: 5px 8px;
    gap: 4px 8px;
  }

  .nav-btn {
    padding: 9px 12px;
    font-size: 0.85rem;
  }

  /* 4択テスト */
  .quiz-question-card {
    padding: 16px 14px;
    margin-bottom: 12px;
  }

  .quiz-question-text {
    font-size: 1.7rem;
  }

  .quiz-choices {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .quiz-choice-btn {
    padding: 13px 14px;
    min-height: 54px;
    font-size: 1rem;
  }

  .quiz-feedback-actions .btn-primary,
  .result-actions .btn-primary,
  .result-actions .btn-secondary {
    width: 100%;
  }

  /* 一覧チェックモード：スマホでは横スクロールなしのカード型リストに自動変換！ */
  .list-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .list-switch-group {
    flex-direction: column;
    align-items: stretch;
  }

  .list-track-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .red-sheet-controls {
    display: grid;
    grid-template-columns: auto repeat(3, 1fr);
    width: 100%;
  }

  .sheet-btn {
    padding: 7px 6px;
    font-size: 0.82rem;
    text-align: center;
  }

  .table-wrap {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
  }

  .word-table thead {
    display: none;
  }

  .word-table,
  .word-table tbody {
    display: block;
    width: 100%;
  }

  .word-table tr {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }

  .word-table td {
    display: block;
    padding: 0;
    border: none;
    text-align: left !important;
  }

  .word-table tr:hover td {
    background: transparent;
  }

  .word-table td.col-speak {
    grid-column: 1;
    grid-row: 1 / 3;
    width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .word-table td.cell-en-td {
    grid-column: 2;
    grid-row: 1;
  }

  .word-table td.cell-ja-td {
    grid-column: 2;
    grid-row: 2;
    font-size: 0.94rem;
  }

  .word-table td.cell-check-row {
    grid-column: 1 / 3;
    grid-row: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px dashed var(--border-color);
    width: 100%;
  }

  .word-table td.cell-check-row .check-cycle-btn {
    width: 100%;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.86rem;
  }

  .check-dir-prefix {
    display: inline;
    font-weight: 700;
    font-size: 0.8rem;
  }

  /* 通常のcol-checkはPCのみ使用、スマホ用はcell-check-rowでまとめる */
  .word-table td.col-check-desktop {
    display: none;
  }

  .app-footer {
    margin-top: 16px;
    font-size: 0.75rem;
  }

  /* 単語帳モードのスマホ微調整 */
  .dict-search-panel {
    padding: 11px;
    margin-bottom: 10px;
  }

  .dict-card {
    padding: 12px;
  }

  .dict-primary-term {
    font-size: 1.24rem;
  }

  .dict-answer-text {
    font-size: 1.06rem;
  }
}

/* PC表示ではスマホ用の結合チェックセルを非表示 */
@media (min-width: 641px) {
  .word-table td.cell-check-row {
    display: none;
  }
}

/* 横向き（ランドスケープ）端末の左右セーフエリア対応 */
@media (min-width: 641px) {
  .app-container {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
}

/* 動きを減らすOS設定への配慮 */
@media (prefers-reduced-motion: reduce) {
  .flashcard,
  .progress-fill,
  .audio-big-btn,
  .btn-judge,
  .quiz-choice-btn,
  .masked-text {
    transition: none !important;
    animation: none !important;
  }
}
