/* =============================================
   AniVerse base — reset, typography, focus, shared controls.
   Loads after tokens.css and before every page/component stylesheet.
   Legacy class names (.cyber-button, .section-title, .form-group …) are kept
   so existing markup keeps working; they now render in the AniVerse system.
   ============================================= */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--av-font-sans);
    font-size: var(--av-fs-body);
    line-height: 1.6;
    background: var(--av-bg);
    color: var(--av-text-1);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

:where(img, svg) {
    max-width: 100%;
}

::selection {
    background: rgba(237, 235, 230, 0.24);
    color: var(--av-text-1);
}

/* --- Typography helpers --- */
:where(h1, h2, h3, h4, h5, h6) {
    font-weight: 600;
    line-height: 1.25;
    color: var(--av-text-1);
}

.av-serif {
    font-family: var(--av-font-serif);
    font-weight: 400;
    letter-spacing: -0.01em;
}

.av-mono {
    font-family: var(--av-font-mono);
    font-variant-numeric: tabular-nums;
}

.av-eyebrow {
    font-family: var(--av-font-mono);
    font-size: var(--av-fs-label);
    line-height: 16px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--av-text-3);
}

.av-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:where(a) {
    color: var(--av-text-1);
    text-underline-offset: 3px;
    transition: color var(--av-dur-fast) var(--av-ease-out);
}

:where(a):hover {
    color: #FFFFFF;
}

/* --- Focus: one spec everywhere, keyboard only --- */
:focus {
    outline: none;
}

:focus-visible {
    outline: var(--av-focus-ring);
    outline-offset: var(--av-focus-offset);
}

/* Programmatic focus targets (Blazor FocusOnNavigate moves focus to the page h1,
   dialogs focus their container): no ring, they are not interactive. */
h1:focus,
[tabindex="-1"]:focus {
    outline: none;
}

/* --- Scrollbar --- */
* {
    scrollbar-color: rgba(237, 235, 230, 0.18) transparent;
    scrollbar-width: thin;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(237, 235, 230, 0.16);
    border: 3px solid var(--av-bg);
    border-radius: var(--av-radius-pill);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(237, 235, 230, 0.28);
}

/* --- Form controls --- */
:where(input, select, textarea) {
    font-family: inherit;
    font-size: var(--av-fs-small);
    color: var(--av-text-1);
    background: var(--av-bg);
    border: 1px solid var(--av-line-strong);
    border-radius: var(--av-radius-control);
    padding: 0.5rem 0.75rem;
    min-height: var(--av-control-h);
    transition: border-color var(--av-dur-fast) var(--av-ease-out), background-color var(--av-dur-fast) var(--av-ease-out);
}

:where(input, select, textarea):hover {
    border-color: var(--av-line-hover);
}

:where(input, select, textarea):focus {
    outline: none;
    border-color: var(--av-text-2);
}

:where(input, select, textarea):focus-visible {
    outline: var(--av-focus-ring);
    outline-offset: 1px;
}

:where(input, textarea)::placeholder {
    color: var(--av-text-3);
    opacity: 1;
}

:where(input, select, textarea):disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

:where(input[type="checkbox"], input[type="radio"], input[type="range"]) {
    min-height: 0;
    padding: 0;
    accent-color: var(--av-text-1);
}

:where(input[type="range"]) {
    background: transparent;
    border: 0;
}

:where(textarea) {
    line-height: 1.55;
    resize: vertical;
}

:where(select) {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2385827C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    padding-right: 2rem;
    cursor: pointer;
}

:where(select option) {
    background: var(--av-surface-1);
    color: var(--av-text-1);
}

:where(button) {
    font-family: inherit;
    color: inherit;
}

/* --- Buttons ---
   .cyber-button       → primary (paper-white fill; one per view)
   .cyber-button-small → secondary (hairline outline)
   .btn-danger         → destructive (clay outline, never filled red)       */
.cyber-button,
.cyber-button-small,
.av-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--av-space-2);
    min-height: var(--av-control-h);
    padding: 0 14px;
    border-radius: var(--av-radius-control);
    font-family: inherit;
    font-size: var(--av-fs-small);
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--av-dur-fast) var(--av-ease-out),
        border-color var(--av-dur-fast) var(--av-ease-out),
        color var(--av-dur-fast) var(--av-ease-out);
}

.cyber-button {
    background: var(--av-text-1);
    border: 1px solid var(--av-text-1);
    color: var(--av-on-paper);
    font-weight: 600;
    padding: 0 16px;
}

.cyber-button:hover {
    background: #FFFFFF;
    border-color: #FFFFFF;
    color: var(--av-on-paper);
}

.cyber-button-small,
.av-btn {
    background: transparent;
    border: 1px solid var(--av-line-strong);
    color: var(--av-text-1);
}

.cyber-button-small:hover,
.av-btn:hover {
    background: var(--av-surface-2);
    border-color: var(--av-line-hover);
    color: var(--av-text-1);
}

.cyber-button:disabled,
.cyber-button-small:disabled,
.av-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-danger,
.cyber-button-small.btn-danger,
.cyber-button.btn-danger {
    background: transparent;
    border-color: var(--av-danger-line);
    color: var(--av-danger);
}

.btn-danger:hover,
.cyber-button-small.btn-danger:hover,
.cyber-button.btn-danger:hover {
    background: var(--av-danger-fill);
    border-color: var(--av-danger);
    color: var(--av-danger);
}

/* --- Page titles --- */
.section-title {
    font-family: var(--av-font-serif);
    font-size: var(--av-fs-display-xl);
    font-weight: 400;
    line-height: 1.07;
    letter-spacing: -0.015em;
    color: var(--av-text-1);
    margin-bottom: var(--av-space-1);
}

.section-title .title-icon {
    display: none;
}

.section-subtitle {
    color: var(--av-text-2);
    font-size: var(--av-fs-small);
}

/* --- Forms (auth, profile) --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--av-space-2);
    margin-bottom: var(--av-space-5);
}

.form-group label {
    font-family: var(--av-font-mono);
    font-size: var(--av-fs-label);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--av-text-3);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    min-height: var(--av-touch);
    font-size: var(--av-fs-body);
}

.form-group textarea {
    min-height: 120px;
}

/* --- Loading --- */
.loading-spinner,
.loading-spinner-small {
    border-radius: 50%;
    border-style: solid;
    border-color: var(--av-track);
    border-top-color: var(--av-text-1);
    animation: av-spin 0.9s linear infinite;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border-width: 2px;
    margin: 0 auto var(--av-space-4);
}

.loading-spinner-small {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

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

/* Kept for legacy stylesheets that still reference it */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Framework error bar --- */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: var(--av-space-3) var(--av-space-5);
    background: var(--av-surface-2);
    border-top: 1px solid var(--av-danger-line);
    color: var(--av-text-1);
    font-size: var(--av-fs-small);
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: var(--av-space-4);
    top: var(--av-space-3);
}

/* --- Boot screen (static markup in index.html, replaced by Blazor) --- */
.av-boot {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--av-space-4);
    color: var(--av-text-3);
    font-size: var(--av-fs-small);
}

/* --- Reduced motion: keep state changes, drop movement --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .loading-spinner,
    .loading-spinner-small {
        animation-duration: 1.6s !important;
        animation-iteration-count: infinite !important;
    }
}
