@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Medium.ttf') format('truetype'); font-weight: 500; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-SemiBold.ttf') format('truetype'); font-weight: 600; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Bold.ttf') format('truetype'); font-weight: 700; }

:root {
    --ink: #1f2a5c;
    --ink-soft: #4a5488;
    --saffron: #f07b2b;
    --surface: #ffffff;
    --canvas: #f4f1ea;
    --line: #e3ded2;
    --muted: #6b6f80;
    --bs-primary: #2d3a8c;
    --bs-primary-rgb: 45, 58, 140;
    --deva: 'Noto Sans Devanagari', 'Nirmala UI', 'Mangal', sans-serif;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Poppins', 'Nirmala UI', system-ui, sans-serif;
    background: var(--canvas);
    color: #222;
    overflow-x: hidden;
}

/* Script fonts: web fonts first, then the system fonts that cover each script offline. */
.script-latn { font-family: 'Poppins', system-ui, sans-serif; }
.script-deva { font-family: var(--deva); }
.script-beng { font-family: 'Noto Sans Bengali', 'Nirmala UI', 'Vrinda', 'Shonar Bangla', sans-serif; }
.script-guru { font-family: 'Noto Sans Gurmukhi', 'Nirmala UI', 'Raavi', sans-serif; }
.script-gujr { font-family: 'Noto Sans Gujarati', 'Nirmala UI', 'Shruti', sans-serif; }
.script-orya { font-family: 'Noto Sans Oriya', 'Nirmala UI', 'Kalinga', sans-serif; }
.script-taml { font-family: 'Noto Sans Tamil', 'Nirmala UI', 'Latha', sans-serif; }
.script-telu { font-family: 'Noto Sans Telugu', 'Nirmala UI', 'Gautami', sans-serif; }
.script-knda { font-family: 'Noto Sans Kannada', 'Nirmala UI', 'Tunga', sans-serif; }
.script-mlym { font-family: 'Noto Sans Malayalam', 'Nirmala UI', 'Kartika', sans-serif; }
.script-mtei { font-family: 'Noto Sans Meetei Mayek', 'Nirmala UI', sans-serif; }
.script-olck { font-family: 'Noto Sans Ol Chiki', 'Nirmala UI', sans-serif; }
.script-arab-nastaliq { font-family: 'Noto Nastaliq Urdu', 'Urdu Typesetting', 'Noto Naskh Arabic', serif; }
.script-arab-naskh { font-family: 'Noto Naskh Arabic', 'Segoe UI', 'Arial', serif; }

/* ---------- Layout ---------- */

.page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    background: linear-gradient(100deg, var(--ink) 0%, #2d3a8c 70%, #3b2f7a 100%);
    color: #fff;
    flex-shrink: 0;
}

.app-logo { width: 44px; height: 44px; }

.app-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
}

.app-title-native {
    font-family: var(--deva);
    font-weight: 600;
    color: #ffc58f;
    margin-left: 6px;
}

.app-tagline { font-size: .8rem; opacity: .8; }

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px 16px 0;
    gap: 8px;
}

.app-footer {
    flex-shrink: 0;
    text-align: center;
    font-size: .75rem;
    color: var(--muted);
    padding: 6px 12px;
}

.app-footer a { color: var(--ink-soft); }

/* ---------- Toolbar ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar .btn { font-size: .875rem; }

.btn-lang {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 2px solid var(--saffron);
    background: #fff7f0;
    border-radius: 10px;
    padding: 4px 12px;
}

.btn-lang:hover { background: #ffeddc; border-color: var(--saffron); }

.lang-native { font-size: 1.15rem; font-weight: 600; color: var(--ink); }
.lang-name { font-size: .85rem; color: var(--muted); }

.btn-primary { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.btn-outline-primary { color: var(--bs-primary); border-color: var(--bs-primary); }
.btn-outline-primary:hover, .btn-outline-primary:disabled:hover { background-color: var(--bs-primary); }
.btn-outline-primary:disabled { color: #9aa0c3; border-color: #c9cce2; }

/* ---------- Status bar ---------- */

.status-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    font-size: .8rem;
    color: var(--muted);
    padding: 0 4px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #b9b9b9;
}

.status-dot.on { background: #2fb36b; box-shadow: 0 0 0 3px rgba(47, 179, 107, .18); }

.status-hint code { background: #ece8de; color: var(--ink); padding: 1px 5px; border-radius: 4px; }
.status-hint span { color: var(--ink); font-size: 1rem; }

.status-message {
    background: var(--ink);
    color: #fff;
    border-radius: 999px;
    padding: 2px 10px;
}

/* ---------- Workspace ---------- */

.workspace {
    flex: 1;
    display: flex;
    gap: 12px;
    min-height: 0;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

#quill-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.ql-toolbar.ql-snow { border: 0; border-bottom: 1px solid var(--line); background: #fbfaf7; }
.ql-container.ql-snow { border: 0; flex: 1; min-height: 0; font-size: inherit; }

.ql-editor {
    height: 100%;
    overflow-y: auto;
    font-size: 1.6rem;
    line-height: 1.7;
    padding: 20px 28px;
    text-rendering: optimizeLegibility;
}

.ql-editor.script-arab-nastaliq { line-height: 2.4; }
.ql-editor.rtl { text-align: right; }
.ql-editor.ql-blank::before { font-style: normal; color: #b0b0b8; left: 28px; right: 28px; }
.ql-editor.rtl.ql-blank::before { text-align: right; }

/* ---------- Keymap panel ---------- */

.keymap-panel {
    width: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.keymap-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #fbfaf7;
}

.keymap-body { overflow-y: auto; padding: 10px 14px 16px; }

.keymap-group-title {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin: 12px 0 6px;
    font-weight: 600;
}

.keymap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 6px;
}

.keymap-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.keymap-cell:hover { border-color: var(--saffron); background: #fff7f0; }

.km-out { font-size: 1.35rem; line-height: 1.3; color: var(--ink); min-height: 1.7rem; }
.km-note { font-size: .75rem; color: var(--muted); line-height: 1.4; }
.km-keys { font-size: .7rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; text-align: center; word-break: break-word; }

.keymap-note { margin-top: 14px; line-height: 1.5; }
.keymap-note code { background: #ece8de; color: var(--ink); padding: 0 4px; border-radius: 3px; }

.inscript-row { display: flex; gap: 3px; margin-bottom: 3px; }
.inscript-row:nth-child(2) { padding-left: 10px; }
.inscript-row:nth-child(3) { padding-left: 18px; }
.inscript-row:nth-child(4) { padding-left: 28px; }

.inscript-key {
    position: relative;
    width: 24px;
    height: 46px;
    flex-shrink: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    line-height: 1.15;
}

.inscript-key span { cursor: pointer; }
.ik-upper { color: var(--ink-soft); font-size: .8rem; }
.ik-lower { color: var(--ink); }
.ik-label { position: absolute; bottom: 1px; right: 2px; font-size: .5rem; color: #aaa; cursor: default; }

/* ---------- Language picker ---------- */

.language-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
}

.language-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    text-align: left;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}

.language-tile:hover { border-color: var(--saffron); box-shadow: 0 6px 16px rgba(31, 42, 92, .08); transform: translateY(-1px); }
.language-tile.active { border: 2px solid var(--saffron); background: #fff7f0; }

.lt-native { font-size: 1.4rem; line-height: 1.6; color: var(--ink); width: 100%; }
.lt-name { font-weight: 600; font-size: .9rem; }
.lt-meta { font-size: .72rem; color: var(--muted); }

.modal-backdrop.show { opacity: .45; }

/* ---------- Boot screen ---------- */

.boot {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--canvas);
}

.boot-logo { width: 72px; height: 72px; }
.boot-title { font-size: 1.6rem; font-weight: 700; color: var(--ink); }
.boot-scripts { font-size: 1.3rem; letter-spacing: .3em; color: var(--ink-soft); font-family: 'Nirmala UI', sans-serif; }

.boot-progress { width: 180px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.boot-progress div {
    height: 100%;
    width: var(--blazor-load-percentage, 10%);
    background: var(--saffron);
    transition: width .1s;
}

#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ---------- Landing page text (below the editor, written by tools/Bhasini.SiteGen) ---------- */

.site-content {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 20px 48px;
    line-height: 1.65;
}

.site-content h1 { font-size: 1.7rem; font-weight: 700; color: var(--ink); margin: 0 0 .4rem; }
.site-content h2 { font-size: 1.2rem; font-weight: 600; color: var(--ink); margin: 2rem 0 .6rem; }
.site-content h3 { font-size: 1rem; font-weight: 600; margin: 1.2rem 0 .4rem; }
.site-content .lead { font-size: 1.05rem; color: var(--ink-soft); }
.site-content .native { font-size: 1.25em; color: var(--ink); }
.site-content a { color: var(--bs-primary); }

.site-content .start-typing {
    display: inline-block;
    margin: .6rem 0 0;
    padding: .45rem 1rem;
    border-radius: 8px;
    background: var(--saffron);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.site-content table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 10px; overflow: hidden; }
.site-content th, .site-content td { padding: .5rem .8rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.site-content th { background: #faf8f3; font-weight: 600; font-size: .85rem; color: var(--muted); }
.site-content td code { color: var(--ink); background: #f1eee6; padding: .1rem .35rem; border-radius: 4px; }

.site-content .key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.site-content .key-grid div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; text-align: center; }
.site-content .key-grid .out { display: block; font-size: 1.35rem; line-height: 1.5; color: var(--ink); }
.site-content .key-grid code { font-size: .8rem; color: var(--muted); }

.site-content .inscript { display: flex; flex-direction: column; gap: 4px; overflow-x: auto; }
.site-content .inscript-line { display: flex; gap: 4px; }
.site-content .inscript-line div { min-width: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; text-align: center; padding: 2px 0; }
.site-content .inscript-line .up { display: block; font-size: .85rem; color: var(--muted); min-height: 1.3em; }
.site-content .inscript-line .lo { display: block; font-size: 1.2rem; color: var(--ink); min-height: 1.5em; }
.site-content .inscript-line code { font-size: .7rem; color: var(--muted); }

.site-content .link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; padding: 0; list-style: none; }
.site-content .link-grid a { display: block; padding: .5rem .7rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); }
.site-content .link-grid a:hover { border-color: var(--saffron); }
.site-content .link-grid small { display: block; color: var(--muted); }

.site-content details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin-bottom: 8px; }
.site-content summary { font-weight: 600; cursor: pointer; }
.site-content details p { margin: .5rem 0 0; }

/* ---------- Small screens ---------- */

@media (max-width: 900px) {
    .keymap-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 92vw); z-index: 1040; border-radius: 0; box-shadow: -8px 0 24px rgba(0, 0, 0, .15); }
}

/* Wider screens: the actions wrapper is invisible to layout, so the toolbar wraps as before. */
.toolbar-actions { display: contents; }

@media (max-width: 640px) {
    /* Header: one slim bar, so the editor gets the screen. */
    .app-header { padding: 6px 12px; gap: 10px; }
    .app-logo { width: 32px; height: 32px; }
    .app-title { font-size: 1.1rem; }
    .app-tagline { display: none; }
    .app-main { padding: 6px 8px 0; gap: 6px; }
    .app-footer { display: none; }

    /* Toolbar: language + keyboard on the first row, then one swipeable row of icon buttons. */
    .toolbar { padding: 6px; gap: 6px; border-radius: 10px; }
    .toolbar-group { flex-wrap: nowrap; gap: 6px; }
    .toolbar .btn { font-size: .85rem; padding: .32rem .6rem; }
    .btn-lang { padding: 3px 10px; gap: 6px; }
    .lang-native { font-size: 1.05rem; }
    .method-switch .btn { padding: .32rem .45rem; font-size: .8rem; }
    .toolbar .form-switch { padding-left: 2.1em; }
    .toolbar .form-switch .form-check-input { margin-left: -2.1em; }
    .btn-label { display: none; }

    .toolbar-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        /* Fade at the right edge hints that the row scrolls. */
        mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
        padding-right: 24px;
    }
    .toolbar-actions::-webkit-scrollbar { display: none; }
    .toolbar-actions .toolbar-group { flex-shrink: 0; }
    /* Open and Save first: Save is the main action and must not hide under the fade. */
    .toolbar-actions .toolbar-group.ms-auto { order: -1; }
    .toolbar-actions .btn { min-width: 40px; min-height: 36px; }
    .toolbar-group.ms-auto { margin-left: 0 !important; }

    /* Status: just the hint, on one line. */
    .status-bar { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; font-size: .78rem; }
    .status-typing, .status-hint.ms-auto { display: none; }
    .status-try { overflow: hidden; text-overflow: ellipsis; }
    .status-message { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 1050; white-space: nowrap; }

    /* Editor: the formatting bar is one row with the less-used controls hidden. */
    .ql-toolbar.ql-snow { padding: 4px 6px; white-space: nowrap; overflow: hidden; }
    .ql-toolbar.ql-snow .ql-formats { margin-right: 6px; }
    .ql-toolbar .ql-formats:nth-child(1) .ql-size,
    .ql-toolbar .ql-formats:nth-child(3),
    .ql-toolbar .ql-strike,
    .ql-toolbar .ql-indent,
    .ql-toolbar .ql-formats:nth-child(5) .ql-align,
    .ql-toolbar .ql-blockquote { display: none !important; }
    .ql-editor { font-size: 1.3rem; padding: 14px 16px; }
    .ql-editor.ql-blank::before { left: 16px; right: 16px; }

    /* Keys: a bottom sheet, so the text stays visible while tapping letters. */
    .keymap-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        height: min(48dvh, 420px);
        z-index: 1040;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, .18);
    }
    .keymap-header { padding: 10px 14px; }
    .keymap-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
    .km-out { font-size: 1.25rem; }
    .inscript-key { width: calc((100vw - 64px) / 13); min-width: 22px; }

    /* Language picker: full screen, three columns, so every language shows at a glance. */
    .language-modal .modal-header { padding: 12px 16px; }
    .language-modal .modal-title { font-size: 1.1rem; }
    .language-modal .modal-header .small { display: none; }
    .language-modal .modal-body { padding: 0 12px 16px; }
    .language-modal .modal-body > input { position: sticky; top: 0; z-index: 1; margin: 0 -12px 10px !important; width: calc(100% + 24px); border-radius: 0; border-width: 0 0 1px; padding: 12px 16px; }
    .language-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .language-tile { align-items: center; text-align: center; padding: 10px 4px; border-radius: 10px; }
    .language-tile:hover { transform: none; }
    .lt-native { font-size: 1.2rem; line-height: 1.5; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .lt-name { font-size: .78rem; }
    .lt-meta { display: none; }

    /* Landing text below the editor. */
    .site-content { padding: 24px 16px 40px; }
    .site-content h1 { font-size: 1.45rem; }
    .site-content h2 { font-size: 1.1rem; margin-top: 1.6rem; }
    .site-content .lead { font-size: 1rem; }
    .site-content th, .site-content td { padding: .45rem .55rem; }
    .site-content .link-grid { grid-template-columns: repeat(2, 1fr); }
    .site-content .key-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
}

@media (max-width: 380px) {
    .lang-name { display: none; }
    .app-title-native { display: none; }
}
