/* Core Application Reset */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
-webkit-tap-highlight-color: transparent;
}

body {
font-family: var(--font-main);
background-color: var(--bg-primary);
color: var(--text-primary);
transition: background-color 0.2s ease, color 0.2s ease;
display: flex;
flex-direction: column;
min-height: 100vh;
overflow-x: hidden;
}

/* Application Top Navigation Header Bar */
.app-header {
height: 56px;
background-color: var(--bg-surface);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.app-header button {
width: var(--touch-target);
height: var(--touch-target);
background: none;
border: none;
cursor: pointer;
fill: var(--text-primary);
display: flex;
align-items: center;
justify-content: center;
}

.app-title {
font-weight: 700;
font-size: 1.25rem;
}

/* Single Page Application State Container Routing Views */
.app-view {
display: none;
flex: 1;
padding: 16px;
animation: viewFade 0.2s ease-in-out;
}

.app-view.active {
display: flex;
flex-direction: column;
}

/* Search Dashboard Framework */
.search-container {
margin-bottom: 16px;
width: 100%;
}

#library-search {
width: 100%;
height: var(--touch-target);
padding: 0 16px;
border: 1px solid var(--text-secondary);
border-radius: 8px;
background: var(--bg-surface);
color: var(--text-primary);
font-size: 1rem;
}

.filter-bar {
display: flex;
gap: 8px;
margin-bottom: 20px;
overflow-x: auto;
padding-bottom: 6px;
}

.filter-btn {
padding: 6px 16px;
border-radius: 16px;
border: 1px solid var(--text-secondary);
background: transparent;
color: var(--text-primary);
cursor: pointer;
white-space: nowrap;
font-size: 0.875rem;
}

.filter-btn.active {
background: var(--accent);
color: #ffffff;
border-color: var(--accent);
}

/* Media/Book Dashboard Flex Grid */
.library-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 16px;
}

.book-card {
background: var(--bg-surface);
border-radius: 12px;
padding: 16px;
cursor: pointer;
transition: transform 0.15s ease, box-shadow 0.15s ease;
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.book-card:hover,
.book-card:focus-visible {
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(0,0,0,0.12);
}

.book-card h4 {
font-size: 1rem;
margin-bottom: 4px;
}

/* Typography Canvas for Reading View */
.reader-canvas {
font-family: var(--font-reader);
font-size: var(--font-size-base);
line-height: var(--line-height-base);
max-width: 65ch;
margin: 0 auto;
width: 100%;
flex: 1;
overflow-y: auto;
padding: 12px 4px;
}

/* Audiobook Container & Custom Layout Mechanics */
.audio-player-container {
max-width: 400px;
margin: 0 auto;
width: 100%;
text-align: center;
padding-top: 24px;
}

.audio-cover-art {
width: 160px;
height: 160px;
background: var(--bg-surface);
margin: 0 auto 24px auto;
display: flex;
align-items: center;
justify-content: center;
font-size: 4rem;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

#main-audio-element {
display: none; /* Hide standard native browser controls */
}

.audio-custom-controls {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
margin: 32px 0;
}

.audio-custom-controls button {
min-width: var(--touch-target);
min-height: var(--touch-target);
padding: 12px 20px;
border-radius: 24px;
border: none;
background: var(--bg-surface);
color: var(--text-primary);
font-weight: bold;
cursor: pointer;
}

.audio-custom-controls .btn-play {
background: var(--accent);
color: white;
padding: 14px 28px;
}

.audio-progress-wrapper input[type="range"] {
width: 100%;
height: 6px;
margin-bottom: 8px;
}

.time-stamps {
display: flex;
justify-content: space-between;
font-size: 0.85rem;
color: var(--text-secondary);
}

/* Accessibility Tools & System Utilities */
.skip-link {
position: absolute;
top: -100px;
left: 0;
background: var(--accent);
color: white;
padding: 8px;
z-index: 200;
}
.skip-link:focus { top: 0; }

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

/* Accessible Modal Layout Forms */
dialog {
margin: auto;
padding: 24px;
border-radius: 12px;
border: 1px solid var(--text-secondary);
background: var(--bg-primary);
color: var(--text-primary);
width: 90%;
max-width: 400px;
}

dialog::backdrop {
background: rgba(0,0,0,0.4);
backdrop-filter: blur(4px);
}

@keyframes viewFade {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); }
}