/* Bubblearn client styles. Colours follow the course PDFs: rose highlights, deep red numbers. */

:root {
    --bg: #fdfcfb;
    --surface: #ffffff;
    --text: #23201f;
    --muted: #77706d;
    --border: #e7e0dd;
    --accent: #b4475a;          /* the PDFs' red numbers and Hungarian words */
    --accent-text: #ffffff;
    --hl: #f3dada;              /* the PDFs' highlight behind vocabulary words */
    --hl-strong: #e9b9bd;
    --hu-hl: #f3dada80;
    --shadow: 0 8px 28px rgb(40 20 20 / 0.16), 0 1px 3px rgb(40 20 20 / 0.12);

    --font-step: 0;             /* -2 … 4, set by the text size buttons */
    --text-size: calc(1.0625rem + var(--font-step) * 0.125rem);
    --toolbar-h: 3rem;
    --player-h: 4rem;           /* updated by player.js from the real height */
    --gutter: 1rem;

    color-scheme: light;
}

:root[data-theme="sepia"] {
    --bg: #f6efe2;
    --surface: #fbf6ec;
    --text: #3a2e22;
    --muted: #84735f;
    --border: #e4d8c3;
    --hl: #efd3c4;
    --hl-strong: #e3b3a0;
    --hu-hl: #efd3c480;
}

/* Dark: chosen explicitly, or "auto" (no data-theme) on a device set to dark mode. */
:root[data-theme="dark"] {
    --bg: #171415;
    --surface: #221e1f;
    --text: #ece6e3;
    --muted: #a39996;
    --border: #3a3334;
    --accent: #e27a8b;
    --accent-text: #1b1213;
    --hl: #4a2c31;
    --hl-strong: #7a3e48;
    --hu-hl: #4a2c3199;
    --shadow: 0 8px 28px rgb(0 0 0 / 0.5), 0 1px 3px rgb(0 0 0 / 0.4);
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]), :root[data-theme="auto"] {
        --bg: #171415;
        --surface: #221e1f;
        --text: #ece6e3;
        --muted: #a39996;
        --border: #3a3334;
        --accent: #e27a8b;
        --accent-text: #1b1213;
        --hl: #4a2c31;
        --hl-strong: #7a3e48;
        --hu-hl: #4a2c3199;
        --shadow: 0 8px 28px rgb(0 0 0 / 0.5), 0 1px 3px rgb(0 0 0 / 0.4);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

/* Elements with display set below (the player is a grid) would ignore "hidden" otherwise. */
[hidden] { display: none !important; }

html {
    /* Anchor links and scrollIntoView stop below the sticky toolbar, not under it. */
    scroll-padding-top: calc(var(--toolbar-h) + env(safe-area-inset-top) + 0.75rem);
    scroll-padding-bottom: calc(var(--player-h) + 1rem);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    line-height: 1.6;
    /* Taps on words shouldn't flash grey on iOS/Android; we show our own highlight. */
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
    color: inherit;
}

a { color: var(--accent); }

.muted { color: var(--muted); }

/* ---------- Toolbar ---------- */

.toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: calc(var(--toolbar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.toolbar-title {
    margin-right: auto;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 0.5rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    cursor: pointer;
    font-size: 1.05rem;
}
.icon-button:hover { background: var(--hl); }
.icon-button svg { width: 1.25rem; height: 1.25rem; fill: currentColor; }

/* Segmented control built from radio buttons, so it works with the keyboard for free. */
.segmented {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    background: var(--surface);
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label > span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-height: 2.1rem;
    padding: 0 0.65rem;
    border-radius: 0.45rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}
.segmented svg { width: 1rem; height: 1rem; fill: currentColor; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented.small label > span { min-height: 1.8rem; padding: 0 0.5rem; font-weight: 500; }

@media (max-width: 480px) {
    .wide-only { display: none; }
}

.settings {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: max(var(--gutter), env(safe-area-inset-right));
    width: min(22rem, calc(100vw - 2 * var(--gutter)));
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem 0;
    font-size: 0.9rem;
}
.stepper { display: inline-flex; gap: 0.25rem; }
.stepper button {
    min-width: 2.75rem;
    height: 2.2rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--bg);
    cursor: pointer;
}

/* ---------- Chapter text ---------- */

main {
    padding: 0 max(var(--gutter), env(safe-area-inset-right)) calc(var(--player-h) + 2rem) max(var(--gutter), env(safe-area-inset-left));
}

.chapter, .vocabulary, .quiz, .book-footer {
    max-width: 40rem;
    margin: 0 auto;
}
body[data-layout="split"] .chapter { max-width: 76rem; }

.chapter {
    padding-top: 1.5rem;
    font-size: var(--text-size);
}

.chapter p { margin: 0; }

/* One row = one paragraph in both languages. */
.row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    column-gap: 2.5rem;
    margin-bottom: 1.1em;
}

/* Text only (no translation) */
body[data-layout="text"] .row > .tr { display: none; }

/* Side by side: one grid, two columns, so paragraph pairs start at the same height. */
body[data-layout="split"] .row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
body[data-layout="split"] .row > .tr { padding-left: 1.25rem; border-left: 1px solid var(--border); }
@media (max-width: 700px) {
    body[data-layout="split"] .row { column-gap: 0.9rem; }
    body[data-layout="split"] .row > .tr { padding-left: 0.8rem; }
    body[data-layout="split"] .chapter { font-size: calc(var(--text-size) * 0.86); }
    body[data-layout="split"] main { --gutter: 0.75rem; }
}

/* Interleaved: the translation under each paragraph, quieter. */
body[data-layout="stack"] .row > .tr {
    margin-top: 0.45em;
    padding-left: 0.8rem;
    border-left: 3px solid var(--hl-strong);
    color: var(--muted);
    font-size: 0.92em;
}

/* Hovering a paragraph shows its partner (only on devices with a real mouse). */
@media (hover: hover) {
    body[data-layout="split"] .row:hover > * { background: color-mix(in srgb, var(--hl) 25%, transparent); }
}

.heading { text-align: center; margin-bottom: 2.25em; }
.heading h1 {
    margin: 0.1em 0;
    font-size: 1.55em;
    font-weight: 400;
    line-height: 1.3;
}
.heading .season { font-size: 1.1em; letter-spacing: 0.12em; text-transform: uppercase; }
.heading .narrator { font-size: 1.3em; font-family: Georgia, "Times New Roman", serif; }
body[data-layout="stack"] .heading > .tr { border-left: 0; padding-left: 0; }

.stage { color: var(--muted); font-style: italic; }

/* Vocabulary words. role=button; spans (not <button>) so a phrase can wrap across lines. */
.term {
    padding: 0.05em 0.1em;
    border-radius: 0.2em;
    background: var(--hl);
    cursor: pointer;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    transition: background-color 0.15s;
}
.term:hover { background: var(--hl-strong); }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* The translation marks the matching phrase more quietly. */
.tr .term { background: var(--hu-hl); }
.term.active, .tr .term.active { background: var(--hl-strong); box-shadow: 0 0 0 1.5px var(--accent); }
.term.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
    0%, 30% { background: var(--accent); color: var(--accent-text); }
}

/* ---------- Vocabulary list ---------- */

.vocabulary, .quiz { padding-top: 2.5rem; }
.vocabulary h2, .quiz h2 {
    margin: 0 0 0.25rem;
    font-weight: 400;
    font-size: 1.6rem;
    letter-spacing: 0.04em;
}
.vocab-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.vocab-list li {
    padding: 0.85rem 0;
    border-top: 1px solid var(--border);
}
.vocab-list .vl-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.5rem; }
.vocab-list .vl-term {
    padding: 0;
    border: 0;
    background: none;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}
.vocab-list .vl-term:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.vocab-list .vl-num { color: var(--accent); font-weight: 700; min-width: 1.5rem; }
.vocab-list .vl-hu { color: var(--accent); font-weight: 600; }
.vocab-list .vl-def { margin: 0.25rem 0 0 2rem; color: var(--muted); font-size: 0.95rem; }

/* ---------- Quiz ---------- */

.question {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
}
.question legend { padding: 0; font-weight: 600; margin-bottom: 0.5rem; }
.question fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.35rem 0;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
}
.option input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; margin: 0; }
.option.correct { border-color: #3c9a5f; background: color-mix(in srgb, #3c9a5f 14%, transparent); }
.option.wrong { border-color: #c4473a; background: color-mix(in srgb, #c4473a 14%, transparent); }
.feedback { margin: 0.5rem 0 0; font-size: 0.92rem; }
.feedback:empty { display: none; }

.book-footer {
    padding: 3rem 0 1rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
}
.book-footer p { margin: 0.2rem 0; }
.book-footer .series { letter-spacing: 0.45em; text-transform: uppercase; font-weight: 700; color: var(--text); }

/* ---------- Vocabulary pop-up ---------- */

.popup {
    position: absolute;          /* in page coordinates: it scrolls with the word it points at */
    z-index: 30;
    width: min(23rem, calc(100vw - 1.5rem));
    padding: 0.9rem 1rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 0.95rem;
    line-height: 1.5;
}
/* Phones: a sheet above the player instead, always fully visible and in thumb reach. */
.popup.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--player-h);
    width: auto;
    max-height: 55vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    border-radius: 1rem 1rem 0 0;
    border-bottom: 0;
    animation: sheet-in 0.18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(1.5rem); opacity: 0; } }

.popup-head { display: flex; align-items: center; gap: 0.5rem; }
.popup-head h3 { margin: 0 auto 0 0; font-size: 1.2rem; line-height: 1.25; }
.popup-head .icon-button { min-width: 2.25rem; height: 2.25rem; font-size: 1.5rem; color: var(--muted); }
.popup-number {
    display: inline-grid;
    place-items: center;
    flex: none;
    min-width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.8rem;
    font-weight: 700;
}
.popup-hu { margin: 0.35rem 0 0; color: var(--accent); font-weight: 600; font-size: 1.05rem; }
.popup-def { margin: 0.5rem 0 0; }
.popup-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}
.popup-nav button {
    min-height: 2.25rem;
    padding: 0 0.6rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}
.popup-nav button:hover { background: var(--hl); }
.popup-nav button:disabled { color: var(--muted); opacity: 0.5; cursor: default; background: none; }

/* ---------- Audio player ---------- */

.player {
    position: fixed;
    z-index: 25;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: auto auto auto auto 1fr auto auto;
    grid-template-areas: "back play fwd cur seek dur speed";
    align-items: center;
    gap: 0.25rem 0.6rem;
    padding: 0.5rem max(var(--gutter), env(safe-area-inset-right)) calc(0.5rem + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
}
#player-back { grid-area: back; }
#player-play { grid-area: play; }
#player-forward { grid-area: fwd; }
#player-current { grid-area: cur; }
#player-seek { grid-area: seek; }
#player-duration { grid-area: dur; }
#player-speed { grid-area: speed; }

/* Phones: the seek bar gets its own full-width row. */
@media (max-width: 560px) {
    .player {
        grid-template-columns: auto 1fr auto auto auto 1fr auto;
        grid-template-areas:
            "cur  seek seek seek seek seek dur"
            ".    .    back play fwd  .    speed";
        row-gap: 0.1rem;
    }
}

.player button {
    display: inline-grid;
    place-items: center;
    border: 0;
    background: transparent;
    cursor: pointer;
}
.player-play {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--accent) !important;
    color: var(--accent-text);
}
.player-play svg { width: 1.5rem; height: 1.5rem; fill: currentColor; }
.player-play .icon-pause { display: none; }
.player.playing .icon-play { display: none; }
.player.playing .icon-pause { display: block; }
.player-skip { width: 2.5rem; height: 2.5rem; border-radius: 50%; }
.player-skip:hover, .player-speed:hover { background: var(--hl) !important; }
.player-skip svg { width: 1.6rem; height: 1.6rem; fill: currentColor; }
.player-skip text { font-size: 6.5px; font-weight: 700; font-family: system-ui, sans-serif; }
.player-time { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.6rem; }
#player-duration { text-align: right; }
.player-speed {
    min-width: 3rem;
    height: 2.2rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Seek bar: the played part is filled in with the accent colour (--p is set by player.js). */
.player-seek {
    --p: 0%;
    width: 100%;
    height: 1.75rem;             /* tall hit area, thin track */
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
.player-seek::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent) var(--p), var(--border) var(--p));
}
.player-seek::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }
.player-seek::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
.player-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
}
.player-seek::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--accent); }
.player-seek:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Lesson navigation ---------- */

.toolbar .back-link { margin-left: -0.5rem; color: var(--text); }
.toolbar .back-link + .toolbar-title { margin-left: -0.25rem; }

.lesson-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    max-width: 40rem;
    margin: 3rem auto 0;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.lesson-nav a { text-decoration: none; }
.lesson-nav .prev, .lesson-nav .next { display: flex; flex-direction: column; color: var(--text); }
.lesson-nav .next { text-align: right; }
.lesson-nav small { color: var(--accent); font-weight: 600; }
.lesson-nav .to-course { font-weight: 600; font-size: 0.9rem; }

.load-error {
    padding: 1rem;
    border: 1px solid #c4473a;
    border-radius: 0.75rem;
    color: #c4473a;
}

/* ---------- Login (Bubblearn.Web: login.html, the toolbar's account link) ---------- */

.toolbar-link {
    max-width: 45vw;
    padding: 0.4rem 0.6rem;
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.95rem;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.toolbar-link:hover { background: var(--hl); }

.login-form { display: grid; gap: 0.5rem; max-width: 22rem; margin-top: 1.5rem; }
.login-form label { font-weight: 600; }
.login-form input {
    min-width: 0;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.login-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-form .code-input { font-size: 1.6rem; letter-spacing: 0.35em; font-variant-numeric: tabular-nums; }
.primary-button, .secondary-button {
    justify-self: start;
    margin-top: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.primary-button { border: 0; background: var(--accent); color: var(--accent-text); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.primary-button:disabled, .secondary-button:disabled { opacity: 0.6; cursor: default; }
.form-message { min-height: 1.6em; margin: 0.25rem 0 0; }
.form-message.error { color: #c4473a; }
.login-links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1.5rem; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }
.link-button:disabled { opacity: 0.6; cursor: default; }

/* ---------- Course list and course outline ---------- */

.page-main {
    max-width: 40rem;
    margin: 0 auto;
    padding: 1.5rem max(var(--gutter), env(safe-area-inset-right)) 3rem max(var(--gutter), env(safe-area-inset-left));
}
.page-title { margin: 0 0 0.25rem; font-weight: 400; font-size: 1.9rem; line-height: 1.25; }

.course-list { list-style: none; margin: 1.25rem 0 0; padding: 0; }
.course-list li { margin-bottom: 1rem; }
.card {
    display: block;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--hl-strong); box-shadow: var(--shadow); }
.card h2 { margin: 0; font-size: 1.3rem; font-weight: 600; }
.card p { margin: 0.4rem 0 0; }
.card-author { margin: 0.1rem 0 0.75rem; color: var(--accent); font-weight: 600; }
.card .card-author { margin: 0.1rem 0 0; }

.outline-section { margin-top: 2rem; }
.outline-section h2 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}
.lesson-list { list-style: none; margin: 0; padding: 0; counter-reset: lesson; }
.lesson-list li { border-top: 1px solid var(--border); }
.lesson-list li:last-child { border-bottom: 1px solid var(--border); }
.lesson-list a {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.85rem 0.25rem;
    color: var(--text);
    text-decoration: none;
}
.lesson-list a::before {
    counter-increment: lesson;
    content: counter(lesson);
    min-width: 1.5rem;
    color: var(--accent);
    font-weight: 700;
}
.lesson-list a:hover { background: color-mix(in srgb, var(--hl) 40%, transparent); }
