:root {
    --ink: #222;
    --muted: #666;
    --line: #ddd;
    --paper: #f2f2f2;
    --white: #fff;
    --green: #268B07;
    --green-deep: #1e6e05;
    --gold: #c9a227;
    --navy: #07111f;
    --font: Tahoma, "Segoe UI", Arial, sans-serif;
    --result-font: "Courier New", Courier, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    line-height: 1.45;
    min-height: 100vh;
    font-size: 15px;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, select { font: inherit; }

/* Courier New ONLY on result sheets */
.result-sheet-font,
.result-sheet-font *:not(.btn-print):not(.btn-secondary):not(.no-print *) {
    font-family: var(--result-font);
}
.nav-row.no-print,
.nav-row.no-print * {
    font-family: var(--font) !important;
}

/* ===== Home ===== */
.page-home { background: var(--navy); color: #fff; }
.home {
    min-height: 100vh;
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 2rem 1.25rem;
}
.home-bg {
    position: absolute; inset: 0;
    background:
        linear-gradient(160deg, rgba(7,17,31,.72), rgba(15,42,63,.45) 42%, rgba(10,40,28,.62)),
        var(--bg) center/cover no-repeat;
    animation: bgDrift 18s ease-in-out infinite alternate;
}
.home-mesh {
    position: absolute; inset: 0; pointer-events: none;
    background:
        radial-gradient(circle at 18% 22%, rgba(212,160,23,.22), transparent 32%),
        radial-gradient(circle at 82% 70%, rgba(14,124,102,.28), transparent 38%);
}
.home-fx {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}
.home-fireworks {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.home-sheets {
    position: absolute;
    inset: 0;
}
.fly-sheet {
    position: absolute;
    top: -12%;
    width: 54px;
    height: 72px;
    padding: 8px 7px;
    border-radius: 4px;
    background: linear-gradient(160deg, #fffdf7, #f3efe4);
    border: 1px solid rgba(255,255,255,.55);
    box-shadow: 0 10px 22px rgba(0,0,0,.28);
    color: #1e6e05;
    display: grid;
    gap: 4px;
    align-content: start;
    animation: sheetThrow linear infinite;
    opacity: .9;
}
.fly-sheet-bar {
    height: 7px;
    border-radius: 2px;
    background: #268B07;
}
.fly-sheet-line {
    height: 3px;
    border-radius: 2px;
    background: rgba(30, 50, 35, .22);
}
.fly-sheet-line.short { width: 60%; }
.fly-sheet strong {
    margin-top: 4px;
    font-size: .52rem;
    letter-spacing: .08em;
    text-align: center;
}
.fly-sheet.s1 { left: 8%;  animation-duration: 9s;  animation-delay: 0s; }
.fly-sheet.s2 { left: 18%; animation-duration: 11s; animation-delay: 1.2s; }
.fly-sheet.s3 { left: 30%; animation-duration: 8.5s; animation-delay: .4s; }
.fly-sheet.s4 { left: 44%; animation-duration: 10s; animation-delay: 2s; }
.fly-sheet.s5 { left: 58%; animation-duration: 9.5s; animation-delay: .8s; }
.fly-sheet.s6 { left: 70%; animation-duration: 12s; animation-delay: 1.6s; }
.fly-sheet.s7 { left: 82%; animation-duration: 8s;  animation-delay: 2.4s; }
.fly-sheet.s8 { left: 90%; animation-duration: 10.5s; animation-delay: .2s; }
@keyframes sheetThrow {
    0% {
        transform: translate3d(0, -10vh, 0) rotate(-18deg) scale(.85);
        opacity: 0;
    }
    12% { opacity: .95; }
    100% {
        transform: translate3d(40px, 115vh, 0) rotate(28deg) scale(1.05);
        opacity: 0;
    }
}
@keyframes bgDrift {
    from { transform: scale(1.02); }
    to { transform: scale(1.06); }
}
.home-stage {
    position: relative; z-index: 2;
    width: min(860px, 100%);
    text-align: center;
}
.brand-mark-wrap {
    position: relative;
    width: 110px;
    height: 110px;
    margin: 0 auto 1rem;
    display: grid;
    place-items: center;
}
.brand-blast {
    position: absolute;
    inset: -18px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(240,193,75,.55), rgba(38,139,7,.18) 45%, transparent 70%);
    animation: logoBlast 2.4s ease-out infinite;
    z-index: 0;
}
.brand-mark {
    position: relative;
    z-index: 1;
    width: 96px; height: 96px; margin: 0;
    border-radius: 12px; object-fit: cover;
    box-shadow: 0 12px 30px rgba(0,0,0,.35);
    animation: logoJump 1.8s cubic-bezier(.34,1.56,.64,1) infinite;
}
@keyframes logoJump {
    0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
    25% { transform: translateY(-18px) scale(1.12) rotate(-4deg); }
    40% { transform: translateY(2px) scale(.96) rotate(2deg); }
    55% { transform: translateY(-10px) scale(1.08) rotate(-2deg); }
    70% { transform: translateY(0) scale(1.02) rotate(0deg); }
}
@keyframes logoBlast {
    0% { transform: scale(.55); opacity: .85; }
    55% { transform: scale(1.35); opacity: .25; }
    100% { transform: scale(1.65); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .brand-mark, .brand-blast, .fly-sheet, .home-bg { animation: none !important; }
    .home-fireworks { display: none !important; }
}
.brand-name {
    font-size: .78rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: rgba(255,255,255,.75);
    margin-bottom: .75rem;
    font-weight: 600;
}
.home-heading {
    font-weight: 700;
    font-size: clamp(1.4rem, 3.2vw, 2rem);
    line-height: 1.25;
    margin-bottom: 1.4rem;
}
.toast-error {
    background: rgba(180,35,24,.9);
    display: inline-block;
    padding: .7rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}
.soft-note { color: rgba(255,255,255,.7); margin-bottom: 1.4rem; }
.timer-block {
    margin: 0 auto 1.6rem;
    padding: 1.15rem 1rem 1.25rem;
    border-radius: 14px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.16);
    max-width: 640px;
}
.timer-caption {
    font-size: .85rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #f3e2a8;
    margin-bottom: .85rem;
    font-weight: 600;
}
.timer-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .55rem;
}
.timer-unit {
    background: rgba(7,17,31,.45);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    padding: .75rem .35rem;
}
.timer-unit strong {
    display: block;
    font-size: clamp(1.3rem, 3.5vw, 2rem);
    font-weight: 700;
    line-height: 1;
}
.timer-unit span {
    display: block;
    margin-top: .4rem;
    font-size: .7rem;
    text-transform: uppercase;
    color: rgba(255,255,255,.62);
}
.timer-date { margin-top: .85rem; font-size: .92rem; color: rgba(255,255,255,.75); }
.live-badge {
    display: inline-flex; align-items: center; gap: .5rem;
    margin-bottom: 1.4rem; padding: .5rem 1rem; border-radius: 999px;
    background: rgba(14,124,102,.28); border: 1px solid rgba(120,220,180,.35); font-weight: 600;
}
.pulse {
    width: .6rem; height: .6rem; border-radius: 50%; background: #3dd68c;
    box-shadow: 0 0 0 0 rgba(61,214,140,.55);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    70% { box-shadow: 0 0 0 12px rgba(61,214,140,0); }
}
.home-ctas { display: flex; flex-wrap: wrap; gap: .7rem; justify-content: center; }
.cta-main, .cta-ghost {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 46px; min-width: 0; padding: .7rem 1.45rem; border-radius: 8px; font-weight: 700;
    font-size: 1rem;
}
.cta-main {
    background: linear-gradient(135deg, #f0c14b, var(--gold));
    color: #1a1405;
}
.cta-main.is-locked { opacity: .55; cursor: not-allowed; }
.cta-ghost {
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    background: rgba(255,255,255,.06);
}
.home-foot {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1.15rem;
    z-index: 3;
    text-align: center;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: .9rem;
    font-weight: 400;
    color: rgba(255,255,255,.78);
    padding: 0 1rem;
}
.home-foot a {
    color: #f0c14b;
    font-weight: 400;
    text-decoration: underline;
}

/* ===== App pages ===== */
.page-app { background: var(--paper); }
.site-top {
    background: var(--green);
    border-bottom: 1px solid #e8e8e8;
    position: sticky; top: 0; z-index: 20; color: #fff;
}
.site-top-inner {
    max-width: 1000px; margin: 0 auto; padding: .8rem 1.15rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.site-brand { display: flex; align-items: center; gap: .75rem; min-width: 0; color: #fff; }
.site-brand img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #fff; }
.site-brand strong { display: block; font-size: .92rem; font-weight: 700; }
.site-brand span {
    display: block; font-size: .85rem; color: rgba(255,255,255,.92);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(60vw, 520px);
}
.top-home {
    font-weight: 700; color: #fff; padding: .4rem .8rem;
    border: 1px solid rgba(255,255,255,.55); border-radius: 4px;
}
.shell { max-width: 1000px; margin: 0 auto; padding: 1.35rem 1.15rem 2rem; }
.surface {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    padding: 1.35rem 1.25rem 1.5rem;
}
.surface.narrow { max-width: 460px; margin: 0 auto; }
.surface.wide { max-width: 100%; }

.search-box h1 { font-size: 1.3rem; font-weight: 700; margin: .55rem 0 .35rem; }
.search-box .help-text { color: var(--muted); font-size: .92rem; margin-bottom: 1rem; }
.back-link { display: inline-block; color: var(--green-deep); font-weight: 600; font-size: .9rem; }
.back-link:hover { text-decoration: underline; }
.chip {
    display: inline-block; margin-bottom: .9rem; padding: .25rem .65rem;
    background: #e8f5e9; color: var(--green-deep); font-size: .85rem; font-weight: 600; border-radius: 4px;
}

.lookup-form { display: grid; gap: .9rem; }
.lookup-form label { display: grid; gap: .3rem; font-weight: 700; font-size: .92rem; }
.lookup-form label em { font-style: normal; font-weight: 500; color: var(--muted); }
.lookup-form input {
    width: 100%; min-height: 44px; padding: .65rem .8rem;
    border: 1px solid #ccc; border-radius: 6px; background: #fff;
}
.lookup-form input:focus {
    outline: none; border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(38,139,7,.15);
}

.btn-search {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; min-height: 44px; border: 0; border-radius: 6px;
    background: var(--green); color: #fff; font-weight: 700; cursor: pointer;
}
.btn-search:hover { background: var(--green-deep); }
.btn-print {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; border: 0; border-radius: 6px;
    background: #1a5fa8; color: #fff; font-weight: 700; cursor: pointer;
    padding: .55rem 1.15rem; font-family: var(--font) !important;
    position: relative;
    z-index: 6;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: rgba(26, 95, 168, .35);
    user-select: none;
}
.btn-print:hover { background: #154d88; }
.btn-print:active { background: #124e7a; }
.btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 40px; padding: .5rem 1rem; border-radius: 6px;
    background: #fff; color: #222; border: 1px solid #ccc; font-weight: 600;
}
.btn-secondary:hover { border-color: var(--green); }
.btn-primary, .btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 40px; padding: .55rem 1.05rem; border-radius: 8px;
    font-weight: 700; cursor: pointer; text-decoration: none; border: 1px solid transparent;
}
.btn-primary { background: #268B07; color: #fff; border-color: #268B07; }
.btn-primary:hover { background: #1e6e05; }
.btn-secondary { background: #fff; color: #222; border-color: #ccc; }
.btn-secondary:hover { border-color: #268B07; }
.nav-row { display: flex; gap: .55rem; flex-wrap: wrap; margin: .5rem 0 1rem; align-items: center; position: relative; z-index: 5; pointer-events: auto; }
.nav-row .btn-print { margin-left: auto; }

.filter-bar {
    display: flex; flex-wrap: wrap; gap: .85rem; margin-bottom: 1rem;
    padding: .85rem; border-radius: 6px; background: #f7faf7; border: 1px solid var(--line);
}
.filter-bar label { display: grid; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.filter-bar select {
    min-width: 130px; padding: .55rem .7rem; border-radius: 6px; border: 1px solid var(--line); background: #fff;
}

.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: .75rem;
}
.tile {
    display: flex; align-items: center; justify-content: center; text-align: center;
    min-height: 90px; padding: 1.1rem; border: 1px solid var(--line); border-radius: 6px; background: #fafafa;
}
.tile:hover { border-color: var(--green); background: #f3faf3; }
.tile strong { font-size: .98rem; }

/* Search / hub pages */
.page-board {
    background:
        radial-gradient(circle at top left, rgba(38,139,7,.08), transparent 40%),
        linear-gradient(180deg, #eef5ee 0%, #f4f6f4 100%);
}
.board-shell { max-width: 720px; }
.board-panel {
    background: #fff;
    border: 1px solid #d7e3d7;
    border-radius: 14px;
    padding: 1.5rem 1.35rem 1.6rem;
    box-shadow: 0 12px 32px rgba(20, 55, 25, .07);
}
.board-panel-head {
    text-align: center;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e6eee6;
}
.board-kicker {
    margin: 0 0 .35rem;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #268B07;
}
.board-panel-title {
    font-size: 1.45rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 .4rem;
    padding: 0;
    border: 0;
    color: #17301d;
}
.board-lead {
    margin: 0 auto;
    max-width: 40ch;
    color: #5f6f61;
    font-size: .92rem;
    line-height: 1.45;
}
.board-exam-chip {
    display: inline-block;
    margin: .85rem auto 0;
    padding: .28rem .7rem;
    border-radius: 999px;
    background: #e8f5e9;
    color: #1e6e05;
    font-size: .82rem;
    font-weight: 700;
}
.board-filter {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .75rem;
    margin: 0 0 1rem;
    padding: .85rem;
    border-radius: 10px;
    background: #f5f9f5;
    border: 1px solid #dce6dc;
}
.board-filter label {
    display: grid;
    gap: .3rem;
    font-size: .78rem;
    font-weight: 700;
    color: #5f6f61;
    text-align: left;
}
.board-filter select {
    min-width: 140px;
    padding: .55rem .7rem;
    border-radius: 8px;
    border: 1px solid #cfd9cf;
    background: #fff;
}
.board-choice {
    list-style: none;
    display: grid;
    gap: .7rem;
    margin: 0;
    padding: 0;
}
.board-choice a {
    display: grid;
    grid-template-columns: 64px 1fr;
    align-items: center;
    gap: .9rem;
    min-height: 78px;
    padding: .9rem 1rem;
    text-align: left;
    background: #f7faf7;
    border: 1px solid #dce6dc;
    border-radius: 12px;
    color: #17301d;
    transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
}
.board-choice a:hover {
    background: #eef8ee;
    border-color: #268B07;
    box-shadow: 0 8px 18px rgba(38,139,7,.1);
    transform: translateY(-1px);
}
.board-choice-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: linear-gradient(145deg, #268B07, #1e6e05);
    border: 0;
    color: #fff;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .06em;
}
.board-choice a:hover .board-choice-mark {
    background: linear-gradient(145deg, #2f9d0c, #268B07);
}
.board-choice strong {
    display: block;
    font-size: 1rem;
    margin-bottom: .15rem;
}
.board-choice small {
    display: block;
    color: #667566;
    font-size: .82rem;
}
.board-lookup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .9rem;
    width: 100%;
}
.board-field {
    display: grid;
    grid-template-columns: 120px minmax(0, 280px);
    align-items: center;
    gap: .85rem;
    width: min(100%, 440px);
}
.board-field span {
    font-weight: 700;
    font-size: .92rem;
    color: #243528;
    text-align: left;
}
.board-lookup input[type="text"] {
    width: 100%;
    height: 48px;
    text-align: center;
    background: #f7faf7;
    border: 1px solid #cfd9cf;
    border-radius: 10px;
    font-size: 1rem;
    padding: 0 .85rem;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
.board-lookup input[type="text"]:focus {
    outline: none;
    background: #fff;
    border-color: #268B07;
    box-shadow: 0 0 0 3px rgba(38,139,7,.16);
}
.board-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    justify-content: center;
    align-items: center;
    margin-top: .45rem;
}
.board-lookup button {
    min-width: 140px;
    min-height: 46px;
    padding: .7rem 1.2rem;
    border-radius: 10px;
    border: 1px solid #268B07;
    background: #268B07;
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.board-lookup button:hover {
    background: #1e6e05;
    border-color: #1e6e05;
}
.board-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    min-height: 46px;
    padding: .7rem 1.1rem;
    border-radius: 10px;
    border: 1px solid #cfd9cf;
    background: #fff;
    color: #243528;
    font-weight: 700;
    text-decoration: none;
}
.board-back:hover {
    border-color: #268B07;
    color: #1e6e05;
}

@media (max-width: 720px) {
    .board-choice a { grid-template-columns: 52px 1fr; min-height: 70px; }
    .board-choice-mark { width: 48px; height: 48px; }
    .board-field {
        grid-template-columns: 96px minmax(0, 1fr);
        width: min(100%, 100%);
        gap: .55rem;
    }
    .board-panel { padding: 1.15rem 1rem 1.25rem; }
    .board-panel-title { font-size: 1.25rem; }
}

/* Board header on result sheets (view + print) */
.result-board-header {
    display: grid !important;
    grid-template-columns: 120px minmax(0, 1fr) 120px;
    grid-template-areas: "logo text qr";
    align-items: center;
    gap: 12px;
    background: var(--result-header-bg, #268B07);
    color: #fff;
    padding: 18px 16px;
    margin: 0 0 16px;
    border: 1px solid color-mix(in srgb, var(--result-header-bg, #268B07) 80%, #000);
    overflow: visible;
    box-sizing: border-box;
    min-height: 136px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.result-board-side {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    overflow: visible;
}
.result-board-logo {
    grid-area: logo;
    justify-self: start;
}
.result-board-qr {
    grid-area: qr;
    justify-self: end;
}
.result-board-logo img,
.result-board-qr img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    background: #fff;
    border-radius: 4px;
    flex-shrink: 0;
    display: block;
    box-sizing: content-box;
}
.result-board-qr img {
    padding: 4px;
    width: 92px;
    height: 92px;
}
.result-board-text {
    grid-area: text;
    text-align: center;
    min-width: 0;
    overflow: hidden;
}
.result-board-text h3,
.result-board-text .result-board-name {
    font-size: 16pt;
    font-weight: 700;
    margin: 0 0 4px;
    line-height: 1.35;
    font-family: "Courier New", Courier, monospace;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}
.result-board-text h4 {
    font-size: 12pt;
    font-weight: 500;
    margin: 0;
    line-height: 1.25;
    font-family: "Courier New", Courier, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.result-sheet-foot {
    margin-top: 1.25rem;
    padding-top: .85rem;
    border-top: 1px solid #d8d8d8;
    text-align: center;
    color: #555;
    font-size: .9rem;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-weight: 400;
}
.result-sheet-foot a {
    color: #268B07;
    font-family: inherit;
    font-weight: 400;
    text-decoration: underline;
}
.result-sheet-wrap { background: #fff; }
.result-sheet-wrap.has-watermark,
.institute-sheet.has-watermark,
.surface.has-watermark {
    position: relative;
    isolation: isolate;
}
.result-sheet-wrap.has-watermark::before,
.institute-sheet.has-watermark::before,
.surface.has-watermark::before {
    content: "";
    position: absolute;
    inset: 12% 10% 18% 10%;
    background-image: var(--result-watermark-url);
    background-repeat: no-repeat;
    background-position: center;
    background-size: min(420px, 55%);
    opacity: .08;
    pointer-events: none;
    z-index: 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.result-sheet-wrap.has-watermark > *,
.institute-sheet.has-watermark > *,
.surface.has-watermark > * {
    position: relative;
    z-index: 1;
}
.result-sheet {
    margin-top: .35rem;
    color: #000;
}
.result-sheet .bio-table,
.result-sheet .marks-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12pt;
    margin-bottom: 18px;
}
.result-sheet .bio-table td,
.result-sheet .marks-table th,
.result-sheet .marks-table td {
    border: 1px solid #000;
    padding: 6px 12px;
    vertical-align: middle;
}
.result-sheet .bio-table td {
    padding: 7px 12px;
    line-height: 1.35;
}
/* HSC student info: a bit more vertical space than SSC */
.exam-hsc .result-sheet .bio-table td {
    padding: 10px 12px;
    line-height: 1.55;
}
.result-sheet .marks-table th,
.result-sheet .marks-table td {
    padding: 8px 10px;
    line-height: 1.45;
}
.result-sheet .bio-table td.lbl {
    width: 18%;
    background: #f7f7f7;
    white-space: nowrap;
}
.result-sheet .marks-table thead th {
    background: var(--result-subject-bg, #268B07) !important;
    color: #fff !important;
    font-weight: 700;
    text-align: center;
    padding: 9px 8px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.result-sheet .marks-table tbody tr:nth-child(even) {
    background: #f4f4f4;
}
.result-sheet .marks-table .c { text-align: center; }
.result-sheet .marks-table .l { text-align: left; }
.result-sheet .marks-table .r { text-align: right; }
.result-sheet .grades-only th { width: auto; }
.result-fail,
.result-fail-row,
.result-fail-row td,
.result-fail-row td b {
    color: #c62828 !important;
}
.result-fail,
.result-fail-row td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 12pt; }
.data-table th, .data-table td {
    border: 1px solid #000; padding: 5px 12px; text-align: left; vertical-align: top;
}
.data-table th { background: #f5f5f5; font-weight: 700; }
.data-table.marks thead th { background: var(--green); color: #fff; text-align: center; }
.data-table.marks td { text-align: center; }
.data-table.marks td:nth-child(2) { text-align: left; }
.num { text-align: right !important; }
.center { text-align: center; }
.result-gpa { color: #000; }

.institute-sheet { max-width: 920px; margin: 0 auto; }
.inst-info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12pt;
    margin: .55rem 0 1.15rem;
    color: #000;
}
.inst-info-table td {
    border: 1px solid #000;
    padding: 8px 12px;
    vertical-align: middle;
    line-height: 1.4;
}
.inst-info-table td.lbl {
    width: 18%;
    background: #f3f7f3;
    font-weight: 700;
    white-space: nowrap;
}
.inst-empty-rolls {
    margin: 1rem 0;
    padding: .85rem 1rem;
    border: 1px solid #f0c7c2;
    background: #fff5f4;
    color: #8a2f28;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: .95rem;
}
.result-section { margin-top: 1.25rem; }
.result-section .section-title { text-align: center; margin-bottom: .5rem; position: relative; }
.result-section .section-title::after {
    content: ""; display: block; width: 100%; border-bottom: 1px dashed #000;
    position: absolute; top: 50%; left: 0; z-index: 1;
}
.result-section .section-title span {
    display: inline-block; background: #fff; position: relative; z-index: 2;
    padding: 0 .65rem; font-weight: 700; color: #000;
}
.rest-block {
    margin-bottom: .65rem;
    color: #000;
    font-size: 11pt;
    font-family: "Courier New", Courier, monospace;
}
.rest-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    column-gap: .55rem;
    row-gap: .15rem;
    width: 100%;
}
.rest-item {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rest-total {
    font-weight: 700;
}
.fail-line { color: #8a2f28; }
.abs-line { color: #6b5a1e; }

.merit-card { display: grid; gap: .65rem; }
.merit-card > div {
    display: flex; justify-content: space-between; align-items: center;
    padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 6px; background: #fafafa;
}
.merit-rank { background: var(--green) !important; color: #fff !important; border: 0 !important; }
.merit-rank span { color: rgba(255,255,255,.85); }
.empty-state { text-align: center; padding: 2rem 1rem; }

.site-foot { text-align: center; color: var(--muted); font-size: .88rem; padding: 0 1.15rem 1.75rem; font-family: "Segoe UI", Tahoma, Arial, sans-serif; font-weight: 400; }
.site-foot a { color: var(--green); font-weight: 400; text-decoration: underline; font-family: inherit; }

/* Admin UI styles live in public/css/admin.css */
.link-btn { background: none; border: 0; font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }
.link-btn.danger { color: #b42318; }
.inline { display: inline; }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: #e8f7ea; color: #145522; }
.flash.err { background: #fdecec; color: #911f16; }
.muted { color: var(--muted); }
.login-box {
    max-width: 400px; margin: 4rem auto; background: #fff; border: 1px solid var(--line);
    border-radius: 8px; padding: 1.35rem; display: grid; gap: .8rem;
}
.login-box form { display: grid; gap: .8rem; }
.login-box h1 { text-align: center; }
.login-page .admin-main { max-width: 520px; }

/* Admin login screen */
.login-page {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top right, rgba(38,139,7,.18), transparent 40%),
        linear-gradient(160deg, #0b1a10 0%, #14301c 45%, #0d2214 100%);
    font-family: Tahoma, "Segoe UI", Arial, sans-serif;
}
.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}
.login-panel {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0,0,0,.28);
    padding: 1.75rem 1.5rem 1.4rem;
}
.login-brand {
    text-align: center;
    margin-bottom: 1.35rem;
}
.login-brand img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 12px;
    margin: 0 auto .85rem;
    box-shadow: 0 8px 20px rgba(0,0,0,.12);
}
.login-brand > p {
    font-size: .78rem;
    color: #666;
    line-height: 1.35;
    margin: 0 0 .55rem;
}
.login-brand h1 {
    font-size: 1.45rem;
    margin: 0 0 .25rem;
    color: #1a1a1a;
}
.login-brand > span {
    display: block;
    font-size: .88rem;
    color: #268B07;
    font-weight: 600;
}
.login-alert {
    background: #fdecec;
    color: #911f16;
    border-radius: 8px;
    padding: .7rem .85rem;
    margin-bottom: 1rem;
    font-size: .9rem;
}
.login-alert p { margin: 0; }
.login-form {
    display: grid;
    gap: .95rem;
}
.login-field {
    display: grid !important;
    gap: .4rem;
    font-weight: 700;
    font-size: .9rem;
    color: #333;
}
.login-field input {
    width: 100%;
    min-height: 46px;
    padding: .7rem .85rem;
    border: 1px solid #ccd5cc;
    border-radius: 8px;
    background: #fbfcfb;
    font: inherit;
    font-weight: 500;
}
.login-field input:focus {
    outline: none;
    border-color: #268B07;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(38,139,7,.16);
}
.login-remember {
    display: flex !important;
    align-items: center;
    gap: .5rem;
    font-weight: 500;
    color: #555;
    font-size: .92rem;
}
.login-remember input {
    width: 16px;
    height: 16px;
    accent-color: #268B07;
}
.login-submit {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 8px;
    background: #268B07;
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    margin-top: .15rem;
}
.login-submit:hover { background: #1e6e05; }
.login-back {
    display: block;
    text-align: center;
    margin-top: 1.1rem;
    color: #268B07;
    font-weight: 600;
    font-size: .9rem;
    text-decoration: none;
}
.login-back:hover { text-decoration: underline; }

@media (max-width: 900px) {
    .site-top-inner { padding: .65rem .85rem; gap: .6rem; }
    .site-brand img { width: 40px; height: 40px; }
    .site-brand strong { font-size: .78rem; line-height: 1.2; }
    .site-brand span {
        display: block;
        white-space: normal;
        font-size: .72rem;
        max-width: 58vw;
    }
    .top-home { padding: .35rem .6rem; font-size: .82rem; }
    .shell { padding: .9rem .75rem 1.5rem; }
    .surface { padding: 1rem .9rem 1.15rem; }
    .surface.narrow { max-width: 100%; }
    .home { padding: 1.25rem .85rem; }
    .brand-mark { width: 72px; height: 72px; }
    .home-heading { font-size: 1.25rem; }
    .home-ctas { flex-direction: column; align-items: center; }
    .cta-main, .cta-ghost { width: auto; min-width: 200px; max-width: 280px; }
    .timer-grid { gap: .35rem; }
    .timer-unit { padding: .55rem .2rem; }
    .timer-unit strong { font-size: 1.15rem; }
    .timer-unit span { font-size: .62rem; }
    .choice-grid { grid-template-columns: 1fr; }
    .tile { min-height: 72px; }
    .nav-row { gap: .45rem; }
    .btn-print, .btn-secondary, .btn-search { font-size: .88rem; }
    .login-panel { padding: 1.35rem 1.1rem 1.15rem; }

    /* Result sheet: stack header so board name has full width */
    .result-board-header {
        grid-template-columns: 64px 1fr 64px;
        grid-template-areas:
            "logo mid qr"
            "text text text";
        gap: 8px 10px;
        padding: 12px 10px;
        min-height: 0;
        align-items: center;
    }
    .result-board-logo { grid-area: logo; width: 64px; justify-self: start; }
    .result-board-qr {
        grid-area: qr;
        width: 64px;
        justify-self: end;
    }
    .result-board-text {
        grid-area: text;
        width: 100%;
        overflow: visible;
    }
    .result-board-side { width: auto; }
    .result-board-logo img {
        width: 56px;
        height: 56px;
    }
    .result-board-qr img {
        width: 56px;
        height: 56px;
        padding: 2px;
    }
    .result-board-text h3,
    .result-board-text .result-board-name {
        font-size: .95rem;
        line-height: 1.3;
        white-space: normal;
        overflow-wrap: break-word;
        word-break: normal;
    }
    .result-board-text h4 {
        font-size: .82rem;
        line-height: 1.3;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    .result-sheet-wrap,
    .institute-sheet,
    .marks-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .result-sheet .bio-table,
    .result-sheet .marks-table,
    .inst-info-table,
    .data-table {
        font-size: 9.5pt;
        width: 100%;
    }
    .result-sheet .bio-table td,
    .result-sheet .marks-table th,
    .result-sheet .marks-table td,
    .inst-info-table td {
        padding: 6px 7px;
    }
    .result-sheet .bio-table td {
        padding: 6px 7px;
        line-height: 1.35;
    }
    .exam-hsc .result-sheet .bio-table td {
        padding: 8px 7px;
        line-height: 1.45;
    }
    .result-sheet .marks-table th,
    .result-sheet .marks-table td {
        padding: 6px 5px;
        line-height: 1.35;
    }
    .result-sheet .bio-table td.lbl,
    .inst-info-table td.lbl {
        width: 32%;
        white-space: normal;
    }
    .inst-info-table td {
        padding: 6px 7px;
        font-size: 9.5pt;
    }
}

@media (max-width: 480px) {
    .site-brand span { display: none; }
    .result-board-header {
        grid-template-columns: 52px 1fr 52px;
        grid-template-areas:
            "logo . qr"
            "text text text";
        gap: 8px;
        padding: 10px 8px;
    }
    .result-board-logo { width: 52px; }
    .result-board-logo img,
    .result-board-qr img {
        width: 48px;
        height: 48px;
    }
    .result-board-text h3,
    .result-board-text .result-board-name {
        font-size: .86rem;
    }
    .result-board-text h4 {
        font-size: .74rem;
    }
    .surface.wide,
    .result-sheet-wrap,
    .institute-sheet {
        padding-left: .7rem;
        padding-right: .7rem;
    }
    .result-sheet .bio-table,
    .result-sheet .marks-table,
    .inst-info-table {
        font-size: 8.8pt;
    }
    /* On very small screens, keep 2-value rows readable */
    .result-sheet .bio-table td.lbl {
        width: 34%;
        font-size: 8.2pt;
    }
}

@media print {
    body { background: #fff !important; }
    .site-top, .site-foot, .no-print, .btn-print, .btn-secondary, .btn-search, .back-link {
        display: none !important;
    }
    .shell { max-width: none; margin: 0; padding: 0; }
    .surface, .institute-sheet, .result-sheet-wrap {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    /* Avoid clipping the right border without thickening lines */
    .result-sheet .bio-table,
    .result-sheet .marks-table {
        width: calc(100% - 1px) !important;
        border-collapse: collapse !important;
    }
    .inst-info-table {
        width: calc(100% - 1px) !important;
        border-collapse: collapse !important;
    }
    .result-sheet .bio-table td,
    .result-sheet .marks-table th,
    .result-sheet .marks-table td,
    .inst-info-table td {
        border: 1px solid #000 !important;
    }
    .inst-info-table td.lbl {
        background: #f3f7f3 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .result-board-header {
        display: grid !important;
        grid-template-columns: 90px minmax(0, 1fr) 90px !important;
        grid-template-areas: "logo text qr" !important;
        align-items: center !important;
        background: var(--result-header-bg, #268B07) !important;
        color: #fff !important;
        padding: 14px 14px !important;
        min-height: 108px !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        break-inside: avoid;
    }
    .result-board-logo { grid-area: logo !important; width: 90px !important; justify-self: start !important; }
    .result-board-text { grid-area: text !important; }
    .result-board-qr { grid-area: qr !important; width: 90px !important; justify-self: end !important; }
    .result-board-side {
        overflow: visible !important;
        width: 90px !important;
    }
    .result-board-text {
        text-align: center !important;
        overflow: hidden !important;
    }
    .result-board-text h3,
    .result-board-text .result-board-name {
        font-size: 14pt !important;
        line-height: 1.35 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: unset !important;
        color: #fff !important;
        margin: 0 0 4px !important;
    }
    .result-board-text h4 {
        font-size: 11pt !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        color: #fff !important;
    }
    .result-board-logo img {
        width: 78px !important;
        height: 78px !important;
        object-fit: contain !important;
        background: #fff !important;
        display: block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .result-board-qr img {
        width: 72px !important;
        height: 72px !important;
        object-fit: contain !important;
        background: #fff !important;
        display: block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .surface.wide,
    .result-sheet-wrap,
    .institute-sheet,
    #print-area {
        overflow: visible !important;
    }
    .result-sheet-foot {
        display: block !important;
        color: #333 !important;
        border-top: 1px solid #999 !important;
        font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
        font-weight: 400 !important;
    }
    .result-sheet-foot,
    .result-sheet-foot * {
        font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
        font-weight: 400 !important;
    }
    .result-sheet-foot a {
        color: #000 !important;
        text-decoration: none !important;
        font-weight: 400 !important;
    }
    .result-sheet-font, .result-sheet-font * {
        font-family: "Courier New", Courier, monospace !important;
        color: #000 !important;
    }
    .result-sheet-font .result-fail,
    .result-sheet-font .result-fail *,
    .result-sheet-font .result-fail-row,
    .result-sheet-font .result-fail-row td,
    .result-sheet-font .result-fail-row td *,
    .result-sheet-font .result-fail-row b {
        color: #c62828 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .result-sheet .bio-table td {
        padding: 6px 10px !important;
        line-height: 1.35 !important;
    }
    .exam-hsc .result-sheet .bio-table td {
        padding: 9px 10px !important;
        line-height: 1.55 !important;
    }
    .result-sheet .marks-table th,
    .result-sheet .marks-table td {
        padding: 7px 8px !important;
        line-height: 1.45 !important;
    }
    .result-sheet .marks-table thead th {
        background: var(--result-subject-bg, #268B07) !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .result-fail,
    .result-fail-row,
    .result-fail-row td,
    .result-fail-row td b {
        color: #c62828 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .result-section .section-title span { background: #fff !important; }
}
