/* rvno.win — GCSE Practice Question Generator
   Builds on ../css/global.css (same variables, fonts, background). */

/* -------------------- */
/* Layout overrides     */
/* -------------------- */

main.gcse-app {
    display: block;
    text-align: left;
    width: min(100%, 880px);
    padding: 1rem 0 3rem;
    font-size: clamp(0.95rem, 1.1vw, 1.05rem);
}

/* -------------------- */
/* Top bar              */
/* -------------------- */

.topbar {
    width: min(100%, 880px);
    margin: 0 auto;
    padding: 0.25rem 0 1rem;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    text-decoration: none;
    font-weight: 700;
    color: var(--text);
}

.brand-sub {
    color: var(--muted);
    font-weight: 400;
}

.session-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.badge {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;

    padding: 0.2rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--accent);
}

/* -------------------- */
/* Cards                */
/* -------------------- */

.card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;

    padding: clamp(1.1rem, 3vw, 1.8rem);
    margin-bottom: 1.25rem;

    backdrop-filter: blur(2px);
}

.card-title {
    margin: 0 0 1rem;
    font-size: 1.15rem;
}

.accent {
    color: var(--accent);
}

.muted {
    color: var(--muted);
}

/* -------------------- */
/* Login                */
/* -------------------- */

.login-card {
    max-width: 420px;
    margin: 8vh auto 0;
    text-align: center;
}

.login-title {
    margin: 0;
    font-size: clamp(1.8rem, 6vw, 2.6rem);
    letter-spacing: 0.02em;
}

.login-subtitle {
    margin: 0.25rem 0 1.75rem;
    color: var(--muted);
}

.login-card form {
    text-align: left;
}

.login-alt {
    margin-top: 1.75rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.login-alt p {
    margin: 0 0 0.6rem;
    font-size: 0.85rem;
}

/* -------------------- */
/* Forms                */
/* -------------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.9rem 1rem;
    margin-bottom: 0.9rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.field label {
    font-size: 0.8rem;
    color: var(--muted);
    letter-spacing: 0.03em;
}

input,
select,
textarea {
    font: inherit;
    /* 16px minimum so iOS does not auto-zoom on focus */
    font-size: max(16px, 0.95rem);

    color: var(--text);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
    border-radius: 9px;

    padding: 0.55rem 0.7rem;
    width: 100%;

    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
    resize: vertical;
    min-height: 4.5rem;
}

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 2rem;
}

input:hover,
select:hover,
textarea:hover {
    border-color: var(--muted);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--link-glow);
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.form-error {
    margin: 0.4rem 0 0.8rem;
    padding: 0.6rem 0.8rem;

    font-size: 0.88rem;
    color: #ffb3b3;
    background: rgba(255, 80, 80, 0.08);
    border: 1px solid rgba(255, 80, 80, 0.35);
    border-radius: 9px;
}

/* -------------------- */
/* Buttons              */
/* -------------------- */

.btn {
    font: inherit;
    font-size: 0.95rem;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;

    padding: 0.6rem 1.2rem;
    border-radius: 9px;
    border: 1px solid var(--border);

    color: var(--text);
    background: rgba(255, 255, 255, 0.04);

    cursor: pointer;
    text-decoration: none;
    user-select: none;

    transition: border-color 0.15s ease, box-shadow 0.15s ease,
        background 0.15s ease, color 0.15s ease, transform 0.05s ease;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--link-glow);
}

.btn:active {
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    color: var(--text);
    border-color: var(--border);
}

.btn-primary {
    background: hsla(var(--accent-hue), 100%, 70%, 0.14);
    border-color: hsla(var(--accent-hue), 100%, 70%, 0.55);
    color: var(--accent);
    font-weight: 700;
}

.btn-primary:hover {
    background: hsla(var(--accent-hue), 100%, 70%, 0.22);
    color: var(--accent);
}

.btn-ghost {
    background: transparent;
}

.btn-danger {
    border-color: rgba(255, 80, 80, 0.5);
    color: #ffb3b3;
    background: rgba(255, 80, 80, 0.07);
}

.btn-danger:hover {
    border-color: #ff7070;
    color: #ff8080;
    box-shadow: 0 0 10px rgba(255, 80, 80, 0.25);
}

.btn-block {
    width: 100%;
    margin-top: 0.4rem;
}

.btn-small {
    font-size: 0.82rem;
    padding: 0.4rem 0.8rem;
}

/* Loading spinner */
.btn-spinner {
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* -------------------- */
/* Quota card           */
/* -------------------- */

.quota-card {
    padding: 1rem clamp(1.1rem, 3vw, 1.8rem);
}

.quota-text {
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.quota-bar {
    height: 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    overflow: hidden;
    background: rgba(0, 0, 0, 0.35);
}

.quota-bar[hidden] {
    display: none;
}

.quota-fill {
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg,
            hsla(var(--accent-hue), 100%, 60%, 0.9),
            hsla(var(--accent-hue), 100%, 75%, 0.9));
    transition: width 0.4s ease;
}

.quota-fill.quota-low {
    background: linear-gradient(90deg, #d9534f, #ff8a80);
}

.quota-note {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
}

/* -------------------- */
/* Results              */
/* -------------------- */

.results {
    margin-bottom: 1.25rem;
}

.results-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.results-meta {
    margin: 0;
    font-size: 0.82rem;
}

.results-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.9rem 0 1.1rem;
}

.question-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.question-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: clamp(1rem, 2.5vw, 1.5rem);
}

.question-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.7rem;
}

.question-number {
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    color: var(--muted);
    text-transform: uppercase;
}

.question-badges {
    display: flex;
    gap: 0.45rem;
    flex-shrink: 0;
}

.chip {
    font-size: 0.72rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    white-space: nowrap;
}

.chip-marks {
    color: var(--accent);
    border-color: hsla(var(--accent-hue), 100%, 70%, 0.5);
}

.question-text {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.answer-toggle {
    margin-top: 0.9rem;
}

.answer-block {
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px dashed var(--border);
}

.answer-block[hidden] {
    display: none;
}

.answer-section + .answer-section {
    margin-top: 0.9rem;
}

.answer-heading {
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
}

.answer-section p {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.6;
}

.mark-scheme {
    margin: 0;
    padding-left: 1.3rem;
    line-height: 1.6;
}

.mark-scheme li + li {
    margin-top: 0.25rem;
}

/* -------------------- */
/* Empty state          */
/* -------------------- */

.empty-state p {
    margin: 0;
    line-height: 1.6;
}

/* -------------------- */
/* Admin panel          */
/* -------------------- */

.admin-panel {
    border-color: hsla(var(--accent-hue), 100%, 70%, 0.4);
}

.admin-tagline {
    margin: -0.5rem 0 1.1rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.admin-friend-usage {
    margin-bottom: 1.1rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    line-height: 1.7;
    background: rgba(0, 0, 0, 0.25);
}

.admin-friend-usage strong {
    color: var(--accent);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.7rem;
    margin: 0 0 1.25rem;
}

.stats-grid > div {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.6rem 0.8rem;
    background: rgba(0, 0, 0, 0.25);
}

.stats-grid dt {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.2rem;
}

.stats-grid dd {
    margin: 0;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.admin-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem;
    align-items: flex-end;
}

.limit-form label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.limit-row {
    display: flex;
    gap: 0.5rem;
}

.limit-row input {
    width: 7rem;
}

/* -------------------- */
/* Small screens        */
/* -------------------- */

@media (max-width: 500px) {
    .topbar {
        padding-bottom: 0.75rem;
    }

    main.gcse-app {
        padding-top: 0.5rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .results-toolbar .btn {
        flex: 1 1 45%;
    }

    .admin-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-controls .btn,
    .limit-row {
        width: 100%;
    }

    .limit-row input {
        flex: 1;
        width: auto;
    }
}

/* -------------------- */
/* Reduced motion       */
/* -------------------- */

@media (prefers-reduced-motion: reduce) {

    .btn,
    input,
    select,
    textarea,
    .quota-fill {
        transition: none;
    }

    .btn-spinner {
        animation-duration: 1.4s;
    }
}

/* -------------------- */
/* Print                */
/* -------------------- */

@media print {

    .topbar,
    .end,
    .quota-card,
    #appView > .card:not(.results),
    #appView > section.card,
    .results-toolbar,
    .empty-state,
    .admin-panel,
    .answer-toggle,
    #loginView {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        padding: 0;
        font-size: 11pt;
    }

    main.gcse-app {
        width: 100%;
        max-width: none;
        padding: 0;
    }

    .results-header .muted {
        color: #444;
    }

    .question-list {
        gap: 0;
    }

    .question-card {
        border: none;
        border-bottom: 1px solid #999;
        border-radius: 0;
        background: none;
        padding: 0.9rem 0;
        page-break-inside: avoid;
    }

    .question-number,
    .chip {
        color: #333;
        border-color: #999;
    }

    .chip-marks {
        color: #000;
        border-color: #000;
    }

    .answer-block {
        border-top: 1px dashed #999;
    }

    .answer-heading {
        color: #000;
    }

    /* Answers stay hidden when printing questions only ... */
    .answer-block {
        display: none !important;
    }

    /* ... and are revealed by the "Print + Answers" button. */
    body.print-answers .answer-block {
        display: block !important;
    }
}
