/* ===================================================================
   --- BASE STYLES ---
   Resetting margins and applying your global theme variables.
=================================================================== */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: auto !important;
    scrollbar-color: auto !important;
}

html {
    scroll-padding-top: 150px; 
    scroll-behavior: smooth; 
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: var(--line-height-body);
    padding-inline: var(--space-xxl);
    padding-block-end: var(--space-xxl);
    margin-inline: 5rem;
}

/* ===================================================================
   --- TYPOGRAPHY & HEADER ---
=================================================================== */

header {
    text-align: center;
    padding-block: var(--space-xl);
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: color-mix(in srgb, var(--bg-base) 75%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-block-end: 1px solid var(--border-subtle);
    margin-inline: calc(var(--space-xxl) * -1);
}

header h1 {
    color: var(--accent-main);
    letter-spacing: var(--letter-spacing-wide);
    line-height: var(--line-height-heading);
    font-size: var(--font-size-xxl);
}

main {
    display: flex;
    flex-direction: column;
    margin-block: var(--space-xl);
}

footer {
    text-align: center;
}

.theme-picker {
    display: flex;
    gap: var(--space-xl);
    align-items: center;
    justify-content: center;
    margin-block-start: var(--space-m);
}

.section-header {
    color: var(--text-primary);
    font-size: var(--font-size-xxl);
    border-block-end: 2px solid var(--border-subtle);
    padding-block-end: var(--space-s);
    margin-block-start: var(--space-xxl);
    margin-block-end: var(--space-xl);
}

header, footer, .theme-picker {
    flex-shrink: 0;
}

.changelog-details,
.readme-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-l);
    padding: var(--space-l);
}

/* ===================================================================
   --- LAYOUT: MODULE GRID ---
   A responsive grid that automatically wraps cards on smaller screens.
=================================================================== */

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-xl);
    margin-block-end: var(--space-xl);
}

.card-actions {
    display: flex;
    gap: var(--space-s);
    align-items: center;
    justify-content: space-between;
}

/* ===================================================================
   --- COMPONENTS: MODULE CARD ---
=================================================================== */

.module-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-large);
    padding: var(--space-xl);
    box-shadow: var(--shadow-popout);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;

    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    gap: 0;
}

/* Interactive hover state */
.module-card:hover {
    box-shadow: var(--shadow-window);
    border-color: var(--border-focus);
}

.module-card h2 {
    color: var(--accent-hover);
    margin-block-end: var(--space-s);
    line-height: var(--line-height-heading);
    font-size: var(--font-size-xl);
}

/* The version number inside the card title */
.module-card h2 span {
    font-size: var(--font-size-s);
    color: var(--text-muted);
    font-weight: normal;
}

.module-card p {
    margin-block-end: var(--space-xl);
    color: var(--text-secondary);
}

.module-card p strong {
    color: var(--text-primary);
}

/* ===================================================================
   --- COMPONENTS: ICONS ---
=================================================================== */
.icon {
    display: inline-block;
    width: var(--font-size-l); 
    height: var(--font-size-l);
    min-width: var(--font-size-l);
    background-color: currentColor;
    background-image: none;
    content: "";
    transform: scaleX(var(--dir-flip));
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-image: var(--mask);
    mask-image: var(--mask);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    margin: 0;
}

.icon.globe                { --mask: url('/assets/globe.svg'); }
.icon.home                 { --mask: url('/assets/home.svg'); }
.icon.book                 { --mask: url('/assets/book.svg'); }
.icon.close                { --mask: url('/assets/close.svg'); }

/* ===================================================================
   --- COMPONENTS: BUTTONS ---
=================================================================== */

.btn {
    background-color: var(--accent-main);
    color: var(--text-inverse);
    border-radius: var( --radius-large);
    border: 1px solid var(--border-main);
    padding: var(--space-s) var(--space-l);
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-icon,
.btn-home {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-main);
    border-radius: var(--radius-large);
    padding: var(--space-s);
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-panel);
    color: var(--text-primary);
}

header .btn-home {
    position: absolute;
    left: var(--space-xxl);
    top: var(--space-xl);
    background-color: var(--accent-main);
    color: var(--text-inverse);
}

.btn-icon:hover {
    border-color: var(--border-focus);
    color: var(--accent-hover);
    box-shadow: var(--shadow-focus);
}

.btn:hover,
.btn-home:hover {
    background-color: var(--accent-hover);
    color: var(--text-inverse);
    box-shadow: var(--shadow-focus);
}

/* ===================================================================
   --- COMPONENTS: SELECT ---
=================================================================== */

select {
    background: var(--bg-panel);
    border: 1px solid var(--border-main);
    color: var(--text-primary);
    border-radius: var(--radius-small);
    min-height: var(--font-size-xl);
    padding: var(--space-s) var(--space-l);
    text-overflow: ellipsis;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}

select,
select::picker(select) {
    appearance: base-select;
}

select::picker(select) {
    position-area: top;
    margin-block-end: var(--space-xs);
    border: 1px solid var(--border-focus);

    scrollbar-width: thin;
    scrollbar-color: var(--accent-main) var(--bg-base);
}

option {
    background: var(--bg-panel);
    color: var(--text-primary);
    padding: var(--space-s) var(--space-m);
}

option:hover,
option:focus {
    background: var(--accent-hover);
    color: var(--text-inverse);
    outline: none;
}

optgroup {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-weight: bold;
    font-style: italic;
    padding-block: 3px 1px;
}

select:disabled {
    background: var(--bg-panel);
    border-color: var(--border-main);
    color: var(--text-muted);
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===================================================================
   --- COMPONENTS: FIELDSET ---
=================================================================== */

fieldset {
    background-color: var(--bg-panel);
    border: 2px solid var(--border-main);
    border-radius: var(--radius-medium);
    box-shadow: var(--shadow-popout);
    padding: var(--space-l);
    margin-block-end: var(--space-l);
    gap: var(--space-xs);
    display: flex;
    flex-direction: column;
}

fieldset legend {
    font-weight: bold;
    color: var(--accent-main);
    padding-inline: var(--space-xs);
    font-size: var(--font-size-l);
}

/* ===================================================================
   --- COMPONENTS: DETAIL / SUMMARY ---
=================================================================== */

details {
    border: 1px solid var(--border-main);
    border-radius: var(--radius-small);
    margin-block-end: var(--space-s);
    background: var(--bg-panel);
    transition: background-color 0.2s;
}

details[open] {
    background: var(--bg-panel);
}

summary {
    padding: var(--space-s) var(--space-m);
    font-weight: bold;
    background: var(--bg-panel);
    color: var(--accent-main);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    user-select: none;
}

summary::before {
    content: "▶";
    display: inline-block;
    margin-inline-end: var(--space-s);
    font-size: var(--font-size-xs);
    transition: transform 0.2s ease;
    color: var(--text-primary);
}

details[open] summary::before {
    transform: rotate(90deg);
    color: var(--accent-main);
}

/* Hide the default webkit arrow */
summary::-webkit-details-marker {
    display: none;
}

/* ===================================================================
   --- COMPONENTS: LISTS ---
=================================================================== */

ol,
ul {
    padding-inline-start: var(--space-xxl);
}

/* ===================================================================
   --- COMPONENTS: LINKS ---
=================================================================== */

a {
    color: var(--accent-main);
}

/* ===================================================================
   --- COMPONENTS: IMAGES ---
=================================================================== */

img:not([src*="img.shields.io"]) {
    margin-block: var(--space-l);
    max-width: 70%;
    max-height: 50vh;
    display: block;
}

img[src*="img.shields.io"] {
    margin-inline-end: var(--space-m);
}

/* ===================================================================
   --- COMPONENTS: TOOLTIPS ---
=================================================================== */

[data-tooltip] {
    anchor-name: --tooltip-anchor;
    anchor-scope: --tooltip-anchor;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;

    position-anchor: --tooltip-anchor;
    top: anchor(bottom);
    left: anchor(left);
    justify-self: anchor-center;
    position-try-fallbacks: flip-block;

    background-color: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border-main);
    border-radius: var(--radius-medium);
    padding: var(--space-s) var(--space-m);
    margin-block-start: var(--space-l);
    font-size: var(--font-size-s);
    box-shadow: var(--shadow-popout);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 100;

    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

/* ===================================================================
   --- COMPONENTS: VIEW TRANSITION ---
=================================================================== */

@media (prefers-reduced-motion: no-preference) {

    ::view-transition-old(root) {
        animation-delay: 1000ms;
    }

    ::view-transition-new(root) {
        animation: circle-in 1000ms;
    }

    @keyframes circle-in {
        from { clip-path: circle(0% at 50% 0%); }
        to { clip-path: circle(120% at 50% 0%); }
    }

}

/* ===================================================================
   --- COMPONENTS: DETAIL LAYOUT & TOC ---
=================================================================== */

.detail-layout {
    display: grid;
    grid-template-columns: 250px 1fr; 
    gap: var(--space-xl);
    align-items: start;
}

.toc-sidebar {
    position: sticky;
    top: 150px; 
    background-color: var(--bg-panel);
    border: 2px solid var(--border-main);
    border-radius: var(--radius-large);
    padding: var(--space-l);
    margin-block-end: var(--space-l);
    box-shadow: var(--shadow-popout);
}

.toc-sidebar h3 {
    color: var(--accent-main);
    margin-block-end: var(--space-m);
    font-size: var(--font-size-l);
    border-block-end: 1px solid var(--border-subtle);
    padding-block-end: var(--space-xs);
}

.toc-nav ol, 
.toc-nav ul {
    list-style: none;
    padding-inline-start: 0;
    margin-block-start: var(--space-xs);
}

.toc-nav ol ol, 
.toc-nav ul ul {
    padding-inline-start: var(--space-l); 
    font-size: var(--font-size-s);
    border-inline-start: 1px solid var(--border-subtle);
    margin-inline-start: var(--space-xs);
}

.toc-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    display: block;
    padding-block: var(--space-xs);
    transition: color 0.2s ease;
}

.toc-nav a:hover {
    color: var(--accent-hover);
}

/* --- MOBILE FALLBACK --- */
@media (max-width: 768px) {
    .detail-layout {
        grid-template-columns: 1fr; 
    }
    
    .toc-sidebar {
        position: relative;
        top: 0;
    }
}

/* ===================================================================
   --- COMPONENTS: LIGHTBOX ---
=================================================================== */

.readme-content img {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.readme-content img:hover {
    transform: scale(1.02);
}

.lightbox {
    margin: auto;
    border: 1px solid var(--border-main);
    border-radius: var(--radius-large);
    background-color: var(--bg-panel);
    padding: var(--space-m);
    box-shadow: var(--shadow-popout);
    max-width: 90vw;
    max-height: 95vh;
}

.lightbox::backdrop {
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.lightbox-header {
    display: flex;
    justify-content: flex-end;
    margin-block-end: var(--space-s);
}

.lightbox img {
    display: block;
    max-width: 100%;
    max-height: calc(90vh - 60px); 
    object-fit: contain;
    padding: 0;
}