/* ---- Tokens ---- */
:root {
    --bg: #0b1220;
    --bg-elev: #131b2e;
    --bg-soft: #1a2440;
    --border: rgba(148, 163, 184, 0.14);
    --border-strong: rgba(148, 163, 184, 0.28);

    --fg: #f8fafc;
    --fg-muted: #94a3b8;
    --fg-dim: #64748b;

    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --success: #4ade80;
    --danger: #f87171;
    --warn: #fbbf24;

    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 24px;

    --shadow-card: 0 20px 50px -20px rgba(8, 15, 35, 0.8);
    --shadow-soft: 0 4px 20px -8px rgba(8, 15, 35, 0.6);

    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --font-ge: "Noto Sans Georgian", "BPG Phone Sans", "Sylfaen", "Inter",
        -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    background: radial-gradient(circle at 20% -10%, #1e293b 0%, var(--bg) 55%);
    color: var(--fg);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overscroll-behavior-y: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
        env(safe-area-inset-bottom) env(safe-area-inset-left);
}

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: rgba(11, 18, 32, 0.85);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--fg);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand:hover { text-decoration: none; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0b1220;
    font-family: var(--font-ge);
    font-size: 1.25rem;
    font-weight: 800;
}

.nav {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    color: var(--fg-muted);
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
    color: var(--fg);
    background: rgba(148, 163, 184, 0.1);
    text-decoration: none;
}

.nav-link.is-active {
    color: var(--fg);
    background: rgba(56, 189, 248, 0.12);
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.25rem;
    border-radius: 12px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1;
    transition: transform 0.08s ease, background 0.15s ease,
        border-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
    background: transparent;
    color: var(--fg);
}

.btn:active {
    transform: translateY(1px) scale(0.99);
}

.btn-lg {
    padding: 0.95rem 1.5rem;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0b1220;
    border-color: transparent;
    box-shadow: var(--shadow-soft);
}

.btn-primary:hover {
    text-decoration: none;
    filter: brightness(1.06);
}

.btn-ghost {
    background: rgba(148, 163, 184, 0.08);
    color: var(--fg);
    border-color: var(--border);
}

.btn-ghost:hover {
    background: rgba(148, 163, 184, 0.14);
    text-decoration: none;
}

.btn-danger {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.18);
    text-decoration: none;
}

.btn-icon {
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
}

/* ---- Home / Hero ---- */
.hero {
    padding-top: 1.5rem;
    text-align: center;
}

.eyebrow {
    display: inline-block;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.hero-title {
    margin: 1rem 0 0.85rem;
    font-size: clamp(1.85rem, 6vw, 2.85rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-weight: 800;
}

.hero-sub {
    margin: 0 auto 1.75rem;
    max-width: 32rem;
    color: var(--fg-muted);
    font-size: 1.05rem;
    line-height: 1.55;
}

.hero-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.alphabet-preview {
    margin-top: 3rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    font-family: var(--font-ge);
    color: var(--fg-dim);
}

.alphabet-preview span {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.05);
    border: 1px solid var(--border);
    font-size: 1.25rem;
    transition: color 0.2s ease, background 0.2s ease;
}

.alphabet-preview span:nth-child(3n) { color: var(--accent); }

/* ---- Quiz ---- */
.quiz {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.quiz-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.35rem;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg-dim);
    font-weight: 600;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
}

.card {
    position: relative;
    padding: 2.5rem 1.5rem 2rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(160deg, #1c2542 0%, #131b2e 100%);
    border: 1px solid var(--border-strong);
    text-align: center;
    box-shadow: var(--shadow-card);
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.75rem;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.card.is-correct {
    border-color: rgba(74, 222, 128, 0.5);
    box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.4),
        0 20px 60px -20px rgba(74, 222, 128, 0.35);
}

.card.is-wrong {
    border-color: rgba(248, 113, 113, 0.55);
    box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.4),
        0 20px 60px -20px rgba(248, 113, 113, 0.35);
    animation: shake 0.45s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.card-direction {
    color: var(--fg-dim);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
}

.card-prompt {
    font-size: clamp(3.5rem, 16vw, 6rem);
    line-height: 1;
    font-weight: 700;
}

.card-prompt.is-georgian {
    font-family: var(--font-ge);
}

.options {
    display: grid;
    gap: 0.6rem;
}

.option {
    appearance: none;
    text-align: left;
    padding: 1.05rem 1.1rem;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--fg);
    font-size: 1.1rem;
    font-weight: 600;
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background 0.15s ease, border-color 0.15s ease,
        transform 0.08s ease, opacity 0.2s ease;
}

.option .option-key {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.1);
    color: var(--fg-muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.option.is-georgian {
    font-family: var(--font-ge);
    font-size: 1.5rem;
}

.option:not(:disabled):hover {
    border-color: var(--border-strong);
    background: var(--bg-soft);
}

.option.is-correct {
    background: rgba(74, 222, 128, 0.16);
    border-color: rgba(74, 222, 128, 0.45);
    color: #d1fae5;
}

.option.is-wrong {
    background: rgba(248, 113, 113, 0.14);
    border-color: rgba(248, 113, 113, 0.4);
    color: #fee2e2;
}

.option:disabled {
    cursor: default;
}

.option.is-dimmed {
    opacity: 0.45;
}

.feedback {
    min-height: 1.5rem;
    text-align: center;
    font-weight: 600;
    color: var(--fg-muted);
}

.feedback.is-correct { color: var(--success); }
.feedback.is-wrong   { color: var(--danger); }

/* ---- Keyboard mode ---- */
.kb {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.mode-toggle {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    padding: 0.25rem;
    border-radius: 999px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    align-self: center;
    width: 100%;
    max-width: 22rem;
}

.mode-toggle-option {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--fg-muted);
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.15s ease, color 0.15s ease;
}

.mode-toggle-option:hover {
    color: var(--fg);
}

.mode-toggle-option.is-active {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0b1220;
    box-shadow: var(--shadow-soft);
}

.kb-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.4rem;
}

.kb-key {
    appearance: none;
    display: grid;
    place-items: center;
    aspect-ratio: 1 / 1;
    min-height: 48px;
    padding: 0.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--fg);
    font-family: var(--font-ge);
    font-size: clamp(1.4rem, 5vw, 1.85rem);
    font-weight: 600;
    line-height: 1;
    transition: background 0.12s ease, border-color 0.12s ease,
        transform 0.08s ease, color 0.12s ease;
}

.kb-key.is-sound {
    font-family: var(--font-ui);
    font-size: clamp(0.85rem, 3vw, 1.1rem);
    letter-spacing: -0.01em;
}

.kb-key:not(:disabled):hover {
    border-color: var(--border-strong);
    background: var(--bg-soft);
}

.kb-key:not(:disabled):active {
    transform: scale(0.96);
}

.kb-key:disabled {
    cursor: default;
}

.kb-key.is-correct {
    background: rgba(74, 222, 128, 0.2);
    border-color: rgba(74, 222, 128, 0.55);
    color: #d1fae5;
}

.kb-key.is-wrong {
    background: rgba(248, 113, 113, 0.18);
    border-color: rgba(248, 113, 113, 0.5);
    color: #fee2e2;
}

.kb-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--fg-dim);
    padding: 1rem 0;
}

@media (max-width: 420px) {
    .kb-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.35rem; }
    .kb-key { min-height: 44px; }
}

@media (min-width: 700px) {
    .kb-grid { grid-template-columns: repeat(9, minmax(0, 1fr)); }
}

/* ---- Dictionary ---- */
.dict-header h1 {
    margin: 0 0 0.4rem;
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.dict-header p {
    margin: 0 0 1.5rem;
    color: var(--fg-muted);
}

.dict-add {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elev);
    margin-bottom: 1.25rem;
}

.dict-add .field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.dict-add button {
    grid-column: 1 / -1;
}

.field label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg-dim);
    font-weight: 600;
}

input[type="text"],
input[type="search"] {
    appearance: none;
    width: 100%;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    color: var(--fg);
    font-size: 1rem;
    transition: border-color 0.15s ease, background 0.15s ease;
}

input[type="text"]:focus,
input[type="search"]:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-soft);
}

input.is-georgian {
    font-family: var(--font-ge);
    font-size: 1.15rem;
}

.dict-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.dict-toolbar input[type="search"] {
    flex: 1;
}

.dict-count {
    color: var(--fg-dim);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.dict-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.dict-row {
    display: grid;
    grid-template-columns: minmax(70px, 1fr) minmax(70px, 1fr) auto;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    align-items: center;
}

.dict-row .field-georgian input {
    font-family: var(--font-ge);
    font-size: 1.2rem;
}

.dict-actions {
    display: flex;
    gap: 0.4rem;
}

.dict-row.is-dirty {
    border-color: rgba(251, 191, 36, 0.45);
}

.dict-row.is-saved {
    border-color: rgba(74, 222, 128, 0.45);
    transition: border-color 0.6s ease;
}

.dict-empty {
    text-align: center;
    color: var(--fg-dim);
    padding: 2rem 0;
}

/* ---- Responsive tweaks ---- */
@media (min-width: 640px) {
    .container { padding: 2rem 1.5rem 4rem; }
    .options { grid-template-columns: 1fr 1fr 1fr; }
    .option { font-size: 1.15rem; }
    .option.is-georgian { font-size: 1.65rem; }
}

@media (max-width: 480px) {
    .topbar { padding: 0.7rem 1rem; }
    .brand-text { display: none; }
    .nav-link { padding: 0.5rem 0.7rem; font-size: 0.9rem; }
    .quiz-stats .stat-value { font-size: 1.2rem; }
}

/* ---- Accessibility ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}
