/* The child's page: a blackboard that fills the screen, a small portrait, a plain desk bar for the controls.
   Calm and adult on purpose: muted colours, no points, no streaks, no bouncing. */

:root {
    --chalk: #f1efe4;
    --chalk-dim: #c9c7b8;
    --chalk-accent: #e6d9a0;
    --board-light: #2c4640;
    --board-dark: #1d332d;
    --frame: #5e4733;
    --frame-dark: #3e2e20;
    --room: #171c1a;
    --desk: #efece1;
    --desk-ink: #26302c;
    --speak-red: #c62828;
    --chalk-step: 0.85s;
    --chalk-write: 0.9s;
}

.talk-root {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--room);
    color: var(--chalk);
    font-family: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
    overflow-x: hidden;
}

.talk-message {
    padding: 2rem 1.5rem;
    font-size: 1.25rem;
}

.talk-message a {
    color: var(--chalk-accent);
}

/* ---- layout of the page ---- */

.talk {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 1500px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    padding: 0.75rem;
}

.talk-stage {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(96px, 14vw, 190px);
    gap: 0.75rem;
    flex: 1 1 auto;
    min-height: 0;
}

.talk-portrait {
    align-self: start;
    min-width: 0;
}

/* ---- the board ---- */

.board {
    box-sizing: border-box;
    min-width: 0;
    min-height: 12rem;
    border: 10px solid var(--frame);
    border-bottom-width: 16px;
    border-radius: 6px;
    background:
        radial-gradient(ellipse at 25% 15%, rgba(255, 255, 255, 0.06), transparent 55%),
        radial-gradient(ellipse at 80% 90%, rgba(255, 255, 255, 0.035), transparent 50%),
        linear-gradient(160deg, var(--board-light), var(--board-dark));
    box-shadow:
        inset 0 0 0 2px var(--frame-dark),
        inset 0 0 70px rgba(0, 0, 0, 0.45),
        0 8px 22px rgba(0, 0, 0, 0.55);
}

.board-surface {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: clamp(0.75rem, 3vmin, 2rem);
    height: 100%;
    padding: clamp(1rem, 4vmin, 3rem);
    overflow-x: hidden;
    overflow-y: auto;
}

.board-symbols {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em 0.9em;
    font-size: clamp(3rem, 15vmin, 8.5rem);
    line-height: 1.05;
}

.board-symbol {
    opacity: 0;
    animation: chalk-appear 0.7s ease-out both;
    animation-delay: calc(var(--i, 0) * var(--chalk-step));
    filter: saturate(0.8);
}

.board-lines {
    display: flex;
    flex-direction: column;
    gap: 0.55em;
    margin: 0;
    padding: 0;
    list-style: none;
}

.board-line {
    color: var(--chalk);
    font-size: clamp(1.4rem, 5vmin, 3rem);
    line-height: 1.25;
    letter-spacing: 0.01em;
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.55), 1px 1px 0 rgba(0, 0, 0, 0.3);
    overflow-wrap: anywhere;
    clip-path: inset(0 100% 0 0);
    animation: chalk-write var(--chalk-write) ease-out both;
    animation-delay: calc(var(--i, 0) * var(--chalk-step));
}

@keyframes chalk-write {
    from {
        clip-path: inset(0 100% 0 0);
    }

    to {
        clip-path: inset(-0.2em -0.2em -0.2em -0.2em);
    }
}

@keyframes chalk-appear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* While the answer is on its way the chalk taps on the board. */
.board-chalk {
    display: flex;
    align-items: flex-end;
    gap: 0.7rem;
    height: 2.2rem;
}

.board-chalk span {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--chalk-dim);
    opacity: 0.6;
    animation: chalk-tap 1s ease-in-out infinite;
}

.board-chalk span:nth-child(2) {
    animation-delay: 0.15s;
}

.board-chalk span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chalk-tap {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    40% {
        transform: translateY(-0.7rem);
        opacity: 1;
    }
}

/* ---- the portrait (a drawn picture, or a neutral placeholder) ---- */

.portrait {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    padding: 0.5rem 0.5rem 0.6rem;
    border: 3px solid var(--frame);
    border-radius: 8px;
    background: #2a312e;
    transition: box-shadow 0.2s ease;
}

.portrait-figure {
    display: block;
    width: 100%;
    max-width: 150px;
    height: auto;
}

.portrait-image {
    border-radius: 4px;
    background: #e6e1d3;
}

.talk-change-teacher {
    color: var(--desk-ink);
}

.portrait-head {
    fill: #c9bba8;
}

.portrait-body {
    fill: #54646d;
}

.portrait-signal {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    height: 12px;
}

.portrait-signal span {
    width: 6px;
    height: 6px;
    border-radius: 3px;
    background: var(--chalk-dim);
    opacity: 0.35;
}

.portrait--listening {
    box-shadow: 0 0 0 3px rgba(230, 217, 160, 0.55);
}

.portrait--thinking .portrait-signal span {
    opacity: 0.9;
    animation: chalk-tap 1s ease-in-out infinite;
}

.portrait--thinking .portrait-signal span:nth-child(2) {
    animation-delay: 0.15s;
}

.portrait--thinking .portrait-signal span:nth-child(3) {
    animation-delay: 0.3s;
}

.portrait--speaking .portrait-signal span {
    opacity: 0.9;
    animation: portrait-speak 0.6s ease-in-out infinite alternate;
}

.portrait--speaking .portrait-signal span:nth-child(2) {
    animation-delay: 0.2s;
}

.portrait--speaking .portrait-signal span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes portrait-speak {
    from {
        height: 4px;
    }

    to {
        height: 12px;
    }
}

/* ---- notice and transcript ---- */

.talk-notice {
    margin: 0;
    padding: 0.6rem 1rem;
    border-left: 4px solid var(--chalk-accent);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.07);
    color: var(--chalk);
    font-size: 1.1rem;
    overflow-wrap: anywhere;
}

/* column-reverse keeps the newest line in view without script; the list inside keeps its normal order. */
.transcript {
    display: flex;
    flex-direction: column-reverse;
    flex: 0 1 auto;
    max-height: 22vh;
    max-height: 22dvh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.045);
}

.transcript ol {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.transcript-line {
    color: var(--chalk-dim);
    overflow-wrap: anywhere;
}

.transcript-line::before {
    content: attr(data-who) ": ";
    font-weight: 600;
}

.transcript-line--tutor {
    color: var(--chalk);
}

/* ---- the desk bar with the controls ---- */

.talk-controls {
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    background: var(--desk);
    color: var(--desk-ink);
}

.mode-choice {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 1 1 100%;
}

.talk-compose {
    display: flex;
    align-items: center;
    flex: 1 1 14rem;
    gap: 0.4rem;
    min-width: 0;
}

.talk-input {
    flex: 1 1 auto;
    min-width: 0;
}

.talk-speak {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: clamp(64px, 11vmin, 96px);
    aspect-ratio: 1;
    margin-inline: auto;
    border: 4px solid #fff;
    border-radius: 50%;
    background: var(--speak-red);
    color: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.talk-speak:focus-visible {
    outline: 3px solid var(--chalk-accent);
    outline-offset: 3px;
}

.talk-speak:active {
    transform: scale(0.97);
}

.talk-compose + .talk-speak {
    margin-inline: 0;
}

.talk-speak--recording {
    animation: speak-pulse 1.2s ease-in-out infinite;
}

@keyframes speak-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.55), 0 4px 10px rgba(0, 0, 0, 0.35); }
    50% { box-shadow: 0 0 0 14px rgba(255, 255, 255, 0), 0 4px 10px rgba(0, 0, 0, 0.35); }
}

.talk-replay {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 48px;
    padding: 0.4rem 0.9rem;
    border: 2px solid currentColor;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.talk-replay:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Small and quiet: it is for the adults around, not for the child. */
.talk-voice-notice {
    margin: 0;
    font-size: 0.8rem;
    opacity: 0.75;
    text-align: center;
}

.askback {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.askback-text {
    flex: 1 1 100%;
    margin: 0;
    text-align: center;
}

.askback-yes,
.askback-no {
    width: clamp(64px, 11vmin, 96px);
    aspect-ratio: 1;
    border: 4px solid #fff;
    border-radius: 50%;
    font-size: clamp(2rem, 6vmin, 3rem);
    line-height: 1;
    background: var(--desk);
    cursor: pointer;
}

.askback-yes:disabled,
.askback-no:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ---- phone ---- */

@media (max-width: 599px) {
    .talk {
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .talk-stage {
        grid-template-columns: minmax(0, 1fr);
    }

    /* The portrait is small and sits in the corner of the board. */
    .talk-portrait {
        position: absolute;
        top: 0.9rem;
        right: 0.9rem;
        width: 60px;
    }

    .talk-portrait .portrait {
        padding: 0.25rem;
        border-width: 2px;
    }

    .talk-portrait .portrait-signal {
        display: none;
    }

    .board {
        border-width: 7px;
        border-bottom-width: 11px;
    }

    .board-surface {
        padding-right: 5rem;
    }

    .transcript {
        max-height: 18dvh;
    }
}

/* ---- the teacher choice: large pictures, usable without reading ---- */

.choose {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.75rem, 3vmin, 1.75rem);
    max-width: 1100px;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: clamp(0.75rem, 3vmin, 2rem);
}

.choose-question {
    margin: 0;
    font-size: clamp(1.5rem, 5vmin, 2.5rem);
    font-weight: 500;
    text-align: center;
}

.teacher-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    gap: clamp(0.6rem, 2.5vmin, 1.5rem);
    width: 100%;
}

.teacher-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.6rem 0.8rem;
    border: 4px solid var(--frame);
    border-radius: 10px;
    background: #2a312e;
    color: var(--chalk);
    font: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.teacher-card:focus-visible {
    outline: 4px solid var(--chalk-accent);
    outline-offset: 3px;
}

.teacher-card[aria-pressed="true"] {
    border-color: var(--chalk-accent);
    box-shadow: 0 0 0 4px rgba(230, 217, 160, 0.45);
}

.teacher-card-picture {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    background: #e6e1d3;
}

.teacher-card-name {
    font-size: clamp(1.2rem, 3.5vmin, 1.75rem);
}

.teacher-intro {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    max-width: 640px;
    padding: 1rem 1.25rem 1.25rem;
    border-radius: 10px;
    background: var(--desk);
    color: var(--desk-ink);
    text-align: center;
}

.teacher-intro-name {
    margin: 0;
    font-size: clamp(1.5rem, 4vmin, 2.25rem);
    font-weight: 600;
}

.teacher-intro-text {
    margin: 0;
    font-size: clamp(1.15rem, 3vmin, 1.6rem);
    line-height: 1.35;
}

.teacher-confirm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    min-height: 72px;
    padding: 0.5rem 1.75rem;
    border: 0;
    border-radius: 36px;
    background: #2f6b46;
    color: #fff;
    font: inherit;
    font-size: clamp(1.2rem, 3.5vmin, 1.75rem);
    cursor: pointer;
}

.teacher-confirm:disabled {
    opacity: 0.6;
    cursor: default;
}

.choose-back,
.choose .talk-notice {
    color: var(--chalk-accent);
}

/* ---- a video offered on the board: picture and title first, the player only after a tap ---- */

.board-video {
    margin-top: 0.5rem;
}

.board-video-start {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 34rem;
    padding: 0.5rem;
    border: 2px solid var(--chalk-dim);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--chalk);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.board-video-start:hover,
.board-video-start:focus-visible {
    border-color: var(--chalk-accent);
}

.board-video-thumb {
    flex: 0 0 auto;
    width: clamp(7rem, 22vw, 11rem);
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 4px;
}

.board-video-title {
    font-size: clamp(1.1rem, 3.5vmin, 1.8rem);
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.board-video-link {
    color: var(--chalk-accent);
    font-size: clamp(1.1rem, 3.5vmin, 1.8rem);
    overflow-wrap: anywhere;
}

.board-video-frame {
    position: relative;
    width: 100%;
    max-width: 40rem;
    aspect-ratio: 16 / 9;
    background: #000;
}

.board-video-player {
    width: 100%;
    height: 100%;
    border: 0;
}

.board-video-close {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
}

/* On a phone the player fills the whole screen. */
@media (max-width: 599px) {
    .board-video-frame {
        position: fixed;
        inset: 0;
        z-index: 50;
        max-width: none;
        aspect-ratio: auto;
    }
}

/* ---- people who prefer no motion get the finished board at once ---- */

@media (prefers-reduced-motion: reduce) {
    .board-line {
        clip-path: none;
        animation: none;
    }

    .board-symbol {
        opacity: 1;
        animation: none;
    }

    .board-chalk span,
    .portrait--thinking .portrait-signal span,
    .portrait--speaking .portrait-signal span {
        animation: none;
        opacity: 0.8;
    }

    .portrait {
        transition: none;
    }

    .talk-speak:active {
        transform: none;
    }

    .talk-speak--recording {
        animation: none;
    }
}
