/* app.css
   Write typing bubble, terms checkbox, install prompt, phone tab bar,
   offline practice.
   Part of the old features.css, split in load order: see index.html. */

/* ===== Write mode: typing bubble ===== */
.write-typing .write-text {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
    min-height: 0;
}
.write-typing .write-text span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.35;
    animation: write-dot 1.2s infinite ease-in-out;
}
.write-typing .write-text span:nth-child(2) { animation-delay: 0.15s; }
.write-typing .write-text span:nth-child(3) { animation-delay: 0.3s; }
@keyframes write-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-4px); opacity: 0.8; }
}
.write-log .write-tutor:not(.write-typing) {
    animation: write-in 0.25s ease-out;
}
@keyframes write-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .write-typing .write-text span,
    .write-log .write-tutor { animation: none; }
}

/* ===== Google / Microsoft sign-in ===== */
.sso-buttons.is-hidden,
.signin-methods:empty { display: none; }

.sso-or {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 10px;
    color: var(--muted);
    font-size: 13px;
}

.sso-or::before,
.sso-or::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--line);
}

.sso-button-list {
    display: grid;
    gap: 8px;
}

.sso-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 11px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
}

.sso-btn:hover { background: var(--hover-fill-soft); }
.sso-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.sso-btn svg { flex: none; }

.sso-note {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12.5px;
    text-align: center;
}

#sso-form .sso-terms {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 10px 0 4px;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--muted);
    cursor: pointer;
}

.signin-methods {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.signin-methods li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow-wrap: anywhere;
}

#signin-methods-connect .sso-btn { font-size: 14px; padding: 8px 12px; }

.no-password-note { margin: 0 0 10px; }

/* ===== Terms checkbox and legal links ===== */
#auth-form .auth-terms {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 6px 0 4px;
    font-size: 13.5px;
    line-height: 1.45;
    color: var(--muted);
    cursor: pointer;
}
#auth-form .auth-terms.is-hidden { display: none; }
#auth-form .auth-terms input {
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    padding: 0;
    flex: none;
    accent-color: var(--primary);
}
.auth-terms a,
.legal-links a { color: var(--primary-ink); }
.welcome-footer .legal-links { display: block; margin-top: 8px; }
.about-legal { margin-top: 10px; font-size: 14px; color: var(--muted); }

/* ===== Install the app ===== */
.install-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(20, 33, 61, 0.45);
}
.install-modal.open { display: flex; }
.install-card {
    width: 100%;
    max-width: 380px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    color: var(--ink);
}
.install-icon { width: 64px; height: 64px; border-radius: 15px; margin-bottom: 10px; }
.install-card h3 { font-size: 19px; margin-bottom: 14px; }
.install-steps { text-align: left; margin-bottom: 14px; }
.install-steps p { margin-bottom: 6px; }
.install-steps ol { padding-left: 20px; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
.install-steps li + li { margin-top: 4px; }
.install-close { width: 100%; margin-top: 4px; }

.profile-app-card {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0 0 18px;
    cursor: pointer;
}
.profile-app-card img { width: 48px; height: 48px; border-radius: 12px; flex: none; }
.profile-app-card > div { flex: 1; min-width: 0; }
.profile-app-card h3 { font-size: 16px; margin-bottom: 2px; }
.profile-app-card .setting-btn { flex: none; }

/* ===== Phone navigation (bottom tab bar) ===== */
.phone-tabs,
.more-sheet { display: none; }

@media (max-width: 700px) {
    body.in-app .phone-tabs {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 800;
        background: var(--surface);
        border-top: 1px solid var(--line);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    }

    .phone-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 4px 2px;
        background: none;
        border: none;
        color: var(--muted);
        font: inherit;
        font-size: 11px;
        text-decoration: none;
        min-width: 0;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .phone-tab svg { width: 24px; height: 24px; }
    .phone-tab span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .phone-tab.active { color: var(--ink); }
    .phone-tab.active svg { color: var(--primary-ink); }

    body.in-app .more-sheet {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 790;
        background: rgba(20, 33, 61, 0.35);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.18s;
    }
    body.in-app .more-sheet.open { opacity: 1; pointer-events: auto; }

    .more-panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 10px calc(76px + env(safe-area-inset-bottom));
        background: var(--surface);
        border-radius: 18px 18px 0 0;
        border-top: 1px solid var(--line);
        transform: translateY(100%);
        transition: transform 0.2s ease-out;
    }
    .more-sheet.open .more-panel { transform: none; }

    .more-item {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        padding: 13px 12px;
        background: none;
        border: none;
        border-radius: 10px;
        color: var(--ink-2);
        font: inherit;
        font-size: 16px;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
    }
    .more-item svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
    .more-item.active,
    .more-item:active { background: var(--surface-2); }
    .more-item.active svg { color: var(--primary-ink); }
    .more-logout { color: var(--danger-ink); margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
    .more-logout svg { color: var(--danger-ink); }

    /* Compact header: logo on the left, language and profile on the right */
    body.in-app .top-navbar {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        min-height: 0;
        gap: 10px;
        padding: calc(10px + env(safe-area-inset-top)) 15px 10px;
        margin-bottom: 14px;
        position: sticky;
        top: 0;
        z-index: 700;
    }
    body.in-app .nav-brand h1 { font-size: 20px; white-space: nowrap; }
    body.in-app .top-navbar .nav-links,
    body.in-app #nav-logout,
    body.in-app #mode-switch { display: none !important; }
    body.in-app .nav-user { gap: 8px; }
    body.in-app #nav-username {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Room for the tab bar under the last thing on each page */
    body.in-app .app-container { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
    body.in-app .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* Opened from the home screen: no install buttons */
html.is-app [data-install] { display: none !important; }

@media (max-width: 700px) {
    .write-actions { flex-wrap: wrap; width: 100%; }
    .write-actions .mode-button-inline { flex: 1 1 auto; min-width: 0; }
    .write-actions #write-new { flex: 0 0 auto; }
}
@media (max-width: 420px) {
    .write-actions #write-new { flex: 1 1 100%; }
}
@media (max-width: 520px) {
    .profile-app-card { flex-wrap: wrap; }
    .profile-app-card > div { flex: 1 1 60%; }
    .profile-app-card .setting-btn { flex: 1 1 100%; }
}

/* ===== Offline practice ===== */
.lessons-head { flex-wrap: wrap; }
.lessons-quiz-link { margin-left: auto; text-decoration: none; font-size: 14px; }
.lessons-downloads-link { text-decoration: none; font-size: 14px; }

/* Phones: the title on its own line, the two buttons side by side below */
@media (max-width: 600px) {
    .lessons-head h2 { flex: 1 1 calc(100% - 60px); }
    .lessons-head .lessons-quiz-link,
    .lessons-head .lessons-downloads-link {
        flex: 1 1 0;
        margin-left: 0;
        min-width: 0;
        padding: 10px 8px;
        font-size: 13px;
        text-align: center;
        white-space: normal;
    }
}
.lesson-section-download { margin-left: auto; white-space: nowrap; font-size: 13.5px; }
.lesson-section-download:disabled { color: var(--success-ink); opacity: 1; cursor: default; }
.lesson-offline-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: bold;
    color: var(--success-ink);
    background: rgba(34, 168, 102, 0.15);
    border-radius: 999px;
    padding: 2px 8px;
}
.lesson-offline-btn { margin: -4px 0 12px; font-size: 14px; }
.lesson-offline-btn:disabled { color: var(--success-ink); opacity: 1; cursor: default; }

.offline-banner {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--warning-tint);
    border: 1px solid var(--warning);
    color: var(--warning-ink);
    font-size: 14px;
}
.offline-banner a { color: var(--ink); font-weight: bold; }

.offline-panel { display: flex; flex-direction: column; gap: 18px; }
.offline-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
}
.page-view .offline-section { background: var(--surface); }
.offline-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.offline-section-head h3 { font-size: 17px; }
.offline-small { padding: 7px 14px; font-size: 13.5px; }
.offline-updated { margin-bottom: 10px; }
.offline-decks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.offline-deck {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
}
.offline-deck-icon { font-size: 26px; }
.offline-deck-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.offline-cat { margin: 14px 0 6px; font-size: 14px; color: var(--muted); font-weight: normal; }
.offline-row { display: flex; align-items: stretch; gap: 6px; margin-bottom: 6px; }
.offline-row-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    min-width: 0;
}
.offline-row-main:hover { border-color: var(--primary); }
.offline-row-title { font-weight: bold; min-width: 0; }
.offline-row-meta { display: flex; align-items: center; gap: 8px; flex: none; }
.offline-stars { color: var(--warning-ink); letter-spacing: 1px; }
.offline-remove {
    flex: none;
    width: 42px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: none;
    color: var(--muted);
    cursor: pointer;
}
.offline-remove:hover { color: var(--danger-ink); border-color: var(--danger); }
.offline-queue {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    align-items: center;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--primary);
    font-size: 14px;
}
.offline-space { text-align: center; }

.offline-back { margin-bottom: 10px; }
.offline-player { display: flex; flex-direction: column; gap: 12px; }
.offline-player-title { font-size: 22px; }
.offline-point-line { display: flex; align-items: center; gap: 8px; }
.offline-speak {
    border: none;
    background: var(--surface-2);
    border-radius: 999px;
    width: 32px;
    height: 32px;
    flex: none;
    cursor: pointer;
    font-size: 15px;
}
.offline-check { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.offline-check > .landing-primary,
.offline-actions .landing-primary,
.offline-actions .setting-btn { align-self: flex-start; }
.offline-q { font-size: 18px; font-weight: bold; }
.offline-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.offline-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 34px 20px;
    min-height: 190px;
    justify-content: center;
    text-align: center;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    cursor: pointer;
}
.offline-card-front { display: flex; align-items: center; gap: 10px; }
.offline-card-word { font-size: 30px; font-weight: bold; }
.offline-card-label { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.offline-card-wrong { font-size: 20px; color: var(--danger-ink); text-decoration: line-through; text-decoration-color: rgba(229, 72, 77, 0.5); }
.offline-card-back { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); width: 100%; }
.offline-card-meaning { font-size: 20px; color: var(--success-ink); font-weight: bold; }
.offline-card-right { font-size: 20px; color: var(--success-ink); font-weight: bold; }
.offline-card-context { color: var(--muted); font-style: italic; }
.offline-actions .offline-yes,
.offline-actions .offline-no { flex: 1; align-self: stretch; }

/* The screen shown when the app is opened without internet */
.offline-screen { min-height: 100vh; background: var(--surface); color: var(--ink); }
.offline-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.offline-status { display: flex; align-items: center; gap: 8px; color: var(--warning-ink); font-size: 14px; }
.offline-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); }
.offline-dot.is-online { background: var(--primary); }
.offline-reload { padding: 8px 14px; font-size: 13.5px; }
.offline-main {
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 18px calc(40px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
}
@media (max-width: 520px) {
    .offline-deck { flex-wrap: wrap; }
    .offline-deck .setting-btn { flex: 1 1 100%; }
    .offline-bar .welcome-brand { font-size: 17px; }
}
body.offline-mode .app-container,
body.offline-mode #welcome,
body.offline-mode #auth-screen,
body.offline-mode .phone-tabs { display: none !important; }
.offline-back {
    align-self: flex-start;
    background: none;
    border: none;
    color: var(--primary-ink);
    font: inherit;
    font-size: 14.5px;
    padding: 4px 0;
    cursor: pointer;
}


/* Lesson rows that scroll sideways, with arrows when they do not fit */
.lesson-row {
    position: relative;
}

.lesson-grid.is-scroll {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(220px, 260px);
    grid-template-columns: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 4px;
    padding: 4px 4px 8px;
    scrollbar-width: none;
}

.lesson-grid.is-scroll::-webkit-scrollbar {
    display: none;
}

.lesson-grid.is-scroll > * {
    scroll-snap-align: start;
}

.lesson-row-arrow {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    margin-top: -22px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink);
    font-size: 26px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(20, 33, 61, 0.18);
    cursor: pointer;
}

.lesson-row-arrow:hover {
    border-color: var(--primary);
    color: var(--primary-ink);
}

.lesson-row-arrow.is-prev { left: -12px; }
.lesson-row-arrow.is-next { right: -12px; }

/* Touch screens swipe the row; the arrows would only get in the way */
@media (pointer: coarse) {
    .lesson-row-arrow { display: none; }
}
