:root {
  --paper: #f8f3ea;
  --card: #fffdf9;
  --text: #302d29;
  --muted: #7a746c;
  --line: #e8ded1;
  --accent: #c75534;
  --accent-soft: #fbe9df;
  --green: #257359;
  --green-soft: #e7f4ed;
  --red: #b9433f;
  --red-soft: #fbe9e7;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--text);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--paper); color: var(--text); }
button { font: inherit; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 2px; }

.site-header { position: sticky; z-index: 20; top: 0; background: rgba(248, 243, 234, 0.96); border-bottom: 1px solid rgba(206, 191, 171, 0.58); }
.header-inner, .page-shell { width: min(1000px, calc(100% - 40px)); margin: 0 auto; }
.header-inner { height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; color: var(--text); font-weight: 750; cursor: pointer; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #294f43; color: #fff; font-size: 0.69rem; font-weight: 800; letter-spacing: 0.03em; }
.save-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.76rem; }
.save-status span { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.page-shell { min-height: calc(100vh - 67px); display: flex; flex-direction: column; }
#app { flex: 1; padding: 46px 0 64px; outline: none; }
.site-footer { padding: 22px 0 28px; display: flex; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.74rem; }

.page-heading { display: flex; align-items: center; gap: 15px; margin-bottom: 28px; }
.welcome-dot { width: 13px; height: 44px; flex: none; border-radius: 10px; background: #e4aa55; }
.page-heading h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.2rem); font-weight: 750; line-height: 1.2; letter-spacing: -0.035em; }
.page-heading p { margin: 6px 0 0; color: var(--muted); font-size: 0.92rem; line-height: 1.55; }

.course-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.course-card { --accent: #c75534; --accent-soft: #fbe9df; min-height: 232px; padding: 23px; display: flex; flex-direction: column; border: 1px solid rgba(207, 191, 170, 0.64); border-radius: 20px; background: var(--card); box-shadow: 0 7px 20px rgba(81, 63, 43, 0.055); transition: transform 160ms ease, box-shadow 160ms ease; }
.course-card[data-course="hp2"] { --accent: #39739a; --accent-soft: #e5f0f6; }
.course-card[data-course="hp3"] { --accent: #6f6d29; --accent-soft: #f2f0cf; }
.course-card[data-course="hp4"] { --accent: #795679; --accent-soft: #f1e6f1; }
.course-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(81, 63, 43, 0.08); }
.course-topline { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.course-number { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-size: 1rem; font-weight: 800; }
.question-count { color: var(--muted); font-size: 0.77rem; }
.course-card h2 { margin: 18px 0 5px; font-size: 1.16rem; font-weight: 750; }
.course-card p { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.5; }
.course-meta { min-height: 18px; margin-top: 13px; color: var(--accent); font-size: 0.75rem; font-weight: 650; }
.course-actions { margin-top: auto; padding-top: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn { min-height: 42px; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--text); font-size: 0.84rem; font-weight: 700; cursor: pointer; transition: transform 120ms ease, background 120ms ease; }
.btn:hover { transform: translateY(-1px); background: #fff; }
.btn-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-soft { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: rgba(255, 255, 255, 0.65); color: var(--text); }

.mini-progress { height: 6px; overflow: hidden; margin-top: 15px; border-radius: 999px; background: #eee6dc; }
.mini-progress span { height: 100%; display: block; border-radius: inherit; background: var(--accent); }
.resume-caption { margin-top: 6px; display: flex; justify-content: space-between; color: var(--muted); font-size: 0.71rem; }

.history-section { margin-top: 46px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 1rem; font-weight: 750; }
.history-list { display: grid; gap: 8px; }
.history-row { padding: 14px 16px; display: grid; grid-template-columns: minmax(140px, 1fr) auto auto; align-items: center; gap: 20px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 253, 249, 0.82); }
.history-course { font-size: 0.86rem; font-weight: 700; }
.history-date, .history-time { color: var(--muted); font-size: 0.72rem; }
.history-score { min-width: 58px; text-align: right; font-size: 0.9rem; font-weight: 800; }
.empty-history { padding: 20px; border: 1px dashed #d3c5b5; border-radius: 14px; color: var(--muted); font-size: 0.82rem; text-align: center; }

.quiz-shell, .result-wrap { --accent: #c75534; --accent-soft: #fbe9df; width: min(790px, 100%); margin: 0 auto; }
.quiz-shell[data-course="hp2"], .result-wrap[data-course="hp2"] { --accent: #39739a; --accent-soft: #e5f0f6; }
.quiz-shell[data-course="hp3"], .result-wrap[data-course="hp3"] { --accent: #6f6d29; --accent-soft: #f2f0cf; }
.quiz-shell[data-course="hp4"], .result-wrap[data-course="hp4"] { --accent: #795679; --accent-soft: #f1e6f1; }
.quiz-topbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px; margin-bottom: 14px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--text); cursor: pointer; }
.icon-btn:hover { background: #fff; }
.icon-btn svg { width: 18px; height: 18px; }
.quiz-title-block { min-width: 0; }
.quiz-course-name { overflow: hidden; margin: 0 0 3px; font-size: 0.89rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.quiz-position { color: var(--muted); font-size: 0.73rem; }
.score-chip { padding: 7px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.74rem; font-weight: 750; white-space: nowrap; }
.progress-track { height: 7px; overflow: hidden; margin-bottom: 17px; border-radius: 999px; background: #e9e0d5; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 220ms ease; }

.question-card { padding: clamp(22px, 5vw, 38px); border: 1px solid rgba(207, 191, 170, 0.7); border-radius: 22px; background: var(--card); box-shadow: 0 9px 26px rgba(81, 63, 43, 0.06); }
.question-meta { margin-bottom: 17px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--accent); font-size: 0.73rem; font-weight: 650; }
.question-meta span:last-child { color: var(--muted); font-weight: 500; }
.question-text { margin: 0 0 25px; font-family: "Segoe UI", Tahoma, Arial, sans-serif; font-size: clamp(1.2rem, 3vw, 1.62rem); font-weight: 720; line-height: 1.43; letter-spacing: -0.018em; }


.option-list { display: grid; gap: 10px; }
.option { width: 100%; min-height: 59px; padding: 11px 15px 11px 11px; display: grid; grid-template-columns: 36px 1fr; align-items: center; gap: 12px; border: 1px solid #e4d9cc; border-radius: 14px; background: #fff; color: var(--text); text-align: left; cursor: pointer; transition: border-color 120ms ease, background 120ms ease, transform 120ms ease; }
.option:hover:not(:disabled) { transform: translateX(2px); border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 38%, #fff); }
.option:disabled { cursor: default; }
.option-key { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; font-weight: 800; }
.option-text { font-size: 0.9rem; font-weight: 500; line-height: 1.45; }
.option.is-dimmed { opacity: 0.46; }
.option.is-correct { border-color: #8cc7aa; background: var(--green-soft); }
.option.is-correct .option-key { background: var(--green); color: #fff; }
.option.is-wrong { border-color: #dda19e; background: var(--red-soft); }
.option.is-wrong .option-key { background: var(--red); color: #fff; }

.quiz-actions { position: sticky; z-index: 10; bottom: 0; margin-top: 14px; padding: 14px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: linear-gradient(to bottom, rgba(248, 243, 234, 0), var(--paper) 34%); }
.keyboard-hint { color: var(--muted); font-size: 0.7rem; }
kbd { min-width: 20px; padding: 2px 4px; border: 1px solid #d5c8ba; border-bottom-width: 2px; border-radius: 5px; background: var(--card); font: 700 0.67rem/1.2 "Segoe UI", sans-serif; text-align: center; }

.result-card { padding: clamp(27px, 6vw, 46px); border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: 0 9px 26px rgba(81, 63, 43, 0.06); }
.result-kicker { margin: 0 0 9px; color: var(--accent); font-size: 0.78rem; font-weight: 700; }
.result-card h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.3; letter-spacing: -0.03em; }
.result-scoreline { margin: 25px 0 18px; display: flex; align-items: baseline; gap: 8px; }
.result-score { color: var(--accent); font-size: clamp(3.6rem, 10vw, 5.5rem); font-weight: 800; line-height: 0.9; letter-spacing: -0.06em; }
.result-total { color: var(--muted); font-size: 1.05rem; font-weight: 700; }
.result-progress { height: 9px; overflow: hidden; margin-bottom: 24px; border-radius: 999px; background: #ece3d8; }
.result-progress span { height: 100%; display: block; border-radius: inherit; background: var(--accent); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 25px; }
.stat-box { padding: 14px; border-radius: 13px; background: #faf6f0; }
.stat-value { display: block; font-size: 1rem; font-weight: 800; }
.stat-label { display: block; margin-top: 3px; color: var(--muted); font-size: 0.7rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.loading-screen, .error-screen { min-height: 52vh; display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.loading-screen p::before { content: ""; width: 15px; height: 15px; margin: 0 9px -3px 0; display: inline-block; border: 2px solid #d8cbbb; border-top-color: var(--accent); border-radius: 50%; animation: spin 650ms linear infinite; }
.error-box { max-width: 580px; padding: 28px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.error-box h1 { margin: 0 0 9px; font-size: 1.3rem; }
.error-box p { margin: 0; color: var(--muted); font-size: 0.87rem; line-height: 1.6; }
.error-box code { margin: 14px 0; padding: 10px 12px; display: block; overflow-x: auto; border-radius: 8px; background: #302d29; color: #fff; text-align: left; white-space: nowrap; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 680px) {
  .header-inner, .page-shell { width: min(100% - 24px, 1000px); }
  .header-inner { height: 60px; }
  #app { padding: 30px 0 46px; }
  .site-footer span:last-child, .keyboard-hint { display: none; }
  .page-heading { align-items: flex-start; }
  .course-grid { grid-template-columns: 1fr; }
  .course-card { min-height: 220px; padding: 20px; }
  .history-row { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .history-date { grid-row: 2; }
  .history-time { display: none; }
  .history-score { grid-column: 2; grid-row: 1 / span 2; }
  .question-card { padding: 21px 16px; }
  .question-meta { align-items: flex-start; }
  .option { grid-template-columns: 32px 1fr; padding: 10px; }
  .option-key { width: 30px; height: 30px; }
  .quiz-actions { justify-content: stretch; }
  .quiz-actions .btn { width: 100%; min-height: 48px; }
  .result-stats { grid-template-columns: 1fr; }
  .result-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
