/* ==========================================================================
   رمان‌ساز — design tokens and base styles.
   Component styles live next to each component (*.razor.css).
   Bootstrap is used for grid and utilities only.
   ========================================================================== */

/* ---- Fonts ----------------------------------------------------------------
   PeydaWeb is the project font (wwwroot/fonts/Peyda/). Vazirmatn (bundled, SIL OFL)
   is the fallback while it loads or if the files are missing. */
@font-face {
    font-family: "PeydaWeb";
    src: url("../fonts/Peyda/PeydaWeb-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "PeydaWeb";
    src: url("../fonts/Peyda/PeydaWeb-Bold.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/vazirmatn/Vazirmatn-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/vazirmatn/Vazirmatn-Medium.ttf") format("truetype");
    font-weight: 500;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/vazirmatn/Vazirmatn-SemiBold.ttf") format("truetype");
    font-weight: 600;
    font-display: swap;
}

@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/vazirmatn/Vazirmatn-Bold.ttf") format("truetype");
    font-weight: 700;
    font-display: swap;
}

/* ---- Tokens ------------------------------------------------------------- */
:root {
    --font-fa: "PeydaWeb", "Vazirmatn", "SF Pro Text", -apple-system, "Segoe UI", Tahoma, sans-serif;

    --text-large-title: 34px;
    --text-title1: 28px;
    --text-title2: 22px;
    --text-title3: 20px;
    --text-headline: 17px;
    --text-body: 17px;
    --text-callout: 16px;
    --text-subhead: 15px;
    --text-footnote: 13px;
    --text-caption1: 12px;
    --text-caption2: 11px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 999px;
    --tap-min: 44px;

    --content-max: 960px;
    --reading-max: 680px;

    --color-blue: #007AFF;
    --color-green: #34C759;
    --color-red: #FF3B30;
    --color-orange: #FF9500;
    --color-yellow: #FFCC00;
    --color-purple: #AF52DE;
    --color-pink: #FF2D55;
    --color-teal: #5AC8FA;
    --color-indigo: #5856D6;

    --accent: var(--color-indigo);
    --accent-soft: rgba(88, 86, 214, 0.12);
    --on-accent: #FFFFFF;

    --label: #000000;
    --label-secondary: rgba(60, 60, 67, 0.6);
    --label-tertiary: rgba(60, 60, 67, 0.3);
    --background: #FFFFFF;
    --background-grouped: #F2F2F7;
    --background-secondary: #FFFFFF;
    --background-elevated: #FFFFFF;
    --separator: rgba(60, 60, 67, 0.29);
    --fill: rgba(120, 120, 128, 0.2);
    --fill-secondary: rgba(120, 120, 128, 0.12);

    --glass-bg: rgba(255, 255, 255, 0.62);
    --glass-border: rgba(255, 255, 255, 0.35);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);

    --success: var(--color-green);
    --danger: var(--color-red);
    --warning: var(--color-orange);

    /* Plot line tints for the story matrix. */
    --plot-1: rgba(88, 86, 214, 0.16);
    --plot-2: rgba(255, 149, 0, 0.18);
    --plot-3: rgba(52, 199, 89, 0.18);
    --plot-4: rgba(255, 45, 85, 0.16);
    --plot-5: rgba(90, 200, 250, 0.2);

    /* Bootstrap hand-off: it should inherit our typography and colours. */
    --bs-body-font-family: var(--font-fa);
    --bs-body-font-size: var(--text-body);
    --bs-body-line-height: 1.8;
    --bs-body-color: var(--label);
    --bs-body-bg: var(--background-grouped);
}

@media (prefers-color-scheme: dark) {
    :root {
        --accent: #7D7AFF;
        --accent-soft: rgba(125, 122, 255, 0.2);

        --label: #FFFFFF;
        --label-secondary: rgba(235, 235, 245, 0.6);
        --label-tertiary: rgba(235, 235, 245, 0.3);
        --background: #000000;
        --background-grouped: #000000;
        --background-secondary: #1C1C1E;
        --background-elevated: #2C2C2E;
        --separator: rgba(84, 84, 88, 0.6);
        --fill: rgba(120, 120, 128, 0.36);
        --fill-secondary: rgba(120, 120, 128, 0.24);

        --glass-bg: rgba(30, 30, 32, 0.6);
        --glass-border: rgba(255, 255, 255, 0.08);
        --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
        --card-shadow: none;

        --plot-1: rgba(125, 122, 255, 0.26);
        --plot-2: rgba(255, 159, 10, 0.24);
        --plot-3: rgba(48, 209, 88, 0.22);
        --plot-4: rgba(255, 55, 95, 0.22);
        --plot-5: rgba(100, 210, 255, 0.22);
    }
}

/* ---- Base --------------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-fa);
    font-size: var(--text-body);
    line-height: 1.8;
    color: var(--label);
    background: var(--background-grouped);
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    line-height: 1.5;
    font-weight: 700;
    margin: 0;
}

p {
    margin: 0;
}

a {
    color: var(--accent);
    text-decoration: none;
}

button {
    font-family: inherit;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

::selection {
    background: var(--accent-soft);
}

.visually-hidden-focusable:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* The one effect reserved for the control layer: bars, sheets, floating buttons. */
.liquid-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Shared buttons; components add their own specifics. */
.btn-app {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--tap-min);
    padding: 0 var(--space-5);
    border: 0;
    border-radius: var(--radius-full);
    font-size: var(--text-headline);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.2s ease;
    white-space: nowrap;
}

.btn-app:active {
    transform: scale(0.97);
}

.btn-app:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

.btn-app.primary {
    background: var(--accent);
    color: var(--on-accent);
}

.btn-app.tinted {
    background: var(--accent-soft);
    color: var(--accent);
}

.btn-app.plain {
    background: transparent;
    color: var(--accent);
    padding: 0 var(--space-3);
}

.btn-app.danger {
    background: rgba(255, 59, 48, 0.12);
    color: var(--danger);
}

.btn-app.small {
    min-height: 36px;
    padding: 0 var(--space-4);
    font-size: var(--text-subhead);
}

/* Directional icons point the other way in RTL. */
[dir="rtl"] .icon-directional {
    transform: scaleX(-1);
}

/* ---- Text fields ---------------------------------------------------------- */
.field {
    width: 100%;
    min-height: var(--tap-min);
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--fill-secondary);
    color: var(--label);
    font-family: inherit;
    font-size: var(--text-body);
    line-height: 1.7;
}

.field::placeholder {
    color: var(--label-tertiary);
}

.field:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

textarea.field {
    resize: vertical;
    min-height: 96px;
}

.field-ltr {
    direction: ltr;
    text-align: start;
}

/* ---- Boot screen (before WebAssembly starts) ------------------------------- */
.boot-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    color: var(--accent);
    padding: var(--space-5);
}

.boot-mark {
    width: 64px;
    height: 64px;
}

.boot-title {
    font-size: var(--text-title1);
    font-weight: 700;
    color: var(--label);
}

.boot-caption {
    color: var(--label-secondary);
    font-size: var(--text-subhead);
}

.boot-bar {
    width: min(240px, 60vw);
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--fill);
    overflow: hidden;
}

.boot-bar span {
    display: block;
    height: 100%;
    width: var(--blazor-load-percentage, 8%);
    background: var(--accent);
    border-radius: inherit;
    transition: width 0.2s ease;
}

.boot-skeleton {
    display: grid;
    gap: var(--space-2);
    width: min(420px, 86vw);
    margin-top: var(--space-6);
}

.boot-skeleton span {
    height: 64px;
    border-radius: var(--radius-md);
    background: var(--background-secondary);
    box-shadow: var(--card-shadow);
    animation: boot-pulse 1.4s ease-in-out infinite;
}

.boot-skeleton span:nth-child(2) { animation-delay: 0.15s; }
.boot-skeleton span:nth-child(3) { animation-delay: 0.3s; }

@keyframes boot-pulse {
    50% { opacity: 0.5; }
}

/* ---- Blazor's fatal error bar --------------------------------------------- */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset-inline: var(--space-4);
    bottom: var(--space-4);
    z-index: 1000;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--background-elevated);
    color: var(--label);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

#blazor-error-ui .reload {
    margin-inline-start: var(--space-3);
    font-weight: 600;
}

#blazor-error-ui .dismiss {
    float: inline-end;
    border: 0;
    background: transparent;
    color: var(--label-secondary);
    font-size: var(--text-title3);
    min-width: var(--tap-min);
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
