/* Almarai (SIL OFL 1.1) — see fonts/almarai/OFL.txt */
@font-face {
    font-family: "Almarai";
    src: url("../fonts/almarai/Almarai-Light.woff2") format("woff2");
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: "Almarai";
    src: url("../fonts/almarai/Almarai-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "Almarai";
    src: url("../fonts/almarai/Almarai-Bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: "Almarai";
    src: url("../fonts/almarai/Almarai-ExtraBold.woff2") format("woff2");
    font-weight: 800;
    font-display: swap;
}

:root {
    --app-font: "Almarai", "Segoe UI", Tahoma, sans-serif;
    --app-bg: #faf7f2;
    --app-surface: #ffffff;
    --app-ink: #1d2a2c;
    --app-muted: #4f5d60;
    --app-primary: #0d5c58;
    --app-primary-ink: #ffffff;
    --app-accent: #b4530a;
    --app-border: #e4ddd2;
    --app-focus: #b4530a;

    --bs-body-font-family: var(--app-font);
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-ink);
    --bs-body-line-height: 1.8;
    --bs-link-color-rgb: 13, 92, 88;
    --bs-link-hover-color-rgb: 9, 66, 63;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--app-font);
    background: var(--app-bg);
    color: var(--app-ink);
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 800;
    line-height: 1.5;
}

/* Bootstrap's primary button, recoloured to the app palette */
.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: #09423f;
    --bs-btn-hover-border-color: #09423f;
    --bs-btn-active-bg: #09423f;
    --bs-btn-active-border-color: #09423f;
}

/* A visible focus ring on every interactive element */
:focus-visible {
    outline: 3px solid var(--app-focus);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    inset-inline-start: 1rem;
    top: 1rem;
    z-index: 1000;
    padding: .5rem 1rem;
    background: var(--app-surface);
    color: var(--app-primary);
    border: 2px solid var(--app-primary);
    border-radius: .5rem;
}

.site-header {
    background: var(--app-primary);
    color: var(--app-primary-ink);
    padding-block: 1rem;
}

.site-brand {
    color: inherit;
    font-size: 1.375rem;
    font-weight: 800;
    text-decoration: none;
}

.site-brand:hover {
    color: inherit;
    text-decoration: underline;
}

.site-main {
    flex: 1;
}

.site-main:focus {
    outline: none;
}

.site-footer {
    border-top: 1px solid var(--app-border);
    color: var(--app-muted);
    font-size: .875rem;
    padding-block: 1.5rem;
    display:none;
}

.hero {
    padding-block: 3rem 2rem;
}

.hero-title {
    font-size: clamp(1.75rem, 4vw + 1rem, 2.75rem);
    color: var(--app-primary);
}

.hero-lead {
    max-width: 40rem;
    font-size: 1.125rem;
    color: var(--app-muted);
}

.status-note {
    max-width: 40rem;
    margin-bottom: 3rem;
    padding: 1.25rem 1.5rem;
    border-inline-start: 4px solid var(--app-accent);
    background: var(--app-surface);
    border-radius: .5rem;
}

.page-section {
    padding-block: 2rem 3rem;
}

.page-title {
    font-size: clamp(1.5rem, 3vw + 1rem, 2.25rem);
    color: var(--app-primary);
}


/* ---- Anatomy drawing ---- */

.anatomy-figure {
    margin: 0;
    padding: 1rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: .75rem;
}

.anatomy {
    display: block;
    width: 100%;
    max-width: 30rem;
    height: auto;
    margin-inline: auto;
    --ana-highlight: #f59e0b;
    --ana-highlight-edge: #7c2d12;
}

.anatomy path {
    stroke-linejoin: round;
    stroke-width: 1.5;
    transition: opacity .2s ease, fill .2s ease, stroke .2s ease;
}

.anatomy-head  { fill: #f2d6c3; stroke: #b98a72; }
.anatomy-air   { fill: #fffaf2; stroke: #c9a28c; }
.anatomy-bone  { fill: #ece0cc; stroke: #a8916f; }
.anatomy-gum   { fill: #e9a79a; stroke: #b5715f; }
.anatomy-soft  { fill: #e3a294; stroke: #b06e5f; }
.anatomy-fold  { fill: #b06e5f; stroke: none; }
.anatomy-tooth { fill: #fffdf7; stroke: #a99c84; }
.anatomy-tongue { fill: #d8726a; stroke: #a24a43; }
.anatomy-lip   { fill: #cf6b64; stroke: #9e4741; }

.anatomy-hidden {
    fill: rgba(255, 253, 247, .7);
    stroke: #8a7d66;
    stroke-dasharray: 3 2;
}

.anatomy .region--line {
    fill: none;
    stroke: transparent;
    stroke-width: 6;
    stroke-linecap: round;
}

.anatomy .region--edge {
    stroke: #7a2f2a;
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
}

/* While something is highlighted, everything else fades so the cue does not rely on colour alone. */
.anatomy.has-active path:not(.is-active) {
    opacity: .45;
}

.anatomy .region.is-active {
    fill: var(--ana-highlight);
    stroke: var(--ana-highlight-edge);
    stroke-width: 3;
    animation: anatomy-pulse 1.4s ease-in-out infinite;
}

.anatomy .region--line.is-active {
    fill: none;
    stroke: var(--ana-highlight);
    stroke-width: 7;
}

.anatomy .region--edge.is-active {
    stroke-width: 4;
    stroke-dasharray: 6 3;
}

@keyframes anatomy-pulse {
    50% { opacity: .65; }
}

.anatomy-status {
    margin-top: .75rem;
    text-align: center;
    font-weight: 700;
    color: var(--app-primary);
}

.region-list {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    padding: 0;
    margin-bottom: 1rem;
    list-style: none;
}

.region-button {
    padding: .375rem .875rem;
    border: 1px solid var(--app-border);
    border-radius: 2rem;
    background: var(--app-surface);
    color: var(--app-ink);
    font: inherit;
}

.region-button:hover {
    border-color: var(--app-primary);
}

.region-button[aria-pressed="true"] {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: var(--app-primary-ink);
}

.region-button:disabled {
    opacity: .5;
    text-decoration: line-through;
}

.region-term {
    font-size: .75rem;
    opacity: .75;
}

/* ---- Letter grid page ---- */

.page-lead {
    font-size: 1.125rem;
    color: var(--app-muted);
}

/* The letters page keeps its intro compact so the grid and drawing fit on one screen */
.page-section:has(.stage) {
    padding-top: 1.25rem;
}

.page-section:has(.stage) .page-title {
    margin-bottom: .25rem;
}

.page-section:has(.stage) .page-lead {
    margin-bottom: .5rem;
}

.letter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(7, minmax(0, 1fr));
    gap: .625rem;
}

/*
 * The letter grid and the drawing are two boxes of identical size: the same
 * height and the drawing's own aspect ratio (its viewBox is 350×450).
 */
.stage {
    /* Fill the screen below the page intro (about 15.5rem tall), within sensible limits */
    --stage-h: clamp(24rem, calc(100vh - 15.5rem), 46rem);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 1.5rem;
}

.stage-box {
    height: var(--stage-h);
    aspect-ratio: 350 / 450;
    margin: 0;
    /* Lets children size themselves from the box (cqh units) */
    container-type: size;
}

@media (max-width: 767.98px) {
    .stage-box {
        width: 100%;
        height: auto;
    }
}

.stage-figure {
    padding: .75rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: .75rem;
    scroll-margin-top: 1rem;
}

.stage-figure .anatomy {
    width: 100%;
    height: 100%;
    max-width: none;
}

.letter-button {
    min-height: 2.75rem;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--app-border);
    border-radius: .75rem;
    background: var(--app-surface);
    color: var(--app-ink);
    font: inherit;
    /* About half of a row's height (7 rows per box) */
    font-size: 7cqh;
    font-weight: 700;
    line-height: 1;
}

.letter-button:hover {
    border-color: var(--app-primary);
    color: var(--app-primary);
}

.letter-button[aria-pressed="true"] {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: var(--app-primary-ink);
    box-shadow: 0 0 0 3px rgba(13, 92, 88, .25);
}

.letter-panel {
    flex: 1 1 22rem;
    max-width: 36rem;
    padding: 1.25rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: .75rem;
}


.letter-panel-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.letter-char {
    flex: none;
    display: grid;
    place-items: center;
    width: 4.5rem;
    height: 4.5rem;
    margin: 0;
    border-radius: 50%;
    background: var(--app-primary);
    color: var(--app-primary-ink);
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1;
}

.examples {
    margin-top: 1rem;
}

.examples-title {
    margin-bottom: .5rem;
    font-size: 1rem;
    color: var(--app-muted);
}

/* Three columns (start / middle / end of the word), three words each */
.examples-columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .5rem;
}

.example-column {
    display: flex;
    flex-direction: column;
    padding: .5rem .25rem;
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: .625rem;
}

.example-label {
    margin: 0 0 .25rem;
    font-size: .8125rem;
    font-weight: 400;
    text-align: center;
    color: var(--app-muted);
}

.example-words {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0;
    list-style: none;
}

.example-word {
    /* Scales with the boxes' height; shrinks on phones so long vowelled words fit */
    font-size: min(calc(var(--stage-h) * .043), 7vw);
    font-weight: 700;
    /* Room above and below for the vowel marks */
    line-height: 1.9;
}

/* Beside the grid and drawing, the examples grow to fill the card down to the listen button */
@media (min-width: 768px) {
    /* No min-height: 0 here, so if the words ever do not fit the panel scrolls rather than clipping them */
    .letter-panel .examples:not([hidden]) {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .examples-columns {
        flex: 1;
    }

    .example-words {
        flex: 1;
        justify-content: space-evenly;
    }
}

.example-letter {
    padding: 0;
    background: none;
    color: var(--app-accent);
}

/* The listen control sits at the bottom of the panel */
.voice {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--app-border);
}

.voice-button {
    flex: 1 1 100%;
}

/*
 * Beside the grid and drawing, the panel has exactly their height: the listen
 * control sits at its bottom edge, and any overflowing text scrolls above it.
 */
@media (min-width: 768px) {
    .letter-panel {
        display: flex;
        flex-direction: column;
        height: var(--stage-h);
        overflow-y: auto;
        padding-bottom: 0;
    }

    .voice {
        position: sticky;
        bottom: 0;
        margin-top: auto;
        padding-bottom: 1rem;
        background: var(--app-surface);
    }
}

.voice-label {
    padding: .125rem .625rem;
    border: 1px dashed var(--app-accent);
    border-radius: 1rem;
    font-size: .8125rem;
    color: var(--app-accent);
    display:none;
}

.voice-status {
    flex-basis: 100%;
    min-height: 1.5em;
    margin: 0;
    font-size: .875rem;
    color: var(--app-muted);
}

.source-quote {
    margin: 1rem 0 0;
    padding: .75rem 1rem;
    border-inline-start: 4px solid var(--app-primary);
    background: var(--app-bg);
    border-radius: .5rem;
}

.source-quote footer {
    font-size: .875rem;
    color: var(--app-muted);
}

.letter-note {
    margin: .75rem 0 0;
    font-size: .9375rem;
}

.letter-inline {
    font-weight: 800;
    color: var(--app-primary);
}

.error-page {
    padding-block: 3rem;
}

.error-code {
    font-size: 4rem;
    font-weight: 800;
    color: var(--app-primary);
    line-height: 1;
}

.error-debug {
    margin-top: 2rem;
    padding: 1rem;
    background: #2b2b2b;
    color: #f5f5f5;
    border-radius: .5rem;
    font-size: .8125rem;
    text-align: left;
    white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Sound unlock (main screen) ---- */

.sound-unlock {
    position: fixed;
    inset: 0;
    z-index: 2000;
    width: 100%;
    border: 0;
    background: rgba(13, 92, 88, .92);
    color: var(--app-primary-ink);
    font: inherit;
    font-size: clamp(1.75rem, 4vw, 3rem);
    font-weight: 800;
}

/* ---- iPad control panel (/panel) ---- */

.bare .site-main {
    display: flex;
}

.remote {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    user-select: none;
    -webkit-user-select: none;
}

.remote button {
    /* No double-tap zoom on the iPad */
    touch-action: manipulation;
}

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

.remote-title {
    margin: 0;
    font-size: 1.5rem;
    color: var(--app-primary);
}

.remote-connection {
    margin: 0;
    font-size: .9375rem;
    color: var(--app-muted);
}

.remote-connection::before {
    content: "";
    display: inline-block;
    width: .625rem;
    height: .625rem;
    margin-inline-end: .5rem;
    border-radius: 50%;
    background: var(--app-border);
}

.remote-connection[data-state="online"]::before {
    background: #2e9d5b;
}

.remote-connection[data-state="offline"] {
    color: #b42318;
}

.remote-connection[data-state="offline"]::before {
    background: #b42318;
}

.remote-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: .625rem;
    min-height: 0;
    /* Lets the letters size themselves from the grid (cqh units) */
    container-type: size;
}

@media (orientation: portrait) {
    .remote-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-rows: repeat(7, minmax(0, 1fr));
    }
}

.remote-letter {
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--app-border);
    border-radius: .875rem;
    background: var(--app-surface);
    color: var(--app-ink);
    font: inherit;
    /* About half a row's height in either orientation */
    font-size: min(12cqh, 7cqw);
    font-weight: 700;
    line-height: 1;
}

@media (orientation: portrait) {
    .remote-letter {
        font-size: min(7cqh, 12cqw);
    }
}

.remote-letter[aria-pressed="true"] {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: var(--app-primary-ink);
    box-shadow: 0 0 0 4px rgba(13, 92, 88, .25);
}

.remote-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem 1rem;
}

.remote-selected {
    flex: 1 1 100%;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
}

.remote-listen {
    flex: 3 1 0;
    min-height: 4.5rem;
    font-size: 1.75rem;
    font-weight: 800;
}

.remote-stop {
    flex: 1 1 0;
    min-height: 4.5rem;
    font-size: 1.25rem;
}
