:root {
  --aws-navy: #232f3e;
  --aws-orange: #ff9900;
  --aws-orange-dark: #ec7211;
  --bg: #f2f3f3;
  --card-bg: #ffffff;
  --border: #d5dbdb;
  --text: #16191f;
  --text-muted: #5f6b7a;
  --green: #1a8754;
  --green-bg: #e7f6ec;
  --red: #d13212;
  --red-bg: #fdecea;
  --blue: #0972d3;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

#app {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.screen { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Hero ---------- */
.hero { text-align: center; margin-bottom: 24px; }
.hero h1 {
  font-size: 2rem;
  margin: 0 0 4px;
  color: var(--aws-navy);
}
.subtitle { color: var(--text-muted); margin: 0 0 12px; }
.user-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.user-badge .user-email { font-weight: 600; }
.count-badge {
  display: inline-block;
  background: var(--aws-navy);
  color: #fff;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  margin: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 1.05rem;
  margin: 22px 0 12px;
  color: var(--aws-navy);
}
.card h2:first-child { margin-top: 0; }

/* ---------- Quiz picker ---------- */
.quiz-list { display: flex; flex-direction: column; gap: 14px; }
.quiz-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 5px solid var(--aws-orange);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
}
.quiz-tile:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.12); }
.quiz-tile h3 { margin: 0 0 6px; color: var(--aws-navy); font-size: 1.2rem; }
.quiz-tile .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-muted); font-size: 0.85rem; }
.quiz-tile .chip { background: #eef1f5; padding: 2px 10px; border-radius: 999px; }
.quiz-tile .chip.exam { background: var(--aws-navy); color: #fff; }

/* ---------- Filters ---------- */
.domain-filters { display: flex; flex-direction: column; gap: 8px; }
.domain-filters label,
.num-options label,
.shuffle-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.domain-filters label:hover,
.num-options label:hover { border-color: var(--aws-orange); }
.domain-filters input,
.num-options input { accent-color: var(--aws-orange); width: 17px; height: 17px; }
.domain-filters .dom-count { margin-left: auto; color: var(--text-muted); font-size: 0.85rem; }
.num-options { display: flex; gap: 10px; flex-wrap: wrap; }
.num-options label { flex: 1; min-width: 120px; }
.num-options small { color: var(--text-muted); font-size: 0.78rem; }
.shuffle-toggle { margin-top: 16px; }
.shuffle-toggle input { accent-color: var(--aws-orange); width: 17px; height: 17px; }

/* ---------- Buttons ---------- */
.primary-btn, .secondary-btn, .ghost-btn {
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  padding: 12px 20px;
  transition: background 0.15s, transform 0.05s;
}
.primary-btn { background: var(--aws-orange); color: #fff; }
.primary-btn:hover { background: var(--aws-orange-dark); }
.primary-btn:active { transform: scale(0.98); }
.secondary-btn { background: #fff; color: var(--aws-navy); border-color: var(--aws-navy); }
.secondary-btn:hover { background: #f0f4f8; }
.ghost-btn { background: transparent; color: var(--text-muted); border-color: var(--border); padding: 6px 14px; font-size: 0.85rem; }
.ghost-btn:hover { color: var(--red); border-color: var(--red); }
.ghost-btn.full { width: 100%; margin-top: 10px; }

#start-btn { width: 100%; margin-top: 24px; padding: 14px; font-size: 1.1rem; }
.error-msg { color: var(--red); text-align: center; margin: 12px 0 0; }

/* ---------- Quiz ---------- */
.quiz-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.progress-info { display: flex; align-items: center; gap: 12px; }
#q-position { font-weight: 700; color: var(--aws-navy); }
.domain-tag {
  font-size: 0.75rem;
  background: #eef1f5;
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: 999px;
}
.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
#progress-fill { height: 100%; width: 0; background: var(--aws-orange); transition: width 0.3s ease; }

.type-hint { font-size: 0.82rem; color: var(--blue); font-weight: 600; margin: 0 0 10px; }
.q-text {
  font-size: 1.08rem;
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

.options-list { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: pre-wrap;
  word-break: break-word;
}
.option:hover { border-color: var(--aws-orange); background: #fffaf2; }
.option input { margin-top: 4px; accent-color: var(--aws-orange); width: 17px; height: 17px; flex-shrink: 0; }
.option.selected { border-color: var(--aws-orange); background: #fff6e9; }
.option.correct { border-color: var(--green); background: var(--green-bg); }
.option.wrong { border-color: var(--red); background: var(--red-bg); }
.option .opt-body { flex: 1; }
.option .opt-letter { font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.option.correct .opt-letter { color: var(--green); }
.option.wrong .opt-letter { color: var(--red); }
.option.disabled { cursor: default; }

/* ---------- Feedback / explanation ---------- */
.feedback { margin-top: 20px; padding: 16px; border-radius: 9px; border-left: 4px solid var(--blue); background: #f0f6fc; }
.feedback.correct { border-left-color: var(--green); background: var(--green-bg); }
.feedback.wrong { border-left-color: var(--red); background: var(--red-bg); }
.feedback .verdict { font-weight: 700; margin: 0 0 10px; font-size: 1.05rem; }
.feedback.correct .verdict { color: var(--green); }
.feedback.wrong .verdict { color: var(--red); }
.explanation { white-space: pre-wrap; word-break: break-word; font-size: 0.92rem; color: var(--text); }
.explanation a { color: var(--blue); word-break: break-all; }

.quiz-nav { display: flex; gap: 12px; justify-content: flex-end; }
.quiz-nav button { min-width: 140px; }

/* ---------- Result ---------- */
.result-title { text-align: center; color: var(--aws-navy); margin-top: 0; }
.score-circle {
  width: 160px; height: 160px;
  margin: 10px auto 16px;
  border-radius: 50%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: conic-gradient(var(--aws-orange) var(--pct, 0%), var(--border) 0);
}
.score-circle::before {
  content: "";
  position: absolute;
  width: 124px; height: 124px;
  border-radius: 50%;
  background: var(--card-bg);
}
.score-circle span, .score-circle small { position: relative; z-index: 1; }
.score-circle span { font-size: 2.4rem; font-weight: 800; color: var(--aws-navy); }
.score-circle small { color: var(--text-muted); font-weight: 600; }
.pass-message { text-align: center; font-size: 1.1rem; font-weight: 700; margin: 0 0 8px; }
.pass-message.pass { color: var(--green); }
.pass-message.fail { color: var(--red); }

.domain-scores { display: flex; flex-direction: column; gap: 12px; }
.dom-score-row .dom-label { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 4px; }
.dom-score-row .bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.dom-score-row .bar > div { height: 100%; background: var(--aws-orange); }

.result-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.result-actions button { flex: 1; min-width: 150px; }

/* ---------- Review ---------- */
.review-list { margin-top: 8px; }
.review-item .q-text { font-size: 1rem; }
.review-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.review-item .rev-num { font-weight: 700; color: var(--aws-navy); }
.review-item .rev-badge { font-size: 0.78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.review-item .rev-badge.ok { background: var(--green-bg); color: var(--green); }
.review-item .rev-badge.ng { background: var(--red-bg); color: var(--red); }

@media (max-width: 560px) {
  .hero h1 { font-size: 1.6rem; }
  .quiz-nav button, .result-actions button { width: 100%; }
  .quiz-nav { flex-direction: column; }
}

/* ---------- Stats ---------- */
.full { width: 100%; }
#open-stats-btn { margin-top: 8px; }
.ghost-btn.full { margin-top: 14px; }
.ghost-btn.danger { color: var(--red); border-color: var(--border); }
.ghost-btn.danger:hover { color: #fff; background: var(--red); border-color: var(--red); }

.stats-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.stats-topbar h1 { color: var(--aws-navy); margin: 0; font-size: 1.6rem; }
.muted { color: var(--text-muted); font-weight: 400; font-size: 0.82rem; margin-left: 8px; }
.storage-note {
  background: #fff8e6;
  border: 1px solid #ffd97a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: #6b5500;
}

.stats-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.stats-table th, .stats-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.stats-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; }
.stats-table td.qid { font-weight: 700; color: var(--aws-navy); white-space: nowrap; }
.ok-text { color: var(--green); font-weight: 700; }
.ng-text { color: var(--red); font-weight: 700; }

.qhist { line-height: 1.9; }
.dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 0.7rem;
  margin-right: 3px;
  color: #fff;
}
.dot.ok { background: var(--green); }
.dot.ng { background: var(--red); }
.qhist-group { margin-bottom: 22px; }
.qhist-group:last-child { margin-bottom: 0; }
.qhist-group h3 { color: var(--aws-navy); font-size: 1rem; margin: 0 0 8px; }
#stats-by-quiz, #stats-by-domain { display: flex; flex-direction: column; gap: 12px; }
