/* ===========================
   保育士試験アプリ デザインシステム v1
   = カラー・タイポ・余白・影・モーションを全て変数化
   = ダークモード対応
   =========================== */

:root {
  /* === ブランドカラー === */
  --brand-primary: #2563eb;          /* 信頼の青 */
  --brand-primary-hover: #1d4ed8;
  --brand-primary-light: #dbeafe;
  --brand-primary-soft: #eff6ff;

  --brand-accent: #f59e0b;           /* 達成の黄 */
  --brand-accent-light: #fef3c7;

  --brand-success: #10b981;          /* 正解の緑 */
  --brand-success-light: #d1fae5;
  --brand-danger: #ef4444;           /* 不正解の赤 */
  --brand-danger-light: #fee2e2;

  /* === グレースケール === */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* === セマンティックトークン === */
  --color-bg: #f8fafc;
  --color-bg-elevated: #ffffff;
  --color-bg-subtle: #f1f5f9;
  --color-bg-overlay: rgba(0,0,0,0.5);

  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-text-inverse: #ffffff;

  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;

  /* === タイポグラフィ === */
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Segoe UI", sans-serif;
  --font-mono: "SF Mono", Monaco, monospace;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;
  --text-5xl: 48px;

  --leading-tight: 1.35;
  --leading-normal: 1.65;
  --leading-relaxed: 1.85;

  /* === 余白 === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* === 角丸 === */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-2xl: 28px;
  --radius-full: 9999px;

  /* === 影 === */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.12);
  --shadow-primary: 0 8px 20px rgba(37, 99, 235, 0.25);

  /* === モーション === */
  --motion-fast: 0.15s;
  --motion-base: 0.25s;
  --motion-slow: 0.5s;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* === レイアウト === */
  --max-width-content: 720px;
  --header-height: 60px;
  --nav-bottom-height: 64px;

  /* === セーフエリア === */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

/* ===========================
   ダークモード
   =========================== */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-bg-elevated: #1e293b;
    --color-bg-subtle: #1e293b;
    --color-text: #f1f5f9;
    --color-text-muted: #cbd5e1;
    --color-text-subtle: #94a3b8;
    --color-border: #334155;
    --color-border-strong: #475569;

    --brand-primary-soft: rgba(37, 99, 235, 0.15);
    --brand-primary-light: rgba(37, 99, 235, 0.25);
    --brand-accent-light: rgba(245, 158, 11, 0.18);
    --brand-success-light: rgba(16, 185, 129, 0.18);
    --brand-danger-light: rgba(239, 68, 68, 0.18);

    --shadow-sm: 0 2px 6px rgba(0,0,0,0.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.30);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
  }
}

/* ===========================
   ベース
   =========================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: var(--safe-bottom);
}

/* リンク */
a { color: var(--brand-primary); text-decoration: none; transition: opacity var(--motion-fast); }
a:hover { opacity: 0.8; }

/* スクロールバー（macOS Safari/Chrome） */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ===========================
   レイアウト・ヘッダー
   =========================== */
.app-header {
  background: linear-gradient(135deg, var(--brand-primary) 0%, #60a5fa 100%);
  color: #fff;
  padding: var(--space-4) var(--space-4);
  padding-top: calc(var(--space-4) + var(--safe-top));
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-md);
}
.app-header h1 { margin: 0; font-size: var(--text-lg); font-weight: 700; }
.app-header .sub { font-size: var(--text-xs); opacity: 0.9; margin-top: 2px; }

.app-main {
  max-width: var(--max-width-content);
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--nav-bottom-height) + var(--space-4) + var(--safe-bottom));
}

/* ===========================
   カード
   =========================== */
.card {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--motion-base) var(--ease-out);
}
.card:hover { box-shadow: var(--shadow-md); }
.card.elevated { box-shadow: var(--shadow-md); }
.card h2 { margin: 0 0 var(--space-3); font-size: var(--text-lg); font-weight: 700; }
.card h3 { margin: 0 0 var(--space-2); font-size: var(--text-base); font-weight: 700; }
.card .card-sub { font-size: var(--text-xs); color: var(--color-text-muted); margin: -8px 0 var(--space-3); }

/* ===========================
   ボタン
   =========================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  border: none;
  font-family: inherit; font-size: var(--text-base); font-weight: 700;
  cursor: pointer;
  transition: all var(--motion-base) var(--ease-spring);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--brand-primary);
  color: #fff;
  box-shadow: var(--shadow-primary);
}
.btn-primary:hover { background: var(--brand-primary-hover); }

.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-subtle); }

.btn-ghost {
  background: transparent;
  color: var(--brand-primary);
}
.btn-ghost:hover { background: var(--brand-primary-soft); }

.btn-large { padding: var(--space-4) var(--space-6); font-size: var(--text-lg); }
.btn-block { width: 100%; }

/* タップ波紋 */
.btn .ripple {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,0.5);
  transform: scale(0); animation: ripple 0.6s linear;
  pointer-events: none;
}
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

/* ===========================
   タグ・バッジ
   =========================== */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 700;
}
.tag-success { background: var(--brand-success-light); color: var(--brand-success); }
.tag-danger { background: var(--brand-danger-light); color: var(--brand-danger); }
.tag-accent { background: var(--brand-accent-light); color: var(--brand-accent); }
.tag-muted { background: var(--gray-100); color: var(--gray-600); }

/* ===========================
   入力フィールド
   =========================== */
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-elevated);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-family: inherit; font-size: var(--text-base);
  color: var(--color-text);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-soft);
}

/* ===========================
   ナビゲーションバー（下部）
   =========================== */
.nav-bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-bg-elevated);
  border-top: 1px solid var(--color-border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
  z-index: 50;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--space-2) 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs); font-weight: 600;
  text-decoration: none;
  transition: color var(--motion-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.nav-item .icon { font-size: 22px; line-height: 1; transition: transform var(--motion-base) var(--ease-spring); }
.nav-item.active { color: var(--brand-primary); }
.nav-item.active .icon { transform: scale(1.15); }
.nav-item.active::after {
  content: ''; position: absolute; top: 0; left: 50%;
  width: 28px; height: 3px; background: var(--brand-primary);
  border-radius: 0 0 var(--radius-full) var(--radius-full);
  transform: translateX(-50%);
}

/* ===========================
   進捗リング
   =========================== */
.ring {
  position: relative; width: 140px; height: 140px; margin: 0 auto;
}
.ring svg { transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--color-border); stroke-width: 12; fill: none; }
.ring .ring-fg {
  stroke: var(--brand-success); stroke-width: 12; fill: none; stroke-linecap: round;
  transition: stroke-dasharray var(--motion-slow) var(--ease-out), stroke var(--motion-base);
}
.ring .label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring .label .num {
  font-size: var(--text-3xl); font-weight: 800; color: var(--color-text); line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ring .label .lbl { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 4px; }

/* ===========================
   アニメーション・ユーティリティ
   =========================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn var(--motion-base) var(--ease-out) both; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up { animation: slideUp var(--motion-slow) var(--ease-out) both; }

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.85); }
  60% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
.pop-in { animation: popIn 0.4s var(--ease-spring) both; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.shake { animation: shake 0.4s var(--ease-out); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.pulse { animation: pulse 2s ease-in-out infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spin { animation: spin 0.8s linear infinite; }

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

/* スケルトン */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-subtle) 25%, var(--color-border) 50%, var(--color-bg-subtle) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-md);
}
@keyframes skeletonShimmer {
  to { background-position: -200% 0; }
}

/* 紙吹雪コンテナ */
.confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 1000;
}

/* ===========================
   ユーティリティ
   =========================== */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.text-success { color: var(--brand-success); }
.text-danger { color: var(--brand-danger); }
.text-primary { color: var(--brand-primary); }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.p-4 { padding: var(--space-4); }

.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }
