:root {
  --navy-950: #172554;
  --navy-900: #1e3a8a;
  --navy-100: #e0e7ff;
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --gold-soft: #fef3c7;
  --paper: #ffffff;
  --bg: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --error: #b91c1c;
  --success: #15803d;
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: var(--navy-900);
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.site-header {
  padding: 16px 20px 22px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: linear-gradient(160deg, var(--navy-950), var(--navy-900));
  border-bottom: 4px solid var(--gold);
  color: #fff;
}

.header-inner {
  display: grid;
  gap: 14px;
  justify-items: center;
  max-width: 880px;
  margin: 0 auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: start;
  min-height: 36px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.22);
}

.back-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
  text-decoration: none;
}

.logo {
  width: 56px;
  height: 56px;
  padding: 4px;
  border-radius: 50%;
  background: #fff;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.tagline {
  margin-top: 2px;
  color: var(--gold-light);
  font-size: 0.8rem;
  font-weight: 500;
}

main {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 16px 56px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 12px 32px -18px rgba(23, 37, 84, 0.35);
}

.login-card {
  max-width: 420px;
  margin: 16px auto;
  padding: 32px 28px;
}

.login-card h1 {
  color: var(--navy-950);
  font-size: 1.45rem;
  text-align: center;
}

.login-sub {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--navy-950);
  font-size: 0.85rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--navy-900);
  background: #fff;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 76px;
}

.toggle-pw {
  position: absolute;
  top: 50%;
  right: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--navy-900);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transform: translateY(-50%);
}

.toggle-pw:hover {
  background: var(--navy-100);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 22px;
  border: 2px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--navy-950);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--navy-900);
}

.btn-gold {
  background: var(--gold);
  color: var(--navy-950);
}

.btn-gold:hover:not(:disabled) {
  background: var(--gold-light);
}

.btn-outline {
  border-color: var(--navy-950);
  background: transparent;
  color: var(--navy-950);
}

.btn-outline:hover:not(:disabled) {
  background: var(--navy-100);
}

.btn-sm {
  min-height: 40px;
  padding: 6px 16px;
  font-size: 0.85rem;
}

.form-msg {
  min-height: 1.4em;
  margin-top: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
}

.form-msg.is-error {
  color: var(--error);
}

.form-msg.is-success {
  color: var(--success);
}

.login-help {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.results-card {
  padding: 20px;
}

.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.student-chip {
  color: var(--navy-950);
  font-size: 0.92rem;
}

.student-chip strong {
  font-size: 1.02rem;
}

.student-chip span:not(:empty)::before {
  content: '\00b7';
  margin: 0 6px;
}

.term-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  padding: 5px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.term-tab {
  flex: 1;
  min-height: 42px;
  padding: 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.term-tab[aria-selected='true'] {
  background: var(--navy-950);
  color: #fff;
}

.report-card {
  position: relative;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}

.report-card::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid var(--gold-light);
  border-radius: 6px;
  pointer-events: none;
}

.report-letterhead {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--gold);
}

.report-letterhead img {
  width: 56px;
  height: 56px;
  flex: none;
}

.school-name {
  color: var(--navy-950);
  font-size: 1.15rem;
  font-weight: 800;
}

.school-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.report-title {
  color: var(--navy-950);
  font-size: 1.25rem;
  text-align: center;
}

.report-year {
  margin: 4px 0 20px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
}

.student-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
  margin: 0 0 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.student-info div {
  display: flex;
  gap: 6px;
}

.student-info dt {
  color: var(--muted);
  font-weight: 600;
}

.student-info dt::after {
  content: ':';
}

.student-info dd {
  margin: 0;
  font-weight: 600;
}

.unavailable {
  padding: 40px 16px;
  color: var(--muted);
  text-align: center;
}

.unavailable h3 {
  margin-bottom: 6px;
  color: var(--navy-950);
  font-size: 1.1rem;
}

.table-wrap {
  margin-bottom: 18px;
  overflow-x: auto;
}

.marks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.marks-table caption {
  margin-bottom: 8px;
  color: var(--navy-950);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

.marks-table th,
.marks-table td {
  padding: 9px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

.marks-table tbody th {
  font-weight: 600;
}

.marks-table thead th {
  background: var(--navy-950);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.marks-table tbody tr:nth-child(even) {
  background: var(--bg);
}

.marks-table tfoot th,
.marks-table tfoot td {
  background: var(--gold-soft);
  color: var(--navy-950);
  font-weight: 800;
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.rating-box {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
}

.rating-box .label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.rating-box .value {
  display: block;
  color: var(--navy-950);
  font-size: 1.3rem;
  font-weight: 800;
}

.feedback-box {
  margin-bottom: 18px;
  padding: 12px 16px;
  border-left: 4px solid var(--gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--gold-soft);
  font-size: 0.9rem;
}

.feedback-box .label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.grading-key {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.capture-mode {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 760px;
  border: 0;
  border-radius: 0;
}

.site-footer {
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
  text-align: center;
}

[data-value^='phone'] {
  white-space: nowrap;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--navy-900);
}

@media (min-width: 720px) {
  .header-inner {
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }

  .back-link {
    grid-column: 1;
    grid-row: 1;
  }

  .brand {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
  }
}

@media (max-width: 480px) {
  .site-header {
    padding: 12px 16px 18px;
  }

  .brand {
    gap: 10px;
  }

  .logo {
    width: 48px;
    height: 48px;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .tagline {
    font-size: 0.7rem;
  }

  main {
    padding: 20px 12px 40px;
  }

  .login-card {
    padding: 26px 20px;
  }

  .results-card {
    padding: 14px;
  }

  .results-toolbar .btn {
    width: 100%;
  }

  .report-card {
    padding: 22px 14px;
  }

  .report-letterhead {
    flex-direction: column;
    text-align: center;
  }

  .student-info {
    grid-template-columns: 1fr;
  }

  .marks-table {
    font-size: 0.82rem;
  }

  .marks-table th,
  .marks-table td {
    padding: 8px;
  }

  .rating-row {
    gap: 6px;
  }

  .rating-box .label {
    font-size: 0.65rem;
  }

  .actions .btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
