/* ---------------------------------------------------------------------------
   Gentle Guru Child Wellbeing Screening

   Hand-written, no framework and no build step: the deployment target is
   shared hosting reached over FTP, where a compile step is one more thing that
   can go wrong and a CSS framework is 30x more bytes than this file.

   Design intent. The person using this is a parent or a teacher describing a
   child they are worried about, and they are already braced for something
   official. So the page has to feel like a letter from a person, not a form
   from an institution:

     - every neutral is tinted warm. A blue-tinted grey reads as a hospital
       corridor, and the teal that this file used to carry read as a medical
       chart; the palette below is cream, warm brown and clay instead.
     - headings are set in a serif. It is the voice of a letter, and it is
       what most reliably stops the page reading as a clinical instrument.
       Body text stays sans: this is read on cheap screens, often outdoors.
     - surfaces are separated by soft warm shadow rather than by hard rules.
       A page made only of 1px boxes reads as a document to be processed.
     - nothing moves, nothing is urgent, and colour is never the only carrier
       of meaning — every state that uses colour also changes text or shape.
     - the crisis block is the one exception to all of the above: it stays
       saturated and unmistakable, because the warmth of the page must never
       cost the one block that has to be found by someone in trouble.

   Contrast is checked, not eyeballed: body text 11.7:1 on the page tint,
   secondary text 7.1:1, the lightest text 4.7:1, the accent 5.2:1 on white
   (so white button text passes) and 4.8:1 as a link on the page tint.
   --------------------------------------------------------------------------- */

:root {
    /* --- warm neutrals ---------------------------------------------------- */
    --ink:         #3a3128;
    --ink-soft:    #5d5145;
    /* The faintest text still has to clear 4.5:1 on --paper-tint. Warm greys
       look lighter than cool ones at the same value, so this is darker than
       the cool grey it replaced, not a copy of it. */
    --ink-faint:   #7a6c5c;

    --paper:       #fffefb;
    --paper-tint:  #faf5ee;
    --paper-sunk:  #f4ece0;
    --rule:        #ece0d2;
    --rule-strong: #ab937a;

    /* --- clay ------------------------------------------------------------- */
    /* Dark enough to carry white button text (5.2:1) and to be readable as a
       link on the page tint (4.8:1). The lighter clays are prettier and fail
       one or the other, which is why this is not a matter of taste. */
    --accent:      #a9553a;
    --accent-dark: #8b452c;
    --accent-tint: #fbeee6;
    --accent-line: #f2d6c6;
    --accent-wash: #f7e4d9;

    /* --- crisis: the one block that is allowed to shout -------------------- */
    --crisis-bg:   #fbe4d0;
    --crisis-rule: #cf8b3f;
    --crisis-ink:  #7a4415;

    --danger:      #9c3b2c;
    --danger-bg:   #fdeeea;
    --danger-rule: #e6b3a4;

    --radius:      14px;
    --radius-sm:   10px;
    --wrap:        760px;

    --shadow-soft: 0 1px 2px rgba(120, 92, 66, 0.05),
                   0 10px 28px -18px rgba(120, 92, 66, 0.30);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, "Noto Sans", "Noto Sans Thai", "Noto Sans SC", sans-serif;
    --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
                    Georgia, "Noto Serif", "Songti SC", serif;
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.65;
    color: var(--ink);
    background: var(--paper-tint);
}

/* A slow warm wash down from the top of the page. It is the cheapest way to
   make every screen feel lit by a lamp rather than by a ceiling panel, and it
   is painted behind the content (negative z-index) so nothing can be
   obscured by it. */
body::before {
    content: "";
    position: fixed;
    inset: 0 0 auto 0;
    height: 340px;
    background: radial-gradient(120% 100% at 50% 0%,
                var(--accent-tint) 0%, rgba(251, 238, 230, 0) 72%);
    pointer-events: none;
    z-index: -1;
}

::selection { background: var(--accent-wash); }

.wrap {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0 22px;
}

/* --- skip link ---------------------------------------------------------- */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent-dark);
    color: #fff;
    padding: 12px 18px;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 10;
}

.skip-link:focus { left: 0; }

/* --- header / footer ---------------------------------------------------- */

.site-header {
    background: linear-gradient(180deg, var(--paper) 0%, #fdf8f1 100%);
    border-bottom: 1px solid var(--rule);
    padding: 20px 0;
}

.site-header .wrap {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.18rem;
    color: var(--accent-dark);
}

.tagline {
    color: var(--ink-faint);
    font-size: 0.9rem;
}

.site-footer {
    margin-top: 60px;
    border-top: 1px solid var(--rule);
    padding: 24px 0 44px;
}

.footer-note {
    margin: 0;
    color: var(--ink-faint);
    font-size: 0.87rem;
    max-width: 60ch;
}

main { padding: 34px 0 0; }

/* --- typography --------------------------------------------------------- */

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--ink);
}

h1 {
    font-size: 1.9rem;
    line-height: 1.22;
    letter-spacing: -0.005em;
    margin: 0 0 16px;
}

h2 {
    font-size: 1.28rem;
    line-height: 1.3;
    margin: 38px 0 12px;
}

h3 {
    font-family: var(--font);
    font-size: 1rem;
    margin: 24px 0 8px;
}

p { margin: 0 0 14px; max-width: 68ch; }

.lede {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--ink-soft);
}

a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

/* --- cards -------------------------------------------------------------- */

.card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 26px 28px;
    margin: 0 0 22px;
}

.card > :last-child { margin-bottom: 0; }

/* The heading rhythm above is set for a heading that follows prose. Inside a
   card the first heading follows nothing, and the 38px lands as a hole at the
   top of the box. */
.card > :first-child,
.module > :first-child,
.pathway-card > :first-child { margin-top: 0; }

.card-plain {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
}

/* --- callouts ----------------------------------------------------------- */

.callout {
    border-radius: var(--radius);
    padding: 18px 22px;
    margin: 0 0 22px;
    border: 1px solid var(--rule);
    background: var(--paper);
}

.callout > :last-child { margin-bottom: 0; }

.callout-title {
    font-family: var(--font-display);
    font-weight: 700;
    margin: 0 0 6px;
    font-size: 1.06rem;
}

/* Deliberately not the peach of --accent-tint: a pale peach next to cream
   reads as pink, and pink on this page reads as a warning. Amber is kept for
   the crisis block alone, so that block stays the only thing on the page
   coloured like it wants to be found. */
.callout--info {
    background: var(--paper-sunk);
    border-color: #dfcdb8;
}

.callout--crisis {
    background: var(--crisis-bg);
    border-color: #f0cfae;
    border-left: 6px solid var(--crisis-rule);
    color: var(--crisis-ink);
}

.callout--crisis .callout-title { color: var(--crisis-ink); }

.callout--danger {
    background: var(--danger-bg);
    border-color: var(--danger-rule);
    border-left: 6px solid var(--danger);
    color: var(--danger);
}

/* --- forms -------------------------------------------------------------- */

.field { margin: 0 0 24px; }

.field-label {
    display: block;
    font-weight: 600;
    margin: 0 0 5px;
}

.field-help {
    display: block;
    color: var(--ink-faint);
    font-size: 0.87rem;
    margin: 0 0 8px;
    max-width: 62ch;
}

.field-optional {
    font-weight: 400;
    color: var(--ink-faint);
    font-size: 0.87rem;
}

input[type="text"],
input[type="date"],
select,
textarea {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
}

textarea { min-height: 92px; resize: vertical; }

input:focus,
select:focus,
textarea:focus { border-color: var(--accent); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
.choice input:focus-visible + label {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.field-error {
    color: var(--danger);
    font-size: 0.89rem;
    margin: 6px 0 0;
    font-weight: 600;
}

/* --- choice lists ------------------------------------------------------- */

.choices {
    display: flex;
    flex-wrap: wrap;
    gap: 9px 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.choice {
    position: relative;
}

/* The radio/checkbox is visually hidden but still focusable and still the
   thing the label points at, so keyboard and screen-reader behaviour is the
   browser's, not a reimplementation. */
.choice input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.choice label {
    display: block;
    padding: 10px 17px;
    border: 1px solid var(--rule-strong);
    border-radius: 999px;
    background: var(--paper);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1.35;
}

.choice label:hover {
    background: var(--accent-tint);
    border-color: var(--accent);
}

/* After the hover rule, deliberately: both selectors have the same
   specificity, so the checked pill has to come second or hovering a chosen
   answer would appear to unchoose it. */
.choice input:checked + label {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 8px 16px -10px rgba(139, 69, 44, 0.8);
}

.choice input:disabled + label {
    opacity: 0.55;
    cursor: not-allowed;
}

/* The N/O option is not a point on the frequency scale, so it is separated
   from 0-3 rather than sitting in the same row as a fourth equal choice. */
.choices--scale .choice--no {
    flex-basis: 100%;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px dashed var(--rule-strong);
}

.choices--scale .choice--no label {
    border-radius: var(--radius-sm);
    font-style: italic;
}

/* --- questions ---------------------------------------------------------- */

.module {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 26px 28px;
    margin: 0 0 22px;
}

.module-title {
    font-size: 1.2rem;
    margin: 0 0 6px;
}

.module-note {
    color: var(--ink-soft);
    font-size: 0.89rem;
    border-left: 3px solid var(--accent-wash);
    padding-left: 14px;
    margin: 12px 0 22px;
    max-width: 66ch;
}

.question {
    border: 0;
    border-top: 1px solid var(--rule);
    margin: 0;
    padding: 20px 0 6px;
}

.question:first-of-type { border-top: 0; }

.question legend {
    font-weight: 600;
    padding: 0;
    margin: 0 0 12px;
    max-width: 66ch;
}

/* The code, not a second counter. A small warm chip rather than the faint
   grey caps this used to be: it gives the eye somewhere to land when scanning
   a module, without reading as a form field label. */
.question-number {
    display: inline-block;
    vertical-align: 2px;
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--accent-dark);
    background: var(--accent-tint);
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    padding: 2px 9px;
    margin-right: 7px;
}

.question--error {
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    padding-left: 14px;
    padding-right: 14px;
}

/* --- buttons ------------------------------------------------------------ */

.button,
button {
    display: inline-block;
    font: inherit;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.3;
    box-shadow: 0 8px 18px -12px rgba(139, 69, 44, 0.75);
}

.button:hover,
button:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.button--secondary {
    background: var(--paper);
    color: var(--accent-dark);
    border-color: var(--rule-strong);
    box-shadow: none;
}

.button--secondary:hover {
    background: var(--accent-tint);
    color: var(--accent-dark);
    border-color: var(--accent);
}

.actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin: 30px 0 8px;
}

/* --- crisis block ------------------------------------------------------- */

.crisis {
    background: var(--crisis-bg);
    border: 1px solid #f0cfae;
    border-left: 6px solid var(--crisis-rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 20px 24px;
    margin: 0 0 22px;
    color: var(--crisis-ink);
}

.crisis h2 {
    margin-top: 0;
    font-size: 1.16rem;
    color: var(--crisis-ink);
}

.crisis-list { margin: 10px 0 0; padding-left: 20px; }
.crisis-list li { margin-bottom: 8px; }
.crisis-phone { font-weight: 700; white-space: nowrap; }
.crisis-available { color: var(--ink-soft); font-size: 0.9rem; }

/* --- report ------------------------------------------------------------- */

.report-meta {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 26px;
    font-size: 0.94rem;
}

.report-meta th,
.report-meta td {
    text-align: left;
    padding: 8px 14px 8px 0;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

.report-meta th {
    color: var(--ink-faint);
    font-weight: 600;
    white-space: nowrap;
    width: 38%;
}

/*
 * On a phone the label/value shape has to change, not just shrink.
 * "Language(s) used at home and school" is a nowrap label that alone needs
 * most of a 360px screen, so keeping the two-column layout forces the page
 * wider than the device and the reader gets a sideways scroll on the two
 * screens that matter most — the confirmation and the report.
 * Stacking keeps each label next to its value, which is also the easier
 * shape to read on a phone.
 */
@media (max-width: 480px) {
    .report-meta th,
    .report-meta td {
        display: block;
        width: auto;
        padding-right: 0;
    }

    .report-meta th {
        white-space: normal;
        border-bottom: 0;
        padding-bottom: 0;
    }

    .report-meta td { padding-top: 2px; padding-bottom: 10px; }
}

.answers { border-collapse: collapse; width: 100%; font-size: 0.94rem; }

.answers th,
.answers td {
    text-align: left;
    padding: 9px 14px 9px 0;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

.answers td:last-child { white-space: nowrap; }

.answer-value { font-weight: 600; }

/* "Not observed" and "not answered" are visibly not answers. Without this a
   reader scanning the column sees a blank cell and reads it as "never". */
.answer-missing {
    color: var(--ink-faint);
    font-style: italic;
    font-weight: 400;
}

.answer-frequent {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--accent-tint);
    border: 1px solid var(--accent-line);
    color: var(--accent-dark);
    font-weight: 600;
}

.pathway-card {
    border: 1px solid var(--rule);
    border-left: 5px solid var(--accent);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow-soft);
    padding: 20px 24px;
    margin: 0 0 16px;
}

.pathway-card--pending { border-left-color: var(--rule-strong); }

.pathway-code {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--accent-dark);
    background: var(--accent-tint);
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    padding: 2px 9px;
    margin: 0 0 8px;
}

.pathway-title {
    font-family: var(--font-display);
    font-size: 1.12rem;
    margin: 0 0 8px;
}

.pathway-note {
    color: var(--ink-faint);
    font-size: 0.87rem;
    font-style: italic;
    margin: 10px 0 0;
}

.prose-block {
    border-left: 3px solid var(--accent-wash);
    padding-left: 15px;
    margin: 0 0 16px;
    white-space: pre-wrap;
}

.prose-block .prose-label {
    display: block;
    font-weight: 600;
    color: var(--ink-soft);
    font-size: 0.9rem;
    white-space: normal;
    margin-bottom: 4px;
}

/* --- link box (report token) -------------------------------------------- */

.link-box {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: stretch;
    margin: 12px 0;
}

.link-box input {
    flex: 1 1 260px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88rem;
    background: var(--paper-sunk);
}

/* --- errors ------------------------------------------------------------- */

.error-page { text-align: left; padding: 40px 0; }
.error-code { color: var(--ink-faint); font-size: 0.9rem; letter-spacing: 0.06em; }

.debug-trace {
    background: var(--ink);
    color: #f7ece0;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- progress ----------------------------------------------------------- */

.progress {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ink-faint);
    font-size: 0.88rem;
    margin: 0 0 20px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    /* appearance:none is what lets the pseudo-elements below be styled at
       all; without it WebKit draws its own bar and ignores them. */
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    border-radius: 999px;
    background: var(--paper-sunk);
    box-shadow: inset 0 1px 2px rgba(120, 92, 66, 0.09);
    overflow: hidden;
}

.progress-bar::-webkit-progress-bar {
    background: var(--paper-sunk);
    border-radius: 999px;
}

.progress-bar::-webkit-progress-value {
    background: linear-gradient(90deg, #c26a4a, var(--accent));
    border-radius: 999px;
}

.progress-bar::-moz-progress-bar {
    background: var(--accent);
    border-radius: 999px;
}

/* --- the honeypot field -------------------------------------------------- */

/*
 * Off-screen rather than display:none. Some form-filling scripts skip inputs
 * that are display:none, and this one exists to be filled in. Nothing in the
 * form's own layout should shift, hence the absolute positioning.
 */
.hidden-field {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* --- narrow screens ----------------------------------------------------- */

@media (max-width: 480px) {
    .wrap { padding: 0 16px; }
    .card, .module { padding: 20px 18px; }
    h1 { font-size: 1.55rem; }
    h2 { font-size: 1.18rem; }
    .choice label { padding: 9px 15px; }
    .actions .button, .actions button { width: 100%; text-align: center; }

    /*
     * The same trap as .report-meta above, one table further down: the answer
     * column is nowrap so that "Often" cannot be split across two lines, but
     * an unanswered item reads "Not observed / Unable to assess" — which as
     * one unbreakable run is wider than a small phone, and dragged the whole
     * report 29px past the right edge.
     *
     * This lives here, at the end of the file, rather than beside the
     * .report-meta rule it belongs with. A @media block adds no specificity,
     * so an override placed *before* the rule it overrides loses to it — the
     * first version of this fix was silently doing nothing for exactly that
     * reason, and the measurement looked identical to not having written it.
     */
    .answers td:last-child {
        white-space: normal;
        /* Without a floor the question column takes everything it can and
           "Not observed / unable to assess" ends up four words on four lines.
           This is a floor, not a width: if the screen is too narrow for both,
           the browser still has the last word and nothing overflows. */
        min-width: 6em;
    }
}

/* --- print -------------------------------------------------------------- */

@media print {
    body::before { display: none; }
    .site-header, .site-footer, .actions, .skip-link, .no-print { display: none; }
    body { background: #fff; font-size: 11pt; }
    .card, .module, .pathway-card, .crisis {
        border-color: #999;
        box-shadow: none;
        break-inside: avoid;
    }
    .crisis, .callout--crisis { background: transparent; }
    .wrap { max-width: none; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
