/* Shamela AI: a compact navigation menu and a full-height workspace.
   Answers and source pages follow the website's book typography. */

@font-face {
    font-family: 'Shamela Kufi';
    src: url('DroidArabicKufiRegular.woff2') format('woff2'), url('DroidArabicKufiRegular.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'Shamela Kufi';
    src: url('DroidArabicKufiBold.woff2') format('woff2'), url('DroidArabicKufiBold.ttf') format('truetype');
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: 'Shamela Kitab';
    src: url('Kitab-Regular.woff2') format('woff2');
    font-display: swap;
}

@font-face {
    font-family: 'Shamela Naskh';
    src: url('NotoNaskhArabic-Variable.woff2') format('woff2'), url('NotoNaskhArabic-Variable.ttf') format('truetype');
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
}

/* The website's book-page face (its "Naskh"). */
@font-face {
    font-family: 'Shamela Book';
    src: url('UthmanTN1.woff2') format('woff2'), url('UthmanTN1.otf') format('opentype');
    font-display: swap;
}

:root {
    color-scheme: light;
    /* Neutral workspace chrome, with brown reserved for brand accents. */
    --background: #fafafa;
    --card: #ffffff;
    --paper: #ffffff;
    --sidebar: #f7f7f7;
    --field: #ffffff;
    --border: #e2e2e2;
    --border-strong: #c9c9c9;
    --ink: #262626;
    --text: #000000;
    --muted: #666666;
    --quiet: #808080;
    --history-heading: #111111;
    /* Brand brown; the mobile app uses this pair as its primary colour. */
    --primary: #76542e;
    --primary-hover: #5d3f20;
    --on-primary: #ffffff;
    --question-background: #262626;
    --question-text: #ffffff;
    --title: #7a5a34;
    --soft: #f2f2f2;
    --soft-strong: #e8e8e8;
    --hover: #ededed;
    --selected: #e3e3e3;
    --badge: #ebebeb;
    /* The avatar and quota badge in the brand brown, as the star above them;
       an idle send button is a neutral grey, as any disabled control. */
    --quota: #76542e;
    --on-quota: #ffffff;
    --primary-idle: #c4c4c4;
    --hamesh: #555555;
    --rule: #cccccc;
    --danger: #9b3730;
    --danger-soft: #f8ece9;
    --notice: #fff4d8;
    --on-notice: #674d18;
    --focus: #286da8;
    --shadow: rgba(0, 0, 0, .14);
    --c1: #5f0000;
    --c2: #005300;
    --c3: #686800;
    --c4: #707070;
    --c5: #005c81;
    --reading-width: 900px;
}

body.night {
    color-scheme: dark;
    --background: #000000;
    --card: #111111;
    --paper: #0b0b0b;
    --sidebar: #111111;
    --field: #161616;
    --border: #262626;
    --border-strong: #3a3a3a;
    --ink: #cccccc;
    --text: #cccccc;
    --muted: #9a9a9a;
    --quiet: #7a7a7a;
    --history-heading: #eeeeee;
    --primary: #c9a77f;
    --primary-hover: #e0c29c;
    --on-primary: #111111;
    --question-background: #2a2a2a;
    --question-text: #eeeeee;
    --title: #c9a77f;
    --soft: #1a1a1a;
    --soft-strong: #242424;
    --hover: #1c1c1c;
    --selected: #272727;
    --badge: #2a2a2a;
    --quota: #c9a77f;
    --on-quota: #111111;
    --primary-idle: #4a4a4a;
    --hamesh: #8a8a8a;
    --rule: #3a3a3a;
    --danger: #e0716a;
    --danger-soft: #2a1614;
    --notice: #2a2412;
    --on-notice: #e6cf92;
    --focus: #6ea8fe;
    --shadow: rgba(0, 0, 0, .6);
    --c1: #c9acac;
    --c2: #97b397;
    --c3: #b3b384;
    --c4: #8c8c8c;
    --c5: #009edd;
    scrollbar-color: #555 #111;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    background: var(--background);
}

::selection {
    background: var(--soft-strong);
    color: var(--ink);
}

body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--background);
    color: var(--ink);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    line-height: 1.7;
}

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

button,
a,
summary {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

/* Monochrome line icons shared with the desktop application. */
.ai-icon {
    display: inline-block;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    background: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

.ai-icon-brand { --icon: url('../images/ai/brand.svg'); }
.ai-icon-compose { --icon: url('../images/ai/compose.svg'); }
.ai-icon-more { --icon: url('../images/ai/more.svg'); }
.ai-icon-pin { --icon: url('../images/ai/pin.svg'); }
.ai-icon-rename { --icon: url('../images/ai/rename.svg'); }
.ai-icon-delete { --icon: url('../images/ai/delete.svg'); }
.ai-icon-send { --icon: url('../images/ai/send.svg'); }
.ai-icon-stop { --icon: url('../images/ai/stop.svg'); }
.ai-icon-next { --icon: url('../images/ai/next.svg'); }
.ai-icon-previous { --icon: url('../images/ai/previous.svg'); }
.ai-icon-return { --icon: url('../images/ai/return.svg'); }
.ai-icon-source { --icon: url('../images/ai/source.svg'); }

.ai-app svg,
.ai-site-header svg,
.ai-account-close svg,
.ai-account-avatar svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* One menu keeps library navigation and the former footer links in reach. */
.ai-site-header {
    position: relative;
    z-index: 50;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 4px 10px;
    background: var(--background);
}

.ai-site-menu { position: relative; }

.ai-site-menu-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 36px;
    padding: 2px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.ai-site-brand {
    color: var(--primary);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
}

.ai-site-menu-button:hover,
.ai-site-menu-button[aria-expanded='true'] { background: var(--hover); }
.ai-site-menu-button svg { width: 16px; height: 16px; }
.ai-site-menu-button[aria-expanded='true'] svg { transform: rotate(180deg); }

.ai-site-navigation {
    position: absolute;
    inset-block-start: calc(100% + 4px);
    inset-inline-start: 0;
    width: min(280px, calc(100vw - 20px));
    max-height: calc(100dvh - 60px);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    box-shadow: 0 8px 28px var(--shadow);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.ai-site-links { margin: 0; padding: 0; list-style: none; }
.ai-site-links-separated { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.ai-site-links a,
.ai-site-links button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    text-align: start;
    cursor: pointer;
}

.ai-site-links svg { flex: 0 0 18px; width: 18px; height: 18px; color: var(--muted); }
.ai-site-links a:hover,
.ai-site-links button:hover { background: var(--hover); }
.ai-site-links a[target='_blank']::after { content: '↗'; margin-inline-start: auto; color: var(--quiet); font: 14px Tahoma, sans-serif; }
.ai-site-links .site-contribution-link a { color: var(--primary); }
.ai-site-mode-state { margin-inline-start: auto; color: var(--primary); }
#site-night-mode[aria-pressed='true'] .ai-site-mode-state::after { content: '✓'; }
.ai-site-fine-links { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; padding: 10px; border-top: 1px solid var(--border); }
.ai-site-fine-links a { color: var(--muted); font-size: 12px; text-decoration: none; }
.ai-site-fine-links a:hover { color: var(--ink); text-decoration: underline; }
.ai-site-header .ai-sidebar-toggle,
.ai-site-header .ai-header-new,
.ai-site-header .ai-mobile-title { display: none; }

.ai-about-dialog {
    width: min(520px, calc(100% - 32px));
    padding: 22px 24px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    color: var(--ink);
    box-shadow: 0 18px 60px var(--shadow);
}

.ai-about-dialog::backdrop {
    background: rgba(28, 20, 12, .58);
}

.ai-about-dialog h2 {
    margin: 0 0 8px;
    color: var(--title);
}

/* Shared controls. */

.ai-shell {
    flex: 1 0 auto;
    width: min(1320px, 100%);
    margin: 0 auto;
    padding: 28px 24px 40px;
}

.ai-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    box-shadow: 0 10px 28px var(--shadow);
}

.ai-centered {
    width: min(460px, 100%);
    margin: clamp(40px, 8vh, 88px) auto;
    padding: 32px;
    text-align: center;
}

input,
textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--field);
    color: var(--ink);
    caret-color: var(--primary);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:hover,
textarea:hover {
    border-color: var(--quiet);
}

input:focus,
textarea:focus {
    outline: 0;
    border-color: var(--focus);
    box-shadow: none;
}

input::placeholder,
textarea::placeholder {
    color: var(--quiet);
    opacity: 1;
}

.ai-primary,
.ai-secondary,
.ai-danger,
.ai-link-button {
    cursor: pointer;
}

.ai-primary,
.ai-secondary,
.ai-danger {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 9px 16px;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
}

.ai-primary:active:not(:disabled),
.ai-secondary:active:not(:disabled),
.ai-danger:active:not(:disabled) {
    transform: translateY(1px);
}

.ai-primary {
    background: var(--primary);
    color: var(--on-primary);
}

.ai-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.ai-secondary {
    border-color: var(--border);
    background: var(--soft);
    color: var(--ink);
}

.ai-secondary:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--soft-strong);
}

.ai-danger {
    background: var(--danger);
    color: #fff;
}

.ai-danger:hover:not(:disabled) {
    background: #7f2b26;
}

.ai-link-button {
    min-height: 36px;
    padding: 4px;
    border: 0;
    background: transparent;
    color: var(--primary);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .24em;
}

.ai-link-button:hover:not(:disabled) {
    color: var(--primary-hover);
    text-decoration-thickness: 2px;
}

.ai-status:empty {
    display: none;
}

.ai-notice,
.ai-status:not(:empty) {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--notice);
    color: var(--on-notice);
}

.ai-notice strong {
    overflow-wrap: anywhere;
}

.ai-muted {
    color: var(--muted);
}

.ai-spinner {
    display: inline-block;
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin-inline-end: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ai-spin .8s linear infinite;
    vertical-align: middle;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

.ai-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Sign in, sign up and the desktop login link. */

.ai-desktop-link {
    margin-bottom: 18px;
    padding: 20px;
    text-align: center;
}

.ai-desktop-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 18px 0;
}

.ai-desktop-actions button {
    white-space: normal;
    overflow-wrap: anywhere;
}

.ai-auth {
    display: grid;
    grid-template-columns: minmax(0, 432px) minmax(0, 600px);
    align-items: center;
    gap: clamp(24px, 4vw, 56px);
    width: min(1088px, 100%);
    margin: 32px auto 56px;
}

.ai-auth-content {
    min-width: 0;
}

.ai-auth-art img {
    display: block;
    width: 100%;
    height: auto;
    mix-blend-mode: multiply;
}

body.night .ai-auth-art img {
    mix-blend-mode: normal;
    opacity: .7;
}

.ai-auth-mark {
    display: block;
    margin-bottom: 18px;
    color: var(--primary);
}

.ai-auth h1 {
    margin: 0 0 8px;
    font-family: 'Shamela Kitab', 'Shamela Kufi', serif;
    font-size: 2.6rem;
    line-height: 1.35;
}

.ai-auth h1 + p {
    margin: 0 0 22px;
    color: var(--muted);
}

.ai-auth-back {
    margin-top: 18px;
}

.ai-auth .ai-auth-benefits {
    margin-top: -4px;
    color: var(--muted);
    font-size: .85rem;
}

.ai-social-login {
    margin-top: 22px;
    text-align: center;
}

.ai-social-login .ai-provider-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.ai-provider-button {
    position: relative;
    min-height: 48px;
    padding: 10px 44px 10px 8px;
    padding-inline: 8px 44px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--field);
    color: var(--ink);
    font-size: .85rem;
    white-space: nowrap;
    cursor: pointer;
}

.ai-provider-button:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--soft);
}

.ai-provider-icon {
    position: absolute;
    top: 50%;
    inset-inline-end: 14px;
    width: 30px;
    height: 30px;
    object-fit: contain;
    transform: translateY(-50%);
}

.ai-provider-icon--apple {
    width: 46px;
    height: 46px;
    inset-inline-end: 6px;
}

body.night .ai-provider-icon--apple {
    filter: invert(1);
}

/* The conversation fills the viewport; the menu sits above the history. */

body:has(#app-panel:not([hidden])) {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body:has(#app-panel:not([hidden])) .ai-shell {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    padding: 0;
}

@media (min-width: 801px) {
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-site-header {
        position: absolute;
        inset-block-start: 6px;
        inset-inline-start: 10px;
        width: calc(var(--ai-sidebar-width, 300px) - 20px);
        min-height: 36px;
        padding: 0;
        background: var(--sidebar);
    }
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-site-menu { width: 100%; }
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-site-menu-button { width: 100%; }
}

.ai-app {
    position: relative;
    display: grid;
    grid-template-columns: var(--ai-sidebar-width, 300px) 8px minmax(0, 1fr);
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--paper);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
}

.ai-app.ai-source-open {
    grid-template-columns: var(--ai-sidebar-width, 300px) 8px minmax(0, 1fr) clamp(340px, 31%, 560px);
}

/* History rail. */

.ai-sidebar {
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    min-height: 0;
    padding: 52px 10px 8px;
    background: var(--sidebar);
}

.ai-thread-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ai-new-thread {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 5px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    text-align: start;
    cursor: pointer;
}

.ai-new-thread .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-new-thread:hover:not(:disabled) {
    background: var(--hover);
}

.ai-history {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

.ai-thread-title-filter {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 10px;
    border-color: var(--border);
    border-radius: 8px;
    font-size: 14px;
}

.ai-loading-note {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px 0;
    color: var(--muted);
    font-size: 14px;
}

.ai-thread-list {
    flex: 1 1 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
    scrollbar-width: thin;
}

.ai-thread-group {
    margin: 8px 0 2px;
    padding: 0 8px;
    color: var(--history-heading);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.6;
}

.ai-thread-group:first-child {
    margin-top: 4px;
}

.ai-threads-empty {
    margin: 10px 0;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

.ai-thread-row {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 32px;
    margin: 1px 0;
    border-radius: 8px;
}

.ai-thread-row:hover {
    background: var(--hover);
}

.ai-thread-row.is-current {
    background: var(--selected);
}

.ai-thread-button {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 5px;
    min-width: 0;
    min-height: 32px;
    padding: 4px 8px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    text-align: start;
    cursor: pointer;
}

.ai-thread-button[aria-current='true'] {
    font-weight: 600;
}

.ai-thread-button .ai-icon {
    width: 13px;
    height: 13px;
    color: var(--muted);
}

.ai-thread-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-thread-actions {
    position: absolute;
    inset-inline-end: 0;
    background: var(--sidebar);
    border-radius: 6px;
    visibility: hidden;
}

.ai-thread-row:hover .ai-thread-actions,
.ai-thread-row:focus-within .ai-thread-actions { background: var(--hover); }
.ai-thread-row.is-current .ai-thread-actions,
.ai-thread-actions[open] { background: var(--selected); }
.ai-thread-row:hover .ai-thread-button,
.ai-thread-row:focus-within .ai-thread-button,
.ai-thread-row.is-current .ai-thread-button,
.ai-thread-row:has(.ai-thread-actions[open]) .ai-thread-button { padding-inline-end: 36px; }

.ai-thread-row:hover .ai-thread-actions,
.ai-thread-row:focus-within .ai-thread-actions,
.ai-thread-row.is-current .ai-thread-actions,
.ai-thread-actions[open] {
    visibility: visible;
}

/* Touch screens have no hover: every row keeps its actions in reach. */
@media (hover: none) {
    .ai-thread-actions {
        visibility: visible;
    }
    .ai-thread-button { padding-inline-end: 36px; }
}

.ai-thread-row.is-renaming .ai-thread-button,
.ai-thread-row.is-renaming .ai-thread-actions {
    display: none;
}

.ai-thread-rename {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 34px;
    margin: 2px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 15px;
}

.ai-thread-actions > summary {
    display: grid;
    width: 28px;
    height: 28px;
    margin: 0 4px;
    place-items: center;
    border-radius: 6px;
    color: var(--muted);
    list-style: none;
    cursor: pointer;
}

.ai-thread-actions > summary::-webkit-details-marker {
    display: none;
}

.ai-thread-actions > summary:hover,
.ai-thread-actions[open] > summary {
    background: var(--selected);
    color: var(--ink);
}

body.night .ai-thread-actions > summary:hover,
body.night .ai-thread-actions[open] > summary {
    background: var(--border-strong);
}

.ai-thread-actions > summary .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-thread-menu {
    position: fixed;
    z-index: 60;
    min-width: 170px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 10px 28px var(--shadow);
}

.ai-thread-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 34px;
    margin: 1px 0;
    padding: 4px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    font-size: 15px;
    text-align: start;
    cursor: pointer;
}

.ai-thread-menu button .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-thread-menu button:hover:not(:disabled) {
    background: var(--selected);
}

.ai-thread-menu hr {
    height: 1px;
    margin: 4px 8px;
    border: 0;
    background: var(--border);
}

.ai-quiet-button {
    flex: 0 0 auto;
    padding: 6px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: 14px;
    cursor: pointer;
}

.ai-quiet-button:hover:not(:disabled) {
    background: var(--hover);
}

.ai-quota-panel {
    flex: 0 0 auto;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
}

.ai-quota-panel p {
    margin: 0;
    color: var(--ink);
    font-size: 14px;
}

.ai-quota-reset {
    margin-top: 2px !important;
    color: var(--muted) !important;
    font-size: 13px !important;
}

.ai-quota-panel hr {
    height: 1px;
    margin: 8px 0;
    border: 0;
    background: var(--border);
}

.ai-quota-note {
    margin: 0;
    padding-inline-start: 1.1em;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.7;
}

.ai-quota-note a {
    color: var(--ink);
}

.ai-account-box {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    padding: 10px 0 2px;
    border-top: 1px solid var(--border);
}

.ai-avatar {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border-radius: 50%;
    background: var(--quota);
    color: var(--on-quota);
    font-family: 'Shamela Kufi', Tahoma, sans-serif;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
}

.ai-avatar:empty {
    visibility: hidden;
}

.ai-account-copy {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.ai-account-email {
    display: block;
    overflow: hidden;
    color: var(--ink);
    font-family: Tahoma, sans-serif;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-account-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-account-link {
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
}

.ai-account-link:hover:not(:disabled) {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: .25em;
}

.ai-account-separator {
    color: var(--quiet);
}

/* The remaining daily quota, in the avatar's brown. */
.ai-quota-badge {
    min-width: 22px;
    height: 22px;
    flex: 0 0 auto;
    padding: 0 6px;
    border: 0;
    border-radius: 11px;
    background: var(--quota);
    color: var(--on-quota);
    font-family: 'Shamela Book', 'Shamela Naskh', serif;
    font-size: 16px;
    font-weight: 700;
    line-height: 22px;
    white-space: nowrap;
    cursor: pointer;
}

.ai-quota-badge:hover,
.ai-quota-badge[aria-expanded='true'] {
    background: var(--primary-hover);
    color: var(--on-primary);
}

.ai-sidebar-resizer {
    position: relative;
    z-index: 21;
    min-width: 0;
    background: var(--sidebar);
    border-inline-start: 1px solid var(--border);
    cursor: col-resize;
    touch-action: none;
}

.ai-sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    inset-inline-start: 2px;
    width: 3px;
    height: 36px;
    border-radius: 3px;
    background: transparent;
    transform: translateY(-50%);
    transition: background-color 160ms ease;
}

.ai-sidebar-resizer:hover::after,
.ai-sidebar-resizer:focus-visible::after,
.ai-sidebar-resizer.is-dragging::after {
    background: var(--border-strong);
}

.ai-sidebar-shade {
    display: none;
}

/* Conversation. */

.ai-workspace {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--paper);
}

.ai-maintenance {
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--notice);
    color: var(--on-notice);
    font-size: 14px;
    text-align: center;
}

.ai-auth-maintenance {
    margin: 0 0 18px;
}

.ai-example-preview {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

.ai-example-preview button {
    flex: 0 0 auto;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--primary);
}

.ai-message-region {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.ai-icon-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.ai-icon-button:hover:not(:disabled) {
    background: var(--hover);
    color: var(--ink);
}

.ai-scroll-top {
    position: absolute;
    inset-block-start: 10px;
    inset-inline-end: 10px;
    z-index: 10;
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 2px 8px var(--shadow);
}

.ai-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.ai-welcome {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 25px 35px;
    text-align: center;
}

.ai-welcome .ai-icon-brand {
    width: 44px;
    height: 44px;
    margin-bottom: 16px;
    color: var(--primary);
}

.ai-welcome h1 {
    margin: 0 0 10px;
    color: var(--ink);
    font-family: 'Shamela Book', 'Shamela Naskh', serif;
    font-size: 2.6rem;
    font-weight: 700;
    line-height: 1.3;
}

.ai-welcome p {
    max-width: 36em;
    margin: 0;
    color: var(--muted);
    font-size: 1.1rem;
}

.ai-examples {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: min(640px, 100%);
    margin-top: 28px;
}

.ai-example {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: transparent;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.6;
    text-align: start;
    cursor: pointer;
}

.ai-example:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--hover);
}

.ai-public-share .ai-examples {
    display: none;
}

.ai-thread-loading {
    flex: 1 1 auto;
    font-size: 15px;
}

.ai-conversation {
    width: 100%;
    max-width: var(--reading-width);
    margin: 0 auto;
    padding: 28px 24px 16px;
}

/* The website's book page typography: answers and source pages alike. */
.ai-book-text {
    color: var(--text);
    font-family: 'Shamela Book', 'Shamela Naskh', serif;
    font-size: 22px;
    line-height: 2;
    overflow-wrap: anywhere;
}

.ai-book-text p {
    margin: 0 0 10px;
}

.ai-book-text span.c1 { color: var(--c1); }
.ai-book-text span.c2 { color: var(--c2); }
.ai-book-text span.c3 { color: var(--c3); }
.ai-book-text span.c4 { color: var(--c4); }
.ai-book-text span.c5 { color: var(--c5); }

.ai-book-text .special {
    font-family: 'Shamela Kitab', serif;
    font-weight: normal;
}

.ai-book-text hr {
    height: 1px;
    margin: 18px 0 10px;
    border: 0;
    background: var(--rule);
}

.ai-book-text .hamesh {
    color: var(--hamesh);
}

.ai-book-text table {
    max-width: 100%;
    margin: 0 0 12px;
    border-collapse: collapse;
}

.ai-book-text th,
.ai-book-text td {
    padding: .3em .6em;
    border: 1px solid var(--border);
}

.ai-book-text a {
    color: inherit;
}

/* Every reader message, including follow-ups, sits in a bubble at the end
   of the side it reads from (dir="auto"), as in every chat, so it stands
   apart from the answer that starts on the other: an Arabic one on the left,
   an English one on the right. Answers retain the book-page typography. */
.ai-turn > .ai-question {
    width: fit-content;
    max-width: 85%;
    margin: 0 0 24px;
    margin-inline-start: auto;
    padding: 12px 18px;
    border-radius: 18px;
    background: var(--question-background);
    color: var(--question-text);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.8;
    text-align: start;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ai-answer {
    margin-top: 16px;
    text-align: start;
}

.ai-activity {
    display: flex;
    align-items: center;
    margin: 0 !important;
    color: var(--muted);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 16px;
}

.ai-activity::before {
    content: '';
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    margin-inline-end: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ai-spin .8s linear infinite;
}

.ai-turn.is-live .ai-answer > :last-child::after {
    content: '';
    display: inline-block;
    width: .45em;
    height: 1em;
    margin-inline-start: .15em;
    background: var(--muted);
    vertical-align: -.15em;
    animation: ai-caret 1s steps(1) infinite;
}

@keyframes ai-caret {
    50% { opacity: 0; }
}

.ai-answer > :first-child {
    margin-top: 0;
}

.ai-answer h1,
.ai-answer h2,
.ai-answer h3,
.ai-answer h4,
.ai-answer h5,
.ai-answer h6,
.ai-answer .ai-heading {
    margin: 18px 0 8px;
    color: var(--title);
    font-size: 1em;
    font-weight: 700;
    line-height: inherit;
}

.ai-answer strong,
.ai-answer b {
    color: var(--text);
}

.ai-answer ul,
.ai-answer ol {
    margin: 0 0 12px;
    padding-inline-start: 1.4em;
}

.ai-answer ol {
    list-style-type: decimal;
}

.ai-answer ol:dir(rtl) {
    list-style-type: arabic-indic;
}

.ai-answer li {
    margin-bottom: 6px;
}

.ai-answer blockquote {
    margin: 0 0 12px;
    padding: 0 1em;
    border-inline-start: 2px solid var(--rule);
    color: var(--muted);
}

.ai-answer code,
.ai-answer pre {
    border-radius: 4px;
    background: var(--badge);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: .75em;
}

.ai-answer code {
    padding: .1em .35em;
}

.ai-answer pre {
    padding: 12px;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
}

.ai-answer pre code {
    padding: 0;
    background: transparent;
}

.ai-answer table {
    display: block;
    overflow-x: auto;
}

.ai-answer a {
    color: var(--c5);
}

/* A citation or footnote number drawn as a small rounded square. */
.ai-citation-badge,
.ai-source-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    height: 1.5em;
    margin: 0 .1em;
    padding: 0 .3em;
    border: 0;
    border-radius: .33em;
    background: var(--badge);
    color: var(--text);
    font-family: 'Shamela Kufi', Tahoma, sans-serif;
    font-size: .6em;
    font-weight: 700;
    line-height: 1;
    vertical-align: .15em;
}

.ai-citation-badge {
    min-width: 1.8em;
    height: 1.7em;
    font-size: .68em;
    cursor: pointer;
}

.ai-citation-badge:hover,
.ai-citation-badge:active,
.ai-citation-badge.is-open {
    background: var(--selected);
}

.ai-citation-badge.is-open {
    box-shadow: inset 0 0 0 1px var(--muted);
}

.ai-source-row.is-open .ai-source-link {
    color: var(--ink) !important;
    text-decoration: underline;
    text-underline-offset: .25em;
}

.ai-sources {
    margin-top: 8px;
    color: var(--hamesh);
    font-size: 18px;
    line-height: 1.8;
}

.ai-sources hr {
    width: 30%;
    margin: 10px 0 8px;
    margin-inline-end: auto;
}

.ai-source-row {
    margin: 0 0 4px !important;
}

.ai-source-row .ai-source-number {
    margin-inline-end: .5em;
}

.ai-source-link {
    color: var(--hamesh) !important;
    text-decoration: none;
}

.ai-source-link:hover {
    color: var(--primary) !important;
    text-decoration: underline;
    text-underline-offset: .25em;
}

.ai-source-detail {
    margin-inline-start: .6em;
}

.ai-failure {
    margin-top: 12px;
    color: var(--hamesh);
    font-size: 18px;
    font-style: italic;
}

.ai-answer-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 22px 0 8px;
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--muted);
}

/* Buttons at rest, so they are not read as one more footnote. */
.ai-answer-action,
.ai-answer-menu summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 0;
    border-radius: 8px;
    background: var(--soft-strong);
    color: var(--ink);
    cursor: pointer;
}

.ai-answer-action:hover,
.ai-answer-menu summary:hover,
.ai-answer-menu[open] summary {
    background: var(--selected);
    background: color-mix(in srgb, var(--soft-strong) 88%, var(--ink));
    color: var(--text);
}

.ai-answer-actions svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.ai-answer-menu { position: relative; }
.ai-answer-menu summary { list-style: none; }
.ai-answer-menu summary::-webkit-details-marker { display: none; }
.ai-answer-menu-items {
    position: fixed;
    min-width: 245px;
    overflow-y: auto;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    box-shadow: 0 5px 18px #0002;
    z-index: 10;
}

.ai-answer-menu-items button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--ink);
    text-align: start;
    cursor: pointer;
}

.ai-answer-menu-items button:hover { background: var(--soft); }
.ai-answer-menu-items small { display: block; color: var(--muted); font-size: 12px; }
.ai-answer-action-status { font-size: 13px; }
.ai-share-dialog {
    width: min(480px, calc(100% - 32px));
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    color: var(--ink);
    font-family: 'Shamela Naskh', Tahoma, sans-serif;
}

.ai-share-dialog::backdrop { background: #0006; }
.ai-share-dialog h2 { margin-top: 0; font-size: 22px; }
.ai-share-dialog input { width: 100%; font-size: 14px; }
.ai-share-controls { display: flex; gap: 10px; margin-top: 18px; }
.ai-public-share .ai-sidebar,
.ai-public-share .ai-sidebar-resizer,
.ai-public-share .ai-sidebar-toggle,
.ai-public-share #question-form,
.ai-public-share #thread-continuation-notice,
.ai-visitor .ai-sidebar,
.ai-visitor .ai-sidebar-resizer,
.ai-visitor .ai-sidebar-toggle,
.ai-visitor #question-form { display: none !important; }
.ai-public-share .ai-app,
.ai-visitor .ai-app { grid-template-columns: minmax(0, 1fr); }
.ai-public-share .ai-app.ai-source-open,
.ai-visitor .ai-app.ai-source-open { grid-template-columns: minmax(0, 1fr) 360px; }
/* Signed out, the sign-in buttons stand where the question box would be. */
.ai-visitor-prompt { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ai-visitor-prompt .ai-provider-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: min(100%, 460px);
}
.ai-visitor-prompt[hidden] { display: none; }
.ai-visitor .ai-run-status { justify-content: center; }
@media (max-width: 800px) {
    .ai-public-share .ai-app.ai-source-open,
    .ai-visitor .ai-app.ai-source-open { grid-template-columns: minmax(0, 1fr); }
}

.ai-turn-rule {
    height: 1px;
    margin: 24px 0 !important;
    border: 0;
    background: var(--rule);
}

/* Composer: status line, question box and the disclaimer, sharing the
   conversation's reading column. */

.ai-composer-area {
    flex: 0 0 auto;
    padding: 4px 16px 10px;
    background: var(--paper);
}

.ai-composer-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: calc(var(--reading-width) - 16px);
    margin: 0 auto;
}

.ai-run-status {
    display: flex;
    align-items: center;
    min-height: 1.6em;
    margin: 0;
    padding: 0 6px;
    color: var(--muted);
    font-size: 15px;
}

/* While the same phrase shows under the running question, the status line
   stays in place and keeps announcing it, but is not drawn. */
.ai-run-status.is-mirrored {
    opacity: 0;
}

.ai-run-status.is-running::before {
    content: '';
    display: inline-block;
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    margin-inline-end: 8px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ai-spin .8s linear infinite;
}

.ai-continuation-message {
    margin: 0;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
    font-size: 15px;
}

.ai-continuation-message .ai-link-button {
    min-height: 0;
    padding: 0;
    color: var(--ink);
    font-weight: 600;
}

.ai-composer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px 10px 10px;
    padding-inline: 14px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    background: var(--field);
    transition: border-color 160ms ease;
}

.ai-composer:focus-within {
    border-color: var(--muted);
}

.ai-composer textarea {
    min-height: 0;
    max-height: 12em;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 17px;
    line-height: 1.75;
    resize: none;
}

.ai-composer textarea:focus {
    box-shadow: none;
}

.ai-composer-bottom {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-composer-spacer {
    flex: 1 1 auto;
}

.ai-send-button,
.ai-cancel-button {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
}

.ai-send-button {
    border: 0;
    background: var(--primary);
    color: var(--on-primary);
}

.ai-send-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.ai-send-button:disabled {
    background: var(--primary-idle);
    opacity: 1;
}

.ai-cancel-button {
    border: 1px solid var(--muted);
    background: transparent;
    color: var(--ink);
}

.ai-cancel-button:hover:not(:disabled) {
    background: var(--hover);
}

.ai-cancel-button .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-disclaimer {
    margin: 0;
    color: var(--quiet);
    font-size: 13px;
    text-align: center;
}

/* Source reader: the cited book page, drawn like a page of the website. */

.ai-source-panel {
    z-index: 30;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-inline-start: 1px solid var(--border);
    background: var(--paper);
}

.ai-source-panel:focus {
    outline: 0;
}

.ai-source-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 8px 6px 16px;
    padding-inline: 16px 8px;
    border-bottom: 1px solid var(--border);
}

.ai-source-heading {
    flex: 1 1 auto;
    min-width: 0;
}

.ai-source-heading h2 {
    margin: 0;
    color: var(--title);
    font-family: 'Shamela Book', 'Shamela Naskh', serif;
    font-size: 21px;
    font-weight: 700;
    line-height: 1.6;
}

.ai-source-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 24px;
}

.ai-source-meta > span {
    color: var(--muted);
    font-size: 14px;
}

.ai-source-return {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
}

.ai-source-return .ai-icon {
    width: 14px;
    height: 14px;
}

.ai-source-return:hover {
    background: var(--hover);
}

.ai-source-close {
    width: 30px;
    height: 30px;
}

.ai-source-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.ai-source-status {
    margin: 0;
    padding: 12px;
    color: var(--muted);
    font-size: 15px;
    text-align: center;
}

.ai-source-status:empty {
    display: none;
}

.ai-source-content {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px 18px 18px;
    overflow-y: auto;
    font-size: 20px;
    outline: none;
}

.ai-source-content:focus-visible {
    box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent);
}

.ai-source-content:empty {
    display: none;
}

.ai-source-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-top: 1px solid var(--border);
}

.ai-source-page {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
}

.ai-source-page .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-source-page:hover:not(:disabled) {
    background: var(--hover);
}

.ai-source-page:disabled {
    border-color: var(--soft);
    opacity: .45;
}

.ai-open-full {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    text-decoration: none;
}

.ai-open-full .ai-icon {
    width: 16px;
    height: 16px;
}

.ai-open-full:hover {
    background: var(--hover);
}

/* Account management. */

.ai-account-dialog {
    color: var(--ink);
}

#account-dialog.ai-account-dialog {
    width: min(520px, calc(100% - 32px));
    max-width: 520px;
    max-height: calc(100dvh - 32px);
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    background: var(--background);
    box-shadow: 0 28px 90px var(--shadow);
}

#account-dialog::backdrop {
    background: rgba(28, 20, 12, .58);
}

#account-dialog[open] {
    animation: ai-account-enter 180ms ease-out;
}

@keyframes ai-account-enter {
    from { opacity: 0; transform: translateY(10px) scale(.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-account-dialog-shell {
    max-height: calc(100dvh - 34px);
    padding: 0 20px 22px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ai-account-header {
    position: sticky;
    z-index: 3;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin: 0 -20px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.ai-account-eyebrow {
    display: block;
    margin-bottom: 2px;
    color: var(--quiet);
    font-family: 'Shamela Kufi', Tahoma, sans-serif;
    font-size: .7rem;
}

.ai-account-header h1 {
    margin: 0;
    color: var(--title);
    font-family: 'Shamela Kitab', 'Shamela Naskh', serif;
    font-size: 1.75rem;
    line-height: 1.25;
}

.ai-account-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: .88rem;
}

.ai-account-close {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
}

.ai-account-close:hover {
    border-color: var(--border-strong);
    background: var(--soft);
    color: var(--ink);
}

.ai-account-status {
    position: sticky;
    z-index: 2;
    top: 104px;
    margin: 14px 0 0;
}

.ai-account-overview {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    margin-top: 22px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
}

.ai-account-avatar {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    border-radius: 14px;
    background: var(--primary);
    color: var(--on-primary);
}

.ai-account-avatar svg {
    width: 28px;
    height: 28px;
}

.ai-account-overview-copy {
    min-width: 0;
}

.ai-account-overview-copy span,
.ai-account-login-method span {
    display: block;
    color: var(--muted);
    font-size: .75rem;
}

.ai-account-overview-copy strong {
    display: block;
    overflow: hidden;
    direction: ltr;
    color: var(--ink);
    font-family: Tahoma, sans-serif;
    font-size: .9rem;
    font-weight: 600;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-account-login-method {
    min-width: 0;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--paper);
}

.ai-account-login-method strong {
    display: block;
    margin-top: 3px;
    color: var(--ink);
    font-size: .84rem;
}

.ai-account-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 16px;
}

#account-dialog .ai-account-section {
    min-width: 0;
    margin: 0;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
}

.ai-account-section-heading {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    margin-bottom: 16px;
}

.ai-account-section-icon {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border-radius: 9px;
    background: var(--soft);
    color: var(--primary);
    font-family: Tahoma, sans-serif;
    font-size: .85rem;
    font-weight: 700;
}

#account-dialog .ai-account-section h2 {
    margin: 0;
    color: var(--ink);
    font-size: 1rem;
}

.ai-account-section-heading p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: .77rem;
    line-height: 1.6;
}

.ai-account-form {
    display: grid;
    gap: 6px;
}

#account-dialog .ai-account-form label {
    margin-top: 7px;
    color: var(--muted);
    font-family: 'Shamela Kufi', Tahoma, sans-serif;
    font-size: .7rem;
}

#account-dialog .ai-account-form button {
    justify-self: stretch;
    margin-top: 12px;
}

#account-dialog .ai-delete-account {
    border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
    background: var(--danger-soft);
}

.ai-account-danger-icon {
    background: var(--danger-soft);
    color: var(--danger);
}

.ai-delete-account .ai-account-section-heading h2,
.ai-delete-account .ai-account-section-heading p {
    color: var(--danger) !important;
}

.ai-delete-confirm {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 10px 11px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--paper);
    line-height: 1.7;
    cursor: pointer;
}

.ai-delete-confirm input {
    width: 17px;
    height: 17px;
    min-height: 0 !important;
    flex: 0 0 17px;
    margin: 3px 0 0;
    accent-color: var(--danger);
}

.ai-conversations-danger {
    width: 100%;
    border-color: color-mix(in srgb, var(--danger) 45%, transparent);
    color: var(--danger);
}

.ai-conversations-danger:hover:not(:disabled) {
    border-color: var(--danger);
    background: var(--danger-soft);
}

/* Narrower windows: the source reader slides over the conversation. */
@media (max-width: 1100px) {
    .ai-app.ai-source-open {
        grid-template-columns: var(--ai-sidebar-width, 300px) 8px minmax(0, 1fr);
    }

    .ai-source-panel {
        position: absolute;
        inset-block: 0;
        inset-inline-end: 0;
        width: min(460px, 92%);
        box-shadow: 0 0 40px var(--shadow);
    }
}

/* Phones: one compact bar and a history drawer. */
@media (max-width: 800px) {
    .ai-site-header { padding: 3px 6px; }
    .ai-site-menu-button { gap: 8px; padding-inline: 8px; }
    .ai-site-navigation { position: fixed; inset-block-start: 48px; inset-inline-start: 8px; }
    body:has(#app-panel:not([hidden])) .ai-site-header { border-bottom: 1px solid var(--border); background: var(--paper); }
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-site-header .ai-sidebar-toggle,
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-header-new { display: grid; }
    body:not(.ai-public-share):not(.ai-visitor):has(#app-panel:not([hidden])) .ai-mobile-title { display: block; }

    .ai-shell {
        padding: 12px 10px 24px;
    }

    .ai-centered {
        margin: 28px auto;
        padding: 24px 20px;
    }

    .ai-auth {
        display: block;
        width: min(432px, 100%);
        margin: 24px auto;
        padding: 0 14px;
    }

    .ai-auth-art,
    .ai-auth-mark {
        display: none;
    }

    .ai-auth h1 {
        font-size: 2.2rem;
    }

    .ai-app,
    .ai-app.ai-source-open {
        grid-template-columns: minmax(0, 1fr);
    }

    .ai-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        width: min(86vw, 320px);
        padding-top: 10px;
        z-index: 70;
        box-shadow: 0 0 40px var(--shadow);
        transform: translateX(100%);
        transition: transform 180ms ease;
    }

    .ai-sidebar.ai-sidebar-open {
        transform: none;
    }

    .ai-sidebar-shade:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 69;
        display: block;
        border: 0;
        background: rgba(0, 0, 0, .35);
    }

    .ai-sidebar-resizer {
        display: none;
    }

    .ai-mobile-title {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        color: var(--ink);
        font-size: 15px;
        font-weight: 600;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ai-conversation {
        padding: 16px 14px 12px;
    }

    .ai-examples {
        grid-template-columns: minmax(0, 1fr);
        margin-top: 20px;
    }

    .ai-social-login .ai-provider-buttons,
    .ai-visitor-prompt .ai-provider-buttons {
        grid-template-columns: minmax(0, 1fr);
    }

    .ai-disclaimer {
        font-size: 11.5px;
        line-height: 1.5;
    }

    .ai-book-text {
        font-size: 20px;
    }

    .ai-turn > .ai-question {
        max-width: 92%;
        padding: 10px 14px;
    }

    .ai-sources {
        font-size: 16px;
    }

    .ai-composer-area {
        padding: 4px 8px 8px;
    }

    .ai-source-panel {
        position: fixed;
        inset: 0;
        width: auto;
        z-index: 80;
    }

    #account-dialog.ai-account-dialog {
        width: 100%;
        max-width: none;
        max-height: 100dvh;
        margin: 0;
        border: 0;
        border-radius: 0;
    }

    .ai-account-dialog-shell {
        max-height: 100dvh;
        padding: 0 16px 22px;
    }

    .ai-account-header {
        margin: 0 -16px;
        padding: 16px;
    }

    .ai-account-header h1 {
        font-size: 1.4rem;
    }

    .ai-account-header p {
        display: none;
    }

    .ai-account-status {
        top: 82px;
    }

    .ai-account-overview {
        grid-template-columns: auto minmax(0, 1fr);
        padding: 16px;
    }

    .ai-account-login-method {
        grid-column: 1 / -1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }

    .ai-spinner {
        animation: none;
    }
}
