:root {
  --bg-app: #f4f6f9;
  --bg-card: #ffffff;
  --bg-subtle: #eef2f6;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-hover: #4338ca;
  --ok-color: #10b981;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;
  --ng-color: #f59e0b;
  --ng-bg: #fffbeb;
  --ng-border: #fde68a;
  --danger-color: #ef4444;
  --danger-bg: #fef2f2;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-card: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -2px rgba(15, 23, 42, 0.04);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --nav-height: 64px;
  --header-height: 54px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

/* アプリシェル */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background-color: var(--bg-app);
}

/* ヘッダー */
.app-header {
  height: var(--header-height);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  z-index: 10;
}

.header-inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.header-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

/* メインエリア */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.view.active {
  display: flex;
}

/* カード共通 */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

/* サマリーカード */
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.summary-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.summary-numbers {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--ok-color);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.summary-stats {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.stat-pill {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.stat-learned {
  background: var(--ok-bg);
  color: #065f46;
}

.stat-unlearned {
  background: var(--ng-bg);
  color: #92400e;
}

/* 絞り込みフィルター */
.filter-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.btn-text-small {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.btn-text-small:active {
  background: var(--accent-soft);
}

.chip-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  appearance: none;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.chip.selected {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.chip:active {
  transform: scale(0.96);
}

.filter-divider {
  height: 1px;
  background: var(--border-color);
  margin: 2px 0;
}

/* 出題オプション */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 420px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
}

.option-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.segmented-control {
  display: flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ボタン */
.start-action-area {
  padding-top: 4px;
}

.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-outline,
.btn-outline-warn,
.btn-outline-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, opacity 0.15s ease;
  border: none;
  text-align: center;
}

.btn-large {
  width: 100%;
  padding: 15px 20px;
  font-size: 1rem;
  min-height: 52px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 0.92rem;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 12px 16px;
  font-size: 0.92rem;
}

.btn-ghost-sm {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
}

.btn-ghost-sm:active {
  background: var(--bg-subtle);
}

/* ========== フラッシュカード学習ビュー ========== */
#view-terms-study {
  flex: 1;
  height: 100%;
  justify-content: space-between;
  gap: 10px;
}

.study-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.study-round-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.round-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 9px;
  border-radius: 999px;
}

.study-counter {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

.study-mini-stats {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.mini-ok {
  color: var(--ok-color);
}

.mini-ng {
  color: var(--ng-color);
}

.study-progress {
  height: 5px;
  flex-shrink: 0;
}

/* カードステージ */
.card-stage {
  flex: 1;
  min-height: 260px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
  perspective: 1000px;
  touch-action: pan-y;
}

.flashcard {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
  will-change: transform;
}

.flashcard.dragging {
  transition: none;
}

.swipe-overlay {
  position: absolute;
  top: 18px;
  padding: 6px 14px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  border: 2px solid currentColor;
}

.swipe-overlay-right {
  left: 18px;
  color: var(--ok-color);
  background: var(--ok-bg);
  transform: rotate(-8deg);
}

.swipe-overlay-left {
  right: 18px;
  color: var(--ng-color);
  background: var(--ng-bg);
  transform: rotate(8deg);
}

.card-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  height: 100%;
  overflow: hidden;
}

.card-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card-meta-tag {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 75%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta-tag.small {
  font-size: 0.72rem;
  padding: 2px 8px;
}

.card-status-dot {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.card-status-dot.learned {
  background: var(--ok-bg);
  color: #065f46;
}

.card-status-dot.unlearned {
  background: var(--ng-bg);
  color: #92400e;
}

/* 表面中央 */
.card-front-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 12px 4px;
  overflow-y: auto;
}

.term-text {
  font-size: clamp(1.45rem, 5vw, 2.1rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.term-reading {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.term-english {
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 999px;
}

.card-hint {
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-shrink: 0;
  padding-top: 8px;
}

/* 裏面 */
.card-back-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.back-term-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-definition-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 2px;
  display: flex;
  align-items: flex-start;
  -webkit-overflow-scrolling: touch;
}

.definition-text {
  margin: auto 0;
  font-size: clamp(1rem, 3.2vw, 1.18rem);
  line-height: 1.75;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* 下部判定ボタン */
.judge-actions {
  display: grid;
  grid-template-columns: 1fr 0.7fr 1fr;
  gap: 10px;
  flex-shrink: 0;
  padding-top: 4px;
}

.btn-judge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
  min-height: 62px;
}

.btn-judge:active {
  transform: scale(0.96);
}

.judge-icon {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}

.judge-label {
  font-size: 0.85rem;
  font-weight: 700;
}

.btn-judge-ng {
  background: var(--ng-bg);
  color: #b45309;
  border-color: var(--ng-border);
}

.btn-judge-flip {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-judge-ok {
  background: var(--ok-bg);
  color: #047857;
  border-color: var(--ok-border);
}

/* ========== 結果ビュー ========== */
.result-card {
  text-align: center;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.result-icon {
  font-size: 3rem;
  line-height: 1;
}

.result-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.result-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.result-stats-box {
  display: flex;
  gap: 14px;
  width: 100%;
  margin: 6px 0;
}

.result-stat-item {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-stat-item.ok {
  background: var(--ok-bg);
  color: #065f46;
}

.result-stat-item.ng {
  background: var(--ng-bg);
  color: #92400e;
}

.result-stat-num {
  font-size: 1.6rem;
  font-weight: 800;
}

.result-stat-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.result-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

/* ========== プレースホルダー・設定ビュー ========== */
.placeholder-card {
  text-align: center;
  padding: 36px 20px;
}

.placeholder-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.placeholder-card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.placeholder-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.section-desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.section-desc code {
  background: var(--bg-subtle);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-app);
  transition: border-color 0.15s ease, background-color 0.15s ease;
  position: relative;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-input-hidden {
  display: none;
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.drop-icon {
  font-size: 1.8rem;
}

.drop-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-text small {
  font-weight: 400;
  color: var(--text-secondary);
}

.import-result {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.5;
}

.import-result.success {
  background: var(--ok-bg);
  color: #065f46;
  border: 1px solid var(--ok-border);
}

.import-result.error {
  background: var(--danger-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.settings-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.file-btn-label {
  cursor: pointer;
}

.settings-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-outline,
.btn-outline-warn,
.btn-outline-danger {
  background: transparent;
  padding: 12px 16px;
  font-size: 0.9rem;
  width: 100%;
}

.btn-outline {
  border: 1.5px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline-warn {
  border: 1.5px solid var(--ng-border);
  color: #b45309;
  background: var(--ng-bg);
}

.btn-outline-danger {
  border: 1.5px solid #fecaca;
  color: var(--danger-color);
  background: var(--danger-bg);
}

/* ========== ボトムナビゲーション ========== */
.bottom-nav {
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-shrink: 0;
  z-index: 20;
}

.nav-item {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}

.nav-item.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.nav-label {
  font-size: 0.72rem;
  font-weight: 700;
}

/* トースト */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 41, 59, 0.92);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

/* ========== 復習クイックボタン & ドリルモード ========== */
.btn-review-pill {
  margin-left: auto;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-review-pill:active {
  background: var(--accent);
  color: #ffffff;
}

.drill-question-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.drill-tags-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.drill-type-badge {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.drill-question-body {
  font-size: clamp(1.05rem, 3.6vw, 1.25rem);
  font-weight: 700;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.blank-slot {
  display: inline-block;
  min-width: 72px;
  padding: 1px 10px;
  margin: 0 3px;
  border-bottom: 2.5px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px 6px 0 0;
  text-align: center;
  font-weight: 800;
}

.blank-slot.filled-ok {
  border-bottom-color: var(--ok-color);
  background: var(--ok-bg);
  color: #065f46;
}

.blank-slot.filled-ng {
  border-bottom-color: var(--danger-color);
  background: var(--danger-bg);
  color: #991b1b;
}

.drill-mode-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drill-answer-box {
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.answer-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #047857;
  margin-bottom: 4px;
}

.answer-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.blank-input-row {
  display: flex;
  gap: 8px;
}

.drill-text-input {
  flex: 1;
  font-size: 1rem;
  font-family: inherit;
  padding: 12px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  color: var(--text-primary);
  outline: none;
  min-width: 0;
}

.drill-text-input:focus {
  border-color: var(--accent);
  background: #ffffff;
}

.btn-submit-blank {
  padding: 12px 18px;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.drill-feedback {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.5;
}

.drill-feedback.ok {
  background: var(--ok-bg);
  color: #065f46;
  border: 1px solid var(--ok-border);
}

.drill-feedback.ng {
  background: var(--danger-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  font-size: 0.96rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-app);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.45;
  word-break: break-word;
}

.choice-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.choice-btn.correct {
  background: var(--ok-bg);
  border-color: var(--ok-color);
  color: #065f46;
}

.choice-btn.wrong {
  background: var(--danger-bg);
  border-color: var(--danger-color);
  color: #991b1b;
}

.choice-btn:disabled {
  cursor: default;
}

.drill-explanation-box {
  background: var(--bg-subtle);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 12px 14px;
}

.explanation-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.explanation-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.drill-judge-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* クラウド同期 UI */
.cloud-config-summary {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
}

.cloud-form-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cloud-user-info {
  font-size: 0.88rem;
  font-weight: 600;
  color: #065f46;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  word-break: break-all;
}
