:root {
  --petrol: #046b80;
  --petrol-dark: #035666;
  --petrol-light: #0e7e95;
  --orange: #e8952f;
  --bg: #e9e9e9;
  --surface: #ffffff;
  --surface-soft: #f5f5f5;
  --border: #bfbfbf;
  --border-light: #d8d8d8;
  --text: #1d1d1d;
  --muted: #666666;
  --danger: #a92229;
  --success: #2e7d4f;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, .button { min-height: 44px; }
:focus-visible { outline: 3px solid rgba(4, 107, 128, .32); outline-offset: 2px; }

.app-header {
  min-height: 54px;
  background: var(--petrol);
  color: #fff;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 5px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand, .auth-brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 650; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: #fff; color: var(--petrol); font-size: 14px; font-weight: 750; }
.app-header nav { display: flex; align-items: stretch; align-self: stretch; }
.app-header nav a { display: inline-flex; align-items: center; padding: 0 14px; text-decoration: none; border-bottom: 3px solid transparent; }
.app-header nav a:hover { background: rgba(255, 255, 255, .08); }
.app-header nav a[aria-current="page"] { border-color: var(--orange); }
.account { justify-self: end; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.account form { margin: 0; }
.account-link { color: #fff; min-height: 44px; display: inline-flex; align-items: center; text-underline-offset: 3px; }
.account-link[aria-current="page"] { color: #fff; text-decoration-color: var(--orange); text-decoration-thickness: 2px; }
.link-button { border: 0; background: transparent; color: #fff; padding: 4px; min-height: 44px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.page { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 60px; }
.page-narrow { width: min(760px, calc(100% - 32px)); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.page-heading h1 { margin: 0; color: var(--petrol); font-size: clamp(1.6rem, 3vw, 2.1rem); font-weight: 700; }
.page-heading p { margin: 5px 0 0; color: var(--muted); }
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.subject-list { background: var(--surface); border: 1px solid var(--border-light); }
.study-year-group { margin-bottom: 28px; }
.study-year-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 9px; }
.study-year-heading h2 { margin: 0; color: var(--petrol); font-size: 1.2rem; }
.study-year-heading span { color: var(--muted); font-size: 13px; }
.subject-row { display: grid; grid-template-columns: minmax(0, 1fr) 180px auto; align-items: center; gap: 24px; padding: 22px; border-bottom: 1px solid var(--border-light); }
.subject-row:last-child { border-bottom: 0; }
.subject-main h2, .subject-main h3 { margin: 0; color: var(--petrol); font-size: 1.15rem; }
.subject-main p { margin: 4px 0 10px; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: 13px; }
.subject-result { display: flex; flex-direction: column; text-align: right; color: var(--muted); font-size: 13px; }
.subject-result strong { color: var(--text); font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.subject-result small { margin-top: 4px; }
.subject-actions { display: grid; gap: 7px; min-width: 155px; }

.button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid #8a8a8a; border-radius: 3px; background: #fff; color: var(--text); padding: 9px 14px; text-decoration: none; cursor: pointer; font-weight: 600; }
.button:hover { background: #f0f0f0; }
.button.primary { background: var(--petrol); border-color: var(--petrol-dark); color: #fff; }
.button.primary:hover { background: var(--petrol-light); }
.button.danger { color: var(--danger); border-color: #cc9a9d; }
.button.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.button.full { width: 100%; }
.button:disabled { opacity: .55; cursor: wait; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-panel { width: min(390px, 100%); background: var(--surface); border: 1px solid var(--border); box-shadow: 0 2px 10px rgba(0, 0, 0, .12); padding: 26px; }
.auth-brand { color: var(--petrol); margin-bottom: 24px; }
.auth-brand .brand-mark { background: var(--petrol); color: #fff; }
.auth-panel h1 { margin: 0; font-size: 1.4rem; color: var(--petrol); }
.auth-panel > .muted { margin: 5px 0 20px; }
.quiet-link { display: block; margin-top: 18px; text-align: center; color: var(--muted); font-size: 14px; }

.form-stack { display: grid; gap: 15px; }
label { display: grid; gap: 5px; color: #303030; font-size: 14px; font-weight: 650; }
input, textarea, select { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 2px; background: #fff; color: var(--text); padding: 9px 10px; }
textarea { min-height: 100px; resize: vertical; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--petrol); }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; grid-column: 1 / -1; }
.muted { color: var(--muted); }
.notice { padding: 10px 12px; margin: 0 0 15px; background: #eef7f8; border: 1px solid #a7cfd5; color: var(--petrol-dark); font-size: 14px; }
.notice.error { background: #f9e8e9; border-color: #dca7aa; color: var(--danger); }
.notice.success { background: #e5f1e9; border-color: #9fc2ad; color: var(--success); }
.hidden { display: none !important; }

.admin-tabs { display: flex; width: 100%; max-width: 100%; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.admin-tabs a { flex: 0 0 auto; padding: 9px 14px; text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
.admin-tabs a[aria-current="page"] { color: var(--petrol); border-color: var(--petrol); font-weight: 700; }
.admin-section { background: var(--surface); border: 1px solid var(--border-light); margin-bottom: 18px; }
.account-details { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 9px 18px; margin: 0; }
.account-details dt { color: var(--muted); }
.account-details dd { margin: 0; overflow-wrap: anywhere; }
.danger-section { border-color: #cf9b9e; }
.danger-section .section-head { border-color: #e3bfc1; }
.danger-section .section-head h2 { color: var(--danger); }
.danger-section .section-body > p { margin: 0 0 16px; }
.danger-section .button.danger { background: var(--danger); border-color: #7f191e; color: #fff; }
.danger-section .button.danger:hover { background: #8e1c22; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 16px; border-bottom: 1px solid var(--border-light); }
.section-head h2 { margin: 0; font-size: 1.05rem; color: var(--petrol); }
.section-body { padding: 16px; }
.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--border-light); margin-bottom: 20px; }
.stat { padding: 18px; border-right: 1px solid var(--border-light); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 1.55rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f3f3f3; color: var(--petrol); text-align: left; font-size: 13px; padding: 9px 11px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 11px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .actions { display: flex; justify-content: flex-end; gap: 7px; }
.data-table form { margin: 0; }
.status { display: inline-block; padding: 2px 7px; border: 1px solid var(--border); border-radius: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status.live { color: var(--success); border-color: #7aac8e; background: #edf6f0; }
.status.known { color: var(--petrol-dark); border-color: #8bbbc4; background: #eef7f8; }
.status.failed { color: var(--danger); border-color: #cc9a9d; background: #f9e8e9; }
.results-history { background: var(--surface); border: 1px solid var(--border-light); }
.results-history .section-head .muted { font-size: 13px; }
.results-table-wrap { overflow-x: auto; }
.results-table { min-width: 560px; }
.results-table td:nth-child(2), .results-table td:nth-child(3) { font-variant-numeric: tabular-nums; }
.token-value { display: flex; align-items: center; gap: 10px; padding: 12px; background: #f3f3f3; border: 1px solid var(--border); margin-bottom: 16px; overflow-wrap: anywhere; }
.token-value code { flex: 1; font-size: 14px; }
.question-list { display: grid; gap: 1px; background: var(--border-light); }
.question-item { background: #fff; padding: 12px; display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; gap: 14px; align-items: start; }
.question-item small { color: var(--muted); }
.question-item p { margin: 0; }
.question-content { min-width: 0; display: grid; gap: 9px; }
.question-content > small { display: block; }
.question-thumb { display: block; width: min(320px, 100%); max-height: 220px; object-fit: contain; object-position: left center; border: 1px solid var(--border-light); background: var(--surface-soft); }
.question-actions { display: grid; gap: 7px; min-width: 145px; }
.question-actions form { margin: 0; }
.image-upload { border: 1px solid var(--border-light); background: var(--surface-soft); padding: 13px; display: grid; gap: 11px; }
.image-upload-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.image-upload-actions .muted { font-size: 13px; }
.image-preview { width: min(420px, 100%); min-height: 120px; border: 1px solid var(--border); background: #fff; padding: 8px; }
.image-preview img { display: block; width: 100%; max-height: 300px; object-fit: contain; }
.empty-state { padding: 34px 20px; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  .app-header { grid-template-columns: 1fr auto; gap: 8px; padding-inline: 12px; }
  .app-header nav { grid-row: 2; grid-column: 1 / -1; justify-content: center; min-height: 42px; }
  .account > span { display: none; }
  .account { gap: 8px; }
  .page { width: min(100% - 20px, 1180px); padding-top: 24px; overflow-x: hidden; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { justify-content: flex-start; }
  .subject-row { grid-template-columns: 1fr; gap: 14px; }
  .subject-result { text-align: left; }
  .subject-row .button, .subject-actions { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .form-actions { grid-column: auto; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--border-light); }
  .admin-section { overflow-x: auto; }
  .data-table { min-width: 650px; }
  .question-item { grid-template-columns: 1fr; }
  .account-details { grid-template-columns: 1fr; gap: 2px; }
  .account-details dd { margin-bottom: 10px; }
}

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