/**
 * Sonic HQ — Modern UI Layer
 *
 * Loaded after style.css. A non-destructive enhancement pass that keeps
 * the Sonic Mania palette (gold field, cream cards, classic blue/red)
 * but brings the depth, motion, and detail work up to date:
 * layered shadows, a consistent radius scale, springy hover states,
 * visible keyboard focus, and reduced-motion support.
 */

:root {
    /* Radius scale */
    --shq-radius-sm: 8px;
    --shq-radius: 14px;
    --shq-radius-lg: 20px;
    --shq-radius-pill: 999px;

    /* Layered shadows (soft ambient + tighter key light) */
    --shq-shadow-sm: 0 1px 2px rgba(7, 27, 73, 0.10), 0 2px 8px rgba(7, 27, 73, 0.08);
    --shq-shadow: 0 2px 4px rgba(7, 27, 73, 0.10), 0 10px 24px rgba(7, 27, 73, 0.12);
    --shq-shadow-lg: 0 4px 8px rgba(7, 27, 73, 0.12), 0 20px 44px rgba(7, 27, 73, 0.18);

    /* Motion */
    --shq-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --shq-ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    --shq-speed: 200ms;

    /* Accent helpers derived from the Mania palette */
    --shq-ink: #122a5c;
    --shq-blue-deep: #2f447f;
    --shq-focus-ring: 0 0 0 3px rgba(56, 92, 174, 0.45);
}

/* ---------------------------------------------------------------------
 * Base polish
 * ------------------------------------------------------------------- */

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

body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--mania-blue, #385cae);
    color: #fff;
}

/* Visible, consistent keyboard focus everywhere */
:focus-visible {
    outline: none;
    box-shadow: var(--shq-focus-ring);
    border-radius: var(--shq-radius-sm);
}

/* Slim, on-palette scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--mania-blue, #385cae) transparent;
}

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

*::-webkit-scrollbar-thumb {
    background: var(--mania-blue, #385cae);
    border-radius: var(--shq-radius-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}

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

/* ---------------------------------------------------------------------
 * Typography rhythm
 * ------------------------------------------------------------------- */

h1, h2, h3, h4 {
    text-wrap: balance;
    letter-spacing: -0.01em;
}

p {
    text-wrap: pretty;
}

.dmbs-post-content,
.card-body {
    line-height: 1.65;
}

/* ---------------------------------------------------------------------
 * Cards: softer depth + lift on hover
 * ------------------------------------------------------------------- */

.card,
.box {
    border-radius: var(--shq-radius);
    box-shadow: var(--shq-shadow-sm);
    transition:
        transform var(--shq-speed) var(--shq-ease),
        box-shadow var(--shq-speed) var(--shq-ease);
}

/* Only lift cards that act as links/teasers, not long-form articles */
.article-grid .card:hover,
.dmbs-widget .card:hover,
.youtube-video-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shq-shadow);
}

.card img,
.dmbs-post-featured-image img {
    border-radius: calc(var(--shq-radius) - 6px);
}

.dmbs-post-featured-image {
    overflow: hidden;
}

.dmbs-post-featured-image img {
    transition: transform 400ms var(--shq-ease);
    display: block;
    width: 100%;
}

a:hover .dmbs-post-featured-image img {
    transform: scale(1.025);
}

/* ---------------------------------------------------------------------
 * Buttons & badges
 * ------------------------------------------------------------------- */

.btn,
.btn-primary,
button.search-submit {
    border-radius: var(--shq-radius-pill);
    font-weight: 700;
    letter-spacing: 0.01em;
    transition:
        transform 150ms var(--shq-ease-spring),
        box-shadow var(--shq-speed) var(--shq-ease),
        background-color var(--shq-speed) var(--shq-ease);
}

.btn-primary {
    background-image: linear-gradient(180deg, var(--mania-blue, #385cae), var(--shq-blue-deep));
    border: none;
    box-shadow: var(--shq-shadow-sm);
}

.btn:hover,
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shq-shadow);
}

.btn:active,
.btn-primary:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shq-shadow-sm);
}

.badge {
    border-radius: var(--shq-radius-pill);
    padding: 0.35em 0.9em;
    font-weight: 700;
}

/* ---------------------------------------------------------------------
 * Navigation: frosted sticky bar
 * ------------------------------------------------------------------- */

.main-menu .menu-section {
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
}

.main-menu .navigation a,
.social-menu a {
    transition:
        color var(--shq-speed) var(--shq-ease),
        transform 150ms var(--shq-ease-spring);
    display: inline-block;
}

.social-menu a:hover {
    transform: translateY(-2px);
}

/* ---------------------------------------------------------------------
 * Content links: animated underline
 * ------------------------------------------------------------------- */

.dmbs-post-content a:not(.btn),
.card-body a:not(.btn) {
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--mania-blue, #385cae) 35%, transparent);
    text-underline-offset: 3px;
    text-decoration-thickness: 2px;
    transition: text-decoration-color var(--shq-speed) var(--shq-ease);
}

.dmbs-post-content a:not(.btn):hover,
.card-body a:not(.btn):hover {
    text-decoration-color: var(--mania-red, #e23f2c);
}

/* ---------------------------------------------------------------------
 * Forms & inputs
 * ------------------------------------------------------------------- */

input[type="text"],
input[type="search"],
input[type="email"],
input[type="url"],
textarea,
select {
    border-radius: var(--shq-radius-sm);
    border: 2px solid rgba(7, 27, 73, 0.15);
    transition: border-color var(--shq-speed) var(--shq-ease), box-shadow var(--shq-speed) var(--shq-ease);
}

input[type="text"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    border-color: var(--mania-blue, #385cae);
    box-shadow: var(--shq-focus-ring);
    outline: none;
}

/* ---------------------------------------------------------------------
 * Media
 * ------------------------------------------------------------------- */

audio {
    border-radius: var(--shq-radius-pill);
    box-shadow: var(--shq-shadow-sm);
    width: 100%;
}

iframe {
    border: 0;
}

/* ---------------------------------------------------------------------
 * Pagination
 * ------------------------------------------------------------------- */

.pagination .page-numbers,
.nav-links .page-numbers {
    border-radius: var(--shq-radius-pill);
    transition: background-color var(--shq-speed) var(--shq-ease), color var(--shq-speed) var(--shq-ease);
}

/* ---------------------------------------------------------------------
 * YouTube feed (styles moved out of inline PHP attributes)
 * ------------------------------------------------------------------- */

.custom-youtube-feed-error {
    color: #b3261e;
    padding: 12px 16px;
    border: 1px solid #f3c1bd;
    background: #fce8e6;
    border-radius: var(--shq-radius-sm);
}

.youtube-playlist-section {
    margin-bottom: 40px;
}

.youtube-video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.youtube-video-item {
    border-radius: var(--shq-radius);
    overflow: hidden;
    transition: transform var(--shq-speed) var(--shq-ease), box-shadow var(--shq-speed) var(--shq-ease);
}

.youtube-video-embed {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: var(--shq-radius-sm);
}

.youtube-video-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.youtube-video-title {
    margin-top: 8px;
    font-size: 14px;
    font-weight: 600;
}

/* ---------------------------------------------------------------------
 * Footer
 * ------------------------------------------------------------------- */

.main-footer {
    margin-top: 3rem;
}

.main-footer a {
    transition: color var(--shq-speed) var(--shq-ease);
}

/* ---------------------------------------------------------------------
 * Accessibility: respect reduced-motion preferences
 * ------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* =====================================================================
 * v10.1 — CUTTING-EDGE LAYER
 *
 * Progressive enhancements using new CSS platform features. Every
 * block is guarded with @supports (or is inert when unsupported),
 * so older browsers simply keep the v10 look.
 * =================================================================== */

/* ---------------------------------------------------------------------
 * 1. View Transitions — app-like crossfade between page loads
 *    (Chrome/Edge 126+, Safari 18+. One rule, huge perceived upgrade.)
 * ------------------------------------------------------------------- */

@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: shq-vt-out 180ms var(--shq-ease) both;
}

::view-transition-new(root) {
    animation: shq-vt-in 240ms var(--shq-ease) both;
}

@keyframes shq-vt-out {
    to { opacity: 0; transform: translateY(-6px); }
}

@keyframes shq-vt-in {
    from { opacity: 0; transform: translateY(10px); }
}

/* ---------------------------------------------------------------------
 * 2. Scroll-driven animations — cards rise in as they enter the
 *    viewport, driven by scroll position (no JS, no observers).
 * ------------------------------------------------------------------- */

@supports (animation-timeline: view()) {
    .dmbs-main .card,
    .article-grid .card,
    .youtube-video-item {
        animation: shq-rise-in linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 38%;
    }
}

@keyframes shq-rise-in {
    from {
        opacity: 0;
        transform: translateY(28px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Frosted nav gains a shadow only once the page is actually scrolled */
@supports (animation-timeline: scroll()) {
    .main-menu.menu-desktop .menu-section {
        animation: shq-nav-elevate linear both;
        animation-timeline: scroll();
        animation-range: 0 120px;
    }
}

@keyframes shq-nav-elevate {
    from { box-shadow: none; }
    to   { box-shadow: 0 8px 30px rgba(7, 27, 73, 0.25); }
}

/* ---------------------------------------------------------------------
 * 3. Spinning conic-gradient border on hover — the "ring" treatment.
 *    Uses registered @property for buttery rotation.
 * ------------------------------------------------------------------- */

@property --shq-ring-angle {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}

@supports (background: conic-gradient(from 1deg, red, blue)) {
    .article-grid .card,
    .youtube-video-item {
        position: relative;
        background-clip: padding-box;
    }

    .article-grid .card::before,
    .youtube-video-item::before {
        content: "";
        position: absolute;
        inset: -2px;
        z-index: -1;
        border-radius: inherit;
        background: conic-gradient(
            from var(--shq-ring-angle),
            var(--mania-blue, #385cae),
            var(--mania-gold, #f2f200),
            var(--mania-red, #e23f2c),
            var(--mania-blue, #385cae)
        );
        opacity: 0;
        transition: opacity var(--shq-speed) var(--shq-ease);
    }

    .article-grid .card:hover::before,
    .youtube-video-item:hover::before {
        opacity: 1;
        animation: shq-ring-spin 3s linear infinite;
    }
}

@keyframes shq-ring-spin {
    to { --shq-ring-angle: 360deg; }
}

/* ---------------------------------------------------------------------
 * 4. Speed-line signature — Sonic's motion streaks.
 *    a) A shine sweep across primary buttons on hover.
 *    b) A three-streak underline that dashes in under post titles.
 * ------------------------------------------------------------------- */

.btn-primary {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

.btn-primary::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(
        105deg,
        transparent 38%,
        rgba(255, 255, 255, 0.45) 50%,
        transparent 62%
    );
    transform: translateX(-120%) skewX(-12deg);
    transition: transform 480ms var(--shq-ease);
}

.btn-primary:hover::after {
    transform: translateX(120%) skewX(-12deg);
}

.blue-box .dmbs-post-title {
    position: relative;
}

.blue-box .dmbs-post-title::after {
    content: "";
    display: block;
    margin-top: 6px;
    height: 4px;
    width: 72px;
    border-radius: var(--shq-radius-pill);
    background:
        linear-gradient(90deg, var(--mania-gold, #f2f200) 0 36px, transparent 36px 44px,
            var(--mania-gold, #f2f200) 44px 60px, transparent 60px 64px,
            var(--mania-gold, #f2f200) 64px 72px);
    transform-origin: left;
    animation: shq-streak-in 500ms var(--shq-ease-spring) both;
}

@keyframes shq-streak-in {
    from { transform: scaleX(0); opacity: 0; }
    to   { transform: scaleX(1); opacity: 1; }
}

/* ---------------------------------------------------------------------
 * 5. Blue header boxes — aurora depth instead of flat fill
 * ------------------------------------------------------------------- */

.blue-box {
    background-image:
        radial-gradient(120% 160% at 0% 0%, rgba(107, 203, 176, 0.35), transparent 55%),
        radial-gradient(140% 180% at 100% 100%, rgba(47, 68, 127, 0.9), transparent 60%),
        linear-gradient(135deg, var(--mania-blue, #385cae), var(--shq-blue-deep, #2f447f));
}

/* ---------------------------------------------------------------------
 * 6. Type with presence — fluid, tighter display headings
 * ------------------------------------------------------------------- */

.dmbs-post-title {
    font-family: "Exo 2", "Open Sans", sans-serif;
    font-weight: 800;
    font-size: clamp(1.35rem, 1.05rem + 1.4vw, 2.1rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.widgettitle {
    font-family: "Exo 2", "Open Sans", sans-serif;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ---------------------------------------------------------------------
 * 7. Interaction details
 * ------------------------------------------------------------------- */

/* Springy icon pop in the social/nav strip */
.social-menu a:active {
    transform: translateY(0) scale(0.9);
}

/* Smooth caret + accent color on native form controls */
:root {
    accent-color: var(--mania-blue, #385cae);
    caret-color: var(--mania-red, #e23f2c);
}

/* Audio players pick up the lift treatment */
audio:hover {
    box-shadow: var(--shq-shadow);
}

/* Tap highlight cleanup on mobile */
a, button {
    -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------------
 * 8. Reduced motion — disable the new motion layers too
 * ------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation: none !important;
    }

    .dmbs-main .card,
    .article-grid .card,
    .youtube-video-item,
    .blue-box .dmbs-post-title::after {
        animation: none !important;
    }

    .article-grid .card:hover::before,
    .youtube-video-item:hover::before {
        animation: none !important;
    }
}

/* ---------------------------------------------------------------------
 * 9. Shared-element transition: featured image card → article hero
 *
 * Each article teaser header (the blue box with the featured image
 * background) and the featured image on the single post carry the
 * same unique view-transition-name (shq-featured-{post ID}), set in
 * single-article-data*.php and single.php. When you click through,
 * the browser morphs the teaser into the full-width hero — position,
 * size, and corner radius are interpolated automatically.
 *
 * All shared groups are tagged with view-transition-class:
 * shq-featured so they can be styled here in one place.
 * ------------------------------------------------------------------- */

/* The moving group: a touch longer than the root crossfade,
   with a smooth glide rather than the default linear feel. */
::view-transition-group(.shq-featured) {
    animation-duration: 420ms;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 5; /* ride above the root fade */
}

/* Let the snapshots fill the morphing box without distortion as the
   aspect ratio changes between the short card and the tall hero. */
::view-transition-image-pair(.shq-featured) {
    isolation: isolate;
    overflow: hidden;
    border-radius: var(--shq-radius-sm);
}

::view-transition-old(.shq-featured),
::view-transition-new(.shq-featured) {
    height: 100%;
    width: 100%;
    object-fit: cover;
    animation-duration: 420ms;
}

/* While morphing, hold the root layers steady a little longer so the
   image is clearly the star of the navigation. */
::view-transition-old(root),
::view-transition-new(root) {
    animation-delay: 40ms;
}

/* Reduced motion: snap instead of morph. */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(.shq-featured),
    ::view-transition-old(.shq-featured),
    ::view-transition-new(.shq-featured) {
        animation: none !important;
    }
}

/* ---------------------------------------------------------------------
 * 10. Seamless jagged edge
 *
 * The old .jagged effect appended a flat-blue image strip (:after)
 * below the box. Now that the title boxes carry a gradient, the
 * strip's solid color no longer matches the box's bottom edge and a
 * seam shows. Instead, a conic-gradient mask carves the zigzag teeth
 * out of the box's own background — the teeth ARE the gradient, so
 * there is nothing to mismatch. The featured image is tucked up
 * underneath so the teeth interlock directly with the artwork.
 *
 * Scoped to title boxes (:not(.has-featured)); teaser cards that use
 * the featured image as the box background keep the original strip.
 * ------------------------------------------------------------------- */

@supports (mask: conic-gradient(from 1deg at 50% 100%, red 1deg, blue 90deg)) {
    .blue-box.jagged:not(.has-featured) {
        /* tooth geometry: 28px wide, 14px tall (matches the old strip) */
        --shq-jag-w: 28px;
        --shq-jag-h: 14px;

        padding-bottom: calc(12px + var(--shq-jag-h)) !important;
        -webkit-mask:
            conic-gradient(from -45deg at 50% 100%, #0000, #000 1deg 89deg, #0000 90deg)
            50% / var(--shq-jag-w) 100%;
        mask:
            conic-gradient(from -45deg at 50% 100%, #0000, #000 1deg 89deg, #0000 90deg)
            50% / var(--shq-jag-w) 100%;
    }

    /* Retire the old image strip — the mask replaces it */
    .blue-box.jagged:not(.has-featured)::after {
        display: none;
    }

    /* Pull the hero up under the teeth so they interlock with the
       artwork instead of leaving a band of card background. */
    .blue-box.jagged:not(.has-featured) + .dmbs-post-featured-image,
    .blue-box.jagged:not(.has-featured) + .negative-margin {
        margin-top: calc(-10px - var(--shq-jag-h)) !important;
        position: relative;
        z-index: 0; /* stays beneath the title box (z-index: 1) */
    }
}
