/*
    EPIC 60 WP6 (AH-7) - This term, the topic page and the printable record.
    Uses the home.css tokens (forest-green shell, light body, state colours, never red) plus a gold accent
    for day circles: full gold = session day at school, gold ring = session day at home, faint = opened only.
*/

.term-page {
    --term-gold: #F2C14E;
    --term-gold-faint: #F7E3AE;
    --term-step-back-fill: #F6D9A2;
    --term-cell-empty: #EEF0EC;
    --term-name-col: 220px;
    --term-cell-min: 22px;
    display: grid;
    /* minmax(0, 1fr): an implicit auto column grows to the timeline's 560px min-width on phones,
       pushing the whole page sideways instead of letting the timeline scroll inside its card. */
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

.term-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.term-hero__eyebrow {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--home-text-muted);
    font-weight: 600;
}

.term-hero__lead {
    font-family: var(--home-font-display);
    font-size: 1.2rem;
    margin: 6px 0 0;
}

.term-card-title {
    font-family: var(--home-font-display);
    font-weight: 600;
    font-size: 1.05rem;
    margin: 0;
}

.term-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.term-note {
    font-size: 0.8rem;
    color: var(--home-text-muted);
    margin: 10px 0 0;
}

/* Days played, week by week */
.term-week {
    display: grid;
    grid-template-columns: 64px repeat(7, 22px) 1fr;
    gap: 6px;
    align-items: center;
    padding: 3px 4px;
    border-radius: 8px;
}

.term-week--current {
    background: #FFF7E0;
    outline: 1px solid var(--term-gold);
}

.term-week__label {
    font-size: 0.8rem;
    font-weight: 600;
}

.term-week__caption {
    font-size: 0.8rem;
    color: var(--home-text-muted);
    padding-left: 4px;
}

.term-week__tick {
    color: var(--home-state-secure);
    font-weight: 700;
    margin-left: 4px;
}

.term-day {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--home-hairline);
    box-sizing: border-box;
    background: var(--home-card);
}

.term-day--school {
    background: var(--term-gold);
    border-color: var(--term-gold);
}

.term-day--home {
    background: var(--home-card);
    border: 3px solid var(--term-gold);
}

.term-day--opened {
    background: var(--term-gold-faint);
    border-color: var(--term-gold-faint);
}

.term-week--holiday .term-day,
.term-day--future {
    background: transparent;
    border: 1px dashed var(--home-state-not-yet);
}

.term-weekday-head {
    font-size: 0.7rem;
    color: var(--home-text-muted);
    text-align: center;
}

/* Term timeline */
.term-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--home-text-muted);
}

.term-legend__swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: -2px;
    margin-right: 4px;
}

.term-timeline__scroller {
    overflow-x: auto;
}

/* Wide enough for the name column plus a readable cell per week shown; scrolls inside its card if not. */
.term-timeline__table {
    min-width: min(100%, calc(var(--term-name-col) + 12px + var(--term-cols, 4) * 26px));
}

.term-grid__timeline {
    grid-column: 1 / -1;
    min-width: 0;
}

.term-row__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

/* Sprint 36 option A: days played, one square per term week. */
.term-weekstrip {
    display: grid;
    gap: 4px;
}

.term-weekstrip__row {
    display: grid;
    grid-template-columns: repeat(var(--weeks), minmax(0, 1fr));
    gap: 4px;
}

.term-weekstrip__nums {
    font-size: 0.66rem;
    color: var(--home-text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.term-weekstrip__cell {
    aspect-ratio: 1;
    border-radius: 6px;
    border: 1.5px solid var(--home-hairline);
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--home-text);
    font-variant-numeric: tabular-nums;
    min-width: 0;
    box-sizing: border-box;
}

.term-weekstrip__cell--met { background: var(--term-gold); border-color: var(--term-gold); color: var(--home-header-from); }
.term-weekstrip__cell--played { border-color: var(--term-gold); }
.term-weekstrip__cell--holiday { border-style: dashed; border-color: var(--home-state-not-yet); }
.term-weekstrip__cell--future { opacity: 0.4; }
.term-weekstrip__cell--current { outline: 2px solid var(--home-header-from); outline-offset: 1px; }

.term-weekstrip__before {
    border: 1.5px dashed var(--home-hairline);
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    color: var(--home-text-muted);
    padding: 4px;
    text-align: center;
    min-width: 0;
}

.term-weekstrip__legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    font-size: 0.72rem;
    color: var(--home-text-muted);
}

.term-weekstrip__key {
    display: inline-block;
    width: 11px;
    height: 11px;
    aspect-ratio: auto;
    margin-right: 5px;
    vertical-align: -1px;
    border-radius: 3px;
}

.term-more {
    justify-self: start;
    background: none;
    border: 0;
    padding: 4px 0;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--home-header-to, #2A5547);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.term-more:focus-visible {
    outline: 2px solid var(--home-header-from);
    outline-offset: 2px;
}

.term-rest__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
}

.term-rest__list li {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 2px 12px;
    padding: 7px 0;
    border-top: 1px solid var(--home-hairline);
    font-size: 0.88rem;
}

.term-rest__list li:first-child {
    border-top: 0;
}

.term-rest__list a {
    color: var(--home-text);
    font-weight: 600;
    text-decoration: none;
}

.term-rest__list a:hover,
.term-rest__list a:focus-visible {
    text-decoration: underline;
}

.term-rest__list small {
    color: var(--home-text-muted);
    font-size: 0.75rem;
}

.term-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--home-text-muted);
    font-weight: 600;
    margin: 14px 0 4px;
}

.term-row {
    display: grid;
    grid-template-columns: var(--term-name-col) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 8px 0;
    border-top: 1px solid var(--home-hairline);
}

.term-row__name {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    background: var(--home-card);
    position: sticky;
    left: 0;
    z-index: 1;
}

.term-row__name a {
    font-weight: 600;
    color: var(--home-text);
    text-decoration: none;
}

.term-row__name a:hover,
.term-row__name a:focus-visible {
    text-decoration: underline;
}

.term-row__caption {
    font-size: 0.75rem;
    color: var(--home-text-muted);
}

.term-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(var(--term-cell-min), 1fr);
    gap: 3px;
    height: 18px;
    position: relative;
}

.term-strip__cell {
    border-radius: 4px;
    background: var(--term-cell-empty);
    position: relative;
}

.term-strip__cell--secure { background: var(--home-state-secure); }
.term-strip__cell--getting-there { background: var(--home-state-getting-there); opacity: 0.55; }
.term-strip__cell--step-back { background: var(--term-step-back-fill); }
.term-strip__cell--not-yet { background: transparent; border: 1px dashed var(--home-state-not-yet); box-sizing: border-box; }
.term-strip__cell--dash { background: transparent; }
.term-strip__cell--dash::after {
    content: "";
    position: absolute;
    left: 25%;
    right: 25%;
    top: 50%;
    border-top: 2px solid var(--home-state-not-yet);
}
.term-strip__cell--holiday { outline: 1px dashed var(--home-state-not-yet); outline-offset: -1px; }

.term-strip__event {
    position: absolute;
    top: -7px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--home-card);
    border: 2px solid var(--home-header-from);
    font-size: 8px;
    font-weight: 700;
    line-height: 10px;
    text-align: center;
    color: var(--home-header-from);
    box-sizing: border-box;
}

.term-strip__event--step-back {
    border-color: var(--home-state-step-back);
    color: #7A4A0C;
}

.term-strip-head {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(var(--term-cell-min), 1fr);
    gap: 3px;
    font-size: 0.7rem;
    color: var(--home-text-muted);
    text-align: center;
}

.term-state {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 8px;
    width: fit-content;
}

.term-state--secure { background: #DDF2E5; color: #1F6B3C; }
.term-state--getting-there { background: #DCE8FA; color: #1F4E9E; }
.term-state--step-back { background: #FBEBD3; color: #7A4A0C; }
.term-state--not-yet { background: transparent; color: var(--home-text-muted); border: 1px dashed var(--home-state-not-yet); }

.term-summary p {
    margin: 0 0 6px;
}

.term-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 12px;
    border: 1px solid var(--home-header-from);
    background: var(--home-header-from);
    color: #FFFFFF;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.term-button--quiet {
    background: var(--home-card);
    color: var(--home-header-from);
}

.term-button:disabled {
    opacity: 0.6;
    cursor: default;
}

.term-button:focus-visible {
    outline: 3px solid var(--term-gold);
    outline-offset: 2px;
}

/* Topic page */
.topic-trend {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    align-items: end;
    height: 120px;
}

.topic-trend__bar {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    height: 100%;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--home-text-muted);
}

.topic-trend__fill {
    width: 100%;
    border-radius: 6px 6px 0 0;
    background: var(--home-state-getting-there);
    opacity: 0.55;
    min-height: 2px;
}

.topic-facts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
}

.topic-facts dt {
    font-size: 0.75rem;
    color: var(--home-text-muted);
}

.topic-facts dd {
    margin: 0;
    font-family: var(--home-font-display);
    font-size: 1.4rem;
}

.topic-clip {
    border: 1px dashed var(--home-state-not-yet);
    border-radius: var(--home-radius);
    padding: 18px;
    text-align: center;
    color: var(--home-text-muted);
}

.topic-flag textarea {
    width: 100%;
    min-height: 64px;
    box-sizing: border-box;
    border: 1px solid var(--home-hairline);
    border-radius: 8px;
    padding: 8px;
    font: inherit;
}

@media (max-width: 640px) {
    .term-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Phone order: weeks, the topics that moved, the summary, then the record. */
    .term-grid__weeks,
    .term-grid__side { display: contents; }
    .term-grid__weeks > :first-child { order: 1; }
    .term-grid__timeline { order: 2; }
    .term-grid .term-summary { order: 3; }
    .term-grid .term-record { order: 4; }

    .term-page {
        --term-name-col: 150px;
    }

    /* The strip starts at the child's first week on a phone. */
    .term-weekstrip__before,
    .term-weekstrip__before-num {
        display: none;
    }

    .term-weekstrip__row {
        grid-template-columns: repeat(var(--weeks-shown), minmax(0, 1fr));
    }

    .topic-facts {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Printable record: plain A4, no shell */
.record-sheet {
    max-width: 190mm;
    margin: 0 auto;
    padding: 12mm;
    font-family: 'Inter', system-ui, sans-serif;
    color: #1C2421;
    background: #FFFFFF;
}

/* The A4 sheet has no sideways scroll on paper: narrower name column and cells so all 16 weeks fit. */
.record-sheet.term-page {
    --term-name-col: 170px;
    --term-cell-min: 18px;
}

.record-sheet .term-timeline__table {
    min-width: 0;
}

.record-sheet h1 {
    font-family: 'Fredoka', 'Inter', sans-serif;
    margin: 0 0 4px;
}

.record-actions {
    margin: 12px 0;
}

@media print {
    .record-actions {
        display: none;
    }

    .record-sheet {
        padding: 0;
    }

    .term-strip__cell,
    .term-day {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: A4;
        margin: 12mm;
    }
}
