:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2a2f3a;
    --text: #ecedef;
    --text-muted: #8d94a3;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.18);
    --good: #4ade80;
    --bad: #f87171;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter",
        "Segoe UI", Roboto, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    touch-action: pan-y;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
    max-width: 560px;
    margin: 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }
.muted  { color: var(--text-muted); }

/* ------- topbar ------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    font-weight: 600;
    letter-spacing: 0.2px;
}

.progress {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--surface-2);
    overflow: hidden;
}

.progress__fill {
    width: 0%;
    height: 100%;
    background: var(--accent);
    transition: width 0.25s ease;
}

.counter {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ------- screens ------- */
.screen {
    flex: 1;
    padding: 18px;
    display: flex;
    flex-direction: column;
}

.loader {
    margin: auto;
    color: var(--text-muted);
}

/* ------- card ------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card--center {
    text-align: center;
    align-items: center;
    padding: 32px 20px;
}

.card__image {
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-2);
}

.card__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card__meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chip {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-right: auto;
}

.card__sentence {
    font-size: 1.35rem;
    line-height: 1.55;
    padding: 6px 0;
    user-select: none;
}

.card__description {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px 18px;
    margin: 0 12px 8px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(91, 140, 255, 0.10), rgba(91, 140, 255, 0.02));
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1rem;
    line-height: 1.4;
    min-height: 76px;
}

.word {
    cursor: pointer;
    border-radius: 4px;
    padding: 0 2px;
    transition: background 0.12s ease;
}

.word:hover { background: var(--surface-2); }

.word.blank {
    display: inline-block;
    min-width: 5.5em;
    text-align: center;
    border-bottom: 2px dashed var(--accent);
    margin: 0 4px;
    padding: 0 6px;
    color: var(--accent);
}

.word.blank.filled {
    border-bottom-style: solid;
    color: var(--text);
}

.btn-link {
    background: none;
    color: var(--accent);
    border: 0;
    padding: 0;
    text-align: left;
    font-size: 0.95rem;
    cursor: pointer;
}

.translation {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ------- options ------- */
.options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.option {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    transition: transform 0.05s, background 0.12s, border-color 0.12s;
}

.option:hover { background: #262b36; }
.option:active { transform: scale(0.98); }

.option.selected {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.option.correct {
    background: rgba(74, 222, 128, 0.18);
    border-color: var(--good);
    color: var(--good);
}

.option.wrong {
    background: rgba(248, 113, 113, 0.18);
    border-color: var(--bad);
    color: var(--bad);
}

.option:disabled { cursor: default; opacity: 0.9; }

/* ------- feedback / next ------- */
.feedback {
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 500;
}

.feedback.correct {
    background: rgba(74, 222, 128, 0.14);
    color: var(--good);
}

.feedback.wrong {
    background: rgba(248, 113, 113, 0.14);
    color: var(--bad);
}

.btn-primary {
    margin-top: 4px;
    width: 100%;
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: 10px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:active { transform: scale(0.99); }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.92rem;
}

.icon-btn {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn.small { width: 30px; height: 30px; font-size: 0.85rem; }

.score {
    font-size: 2.2rem;
    font-weight: 700;
    margin: 8px 0;
    color: var(--accent);
}

/* ------- chips & grammar panel ------- */
.chip--button {
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-size: 0.78rem;
}

.chip--button:hover { filter: brightness(1.15); }
.chip--button.active {
    background: var(--accent);
    color: white;
}

.chip__info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 0.78rem;
    opacity: 0.9;
}

.grammar-panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.grammar-panel__title {
    font-weight: 600;
    margin-bottom: 2px;
}

.grammar-panel__summary {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.grammar-panel__body strong { color: var(--accent); }

/* ------- anchored word popover ------- */
.wpop {
    position: absolute;
    z-index: 90;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
    padding: 8px 10px;
    width: max-content;
    max-width: 260px;
    animation: wpopIn 0.12s ease-out;
}

@keyframes wpopIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.wpop.fadeout { animation: wpopOut 0.25s ease-in forwards; }

@keyframes wpopOut {
    to { opacity: 0; transform: translateY(-4px); }
}

.wpop__row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.95rem;
}

.wpop__head .wpop__word {
    font-weight: 600;
    color: var(--text);
}

.wpop__ipa {
    font-size: 0.8rem;
    font-family: ui-monospace, monospace;
}

.wpop__divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.wpop__translation {
    cursor: pointer;
    border-radius: 6px;
    padding: 6px;
    transition: background 0.12s;
}
.wpop__translation:hover { background: var(--surface-2); }

.wpop__variant {
    padding: 4px 6px;
}

.wpop__variant input {
    flex: 1;
    background: transparent;
    border: 0;
    border-bottom: 1px solid transparent;
    color: var(--text);
    font: inherit;
    outline: none;
    padding: 4px 2px;
    cursor: text;
}

.wpop__variant input::placeholder {
    color: var(--text-muted);
}

.wpop__variant input:focus {
    border-bottom-color: var(--accent);
}

.wpop__note {
    font-size: 0.82rem;
    padding-top: 0;
}

.iconmini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: var(--accent);
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.word.tapped {
    background: var(--accent-soft);
    color: var(--accent);
}
