/*
 * The free tools: the bingo caller, the time calculator and the day counter. Loaded after
 * /styles.css on their pages only, and built from its tokens (DESIGN.md): parchment and warm paper,
 * forge ink, copper for interaction, Fraunces for the figures that matter.
 */
:root {
    --paper: #FFFBF2;
    --line: rgba(44, 36, 22, 0.24);
    --error: #8C3B2B;
    --inset: 3rem;
}

.tool-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 1rem var(--inset);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 1;
}

.tool {
    padding: 0 var(--inset) 0;
}

.tool-intro,
.day-answer {
    padding-top: clamp(2.5rem, 6vh, 4rem);
}

.tool h1 {
    max-width: 18ch;
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(2.75rem, 7vw, 4.75rem);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -0.03em;
    text-wrap: balance;
}

.tool-lede {
    max-width: 38rem;
    margin-top: 1.25rem;
    color: var(--text-muted);
    font-size: 1.125rem;
    text-wrap: pretty;
}

.tool-note {
    margin-top: 1rem;
    color: var(--text-muted);
}

.micro-label,
.field label,
.day-facts dt {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* Buttons and fields */
.caller-button,
.quiet-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.caller-button {
    min-height: 56px;
    padding: 0.75rem 1.5rem;
    border: 0;
    background: var(--text);
    color: var(--bg);
    font-size: 1.125rem;
}

.caller-button:hover:not(:disabled) {
    background: var(--accent-dark);
}

.quiet-button {
    min-height: 44px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    font-size: 0.9375rem;
}

.quiet-button:hover:not(:disabled) {
    border-color: var(--accent-dark);
    color: var(--accent-dark);
}

.caller-button:disabled,
.quiet-button:disabled {
    cursor: default;
    opacity: 0.4;
}

.tool input,
.tool select {
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--paper);
    color: var(--text);
    font: inherit;
    font-size: 1.125rem;
}

.tool input:focus-visible,
.tool select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Bingo caller */
.caller {
    margin-top: 2.5rem;
}

.caller-settings {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem 1.5rem;
    margin-bottom: 2rem;
}

.segmented {
    display: inline-flex;
    border: 0;
}

.segmented label {
    position: relative;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0.5rem 1.125rem;
    border: 1px solid var(--line);
    font-weight: 600;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.segmented label + label span {
    border-left: 0;
}

.segmented input:checked + span {
    border-color: var(--text);
    background: var(--text);
    color: var(--bg);
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.caller-voice {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
}

.caller-voice select {
    min-height: 44px;
    padding: 0 0.75rem;
    font-size: 1rem;
}

.caller-stage {
    display: grid;
    grid-template-columns: minmax(16rem, 21rem) minmax(0, 1fr);
    align-items: start;
    gap: 3rem;
}

.caller-call {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* The current call: a flat ivory ball with a copper ring, as Herald draws it. */
.caller-ball {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: clamp(11rem, 44vw, 15rem);
    aspect-ratio: 1;
    border: 2px solid var(--text);
    border-radius: 50%;
    background: var(--paper);
    box-shadow:
        inset 0 0 0 0.5rem var(--paper),
        inset 0 0 0 0.875rem var(--accent);
    font-family: 'Fraunces', Georgia, serif;
    font-variant-numeric: lining-nums;
    font-weight: 900;
    line-height: 1;
}

.ball-letter {
    margin-bottom: -0.25rem;
    font-size: clamp(2.25rem, 8vw, 3rem);
}

.ball-letter:empty {
    display: none;
}

.ball-number {
    font-size: clamp(4.5rem, 18vw, 6.25rem);
    letter-spacing: -0.02em;
}

.caller-ball.is-empty .ball-number {
    color: var(--text-muted);
    font-weight: 400;
}

.caller-status {
    margin: 1.25rem 0 1.25rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.caller-call .caller-button {
    width: 100%;
}

.caller-secondary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    width: 100%;
    margin-top: 0.75rem;
}

.caller-recent {
    width: 100%;
    margin-top: 2rem;
}

.recent-calls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 2.5rem;
    list-style: none;
}

.recent-calls li {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0 0.875rem;
    border: 1px solid var(--border);
    background: var(--paper);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

/* The board. 75-ball: a lettered row of fifteen for each of B I N G O, or a column each on a phone.
   90-ball: rows of ten. */
.board {
    display: grid;
    gap: 4px;
    font-variant-numeric: tabular-nums;
}

.board--ball75 {
    grid-template-columns: 2rem repeat(15, minmax(0, 1fr));
}

.board--ball90 {
    grid-template-columns: repeat(10, minmax(0, 1fr));
}

.board-letter,
.board-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
}

.board-letter {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 700;
}

.board-cell {
    border: 1px solid var(--border);
    background: var(--paper);
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.board-cell.is-called {
    border-color: var(--text);
    background: var(--text);
    color: var(--bg);
    font-weight: 600;
}

.board-cell.is-current {
    border-color: var(--accent-dark);
    background: var(--accent-dark);
}

.caller-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

/* Big screen: Herald's TV room (/tools/bingo-screen/) over the whole window, the controls in a
   corner that fades while nobody touches anything. */
.has-big-screen {
    overflow: hidden;
}

.big-screen {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #F6F1E7;
}

.big-screen iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    pointer-events: none;
}

.big-screen-controls {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.5rem;
    background: rgba(255, 251, 242, 0.94);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.big-screen.is-awake .big-screen-controls {
    opacity: 1;
    pointer-events: auto;
}

.big-screen-controls .quiet-button {
    background: var(--paper);
}

/* Time calculator: a tape of lines and the total at its foot. */
.timecalc {
    max-width: 40rem;
    margin-top: 2.5rem;
}

.tape {
    list-style: none;
    border-top: 1px solid var(--border);
}

.tape-line {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 10.5rem 44px;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.tape-sign,
.tape-remove {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 1.375rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

.tape-sign[data-sign="-"] {
    border-color: var(--text);
    background: var(--text);
    color: var(--bg);
}

.tape-remove {
    border-color: transparent;
    color: var(--text-muted);
}

.tape-remove:hover,
.tape-sign:hover {
    color: var(--accent-dark);
}

.tape-sign[data-sign="-"]:hover {
    color: var(--bg);
    background: var(--accent-dark);
}

.tape-input {
    width: 100%;
    padding: 0 0.75rem;
    font-variant-numeric: tabular-nums;
}

.tape-value {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.has-error .tape-value {
    color: var(--error);
    font-size: 0.875rem;
    line-height: 1.3;
    text-align: left;
}

.tape-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.tape-total {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 2px solid var(--text);
}

.total-value {
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(3.5rem, 12vw, 5rem);
    font-variant-numeric: lining-nums tabular-nums;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.02em;
}

.total-detail {
    margin-top: 0.5rem;
    color: var(--text-muted);
    font-size: 1.125rem;
    font-variant-numeric: tabular-nums;
}

.tool-formats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0 2rem;
    max-width: 48rem;
    margin-bottom: 1.5rem;
}

.tool-formats div {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.tool-formats dt {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.tool-formats dd {
    color: var(--text-muted);
}

/* Day counter */
.days-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1.5rem;
    margin-top: 2.5rem;
}

.field input {
    padding: 0 0.75rem;
}

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

.field-row .quiet-button {
    min-height: 48px;
}

.days-result {
    margin-top: 2.5rem;
}

.days-result[hidden] {
    display: none;
}

.day-count {
    margin-top: 2rem;
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(4.5rem, 16vw, 9rem);
    font-variant-numeric: lining-nums;
    font-weight: 900;
    line-height: 0.9;
    letter-spacing: -0.03em;
}

.days-result .day-count {
    margin-top: 0;
}

.day-count [data-out="unit"] {
    font-size: 0.32em;
    font-weight: 400;
    letter-spacing: 0;
}

/* Upright: the italic face is not preloaded, and swapping it in late would move the page. */
.day-sentence {
    max-width: 40rem;
    margin-top: 0.75rem;
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(1.25rem, 3vw, 1.625rem);
    line-height: 1.35;
    text-wrap: pretty;
}

.day-today {
    display: none;
    margin-top: 0.5rem;
    color: var(--accent-dark);
    font-weight: 600;
}

.is-today .day-today {
    display: block;
}

.day-asof {
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.day-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1.5rem 2rem;
    max-width: 76rem;
    margin-top: 2.5rem;
}

.day-facts div {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.day-facts dd {
    font-size: 1.125rem;
    font-weight: 600;
    text-wrap: pretty;
}

.day-method {
    max-width: 40rem;
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.day-table {
    width: 100%;
    max-width: 36rem;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.day-table th {
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-align: left;
    text-transform: uppercase;
}

.day-table td {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.day-table th:last-child,
.day-table td:last-child {
    text-align: right;
}

.day-group + .day-group {
    margin-top: 2rem;
}

.day-group h3 {
    margin-bottom: 0.5rem;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 700;
}

.day-links {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: 0 2rem;
    max-width: 72rem;
    list-style: none;
}

.day-links a,
.day-all a,
.tool-app-more a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s ease;
}

.day-links a {
    display: block;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
}

.day-links a:hover,
.day-all a:hover,
.tool-app-more a:hover {
    color: var(--accent-dark);
}

.day-all {
    margin-top: 1.5rem;
}

.day-all a,
.tool-app-more a {
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-underline-offset: 3px;
}

/* Sections below a tool */
.tool-section,
.tool-faq {
    margin-top: 4.5rem;
}

.tool-section h2,
.tool-faq h2,
.tool-app h2 {
    margin-bottom: 1rem;
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(1.625rem, 3vw, 2.125rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

.tool-section > p,
.tool-faq p {
    max-width: 40rem;
    text-wrap: pretty;
}

.tool-section > p + p {
    margin-top: 1rem;
}

.tool-steps {
    max-width: 40rem;
    padding-left: 1.25rem;
}

.tool-steps li + li {
    margin-top: 0.5rem;
}

.tool-faq {
    padding-bottom: 5rem;
}

.tool-faq h3 {
    max-width: 40rem;
    margin: 1.75rem 0 0.375rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.tool-faq p {
    color: var(--text-muted);
}

/* The app the tool belongs to, on a warm paper band. */
.tool-app {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 1.5rem;
    margin: 4.5rem calc(var(--inset) * -1) 0;
    padding: 3.5rem var(--inset);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--bg-warm);
}

main > .tool-app:last-child {
    margin-bottom: 0;
}

.tool-app-icon {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    box-shadow: 0 16px 32px -14px rgba(44, 36, 22, 0.35);
}

.tool-app-copy > p {
    max-width: 38rem;
    color: var(--text-muted);
    text-wrap: pretty;
}

.tool-app .store-links {
    margin-top: 1.5rem;
}

.store-note {
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.tool-app-more {
    margin-top: 1.25rem;
}

.day-more {
    padding-bottom: 5rem;
}

@media (max-width: 900px) {
    .caller-stage {
        grid-template-columns: minmax(0, 1fr);
        gap: 2.5rem;
    }

    .caller-call {
        max-width: 26rem;
        width: 100%;
        margin: 0 auto;
    }
}

@media (max-width: 640px) {
    :root {
        --inset: 1.25rem;
    }

    .tool-header {
        padding-block: 0.75rem;
    }

    .caller {
        margin-top: 2rem;
    }

    .caller-settings {
        margin-bottom: 1.5rem;
    }

    .caller-ball {
        width: clamp(9.5rem, 40vw, 11rem);
    }

    .ball-number {
        font-size: clamp(4rem, 15vw, 4.75rem);
    }

    .ball-letter {
        font-size: clamp(1.75rem, 6vw, 2.25rem);
    }

    .caller-status {
        margin: 0.875rem 0;
    }

    /* On a phone, B I N G O stand as five columns, each headed by its letter. */
    .board--ball75 {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-template-rows: repeat(16, auto);
        grid-auto-flow: column;
    }

    .board-letter,
    .board-cell {
        min-height: 2.125rem;
    }

    .board--ball90 .board-cell {
        font-size: 0.875rem;
    }

    .tape-line {
        grid-template-columns: 44px minmax(0, 1fr) 44px;
        grid-template-areas:
            "sign input remove"
            ". value .";
        row-gap: 0.25rem;
    }

    .tape-sign {
        grid-area: sign;
    }

    .tape-input {
        grid-area: input;
    }

    .tape-remove {
        grid-area: remove;
    }

    .tape-value {
        grid-area: value;
        text-align: left;
    }

    .tape-value:empty {
        display: none;
    }

    .tool-app {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.25rem;
        padding-block: 3rem;
    }
}
