/* === Variables === */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --fail: #dc2626;
  --fail-hover: #b91c1c;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

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

/* === Screen Management === */
.screen {
  display: none;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.screen.active {
  display: block;
}

/* === App Header === */
.app-header {
  text-align: center;
  padding: 24px 0 16px;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* === Cards === */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: var(--text);
}

/* === CSV Upload === */
.hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.file-label {
  display: block;
  cursor: pointer;
}

.file-label input[type="file"] {
  display: none;
}

.file-button {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.2s;
}

.file-button:hover {
  background: var(--primary-hover);
}

.csv-status {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--success);
}

.csv-status.error {
  color: var(--fail);
}

/* === Settings === */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-row label {
  font-size: 0.95rem;
  font-weight: 500;
}

.setting-row select,
.setting-row input[type="number"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.setting-row input[type="number"] {
  width: 70px;
  text-align: center;
}

/* === Toggle Switch === */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 26px;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-align: center;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  margin-top: 16px;
}

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

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

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

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

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

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

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

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  font-size: 0.85rem;
  padding: 8px 16px;
  margin-top: 12px;
}

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

.btn-icon {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
  line-height: 1;
}

/* === Quiz Header === */
.quiz-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.progress-info {
  flex: 1;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.overall-progress-text {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* === Progress Bar === */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 20px;
  overflow: hidden;
}

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

/* === Quiz Card === */
.quiz-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow-lg);
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.question-area {
  flex: 1;
}

.category-badge {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* === Answer Area === */
.answer-reveal-area {
  margin-top: 24px;
  text-align: center;
}

.answer-area {
  margin-top: 20px;
  border-top: 2px solid var(--border);
  padding-top: 20px;
}

.answer-content {
  margin-bottom: 16px;
}

.answer-content h3,
.explanation-content h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

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

.explanation-content {
  margin-bottom: 20px;
}

.explanation-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

.eval-buttons {
  display: flex;
  gap: 12px;
}

.eval-buttons .btn {
  flex: 1;
}

/* === Result Screen === */
.result-card {
  text-align: center;
}

.score-display {
  padding: 20px 0;
}

.score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 6px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.score-percent {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.score-detail {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.category-results {
  text-align: left;
  margin: 16px 0;
}

.category-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.category-result-item:last-child {
  border-bottom: none;
}

.category-result-bar {
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-left: 8px;
}

.category-result-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.result-actions .btn {
  margin-top: 0;
}

/* === History === */
.history-list {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  color: var(--text-secondary);
}

.history-score {
  font-weight: 600;
  color: var(--primary);
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 16px 0;
  font-size: 0.9rem;
}

/* === Utilities === */
.hidden {
  display: none !important;
}

/* === Responsive === */
@media (min-width: 768px) {
  .screen {
    padding: 24px;
  }

  .quiz-card {
    padding: 32px 28px;
  }

  .eval-buttons .btn {
    font-size: 1.05rem;
    padding: 14px 24px;
  }
}
