/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #ececf0;
    --text: #1a1a2e;
    --muted: #8a8a96;
    --border: #e3e3e8;
    --accent: #0a84ff;
    --accent-text: #ffffff;
    --ok: #1fa855;
    --ok-bg: #e3f6ea;
    --fail: #e5484d;
    --fail-bg: #fde8e8;
    --shadow: 0 2px 8px rgb(0 0 0 / .06);
    --radius: 16px;
    --radius-sm: 12px;
    --gutter: 16px;
    --header-h: 52px;
    --content-w: 640px;
    --duration: 200ms;

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111216;
        --surface: #1c1d23;
        --surface-2: #2a2b33;
        --text: #ececf1;
        --muted: #9a9aa6;
        --border: #2c2d35;
        --accent: #3d9bff;
        --ok: #3ccf74;
        --ok-bg: #173323;
        --fail: #ff6b6f;
        --fail-bg: #3a1c1e;
        --shadow: 0 2px 8px rgb(0 0 0 / .4);
    }
}

/* ==========================================================================
   Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

/* Background on <html>, not only <body>: no white flash between pages */
html {
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
button { font: inherit; color: inherit; }
img { display: block; }
p { margin: 0; }

/* ==========================================================================
   View Transitions
   ========================================================================== */

/* Cross-document: navigation between screens (MPA) */
@view-transition {
    navigation: auto;
}

::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
    animation-duration: var(--duration);
}

/* Present on every screen: stays in place instead of blinking */
.app-header { view-transition-name: site-header; }

/* The card: one element per page carries this name (unique at transition time) */
.vt-card { view-transition-name: card; }

::view-transition-old(card) {
    animation: var(--duration) ease-in both vt-slide-out-left;
}
::view-transition-new(card) {
    animation: var(--duration) ease-out both vt-slide-in-right;
}
html[data-transition-back]::view-transition-old(card) {
    animation-name: vt-slide-out-right;
}
html[data-transition-back]::view-transition-new(card) {
    animation-name: vt-slide-in-left;
}

@keyframes vt-slide-out-left { to { transform: translateX(-30%); opacity: 0; } }
@keyframes vt-slide-in-right { from { transform: translateX(30%); opacity: 0; } }
@keyframes vt-slide-out-right { to { transform: translateX(30%); opacity: 0; } }
@keyframes vt-slide-in-left { from { transform: translateX(-30%); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
}

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 56px 1fr 56px;
    align-items: center;
    min-height: calc(var(--header-h) + env(safe-area-inset-top));
    /* same column as .screen: on wide screens the buttons stay next to the content */
    padding: env(safe-area-inset-top) max(4px, calc((100% - var(--content-w)) / 2 + 4px)) 0;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.app-header__title {
    overflow: hidden;
    text-align: center;
    font-weight: 650;
    font-size: 17px;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.app-header__title small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.app-header__side { display: flex; }
.app-header__side--end { justify-content: flex-end; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn--muted { color: var(--muted); font-size: 18px; }

.avatar-link {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    text-decoration: none;
}
.avatar-link img,
.avatar-link span {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
.avatar-link span {
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

/* ==========================================================================
   Screen
   ========================================================================== */

.screen {
    max-width: var(--content-w);
    margin: 0 auto;
    padding: 8px var(--gutter) calc(96px + env(safe-area-inset-bottom));
}

/* Study/quiz: content centered vertically, no FAB space */
.screen--stage {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* ==========================================================================
   Components
   ========================================================================== */

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

.tile {
    display: grid;
    gap: 4px;
    padding: 16px 18px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
}
a.tile:active, .tile__main:active { opacity: .7; }

.tile--row {
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 0 6px 0 0;
}
.tile__main {
    display: grid;
    gap: 3px;
    min-width: 0;
    padding: 14px 0 14px 18px;
    color: inherit;
    text-decoration: none;
}
.tile__title { font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.tile__text { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.tile__meta { color: var(--muted); font-size: 13px; }
.tile .progress { margin-top: 6px; }

.status { font-weight: 600; }
.status--new { color: var(--muted); }
.status--learning { color: #f59e0b; }
.status--reviewing { color: var(--accent); }
.status--mastered { color: var(--ok); }

.progress {
    overflow: hidden;
    height: 8px;
    border-radius: 4px;
    background: var(--surface-2);
}
.progress--mini { height: 4px; }
.progress__fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width var(--duration) ease-out;
}

.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.progress-row .progress { flex: 1; }
.progress-row__value { min-width: 40px; color: var(--muted); font-size: 14px; font-weight: 600; text-align: right; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    padding: 12px 20px;
    border: 1.5px solid transparent;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.btn--danger { background: var(--fail-bg); color: var(--fail); }
.btn--choice {
    justify-content: flex-start;
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    text-align: left;
}
.btn.is-disabled { opacity: .35; pointer-events: none; }
.btn.htmx-request, form.htmx-request .btn { opacity: .6; }

.actions {
    display: flex;
    gap: 10px;
}
.actions__main { flex: 2; display: flex; }
.actions > .btn { flex: 1; }
.actions--sticky {
    position: sticky;
    bottom: 0;
    margin-top: 16px;
    padding: 12px 0 env(safe-area-inset-bottom);
    background: linear-gradient(transparent, var(--bg) 30%);
}

.fab {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: calc(24px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
    color: var(--accent-text);
    font-size: 32px;
    font-weight: 300;
    text-decoration: none;
}

.empty {
    display: grid;
    gap: 8px;
    padding: 64px 24px;
    text-align: center;
}
.empty__title { font-size: 20px; font-weight: 650; }
.empty__text { color: var(--muted); }

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--fail-bg);
    color: var(--fail);
}

/* ==========================================================================
   Forms (Symfony form_widget, div layout)
   ========================================================================== */

.form { display: grid; gap: 12px; }
.form > div { display: grid; gap: 14px; }
.form label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.form input[type=text], .form textarea, .form select, .input {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 17px; /* >= 16px: iOS does not zoom on focus */
}
.form input:focus, .form textarea:focus, .form select:focus, .input:focus {
    outline: none;
    border-color: var(--accent);
}
.form [aria-invalid=true] { border-color: var(--fail); }
.form ul { margin: 6px 0 0; padding: 0; list-style: none; color: var(--fail); font-size: 14px; }
.form .help-text, .form [id$=_help] { margin-top: 6px; color: var(--muted); font-size: 13px; }

.danger-zone { margin-top: 32px; }

/* ==========================================================================
   Deck screen
   ========================================================================== */

.deck-summary { display: grid; gap: 12px; margin-bottom: 16px; }
.deck-summary:empty { display: none; }

/* ==========================================================================
   Stage (study / quiz)
   ========================================================================== */

.stage {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 16px;
}
.stage__counter { color: var(--muted); font-size: 14px; font-weight: 600; text-align: center; }
.stage__controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
}
.stage__controls .btn { font-size: 20px; }

.speak-btn { width: 48px; height: 48px; background: var(--surface); box-shadow: var(--shadow); }
.speak-btn--big { width: 96px; height: 96px; margin: 8px auto; }
.speak-btn--big svg { width: 44px; height: 44px; }

/* Flashcard: CSS-only flip driven by a checkbox */
.flashcard {
    position: relative;
    display: block;
    height: clamp(280px, 55dvh, 440px);
    perspective: 1200px;
    cursor: pointer;
}
.flashcard__toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.flashcard__inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform 250ms ease-out;
}
.flashcard__toggle:checked + .flashcard__inner { transform: rotateY(180deg); }
.flashcard__toggle:focus-visible + .flashcard__inner { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: var(--radius); }
.flashcard__face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}
.flashcard__face--back { transform: rotateY(180deg); }
.flashcard__term, .flashcard__translation { font-size: 32px; font-weight: 700; overflow-wrap: anywhere; }
.flashcard__hint { color: var(--muted); font-size: 14px; }
.flashcard__examples { display: grid; gap: 6px; color: var(--muted); font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
    .flashcard__inner { transition: none; }
}

/* Quiz */
.quiz-progress { margin: 4px 0 12px; }

.quiz-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 200px;
    padding: 28px 20px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
}
.quiz-card__hint { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.quiz-card__term { font-size: 30px; font-weight: 700; overflow-wrap: anywhere; }
.quiz-card__note { color: var(--muted); font-size: 14px; }
.quiz-card__term-row { display: flex; align-items: center; justify-content: center; gap: 10px; }
.quiz-card__translation { font-size: 20px; }
.quiz-card__wrong { color: var(--fail); font-size: 20px; text-decoration: line-through; }
.quiz-card__examples {
    display: grid;
    gap: 6px;
    width: 100%;
    margin: 8px 0 0;
    padding: 14px 0 0 18px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 15px;
    text-align: left;
}
.quiz-card--reveal { justify-content: flex-start; }

.verdict {
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
}
.verdict--ok { background: var(--ok-bg); color: var(--ok); }
.verdict--fail { background: var(--fail-bg); color: var(--fail); }

.quiz-answer {
    display: grid;
    gap: 10px;
}
.input--big { font-size: 20px; text-align: center; }

/* Result */
.result { display: grid; gap: 4px; padding: 24px 0; text-align: center; }
.result__emoji { font-size: 48px; }
.result__score { font-size: 40px; font-weight: 800; }
.result__text { color: var(--muted); }

.mark { padding: 0 14px; font-size: 20px; font-weight: 700; }
.mark--ok { color: var(--ok); }
.mark--fail { color: var(--fail); }

/* ==========================================================================
   Login / profile
   ========================================================================== */

.welcome { display: grid; justify-items: center; gap: 14px; padding: 48px 8px; text-align: center; }
.welcome__logo { font-size: 64px; }
.welcome__title { margin: 0; font-size: 24px; line-height: 1.25; }
.welcome__text { color: var(--muted); }

.btn-telegram {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 13px 24px 13px 16px;
    border-radius: 999px;
    background: #2aabee;
    color: #fff;
    font-weight: 650;
    text-decoration: none;
}
.btn-telegram:active { background: #229ed9; }

.profile { display: grid; justify-items: center; gap: 6px; padding: 32px 0; text-align: center; }
.profile__avatar { border-radius: 50%; margin-bottom: 8px; }
.profile__name { margin: 0; font-size: 24px; }
.profile__username, .profile__meta { color: var(--muted); }
