html { scroll-behavior: smooth; }

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

body {
    font-family: 'Google Sans', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
}

/* ── Filled form fields: no borders, tonal fill that never blends into the card behind ── */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):not([type="color"]):not(.rp-search input),
select, textarea {
    background-color: var(--md-sys-color-surface-container-highest) !important;
    border-color: transparent !important;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: inset 0 -2px 0 var(--md-sys-color-primary); }
select option { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface); }

/* ── M3 type-role classes ───────────────────────────────────────────────── */
.m3-display-sm { font: var(--md-sys-typescale-display-small); }
.m3-headline-lg { font: var(--md-sys-typescale-headline-large); }
.m3-headline-md { font: var(--md-sys-typescale-headline-medium); }
.m3-headline-sm { font: var(--md-sys-typescale-headline-small); }
.m3-title-lg { font: var(--md-sys-typescale-title-large); }
.m3-title-md { font: var(--md-sys-typescale-title-medium); }
.m3-title-sm { font: var(--md-sys-typescale-title-small); }
.m3-body-lg { font: var(--md-sys-typescale-body-large); }
.m3-body-md { font: var(--md-sys-typescale-body-medium); }
.m3-body-sm { font: var(--md-sys-typescale-body-small); }
.m3-label-lg { font: var(--md-sys-typescale-label-large); }
.m3-label-md { font: var(--md-sys-typescale-label-medium); }
.m3-label-sm { font: var(--md-sys-typescale-label-small); }
/* Status chips */
.m3-border-danger { border-color: color-mix(in srgb, var(--app-danger) 30%, transparent); }
.m3-bg-success { background: var(--app-success); }
.m3-bg-warning { background: var(--app-warning); }
.m3-bg-danger { background: var(--app-danger); }
.m3-btn-danger-soft { background: var(--app-danger-container); color: var(--app-danger); }
.m3-btn-danger-soft:hover { background: var(--app-danger); color: var(--md-sys-color-on-error); }
.m3-status-success { background: var(--app-success-container); color: var(--app-success); }
.m3-status-warning { background: var(--app-warning-container); color: var(--app-warning); }
.m3-status-info { background: var(--app-info-container); color: var(--app-info); }
.m3-status-danger { background: var(--app-danger-container); color: var(--app-danger); }
/* htmx: dim a swapping region, show indicators only in flight */
.htmx-request { opacity: .6; transition: opacity var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard); }

/* ── M3 chip / text field / dialog primitives (use on new markup; migrate old per-page styles onto these) ── */
.m3-chip {
    display: inline-flex; align-items: center; gap: 0.5rem; min-height: 32px; padding: 0 0.75rem;
    border: 1px solid transparent; border-radius: var(--md-sys-shape-corner-small);
    background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-large); cursor: pointer;
    transition: background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-chip:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface-variant) calc(var(--md-sys-state-hover) * 100%), transparent); }
.m3-chip[aria-pressed="true"], .m3-chip.selected {
    background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); border-color: transparent;
}
.m3-textfield {
    width: 100%; min-height: 48px; padding: 0.75rem 1rem; font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface); background: var(--md-sys-color-surface-container-highest);
    border: 1px solid transparent; border-radius: var(--md-sys-shape-corner-extra-small);
}
.m3-textfield:focus { outline: 2px solid var(--md-sys-color-primary); outline-offset: -1px; border-color: var(--md-sys-color-primary); }
.m3-textfield::placeholder { color: var(--md-sys-color-on-surface-variant); }
.m3-textfield[aria-invalid="true"] { border-color: var(--md-sys-color-error); }
.m3-textfield[readonly] { background: var(--md-sys-color-surface-container-high); cursor: default; }
.m3-dialog {
    background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface);
    border-radius: var(--md-sys-shape-corner-extra-large); padding: 1.5rem; max-width: 35rem; width: calc(100% - 2rem);
    box-shadow: var(--md-sys-elevation-3);
}
.m3-dialog-title { font: var(--md-sys-typescale-headline-small); margin: 0 0 1rem; }

/* ── Poster card grid + card (same design as the media library cards) ── */
.m3-poster-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (min-width: 640px)  { .m3-poster-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; } }
@media (min-width: 1024px) { .m3-poster-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .m3-poster-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1536px) { .m3-poster-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.m3-poster-card {
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--md-sys-color-surface-container-low); border: 1px solid transparent;
    border-radius: var(--md-sys-shape-corner-extra-large);
    transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
                border-color var(--md-sys-motion-duration-short4), box-shadow var(--md-sys-motion-duration-short4);
}
.m3-poster-card:hover, .m3-poster-card:focus-visible {
    transform: translateY(-4px); box-shadow: var(--md-sys-elevation-2);
}
.m3-poster { position: relative; overflow: hidden; aspect-ratio: 2 / 3; background: var(--md-sys-color-surface-container-highest); }
.m3-poster img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 300ms var(--md-sys-motion-easing-standard); }
.m3-poster-card:hover .m3-poster img { transform: scale(1.05); }
.m3-poster::after {
    content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 300ms;
    background: linear-gradient(to top, rgba(0,0,0,.8), rgba(0,0,0,.1), transparent);
}
.m3-poster-card:hover .m3-poster::after { opacity: 1; }
.m3-poster .noimg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--md-sys-color-on-surface-variant); }
/* Pills over posters sit on a scrim, so white text is intentional */
.m3-poster-pill {
    position: absolute; z-index: 1; display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.625rem;
    border-radius: var(--md-sys-shape-corner-full); background: rgba(0,0,0,.6); color: #fff; font: var(--md-sys-typescale-label-small); font-weight: 700;
}
.m3-poster-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.m3-poster-title {
    font-weight: 700; font-size: 0.875rem; line-height: 1.25rem; color: var(--md-sys-color-on-surface);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5rem;
}
@media (min-width: 640px) { .m3-poster-title { font-size: 1rem; line-height: 1.5rem; min-height: 3rem; } }
.m3-poster-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.75rem; color: var(--md-sys-color-on-surface-variant); }
.m3-poster-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0 1rem 1rem; margin-top: auto; }

/* ── M3 Unified Component Utilities ─────────────────────────────────────── */
/* M3 Buttons */
.m3-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    min-width: 64px;
    padding: 0 1.5rem;
    border-radius: var(--md-sys-shape-corner-full);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    text-decoration: none;
    position: relative;
    cursor: pointer;
    border: none;
    transition: background-color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
                box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
                color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
    user-select: none;
    white-space: nowrap;
}
.m3-btn::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    transition: opacity var(--md-sys-motion-duration-short2) linear;
    pointer-events: none;
}
.m3-btn:hover::before { opacity: var(--md-sys-state-hover); }
.m3-btn:focus-visible::before { opacity: var(--md-sys-state-focus); }
.m3-btn:active::before { opacity: var(--md-sys-state-pressed); }
.m3-btn:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }

.m3-btn-filled {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--md-sys-elevation-0);
}
.m3-btn-filled:hover { box-shadow: var(--md-sys-elevation-1); }

.m3-btn-tonal {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    box-shadow: var(--md-sys-elevation-0);
}
.m3-btn-tonal:hover { box-shadow: var(--md-sys-elevation-1); }

.m3-btn-elevated {
    background: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-primary);
    box-shadow: var(--md-sys-elevation-1);
}
.m3-btn-elevated:hover { box-shadow: var(--md-sys-elevation-2); }

.m3-btn-outlined {
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-primary);
    border: 1px solid transparent;
}
.m3-btn-outlined:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }

.m3-btn-text {
    background: transparent;
    color: var(--md-sys-color-primary);
    padding: 0 0.75rem;
}
.m3-btn-text:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }

/* Backward-compatible button mappings */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 1.5rem;
    border-radius: var(--md-sys-shape-corner-full);
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    font-weight: 500;
    font-size: 0.875rem;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s ease, filter 0.15s ease;
    box-shadow: var(--md-sys-elevation-0);
}
.btn-primary:hover { box-shadow: var(--md-sys-elevation-1); filter: brightness(1.04); }
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 1.25rem;
    border-radius: var(--md-sys-shape-corner-full);
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    font-weight: 500;
    font-size: 0.875rem;
    border: none;
    transition: background-color 0.2s ease;
}
.btn-ghost:hover { background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 12%, var(--md-sys-color-secondary-container)); }

/* M3 Cards */
.m3-card {
    border-radius: var(--md-sys-shape-corner-medium);
    padding: 1rem;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-card-elevated {
    background: var(--md-sys-color-surface-container-low);
    box-shadow: var(--md-sys-elevation-1);
    border: none;
}
.m3-card-elevated:hover { box-shadow: var(--md-sys-elevation-2); }
.m3-card-filled {
    background: var(--md-sys-color-surface-container-highest);
    border: none;
}
.m3-card-outlined {
    background: var(--md-sys-color-surface);
    border: 1px solid transparent;
}

/* Backward-compatible card mappings */
.glass-panel, .surface-card {
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid transparent;
    box-shadow: var(--md-sys-elevation-1);
    border-radius: var(--md-sys-shape-corner-medium);
}
.glass-pill { border-radius: var(--md-sys-shape-corner-full); }

/* M3 Text Fields */
.m3-textfield, .field {
    width: 100%;
    background: var(--md-sys-color-surface-container-lowest);
    color: var(--md-sys-color-on-surface);
    border: 1px solid transparent;
    border-radius: var(--md-sys-shape-corner-small);
    padding: 0.65rem 1rem;
    font-size: 0.875rem;
    transition: border-color var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
                box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.m3-textfield:focus, .field:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

/* M3 Chips */
.m3-chip, .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 32px;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0 0.75rem;
    border-radius: var(--md-sys-shape-corner-small);
    background: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-on-surface);
    border: 1px solid transparent;
}

/* M3 Switches */
.m3-switch {
    display: inline-flex;
    align-items: center;
    position: relative;
    cursor: pointer;
}
.m3-switch-input { position: absolute; opacity: 0; width: 0; height: 0; }
.m3-switch-track {
    width: 52px;
    height: 32px;
    border-radius: var(--md-sys-shape-corner-full);
    background: var(--md-sys-color-surface-container-highest);
    border: 1px solid transparent;
    position: relative;
    transition: background-color var(--md-sys-motion-duration-short4), border-color var(--md-sys-motion-duration-short4);
}
.m3-switch-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--md-sys-color-outline);
    position: absolute;
    top: 6px;
    left: 6px;
    transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized),
                width var(--md-sys-motion-duration-short4),
                height var(--md-sys-motion-duration-short4),
                background-color var(--md-sys-motion-duration-short4);
}
.m3-switch-input:checked + .m3-switch-track {
    background: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}
.m3-switch-input:checked + .m3-switch-track .m3-switch-thumb {
    transform: translateX(20px);
    width: 24px;
    height: 24px;
    top: 2px;
    left: 4px;
    background: var(--md-sys-color-on-primary);
}

.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
::selection { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }

* { scrollbar-width: thin; scrollbar-color: var(--md-sys-color-outline-variant) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline-variant); border-radius: var(--md-sys-shape-corner-full); }
*::-webkit-scrollbar-thumb:hover { background: var(--md-sys-color-outline); }
