* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 15px;
  background: #f2f2f2;
  font-family: Arial, sans-serif;
  overflow-x: hidden;
  color: #111;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
}

/* ================= INSTRUCTION ================= */
.instruction-box {
  max-width: 860px;
  margin: 0 auto 15px auto;
  background: #ffffff;
  border: 1px solid #d8d8d8;
  border-left: 5px solid #198754;
  padding: 14px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.7;
  font-weight: 700;
}

.instruction-box h3 {
  margin: 0 0 8px 0;
  color: #177a32;
  font-size: 18px;
}

.instruction-box span {
  color: #c00000;
  font-weight: 900;
}

/* ================= SEARCH ================= */
.search {
  text-align: center;
  margin-bottom: 20px;
}

.search input {
  width: 260px;
  max-width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid #bbb;
}

.search button {
  padding: 10px 20px;
  border: none;
  background: #198754;
  color: #fff;
  cursor: pointer;
  font-weight: bold;
  margin-top: 8px;
  border-radius: 4px;
}

/* ================= DROPDOWN ================= */
.year-selector {
  text-align: center;
  margin-bottom: 20px;
}

.year-selector label {
  font-weight: 700;
  color: #1f5e46;
  margin-right: 12px;
  font-size: 1rem;
}

.year-selector select {
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 30px;
  border: 1px solid #bbb;
  background: #fff;
  cursor: pointer;
  outline: none;
  width: 320px;
  max-width: 95%;
}

/* ================= OUTPUT ================= */
#output {
  width: 100%;
  overflow-x: hidden;
}

/* ================= CARD ================= */
.card {
  width: 190mm;
  max-width: 100%;
  background: #fff;
  border: 1px solid #999;
  padding: 10mm;
  margin: auto;
  overflow: hidden;
}

.header { text-align: center; }
.header img { width: 85px; max-width: 100%; }
.title { font-size: 24px; font-weight: 900; color: #177a32; line-height: 1.3; }
.sub { font-size: 14px; font-weight: 700; }

.exam {
  width: 230px;
  max-width: 100%;
  margin: 12px auto 8px auto;
  background: #000;
  color: #fff;
  text-align: center;
  padding: 10px;
  font-size: 18px;
  font-weight: 900;
}

.exam-name {
  width: 320px;
  max-width: 100%;
  margin: 0 auto 10px auto;
  border: 1px solid #000;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 900;
  background: #f7f7f7;
}

.session {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 12px;
}

.info {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  table-layout: fixed;
  word-wrap: break-word;
}

.info td {
  border: 1px solid #000;
  padding: 8px;
  font-size: 14px;
  overflow-wrap: break-word;
}

.label {
  font-weight: 900;
  width: 20%;
  background: #f7f7f7;
}

.value { font-weight: 700; }

.subjects {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  table-layout: fixed;
}

.subjects th {
  border: 1px solid #000;
  background: #000;
  color: #fff;
  text-align: center;
  padding: 10px;
  font-size: 15px;
}

.subjects td {
  border: 1px solid #000;
  padding: 8px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.fourth {
  width: fit-content;
  max-width: 100%;
  margin: 12px auto;
  border: 1px solid #000;
  padding: 8px 15px;
  font-weight: 900;
  font-size: 14px;
  background: #f7f7f7;
  text-align: center;
  word-break: break-word;
}

.warning {
  margin-top: 15px;
  font-size: 15px;
  line-height: 1.7;
}

.warning h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 900;
}

.warning ul {
  margin: 0;
  padding-left: 18px;
}

.signature {
  width: 220px;
  max-width: 100%;
  margin: 60px auto 0 auto;
  text-align: center;
  font-size: 14px;
  font-weight: 900;
}

.signature .line {
  border-top: 2px solid #000;
  margin-bottom: 6px;
}

.signature-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-top: 50px;
  width: 100%;
  flex-wrap: wrap;
}

.signature-item {
  flex: 1;
  min-width: 160px;
  text-align: center;
  font-weight: 900;
  font-size: 14px;
}

.signature-item .line {
  border-top: 2px solid #000;
  margin-bottom: 6px;
  width: 80%;
  margin-left: auto;
  margin-right: auto;
}

.principal-signature-img {
  max-width: 130px;
  height: auto;
  margin-bottom: 4px;
  display: inline-block;
}

.signature-label {
  font-weight: 900;
  margin-top: 6px;
}

.print {
  text-align: center;
  margin-top: 20px;
}

.print button {
  padding: 10px 25px;
  background: red;
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: bold;
  border-radius: 4px;
}

.global-footer {
  margin-top: 25px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: #4a4a4a;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
  padding: 12px 15px;
  width: 100%;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
  border-radius: 6px;
  letter-spacing: 0.3px;
}

.global-footer span {
  font-weight: 600;
  color: #2c6e2c;
}

@media screen and (max-width: 768px) {
  body { padding: 8px; }
  .card { width: 100%; padding: 15px; }
  .title { font-size: 20px; }
  .sub { font-size: 13px; }
  .exam { width: 190px; font-size: 16px; padding: 8px; }
  .exam-name { width: 95%; font-size: 13px; }
  .session { font-size: 14px; }
  .info td { font-size: 13px; padding: 6px; }
  .subjects th, .subjects td { font-size: 13px; padding: 7px; }
  .warning { font-size: 13px; line-height: 1.6; }
  .signature { margin-top: 45px; font-size: 13px; }
  .signature-row { flex-direction: column; align-items: center; gap: 25px; margin-top: 35px; }
  .signature-item { width: 100%; }
  .principal-signature-img { max-width: 100px; }
  .global-footer { font-size: 10px; padding: 10px 12px; margin-top: 20px; }
  .year-selector select { width: 95%; margin-top: 8px; }
  .instruction-box { font-size: 13px; }
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  html, body {
    width: 210mm;
    height: 297mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }
  body * {
    visibility: hidden;
  }
  #output,
  #output * {
    visibility: visible;
  }
  #output {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin: 0;
    padding: 0;
  }
  .card {
    width: 190mm;
    max-width: none;
    margin: 5mm auto 0 auto;
    border: none;
    padding: 8mm 10mm 5mm 10mm;
    page-break-inside: avoid;
  }
  .search,
  .print,
  .year-selector,
  .instruction-box,
  .global-footer {
    display: none !important;
  }
  .subjects th,
  .subjects td {
    text-align: center !important;
  }
  .signature-row {
    display: flex !important;
    justify-content: space-between !important;
    flex-direction: row !important;
    margin-top: 40px !important;
  }
  .principal-signature-img {
    max-width: 110px;
  }
}