:root {
  --maroon-950: #3b0b18;
  --maroon-800: #651329;
  --maroon-700: #7b1b34;
  --maroon-600: #962646;
  --navy-950: #061426;
  --navy-800: #0d2947;
  --navy-700: #153b61;
  --gold-500: #d8aa35;
  --cream-100: #fbf8f2;
  --cream-200: #f2eadf;
  --white: #fff;
  --ink: #172033;
  --muted: #667085;
  --border: #e4dcd2;
  --success: #18794e;
  --danger: #b42318;
  --warning: #a15c00;
  --shadow-sm: 0 6px 20px rgba(14, 28, 48, .08);
  --shadow-lg: 0 22px 60px rgba(11, 25, 44, .18);
  --radius-sm: .65rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;
  --container: 1180px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--cream-100);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, Arial, sans-serif;
  line-height: 1.65;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.container { width: min(calc(100% - 2rem), var(--container)); margin-inline: auto; }
.section { padding-block: clamp(2.5rem, 6vw, 5rem); }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 1000; background: #fff; padding: .75rem 1rem; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.site-header { position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.96); border-bottom: 1px solid rgba(123,27,52,.12); backdrop-filter: blur(12px); }
.header-inner { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: .75rem; }
.brand img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid var(--cream-200); }
.brand span { display: grid; line-height: 1.25; }
.brand strong { color: var(--maroon-700); font-size: 1.15rem; letter-spacing: .02em; }
.brand small { color: var(--muted); font-size: .76rem; }
.site-nav { display: flex; align-items: center; gap: 1.1rem; font-weight: 650; }
.site-nav > a:not(.btn):hover { color: var(--maroon-700); }
.nav-toggle { display: none; border: 1px solid var(--border); border-radius: .65rem; background: #fff; padding: .55rem .8rem; }

.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid transparent; border-radius: .75rem; padding: .72rem 1.15rem; font-weight: 750; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 3px solid rgba(216,170,53,.45); outline-offset: 2px; }
.btn-primary { color: #fff; background: linear-gradient(135deg, var(--maroon-700), var(--maroon-600)); box-shadow: 0 8px 22px rgba(123,27,52,.22); }
.btn-secondary { color: #fff; background: var(--navy-800); }
.btn-outline { color: var(--maroon-700); border-color: rgba(123,27,52,.32); background: #fff; }
.btn-ghost { color: var(--navy-800); border-color: var(--border); background: transparent; }
.btn-danger { color: #fff; background: var(--danger); }
.btn-small { min-height: 38px; padding: .5rem .85rem; font-size: .92rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.hero { position: relative; min-height: min(78vh, 760px); display: grid; align-items: center; color: #fff; overflow: hidden; background: var(--navy-950); }
.hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(6,20,38,.96) 0%, rgba(6,20,38,.78) 44%, rgba(6,20,38,.24) 100%), url("../../images/hero-section-desktop.jpg") center/cover no-repeat; }
.hero::after { content: ""; position: absolute; inset: auto -10% -45% 35%; height: 70%; background: radial-gradient(circle, rgba(216,170,53,.28), transparent 65%); }
.hero-content { position: relative; z-index: 1; max-width: 650px; padding-block: 5rem; }
.eyebrow { display: inline-flex; align-items: center; gap: .5rem; color: #f4d378; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.eyebrow::before { content: ""; width: 2.5rem; height: 2px; background: currentColor; }
.hero h1 { margin: .8rem 0 1rem; font-size: clamp(2.4rem, 6vw, 5.2rem); line-height: 1.08; letter-spacing: -.03em; }
.hero h1 span { display: block; color: #43dbea; }
.hero p { max-width: 580px; color: #dbe6f2; font-size: clamp(1rem, 2vw, 1.2rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.8rem; }
.hero .btn-outline { color: #fff; border-color: rgba(255,255,255,.38); background: rgba(255,255,255,.08); }

.intro-grid, .card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
.feature-card, .content-card, .subject-card, .paper-card, .result-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.feature-card { padding: 1.5rem; }
.feature-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: .8rem; background: #f8e7ec; color: var(--maroon-700); font-weight: 850; }
.feature-card h3 { margin: 1rem 0 .35rem; }
.feature-card p { margin: 0; color: var(--muted); }
.section-heading { max-width: 700px; margin-bottom: 1.6rem; }
.section-heading h1, .section-heading h2 { margin: .25rem 0; line-height: 1.25; color: var(--navy-950); }
.section-heading p { color: var(--muted); margin: .5rem 0 0; }

.auth-page { min-height: calc(100vh - 76px); display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(circle at top right, rgba(123,27,52,.14), transparent 30%), linear-gradient(145deg, #faf7f1, #eef4f8); }
.auth-card { width: min(100%, 470px); padding: clamp(1.5rem, 5vw, 2.5rem); background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.auth-card h1 { margin: 0; color: var(--navy-950); }
.auth-card > p { color: var(--muted); }
.form-group { display: grid; gap: .4rem; margin-bottom: 1rem; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; }
.form-group label { font-weight: 700; }
.form-control { width: 100%; min-height: 46px; border: 1px solid #cfc7be; border-radius: .7rem; background: #fff; color: var(--ink); padding: .7rem .85rem; }
textarea.form-control { min-height: 110px; resize: vertical; }
.form-control[disabled], .form-control[readonly] { background: #f5f2ed; color: #667085; }
.form-hint, .muted { color: var(--muted); font-size: .9rem; }
.form-error { color: var(--danger); font-size: .9rem; }
.alert { padding: .85rem 1rem; margin-bottom: 1rem; border-radius: .75rem; }
.alert-error { color: #7a271a; background: #fee4e2; border: 1px solid #fecdca; }
.alert-warning { color: #7a2e0e; background: #fffaeb; border: 1px solid #fedf89; }
.alert-success { color: #085d3a; background: #dcfae6; border: 1px solid #a6f4c5; }

.portal-hero { padding: 2.5rem 0 1rem; background: linear-gradient(135deg, var(--navy-950), var(--navy-700)); color: #fff; }
.portal-hero h1 { margin: 0; }
.portal-hero p { color: #d9e4ef; }
.subject-card, .paper-card { display: grid; padding: 1.35rem; transition: border-color .2s ease, transform .2s ease; }
.subject-card:hover, .paper-card:hover { border-color: rgba(123,27,52,.45); transform: translateY(-2px); }
.card-kicker { color: var(--maroon-700); font-weight: 750; font-size: .86rem; }
.subject-card h2, .paper-card h2 { margin: .35rem 0; font-size: 1.15rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; padding-top: 1rem; color: var(--muted); font-size: .9rem; }
.status-pill { display: inline-flex; width: fit-content; border-radius: 999px; padding: .25rem .65rem; font-size: .82rem; font-weight: 750; }
.status-ready { color: #087443; background: #dcfae6; }
.status-complete { color: #175cd3; background: #eff8ff; }
.status-locked { color: #7a2e0e; background: #fffaeb; }

.exam-shell { padding-block: 1.5rem 5rem; }
.exam-toolbar { position: sticky; top: 76px; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; padding: .8rem 1rem; color: #fff; background: rgba(6,20,38,.96); border-radius: .85rem; box-shadow: var(--shadow-sm); }
.exam-progress { display: flex; flex-wrap: wrap; gap: .6rem; }
.exam-progress span { padding: .25rem .65rem; border-radius: 999px; background: rgba(255,255,255,.11); font-size: .88rem; }
.save-status { color: #b8f1d3; font-size: .88rem; }
.question-list { display: grid; gap: 1rem; }
.question-card { scroll-margin-top: 155px; padding: clamp(1rem, 3vw, 1.5rem); background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.question-card.is-answered { border-left: 5px solid var(--success); }
.question-number { color: var(--maroon-700); font-weight: 850; }
.question-text { margin: .35rem 0 1rem; font-size: 1.06rem; font-weight: 700; }
.choice-list { display: grid; gap: .7rem; }
.choice-option { position: relative; display: grid; grid-template-columns: 42px 1fr; align-items: start; gap: .7rem; padding: .85rem; border: 1px solid #ddd4ca; border-radius: .85rem; cursor: pointer; background: #fff; }
.choice-option:hover { border-color: var(--maroon-600); background: #fffafb; }
.choice-option:has(input:checked) { border-color: var(--maroon-600); background: #fff2f5; box-shadow: 0 0 0 2px rgba(123,27,52,.08); }
.choice-option input { position: absolute; opacity: 0; }
.choice-label { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--cream-200); color: var(--maroon-700); font-weight: 850; }
.choice-option:has(input:checked) .choice-label { color: #fff; background: var(--maroon-700); }
.exam-submit { margin-top: 1.5rem; padding: 1.3rem; text-align: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); }

.result-card { max-width: 680px; margin-inline: auto; padding: clamp(1.4rem, 4vw, 2.5rem); text-align: center; }
.score-ring { width: 170px; height: 170px; display: grid; place-items: center; margin: 1rem auto; border-radius: 50%; background: conic-gradient(var(--maroon-700) var(--score, 0%), #eadfd6 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 13px; border-radius: 50%; background: #fff; }
.score-ring span { position: relative; display: grid; line-height: 1.15; font-size: 2rem; font-weight: 850; color: var(--navy-950); }
.score-ring small { font-size: .85rem; color: var(--muted); }
.result-status { font-size: 1.2rem; font-weight: 850; }
.result-status.pass { color: var(--success); }
.result-status.fail { color: var(--danger); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin: 1.4rem 0; }
.result-grid div { padding: .85rem; background: var(--cream-100); border-radius: .75rem; }
.result-grid strong { display: block; font-size: 1.15rem; color: var(--navy-950); }

.site-footer { padding: 2.2rem 0; color: #dce5ed; background: var(--navy-950); }
.footer-inner { display: flex; justify-content: space-between; gap: 2rem; align-items: end; }
.site-footer p { margin: .25rem 0 0; color: #aebdca; }
.toast-region { position: fixed; right: 1rem; bottom: 1rem; z-index: 1000; display: grid; gap: .6rem; }
.toast { max-width: min(390px, calc(100vw - 2rem)); padding: .85rem 1rem; color: #fff; background: var(--navy-800); border-radius: .75rem; box-shadow: var(--shadow-lg); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
body > .toast { position: fixed; right: 1rem; top: 5.5rem; z-index: 1000; }
.empty-state { padding: 2.5rem 1rem; text-align: center; background: #fff; border: 1px dashed #cfc5ba; border-radius: var(--radius-md); }
.empty-state h1, .empty-state h2 { color: var(--navy-950); }

@media (max-width: 820px) {
  .nav-toggle { display: inline-flex; }
  .site-nav { display: none; position: absolute; top: 68px; left: 1rem; right: 1rem; align-items: stretch; flex-direction: column; padding: 1rem; background: #fff; border: 1px solid var(--border); border-radius: 1rem; box-shadow: var(--shadow-lg); }
  .site-nav.is-open { display: flex; }
  .site-nav .btn { width: 100%; }
  .intro-grid, .card-grid { grid-template-columns: 1fr; }
  .footer-inner { align-items: start; flex-direction: column; }
  .hero { min-height: 680px; }
  .hero::before { background: linear-gradient(180deg, rgba(6,20,38,.68), rgba(6,20,38,.98) 70%), url("../../images/hero-section-desktop.jpg") 66% center/cover no-repeat; }
  .hero-content { align-self: end; padding-block: 13rem 3rem; }
  .exam-toolbar { top: 70px; align-items: flex-start; flex-direction: column; }
  .result-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .container { width: min(calc(100% - 1.25rem), var(--container)); }
  .brand small { display: none; }
  .brand img { width: 46px; height: 46px; }
  .hero h1 { font-size: 2.4rem; }
  .hero-actions .btn { width: 100%; }
  .choice-option { grid-template-columns: 38px 1fr; padding: .75rem; }
  .form-row { grid-template-columns: 1fr; }
}

@media print {
  .site-header, .site-footer, .exam-toolbar, .btn, .toast-region { display: none !important; }
  body { background: #fff; color: #000; }
  .section { padding: 0; }
}
