/* ====================================
   Base Styles
======================================= */

/* ====================================
   Utility Classes
======================================= */

/* CSP-safe visibility toggle — use instead of inline style="display:none" */
.hidden { display: none !important; }

/* Sentinel element for IntersectionObserver-based infinite scroll */
.load-more-trigger { height: 1px; }

/* Progress bar initial state */
.progress-fill--zero { width: 0%; }

/* ====================================
   Cross-Browser Reset & Normalize
   Ensures consistent rendering across Safari, Chrome, Firefox
======================================= */

/* Universal box-sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Remove loud blue focus outlines globally, use subtle alternative */
*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

/* Normalize button and input appearance across browsers */
button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    margin: 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Reset button styles completely for Safari */
button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* A disabled control showing the hand cursor reads as broken; fall back to
   the arrow (components may override with not-allowed where they prefer). */
button:disabled {
    cursor: default;
}

/* Ensure select maintains dropdown functionality */
select {
    cursor: pointer;
}

/* Range inputs are interactive but browsers default them to the arrow. */
input[type="range"] {
    cursor: pointer;
}

/* Prevent iOS font size adjustment */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
    /* Density: 100% (default) preserves the browser/user base size exactly. */
    font-size: var(--density-font);
}

/* Prevent pinch-to-zoom and double-tap-to-zoom on mobile.
   iOS Safari 16.4+ ignores viewport user-scalable=no;
   CSS touch-action is the reliable cross-browser approach. */
html, body {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: var(--color-background);
    color: var(--color-text-primary);
    min-height: 100vh;
    transition: background-color var(--transition-slow);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    line-height: 1.5;
    overflow-x: hidden;
    width: 100%;
}

/* Mobile: add bottom padding for bottom tab bar + safe area */
@media (max-width: 767px) {
    body {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    }

    body:has(.youtube-player.visible),
    body:has(.nts-audio-player.visible) {
        padding-bottom: var(--nts-player-offset);
    }

    /* Prevent any child (e.g. absolutely-positioned dropdowns) from
       widening the viewport and enabling horizontal scroll / zoom. */
    #page-content,
    .container {
        overflow-x: clip;
    }
}

/* Desktop: reserve the fixed transport's height while a player bar is on
   screen, so the tail of the page can scroll clear of it and stays clickable
   (the mobile equivalent lives in the block above). */
@media (min-width: 768px) {
    body:has(.nts-audio-player.visible) #page-content,
    body:has(.youtube-player.visible) #page-content {
        padding-bottom: var(--nts-player-offset);
    }
}

a {
    color: var(--color-text-primary);
    text-decoration: none;
}

.container {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--container-padding);
}

h1 {
    text-align: left;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    transition: color var(--transition-base);
}

/* Legacy header styles - kept for backward compatibility, prefer page-layout.css classes */
.header-container {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -webkit-align-items: center;
    align-items: center;
    width: 100%;
    margin-bottom: 0.5rem;
    box-sizing: border-box;
}

.title-container {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: calc(var(--spacing-base) * 2);
}

.controls {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: flex-end;
    justify-content: flex-end;
    gap: 1rem;
    -webkit-flex-wrap: nowrap;
    flex-wrap: nowrap;
}

.controls-container {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: calc(var(--spacing-base) * 2);
}

/* Sorting Controls */
.sorting-controls {
    display: flex;
    align-items: center;
}

.sort-dropdown {
    padding: calc(var(--spacing-base) * 1.5) calc(var(--spacing-base) * 2);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-md);
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition-base), background-color var(--transition-base);
    min-width: 140px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666666' stroke-width='2' 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 calc(var(--spacing-base) * 1.5) center;
    background-size: 16px;
    padding-right: calc(var(--spacing-base) * 5);
}

.sort-dropdown:hover {
    background-color: var(--color-surface-alt);
}

.sort-dropdown:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .sort-dropdown {
        background: var(--color-dark-surface-alt);
        border-color: var(--color-dark-border);
        color: var(--color-dark-text-primary);
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b0b0b0' stroke-width='2' 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 calc(var(--spacing-base) * 1.5) center;
        background-size: 16px;
    }
    
    .sort-dropdown:focus {
        border-color: var(--color-dark-text-primary);
    }
}

.back-link {
    margin-right: 0;
    width: 60px;
    flex: 0 0 auto;
}

.back-link::before {
    content: '←';
}

.download-buttons {
    display: -webkit-flex;
    display: flex;
    gap: calc(var(--spacing-base) * 2);
    -webkit-flex: 0 0 auto;
    flex: 0 0 auto;
}

.hidden {
    display: none !important;
    visibility: hidden !important;
} 

/* Headings that exist for structure, not for the eye. The feed and search
   pages are deliberately untitled in the design — the cards and the search
   input are the page — but every page still needs exactly one h1 to name it
   for assistive tech and crawlers. Clipped rather than display:none, which
   would take it out of the accessibility tree along with the layout. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
