* { box-sizing: border-box; }

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --bg: #f4f7fb;
  --card: #fff;
  --text: #172033;
  --muted: #687386;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #15803d;
}

body {
  margin: 0;
  padding: 25px 16px 40px;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #e9e7ff, transparent 35%), var(--bg);
}

.app { width: min(1080px, 100%); margin: auto; }

.hero { text-align: center; padding: 18px 10px 25px; }
.badge { display: inline-block; padding: 7px 12px; border-radius: 999px; background: #eef2ff; color: var(--primary-dark); font-size: 13px; font-weight: 800; }
.hero h1 { margin: 12px 0 7px; font-size: clamp(30px, 5vw, 45px); line-height: 1.08; }
.hero p { margin: 0; color: var(--muted); }

.card, .result-card {
  background: rgba(255,255,255,.97);
  border: 1px solid var(--border);
  border-radius: 19px;
  box-shadow: 0 12px 35px rgba(30,41,59,.08);
}
.card { padding: 22px; margin-bottom: 18px; }

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 18px;
}
h2 { margin: 0 0 5px; font-size: 21px; }
.section-heading p, .note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}
label span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #cfd6e2;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 3px solid rgba(79,70,229,.13); border-color: var(--primary); }

.result-card {
  margin-bottom: 18px;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: linear-gradient(135deg, #eef2ff, #fff);
}
.result-label { margin: 0 0 3px; color: var(--muted); font-size: 12px; font-weight: 900; letter-spacing: .08em; }
#result { font-size: 64px; line-height: 1; font-weight: 900; color: var(--primary-dark); }
#result-status { margin: 8px 0 0; font-weight: 800; color: var(--muted); }
.result-meta { display: flex; gap: 10px; }
.result-meta div { min-width: 125px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.result-meta span, .result-meta strong { display: block; }
.result-meta span { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.result-meta strong { font-size: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f8fafc; color: #4b5563; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
td { font-size: 13px; }
.subject-name { font-weight: 700; }
.mark-input { width: 100px; min-height: 38px; }
.grade-view, .gp-view { font-weight: 900; }
.type { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.type.required { background: #eef2ff; color: #3730a3; }
.type.optional { background: #ecfdf5; color: #166534; }

.primary-btn, .secondary-btn {
  border: 0; border-radius: 11px; padding: 11px 17px; font: inherit; font-weight: 800; cursor: pointer;
}
.primary-btn { color: #fff; background: var(--primary); box-shadow: 0 8px 20px rgba(79,70,229,.22); }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { border: 1px solid var(--border); background: #fff; color: var(--text); }
.actions { display: flex; justify-content: center; margin: 22px 0; }

.grades { display: grid; grid-template-columns: repeat(7,1fr); gap: 8px; margin-top: 15px; }
.grades div { padding: 12px 6px; text-align: center; border: 1px solid var(--border); border-radius: 11px; background: #fafbff; }
.grades b, .grades span, .grades small { display: block; }
.grades b { font-size: 17px; }
.grades span { font-weight: 800; }
.grades small { color: var(--muted); font-size: 10px; }
.grades .fail { background: #fff1f2; color: var(--danger); }

footer { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; padding: 5px; }

/* Result sheet */
.print-sheet {
  display: none;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 14mm;
  background: #fff;
  color: #111827;
  border: 1px solid #cbd5e1;
}
.board-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  text-align: center;
  padding-bottom: 12px;
}
.board-emblem { font-size: 30px; }
.official-title { font-size: 19px; font-weight: 900; letter-spacing: .05em; }
.official-subtitle { margin-top: 2px; font-size: 12px; font-weight: 700; letter-spacing: .13em; }
.sheet-title {
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .08em;
  border-top: 2px solid #111827;
  border-bottom: 2px solid #111827;
  padding: 7px;
  margin-bottom: 10px;
}
.info-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #111827;
}
.info-table div, .candidate-grid div {
  display: flex;
  gap: 7px;
  padding: 6px 8px;
  border-right: 1px solid #111827;
  border-bottom: 1px solid #111827;
  font-size: 11px;
}
.info-table div:nth-child(even) { border-right: 0; }
.info-table b, .candidate-grid b { min-width: 105px; }
.section-title {
  margin-top: 13px;
  padding: 6px 8px;
  border: 1px solid #111827;
  border-bottom: 0;
  background: #f1f5f9;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
}
.candidate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #111827;
}
.candidate-grid div:nth-child(even) { border-right: 0; }
.print-subjects { min-width: 0; border: 1px solid #111827; }
.print-subjects th, .print-subjects td {
  padding: 6px 5px;
  border: 1px solid #111827;
  font-size: 10px;
}
.print-subjects th { background: #f1f5f9; text-align: center; }
.print-subjects td:nth-child(3), .print-subjects td:nth-child(4), .print-subjects td:nth-child(5), .print-subjects td:nth-child(6) { text-align: center; }
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border: 1px solid #111827;
}
.summary-grid div { padding: 8px; border-right: 1px solid #111827; display: flex; justify-content: space-between; font-size: 11px; }
.summary-grid div:last-child { border-right: 0; }
.sheet-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 35px;
  padding-top: 8px;
  border-top: 1px solid #94a3b8;
  font-size: 9px;
  color: #475569;
}

@media (max-width: 800px) {
  .form-grid { grid-template-columns: repeat(2,1fr); }
  .result-card { display: block; }
  .result-meta { margin-top: 18px; flex-wrap: wrap; }
  .grades { grid-template-columns: repeat(4,1fr); }
}
@media (max-width: 500px) {
  body { padding: 12px 9px; }
  .card, .result-card { padding: 16px; border-radius: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .grades { grid-template-columns: repeat(2,1fr); }
  .result-meta { display: grid; grid-template-columns: 1fr 1fr; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { margin: 0; padding: 0; background: #fff; }
  .app { width: 100%; }
  .no-print { display: none !important; }
  .print-sheet { display: block; border: 0; margin: 0; }
}
