﻿/* Engine (/Engine, /Engine/Demo): EngineCore, IpaSearch, EngineReferenceCard. Also the shared LabelSwitch and AudioPlayer
   (used in lessons too). The detail dialogs use LibraryStyleDetail (library.css). */

/* minmax(0, 1fr): the card row is wider than the screen; without it the grid columns grow with it and the whole
   page (top bar included) gets wider than the viewport. */
.eng-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    max-width: 1760px;
    margin: 0 auto;
    padding: 28px 40px 32px;
}

.eng-core {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    min-width: 0;
}

/* ---------- Toolbar ---------- */

.eng-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 16px 28px;
    padding: 16px 18px;
    border: 1px solid var(--en-line);
    border-radius: var(--en-radius-lg);
    background: var(--en-surface);
}

.eng-toolbar-search {
    display: grid;
    gap: 10px;
    flex: 1 1 520px;
    min-width: 0;
}

.eng-search {
    display: flex;
    gap: 8px;
}

.eng-search-box {
    position: relative;
    flex: 1;
    min-width: 0;
}

/* Suggestion list below the search field (IpaSearch) */
.eng-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 900;
    max-height: 300px;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    border: 1px solid var(--en-line);
    border-radius: var(--en-radius-md);
    background: var(--en-surface);
    box-shadow: var(--en-shadow-2);
    list-style: none;
}

.eng-suggestion {
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--en-ink-soft);
    cursor: pointer;
}

.eng-suggestion b {
    font-weight: 700;
    color: var(--en-ink);
}

.eng-suggestion:hover,
.eng-suggestion.is-active {
    background: var(--en-mouth-soft);
    color: var(--en-mouth-ink);
}

.eng-suggestion:hover b,
.eng-suggestion.is-active b {
    color: inherit;
}

.eng-full-version {
    justify-self: start;
}

.eng-toolbar-switches,
.eng-toolbar-copy {
    display: grid;
    gap: 10px;
}

.eng-toolbar-copy {
    justify-items: stretch;
}

/* ---------- Word and cards ---------- */

.eng-word {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    min-width: 0;
}

.eng-word-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 16px;
}

.eng-word-title {
    margin: 0;
    font: 700 clamp(2rem, 1.5rem + 1.6vw, 2.8rem)/1.1 var(--en-font-display);
    letter-spacing: -0.02em;
    color: var(--en-ink);
}

.eng-word-ipa {
    font: 400 1.6rem/1.2 var(--en-font-ipa);
    color: var(--en-ink-soft);
}

.eng-cards-scroll {
    padding-bottom: 6px;
}

.eng-cards {
    display: flex;
    gap: 12px;
    width: max-content;
}

.eng-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 128px;
    padding: 14px;
    border: 1px solid var(--en-line);
    border-radius: var(--en-radius-lg);
    background: var(--en-surface);
    box-shadow: var(--en-shadow-1);
}

.eng-cards.is-practice .eng-card {
    min-width: 96px;
    padding: 10px 12px 12px;
}

.eng-card-ipa {
    font: 400 1.7rem/1.1 var(--en-font-ipa);
    text-align: center;
    color: var(--en-ink);
}

.eng-card-steps {
    display: flex;
    flex: 1;
    gap: 8px;
}

.eng-card-audio {
    display: block;
}

/* Mouth + Tongue Style of one step (EngineReferenceCard) */

.eng-ref {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
}

.eng-ref-button {
    display: grid;
    flex: 1;
    justify-items: center;
    align-content: center;
    gap: 4px;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--en-line-strong);
    border-radius: var(--en-radius-md);
    background: var(--en-surface);
    color: var(--en-ink);
    font: inherit;
    cursor: pointer;
}

.eng-ref-button:hover {
    border-color: var(--en-mouth);
    background: var(--en-surface-2);
}

.eng-ref-button:focus-visible {
    outline: 2px solid var(--en-mouth);
    outline-offset: 2px;
}

.eng-ref-button img {
    object-fit: contain;
}

.eng-ref-name {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.eng-ref-code {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.eng-audio {
    max-width: 420px;
}

/* ---------- LabelSwitch ---------- */

.en-labelswitch {
    display: flex;
    align-items: center;
    gap: 10px;
}

.en-labelswitch-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--en-ink-muted);
}

.en-labelswitch.is-left .en-labelswitch-label:first-child,
.en-labelswitch.is-right .en-labelswitch-label:nth-of-type(2) {
    color: var(--en-mouth-ink);
}

.en-labelswitch-track {
    position: relative;
    flex: none;
    width: 40px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--en-surface-3);
    cursor: pointer;
    transition: background-color .15s;
}

.en-labelswitch-track[aria-checked="true"] {
    background: var(--en-mouth);
}

.en-labelswitch-track:focus-visible {
    outline: 2px solid var(--en-mouth);
    outline-offset: 2px;
}

.en-labelswitch-track:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.en-labelswitch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    transition: transform .15s;
}

.en-labelswitch-track[aria-checked="true"] .en-labelswitch-thumb {
    transform: translateX(18px);
}

.en-labelswitch-lock {
    display: inline-flex;
    color: var(--en-ink-muted);
    cursor: help;
}

/* ---------- AudioPlayer ---------- */

.en-audio {
    display: grid;
    gap: 10px;
    padding: 14px 16px;
    border: 1px solid var(--en-line);
    border-radius: var(--en-radius-lg);
    background: var(--en-surface);
}

.en-audio audio {
    width: 100%;
}

.en-audio audio:not([controls]) {
    display: none;
}

.en-audio-title {
    font-weight: 600;
}

.en-audio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--en-ink-muted);
}

.en-audio-range {
    flex: 1;
    min-width: 120px;
    accent-color: var(--en-mouth);
}

.en-audio-value {
    min-width: 6.5em;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--en-ink-soft);
}

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
    .eng-page {
        padding: 20px 16px 28px;
    }

    .eng-toolbar-copy {
        grid-auto-flow: column;
    }

    .eng-cards {
        gap: 8px;
    }

    .eng-audio {
        max-width: none;
    }
}

/* Phone: compact like the former Engine. Search and icon-only buttons in one row, switches left, copy buttons right. */
@media (max-width: 600px) {
    .eng-page {
        gap: 14px;
        padding: 14px 12px 20px;
    }

    .eng-core {
        gap: 14px;
    }

    .eng-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
        padding: 12px;
    }

    .eng-toolbar-search {
        grid-column: 1 / -1;
    }

    .eng-toolbar-copy {
        grid-auto-flow: row;
    }

    .eng-button-text {
        display: none;
    }

    .eng-search-button {
        width: 42px;
        height: 42px;
        padding: 0;
        justify-content: center;
    }

    .en-labelswitch {
        gap: 8px;
    }

    .en-labelswitch-label {
        min-width: 0 !important;
        font-size: 0.8rem;
    }

    .eng-word {
        gap: 10px;
    }

    .eng-word-title {
        font-size: 1.7rem;
    }

    .eng-word-ipa {
        font-size: 1.25rem;
    }

    .eng-card,
    .eng-cards.is-practice .eng-card {
        min-width: 0;
        gap: 6px;
        padding: 8px;
    }

    .eng-card-ipa {
        font-size: 1.4rem;
    }

    .en-audio {
        padding: 10px 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .en-labelswitch-track,
    .en-labelswitch-thumb {
        transition: none;
    }
}
