:root {
    --sidebar-width: 272px;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --surface: #ffffff;
    --page: #f6f8fb;
    --primary: #2854c5;
    --accent: #0f766e;
    --warning: #b45309;
    --danger: #b91c1c;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    letter-spacing: 0;
}
html,
body { overflow-x: hidden; }
body {
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, .08), transparent 360px),
        linear-gradient(180deg, #fbfcff, var(--page));
    color: var(--ink);
    min-height: 100vh;
}
a { text-decoration: none; }

.app-sidebar {
    background: linear-gradient(180deg, #182230, #111827);
    color: #fff;
    height: 100vh;
    left: 0;
    padding: 18px 16px;
    position: fixed;
    top: 0;
    width: var(--sidebar-width);
    z-index: 10;
}

.brand {
    align-items: center;
    color: inherit;
    display: flex;
    font-weight: 700;
    gap: 10px;
    margin-bottom: 20px;
}

.brand-mark {
    align-items: center;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.nav-section {
    color: #94a3b8;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    padding: 8px 12px;
    text-transform: uppercase;
}

.app-sidebar .nav-link {
    align-items: center;
    border-radius: 8px;
    color: #cbd5e1;
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.app-sidebar .nav-link.active,
.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, .09);
    color: #fff;
    transform: translateX(2px);
}

.app-main { margin-left: var(--sidebar-width); min-height: 100vh; }

.app-topbar {
    align-items: center;
    backdrop-filter: blur(16px);
    background: rgba(255,255,255,.86);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.role-chip,
.status-pill {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #475569;
    display: inline-flex;
    font-size: .82rem;
    font-weight: 700;
    min-height: 34px;
    padding: 0 12px;
    white-space: nowrap;
}

.metric-card,
.panel,
.auth-panel,
.student-hero,
.tenant-strip {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .06);
}

.metric-card {
    min-height: 118px;
    overflow: hidden;
    padding: 18px;
    position: relative;
}
.metric-card::before {
    background: linear-gradient(180deg, var(--primary), var(--accent));
    border-radius: 4px;
    content: "";
    height: 54px;
    left: 0;
    position: absolute;
    top: 18px;
    width: 4px;
}
.metric-card.compact { min-height: 96px; }
.metric-label { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.metric-value { font-size: clamp(1.45rem, 1.2rem + .8vw, 2.1rem); font-weight: 800; margin-top: 6px; }
.panel { padding: 20px; }

.student-hero,
.tenant-strip,
.typing-toolbar {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.student-hero,
.tenant-strip { padding: 24px; }
.quick-actions {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px;
}
.search-box { max-width: 280px; }

.auth-page {
    background:
        linear-gradient(135deg, rgba(40, 84, 197, .10), rgba(15, 118, 110, .12)),
        #f8fafc;
}

.auth-shell {
    align-items: center;
    display: flex;
    gap: 28px;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-copy {
    max-width: 470px;
    min-width: 0;
    padding: 24px;
    width: min(470px, calc(100vw - 48px));
}
.auth-copy h1 {
    font-size: clamp(2rem, 3vw, 3.2rem);
    font-weight: 850;
    line-height: 1.06;
    margin: 12px 0 16px;
}
.auth-copy p {
    color: #475569;
    font-size: 1.05rem;
    line-height: 1.7;
}
.eyebrow {
    color: var(--accent);
    font-size: .8rem;
    font-weight: 850;
    text-transform: uppercase;
}
.auth-highlights {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}
.auth-highlights span {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #334155;
    font-weight: 700;
    padding: 9px 12px;
}
.auth-subtitle {
    margin-left: auto;
    margin-right: auto;
    max-width: 300px;
}
.auth-shell.wide .auth-panel {
    max-width: 760px;
    width: min(760px, calc(100vw - 48px));
}
.auth-panel {
    max-width: 450px;
    min-width: 0;
    padding: 30px;
    width: min(450px, calc(100vw - 48px));
}

.typing-toolbar {
    background: rgba(255,255,255,.94);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.typing-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.icon-btn {
    align-items: center;
    display: inline-flex;
    height: 40px;
    justify-content: center;
    width: 42px;
}

.status-pill.success { background: #ecfdf5; border-color: #bbf7d0; color: #15803d; }
.status-pill.warning { background: #fffbeb; border-color: #fde68a; color: var(--warning); }
.status-pill.danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

.typing-progress { height: 10px; min-width: 220px; width: 30%; }
.reference-text {
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1.28rem;
    line-height: 1.9;
    min-height: 132px;
    padding: 18px;
}

.reference-text .correct { color: #15803d; }
.reference-text .wrong { background: #fee2e2; color: #b91c1c; }
.reference-text .current { border-bottom: 3px solid var(--primary); }
.typing-input { font-size: 1.2rem; line-height: 1.7; resize: vertical; }

.keyboard { display: grid; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.key-row { display: flex; gap: 6px; min-width: 860px; }
.key {
    align-items: center;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    display: inline-flex;
    font-weight: 700;
    height: 44px;
    justify-content: center;
    min-width: 44px;
    padding: 0 10px;
    transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.key.wide { min-width: 84px; }
.key.space { flex: 1; }
.key.active { background: #dbeafe; border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.key.error { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }
.keyboard.has-key-map .key {
    flex-direction: column;
    gap: 1px;
    height: 66px;
    line-height: 1.1;
}
.key-map {
    color: var(--accent);
    font-family: "Noto Sans Devanagari", "Mangal", system-ui, sans-serif;
    font-size: .76rem;
    font-weight: 850;
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.key-map-shift {
    color: var(--warning);
    font-size: .68rem;
}
.keyboard.map-hidden .key-map {
    display: none;
}
.keyboard.map-hidden.has-key-map .key {
    height: 44px;
}

.keyboard-controls {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.keyboard-map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.keyboard-map-legend span {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #475569;
    font-size: .82rem;
    font-weight: 700;
    padding: 7px 10px;
}

.activity-list { color: var(--muted); display: grid; gap: 12px; }

.learn-hero {
    align-items: center;
    background:
        linear-gradient(135deg, rgba(40, 84, 197, .08), rgba(15, 118, 110, .10)),
        #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    padding: 26px;
}

.learn-hero h2 {
    font-size: clamp(1.7rem, 2.2vw, 2.5rem);
    font-weight: 850;
    margin: 8px 0 10px;
}

.learn-hero p {
    color: #475569;
    margin: 0;
    max-width: 760px;
}

.learn-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.finger-map {
    display: grid;
    gap: 10px;
}

.finger-map div,
.daily-rule div {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 12px;
}

.finger-map span,
.daily-rule span,
.lesson-card span {
    color: var(--muted);
}

.lesson-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.lesson-card {
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    display: grid;
    gap: 8px;
    min-height: 150px;
    padding: 16px;
    transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.lesson-card i {
    align-items: center;
    background: #e0f2fe;
    border-radius: 8px;
    color: var(--primary);
    display: inline-flex;
    font-size: 1.15rem;
    height: 38px;
    justify-content: center;
    width: 38px;
}

.lesson-card:hover {
    border-color: rgba(40, 84, 197, .45);
    box-shadow: 0 14px 30px rgba(15, 23, 42, .08);
    transform: translateY(-2px);
}

.daily-rule {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.daily-rule div {
    display: grid;
}

.settings-panel {
    max-width: 980px;
}

.system-check-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.system-check-item {
    align-items: center;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 12px;
    min-height: 86px;
    padding: 14px;
}

.system-check-icon {
    align-items: center;
    border-radius: 8px;
    display: inline-flex;
    flex: 0 0 38px;
    height: 38px;
    justify-content: center;
    width: 38px;
}

.system-check-item.ok .system-check-icon {
    background: #ecfdf5;
    color: #15803d;
}

.system-check-item.fail .system-check-icon {
    background: #fef2f2;
    color: var(--danger);
}

.system-check-item span {
    color: var(--muted);
    display: block;
    font-size: .9rem;
    margin-top: 2px;
    overflow-wrap: anywhere;
}

.kruti-panel {
    overflow: hidden;
}

.kruti-filters {
    flex-wrap: wrap;
}

.kruti-map-wrap {
    border: 1px solid var(--line);
    border-radius: 8px;
    max-height: 560px;
}

.kruti-map-table {
    margin-bottom: 0;
}

.kruti-map-table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: .75rem;
    position: sticky;
    text-transform: uppercase;
    top: 0;
    z-index: 1;
}

.kruti-map-table kbd {
    background: #111827;
    border-radius: 6px;
    box-shadow: none;
    display: inline-flex;
    justify-content: center;
    min-width: 32px;
}

.kruti-output {
    color: #111827;
    font-family: "Noto Sans Devanagari", "Mangal", system-ui, sans-serif;
    font-size: 1.12rem;
    font-weight: 800;
}

.kruti-preview-box {
    background: #fbfdff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.kruti-preview {
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    color: #111827;
    font-family: "Noto Sans Devanagari", "Mangal", system-ui, sans-serif;
    font-size: 1.45rem;
    line-height: 1.7;
    margin-top: 12px;
    min-height: 104px;
    padding: 14px;
    white-space: pre-wrap;
}

.kruti-rule-list {
    display: grid;
    gap: 10px;
}

.kruti-rule-list div {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 4px;
    padding: 12px;
}

.kruti-rule-list span {
    color: #475569;
    font-size: .93rem;
}

.table td,
.table th {
    vertical-align: middle;
}

@media (max-width: 991.98px) {
    .auth-shell {
        align-items: stretch;
        flex-direction: column;
        padding: 22px 16px;
    }
    .auth-copy {
        max-width: 760px;
        padding: 0;
    }
    .auth-shell > * {
        max-width: 100%;
        width: 100%;
    }
    .app-sidebar {
        height: auto;
        position: static;
        width: 100%;
    }
    .app-sidebar .nav { flex-direction: row !important; overflow-x: auto; }
    .nav-section { display: none; }
    .app-sidebar .nav-link { white-space: nowrap; }
    .app-main { margin-left: 0; }
    .app-topbar,
    .student-hero,
    .tenant-strip,
    .typing-toolbar {
        align-items: stretch;
        flex-direction: column;
    }
    .typing-progress { width: 100%; }
    .typing-actions { justify-content: flex-start; }
    .keyboard-controls { justify-content: flex-start; }
    .learn-hero {
        align-items: stretch;
        flex-direction: column;
    }
    .learn-hero-actions {
        justify-content: flex-start;
    }
    .lesson-grid,
    .daily-rule,
    .system-check-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 575.98px) {
    .app-topbar { padding: 14px 16px; }
    .auth-shell {
        display: block;
        padding: 20px 12px;
    }
    .auth-shell > * {
        max-width: none !important;
        width: auto !important;
    }
    .auth-panel {
        box-sizing: border-box !important;
        margin-left: auto;
        margin-right: auto;
        margin-top: 24px;
        max-width: calc(100vw - 48px) !important;
        padding: 20px 16px;
        width: calc(100vw - 48px) !important;
    }
    .auth-copy h1 {
        font-size: 1.58rem;
        line-height: 1.18;
        max-width: 320px;
        overflow-wrap: normal;
        word-break: normal;
    }
    .auth-copy p {
        font-size: .94rem;
        max-width: 330px;
    }
    .auth-highlights { gap: 8px; }
    .auth-highlights span { padding: 8px 10px; }
    .auth-panel .justify-content-between {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 8px;
    }
    .mode-group,
    .mode-group .btn {
        display: grid;
        width: 100%;
    }
    .metric-card { min-height: 106px; padding: 16px; }
    .reference-text { font-size: 1.08rem; padding: 14px; }
    .lesson-grid,
    .daily-rule,
    .system-check-grid {
        grid-template-columns: 1fr;
    }
    .finger-map div {
        align-items: flex-start;
        flex-direction: column;
    }
    .kruti-filters,
    .kruti-filters .btn,
    .learn-hero-actions,
    .learn-hero-actions .btn {
        display: grid;
        width: 100%;
    }
    .kruti-map-wrap {
        max-height: 520px;
    }
}
