/* ========================================
   資格試験学習アプリ - スタイルシート
   ======================================== */

/* --- CSS Variables (Light Theme) --- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f7fa;
  --bg-tertiary: #e8ecf1;
  --text-primary: #1a1a2e;
  --text-secondary: #555770;
  --text-muted: #8888a0;
  --border-color: #dde1e8;
  --accent: #4361ee;
  --accent-hover: #3651d4;
  --accent-light: #eef1ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --code-bg: #f0f2f5;
  --code-text: #24292e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 220px;
  --bottomnav-height: 56px;
  --transition: 0.2s ease;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #22223a;
  --bg-tertiary: #2a2a44;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a88;
  --border-color: #3a3a55;
  --accent: #6380f0;
  --accent-hover: #7b94ff;
  --accent-light: #2a2a55;
  --success: #34d399;
  --success-light: #1a2e28;
  --danger: #f87171;
  --danger-light: #2e1a1a;
  --warning: #fbbf24;
  --warning-light: #2e2a1a;
  --code-bg: #2a2a44;
  --code-text: #d4d4e8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* --- Layout --- */
#app {
  display: flex;
  min-height: 100vh;
}

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.exam-badge {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-list {
  list-style: none;
  padding: 8px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  margin: 2px 8px;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.nav-item:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
}

#main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  max-width: 900px;
}

#bottom-nav {
  display: none;
}

/* --- Pages --- */
.page {
  animation: fadeIn 0.15s ease;
}

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

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 8px;
}

/* --- Stats Grid --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Today Task Grid --- */
.today-task-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.task-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.task-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.task-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Dashboard Section --- */
.dashboard-section {
  margin-bottom: 24px;
}

.dashboard-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

/* --- Section Progress --- */
.section-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-item {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.section-stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress-bar {
  width: 80px;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

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

.progress-fill.mastered {
  background: var(--success);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--border-color);
}

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

.btn-outline:hover {
  background: var(--bg-secondary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-color);
  font-size: 1.2rem;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-secondary);
}

.btn-icon.active {
  color: var(--warning);
  border-color: var(--warning);
  background: var(--warning-light);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-outline {
  border: 1px solid var(--border-color);
  background: transparent;
}

.badge-importance {
  background: var(--accent-light);
  color: var(--accent);
}

.section-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Difficulty colors */
.badge-basic {
  background: var(--success-light);
  color: var(--success);
}

.badge-standard {
  background: var(--warning-light);
  color: #b45309;
}

[data-theme="dark"] .badge-standard {
  color: var(--warning);
}

.badge-advanced {
  background: var(--danger-light);
  color: var(--danger);
}

/* --- Quiz --- */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.quiz-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.quiz-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.7;
  margin-bottom: 16px;
  font-weight: 500;
}

/* --- Code Block --- */
.code-block {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
  font-family: "Cascadia Code", "Fira Code", Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

.code-block code {
  font-family: inherit;
}

/* --- Choices --- */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  transition: all var(--transition);
  line-height: 1.5;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-light);
}

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

.choice-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.choice-text {
  flex: 1;
  padding-top: 3px;
}

/* Choice states */
.choice-btn.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
}

.choice-btn.correct .choice-label {
  background: var(--success);
  color: #fff;
}

.choice-btn.incorrect {
  border-color: var(--danger);
  background: var(--danger-light);
}

.choice-btn.incorrect .choice-label {
  background: var(--danger);
  color: #fff;
}

.choice-btn.dimmed {
  opacity: 0.5;
}

/* --- Result Panel --- */
.result-panel {
  margin-top: 20px;
  padding: 20px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.result-indicator {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
}

.result-indicator.correct {
  background: var(--success-light);
  color: var(--success);
}

.result-indicator.incorrect {
  background: var(--danger-light);
  color: var(--danger);
}

.explanation {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 16px;
  white-space: pre-wrap;
}

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

/* --- Session Complete --- */
.complete-card {
  text-align: center;
  padding: 32px 20px;
}

.complete-card h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
}

.complete-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.complete-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- Bookmarks --- */
.bookmarks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}

.bookmark-item:hover {
  background: var(--accent-light);
}

.bookmark-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
  min-width: 100px;
}

.bookmark-question {
  flex: 1;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 4px;
  transition: color var(--transition);
}

.bookmark-remove:hover {
  color: var(--danger);
}

/* --- Settings --- */
.settings-group {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-group h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.setting-item {
  margin-bottom: 16px;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.file-upload-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  transition: all var(--transition);
  cursor: pointer;
}

.file-upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-upload-area p {
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.data-info {
  margin-top: 8px;
  padding: 12px;
  background: var(--success-light);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--success);
}

.theme-toggle {
  display: flex;
  gap: 4px;
}

.theme-toggle .btn-sm.active {
  background: var(--accent);
  color: #fff;
}

select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

/* --- Toast Notification --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--text-primary);
  color: var(--bg-primary);
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

.hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* --- Accent button --- */
.btn-accent {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #fff;
  border: none;
}

.btn-accent:hover {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
}

/* --- Weakness Analysis --- */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topic-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.topic-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.topic-stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topic-accuracy {
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}

.topic-accuracy.low {
  color: var(--danger);
}

.topic-accuracy.mid {
  color: var(--warning);
}

.topic-accuracy.high {
  color: var(--success);
}

.weakness-actions {
  text-align: center;
  padding: 20px 0;
}

/* --- Mock Exam --- */
.mock-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mock-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.mock-name {
  font-size: 1rem;
  font-weight: 600;
}

.mock-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Quiz Timer --- */
.quiz-timer {
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-secondary);
  padding: 4px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.quiz-timer.timer-warning {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-light);
}

.quiz-timer.timer-expired {
  color: var(--danger);
  background: var(--danger-light);
  border-color: var(--danger);
}

/* --- Mock Result Detail --- */
.mock-result-detail {
  margin-bottom: 20px;
  text-align: left;
}

.mock-result-detail h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
}

.mock-elapsed {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}

.mock-section-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ===== Responsive: Mobile (<600px) ===== */
@media (max-width: 600px) {
  #sidebar {
    display: none;
  }

  #main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottomnav-height) + 16px);
    max-width: 100%;
  }

  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottomnav-height);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    align-items: center;
    justify-content: space-around;
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    transition: color var(--transition);
    flex: 1;
  }

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

  .tab-icon {
    font-size: 1.2rem;
  }

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

  .today-task-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .complete-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .page-title {
    font-size: 1.25rem;
  }

  .quiz-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .choice-btn {
    padding: 10px 12px;
  }

  .settings-group {
    padding: 16px;
  }
}

/* ===== Responsive: Tablet (600-900px) ===== */
@media (min-width: 601px) and (max-width: 900px) {
  :root {
    --sidebar-width: 180px;
  }

  #main-content {
    padding: 20px;
  }
}

/* ===== Print --- hide navigation ===== */
@media print {
  #sidebar, #bottom-nav {
    display: none;
  }
  #main-content {
    margin-left: 0;
  }
}
