/* ===== CSS Custom Properties: Pure White ===== */
:root {
  --header-height: 48px;
  --color-primary: #111111;
  --color-primary-dark: #000000;
  --color-primary-light: #f0f0f0;
  --color-correct: #111111;
  --color-correct-light: #e8f5e8;
  --color-incorrect: #666666;
  --color-incorrect-light: #f5f0f0;
  --color-neutral: #aaaaaa;
  --color-neutral-light: #f5f5f5;
  --color-bookmark: #111111;
  --color-bookmark-active: #000000;
  --color-bg: #fafafa;
  --color-card: #ffffff;
  --color-text: #111111;
  --color-text-secondary: #999999;
  --color-border: #e8e8e8;
  --color-timer-warning: #cc3333;
  --color-exam: #333333;
  --color-exam-light: #f0f0f0;
  --font-main: 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  --radius: 4px;
  --radius-lg: 8px;
  --shadow: none;
  --shadow-md: none;
}

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

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

body {
  font-family: var(--font-main);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  min-height: 100vh;
  padding-top: var(--header-height);
}

/* ===== Layout ===== */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== App Header ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}

.app-header-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #111;
  letter-spacing: -0.01em;
}

.hamburger-btn {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px;
  border-radius: var(--radius);
  transition: background 0.12s;
}
.hamburger-btn:hover { background: #f0f0f0; }
.hamburger-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: #111;
  border-radius: 1px;
}

/* ===== Side Menu ===== */
.side-menu {
  position: fixed;
  top: 0; left: -280px;
  width: 280px;
  height: 100%;
  background: #fff;
  border-right: 1px solid var(--color-border);
  z-index: 200;
  transition: left 0.25s ease;
  overflow-y: auto;
}
.side-menu.open { left: 0; }

.side-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-height);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.75rem;
  font-weight: 700;
  color: #999;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.side-menu-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: #999;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.12s;
}
.side-menu-close:hover { background: #f0f0f0; color: #333; }

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

.side-menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  text-decoration: none;
  color: #333;
  transition: background 0.1s;
}
.side-menu-item:hover { background: #f5f5f5; }
.side-menu-item.active { background: #f0f0f0; }
.side-menu-item.active .side-menu-item-label { color: #111; font-weight: 700; }

.side-menu-item-label { font-size: 0.95rem; font-weight: 600; color: #333; }
.side-menu-item-desc { font-size: 0.78rem; color: #999; }

/* ===== Menu Overlay ===== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 150;
  display: none;
}
.menu-overlay.open { display: block; }

/* ===== Timer Bar ===== */
#timer-bar {
  position: fixed;
  top: var(--header-height); left: 0; right: 0;
  z-index: 90;
  background: #111;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 700;
  transition: background 0.3s;
}
#timer-bar.warning { background: #cc3333; }
#timer-bar.hidden { display: none; }
#timer-display { font-variant-numeric: tabular-nums; letter-spacing: 0.05em; }

body.has-timer { padding-top: calc(var(--header-height) * 2); }

/* ===== Card ===== */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  border: 1px solid var(--color-border);
}

/* ===== Top Screen ===== */
.top-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: calc(100vh - var(--header-height));
  padding: 32px 16px 40px;
}

@media (min-height: 700px) and (min-width: 600px) {
  .top-screen { justify-content: center; }
}

.top-screen .logo {
  font-size: 2rem;
  font-weight: 900;
  color: #111;
  margin-bottom: 8px;
  letter-spacing: -0.03em;
}

.top-screen .subtitle {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  margin-bottom: 40px;
  text-align: center;
  line-height: 1.7;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}

.mode-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  border: 1px solid var(--color-border);
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}
.mode-card:hover {
  border-color: #111;
  background: #fafafa;
}

.mode-card .mode-icon { font-size: 1.5rem; margin-bottom: 10px; }
.mode-card .mode-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111;
  margin-bottom: 6px;
}
.mode-card .mode-desc {
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
}
.mode-card .mode-meta {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid #ddd;
  color: #666;
  background: #fafafa;
}
.badge-blue { background: #fafafa; color: #555; border-color: #ddd; }
.badge-purple { background: #fafafa; color: #555; border-color: #ddd; }
.badge-amber { background: #fafafa; color: #555; border-color: #ddd; }

/* ===== Exam Shuffle Toggle ===== */
.exam-shuffle-row {
  margin-top: 12px;
  border-top: 1px solid var(--color-border);
  padding-top: 10px;
}
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  user-select: none;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
  width: 34px;
  height: 18px;
  background: #ccc;
  border-radius: 9px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
}
.toggle-label input:checked + .toggle-switch { background: #111; }
.toggle-label input:checked + .toggle-switch::after { left: 18px; }

/* ===== Bookmark Entry (top screen) ===== */
.bookmark-entry {
  margin-top: 16px;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

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

.quiz-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-bookmarks-link {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 5px 10px;
  transition: border-color 0.12s, color 0.12s;
}
.btn-bookmarks-link:hover { border-color: #111; color: #111; }

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

.progress-bar-wrap {
  background: #eeeeee;
  border-radius: 0;
  height: 2px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: #111;
  transition: width 0.3s;
}

.btn-bookmark {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s;
  font-family: var(--font-main);
}
.btn-bookmark:hover { border-color: #111; color: #111; }
.btn-bookmark.bookmarked {
  background: #111;
  border-color: #111;
  color: #fff;
}
.btn-bookmark .star { font-size: 0.8rem; }

/* ===== Question Card ===== */
.question-number {
  font-size: 0.72rem;
  font-weight: 700;
  color: #bbb;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.question-text {
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 20px;
  white-space: pre-wrap;
  color: #111;
}

.code-block {
  background: #f5f5f5;
  color: #333;
  border-radius: var(--radius);
  padding: 14px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
  margin-bottom: 16px;
  white-space: pre;
  border: 1px solid #e8e8e8;
}

.multiple-hint {
  font-size: 0.78rem;
  color: #555;
  background: #f5f5f5;
  border-radius: var(--radius);
  padding: 5px 10px;
  margin-bottom: 14px;
  font-weight: 600;
  border: 1px solid #e8e8e8;
}

/* ===== Options ===== */
.options-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
  user-select: none;
  background: #fafafa;
}
.option-item:hover:not(.submitted) { border-color: #111; background: #fff; }
.option-item.selected:not(.submitted) { border-color: #111; background: #111; color: #fff; }

/* After submission */
.option-item.correct {
  border-color: #2a7a2a;
  background: #e8f5e8;
  color: #1a4a1a;
}
.option-item.incorrect-selected {
  border-color: #ccc;
  background: #f5f5f5;
  color: #777;
}
.option-item.unselected-correct {
  border-color: #2a7a2a;
  background: #e8f5e8;
  color: #1a4a1a;
}
.option-item.submitted { cursor: default; }
.option-item.submitted:hover { border-color: inherit; background: inherit; color: inherit; }

.option-input { display: none; }

.option-marker {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 50%;
  border: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 1px;
  background: #eee;
  color: #aaa;
  transition: all 0.1s;
}
.option-item.selected:not(.submitted) .option-marker {
  background: #fff;
  color: #111;
  border-color: #fff;
}
.option-item.correct .option-marker {
  background: #2a7a2a;
  color: #fff;
  border-color: transparent;
}
.option-item.incorrect-selected .option-marker {
  background: #aaa;
  color: #fff;
  border-color: transparent;
}
.option-item.unselected-correct .option-marker {
  background: #2a7a2a;
  color: #fff;
  border-color: transparent;
}

.option-item.multiple .option-marker { border-radius: 3px; }

.option-label { font-size: 0.92rem; line-height: 1.55; flex: 1; }

/* ===== Feedback Message ===== */
.feedback {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.88rem;
  display: none;
  border: 1px solid #ddd;
}
.feedback.show { display: block; }
.feedback.correct {
  background: #e8f5e8;
  color: #1a4a1a;
  border-color: #b0d8b0;
}
.feedback.incorrect {
  background: #f5f5f5;
  color: #555;
  border-color: #ddd;
}

/* ===== Explanation ===== */
.explanation {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.7;
  color: #444;
  background: #f7f7f7;
  border: 1px solid #e0e0e0;
  border-left: 3px solid #999;
}

/* ===== Action Buttons ===== */
.quiz-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s;
  text-decoration: none;
}

.btn-primary {
  background: #111;
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #000; }
.btn-primary:disabled { background: #ccc; color: #fff; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: #111;
  border: 1px solid #111;
}
.btn-outline:hover { background: #111; color: #fff; }

.btn-ghost {
  background: transparent;
  color: #666;
  border: 1px solid #ddd;
}
.btn-ghost:hover { background: #f5f5f5; border-color: #aaa; color: #333; }

.btn-exam {
  background: #111;
  color: #fff;
}
.btn-exam:hover { background: #000; }

.btn-full { width: 100%; }

.nav-buttons {
  display: flex;
  gap: 8px;
}
.nav-buttons .btn { flex: 1; }

/* ===== Result Screen ===== */
.result-screen {
  padding: 32px 16px;
  min-height: 100vh;
}

.result-header {
  text-align: center;
  margin-bottom: 24px;
}
.result-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: #111;
}
.result-mode-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid #ddd;
  color: #666;
}

.score-card {
  text-align: center;
  padding: 32px;
  margin-bottom: 20px;
}
.score-number {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
  color: #111;
  margin-bottom: 6px;
  letter-spacing: -0.03em;
}
.score-number.high { color: #2a7a2a; }
.score-number.low { color: #aaa; }
.score-label { color: #aaa; font-size: 0.85rem; }
.score-percent {
  font-size: 1.6rem;
  font-weight: 700;
  color: #bbb;
  margin-top: 4px;
}

.score-detail {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}
.score-detail-item { text-align: center; }
.score-detail-item .val {
  font-size: 1.4rem;
  font-weight: 700;
  color: #111;
}
.score-detail-item .val.correct { color: #2a7a2a; }
.score-detail-item .val.incorrect { color: #aaa; }
.score-detail-item .lbl { font-size: 0.78rem; color: #bbb; margin-top: 2px; }

/* ===== Bookmark Review ===== */
.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #111;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.review-item {
  border: 1px solid #e8e8e8;
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.review-summary {
  padding: 12px 14px;
  cursor: pointer;
  background: #fafafa;
  font-weight: 600;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  user-select: none;
  color: #333;
}
.review-summary::-webkit-details-marker { display: none; }
.review-summary::after { content: '▼'; margin-left: auto; font-size: 0.7rem; color: #bbb; }
details[open] .review-summary::after { content: '▲'; }

.review-body {
  padding: 16px;
  border-top: 1px solid #eee;
  background: #fff;
}
.review-question-text {
  font-size: 0.88rem;
  margin-bottom: 12px;
  white-space: pre-wrap;
  line-height: 1.65;
  color: #333;
}
.review-options { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.review-option {
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  border: 1px solid #eee;
  color: #888;
  background: #fafafa;
}
.review-option.correct-answer {
  border-color: #b0d8b0;
  background: #e8f5e8;
  color: #1a4a1a;
  font-weight: 600;
}
.review-code {
  background: #f5f5f5;
  color: #333;
  border-radius: var(--radius);
  padding: 12px;
  font-family: monospace;
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: pre;
  margin-bottom: 12px;
  border: 1px solid #e8e8e8;
}

/* ===== Result Actions ===== */
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

/* ===== Exit Confirmation Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #111;
  margin: 0 0 4px;
  text-align: center;
}
.modal-discard { color: var(--color-incorrect) !important; }

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .card { padding: 16px; }
  .score-number { font-size: 2.8rem; }
  .mode-card { padding: 18px; }
}

@media (min-width: 600px) {
  .mode-cards { flex-direction: row; }
  .mode-card { flex: 1; }
  .quiz-actions { flex-direction: row; }
  .quiz-actions .btn-full { flex: 1; }
  .result-actions { flex-direction: row; }
}
