/* --- Global Color Variables & Theme Tokens --- */

:root {
    /* Base palette */
    --color-black: #000;
    --color-white: #FFF;
    --color-gray: #666;
    --color-gray-light: #999;
    --color-highlight: #349CE3;

    /* Theme transition */
    --theme-duration: 350ms;
    --theme-easing: ease;

    /* Light theme */
    --page-background: var(--color-white);
    --page-text: var(--color-black);
    --interface-border: var(--color-black);
    --track-text: var(--color-black);
    --track-hover: var(--color-highlight);
    --scrubber-color: var(--color-black);
    --scrubber-handle-background: var(--color-white);
    --toggle-border: var(--color-gray-light);
    --toggle-knob: var(--color-gray-light);

    /* Fixed colors used over the visualizer */
    --visualizer-background: var(--color-black);
    --visualizer-control: var(--color-white);
}

body.dark-mode {
    color-scheme: dark;
    --page-background: var(--color-black);
    --page-text: var(--color-white);
    --interface-border: var(--color-gray);
    --track-text: var(--color-white);
    --track-hover: var(--color-highlight);
    --scrubber-color: var(--color-gray-light);
    --scrubber-handle-background: var(--color-black);
    --toggle-border: var(--color-gray-light);
    --toggle-knob: var(--color-highlight);
}

/* --- CSS Reset & Base Styles --- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
	font-family: monospace;
	background-color: var(--page-background);
	color: var(--page-text);
	overflow: hidden;
	font-size: 16px;
}

body.theme-ready {
    transition:
        background-color var(--theme-duration) var(--theme-easing),
        color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .brand-zone {
    transition:
        opacity 0.4s ease,
        border-color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .track-nav {
    transition:
        opacity 0.4s ease,
        border-color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .track-btn {
    transition: color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .track-scrubber {
    transition: color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .scrubber-rail {
    transition: background-color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .scrubber-handle {
    transition:
        background-color var(--theme-duration) var(--theme-easing),
        border-color var(--theme-duration) var(--theme-easing);
}

body.theme-ready .ctrl-btn {
    transition:
        transform 0.2s ease,
        opacity 0.2s ease,
        color var(--theme-duration) var(--theme-easing);
}

/* --- Base Layout (Landing Page) --- */

.app-container {
    display: grid;
    height: 100dvh; 
    width: 100vw;
    grid-template-columns: 100%;
    grid-template-rows: 1fr 0px auto; 
    grid-template-areas: 
        "brand"
        "visualizer"
        "nav";
    transition: grid-template-columns 0.8s cubic-bezier(0.77, 0, 0.175, 1),
                grid-template-rows 0.8s cubic-bezier(0.77, 0, 0.175, 1);
}

/* --- Zone Setup --- */

.brand-zone {
    position: relative;
	grid-area: brand;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 2rem;
	text-align: center;
	transition: opacity 0.4s ease;
}

.logo {
	width: 70%;
	max-width: 225px;
	margin: 0 0 60px;
	cursor: pointer; 
  	transition: all 0.3s ease;
}

.logo:hover {
  	opacity: 0.7;
}

.character {
    position: absolute;
    display: block;
    width: 50px;
    top: 50px;
    left: 15px;
    border-bottom: 1px solid var(--color-black);
    padding: 0 0 10px;
    aspect-ratio: 2 / 5;
}

body.dark-mode .character {
    border-bottom: 1px solid var(--color-gray);
}

.character img {
    display: block;
    width: 100%;
    height: auto;
    opacity: 0.55;
    filter: grayscale(100%);
    transition: opacity 0.35s ease, filter 0.35s ease;
}

.character:hover img,
.character:focus-visible img {
    filter: grayscale(0%);
    opacity: 1;
}

/* Main thought bubble */

.character a::after {
	content: attr(data-thought);

	position: absolute;
	top: 5px;
	left: calc(100% + 28px);

	width: 130px;
	padding: 11px 14px;

	background: #fff;
	border: 2px solid #111;
	border-radius: 50%;

	color: #111;
	font-family: monospace;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.3;
	text-align: center;

	opacity: 0;
	visibility: hidden;
	pointer-events: none;

	transform: translate(-8px, 6px) scale(0.7) rotate(-4deg);
	transform-origin: left center;

	transition:
		opacity 0.2s ease,
		transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1),
		visibility 0s linear 0.35s;
}


/* Small thought-bubble circles */

.character a::before {
	content: "";

	position: absolute;
	top: 35px;
	left: calc(100% + 7px);

	width: 6px;
	height: 6px;

	background: #fff;
	border: 2px solid #111;
	border-radius: 50%;

	box-shadow:
		11px -8px 0 0 #fff,
		11px -8px 0 2px #111;

	opacity: 0;
	visibility: hidden;
	pointer-events: none;

	transform: scale(0.4);

	transition:
		opacity 0.2s ease,
		transform 0.25s ease,
		visibility 0s linear 0.35s;
}


/* Reveal thought bubble */

.character:hover a::after,
.character:focus-within a::after {
	opacity: 1;
	visibility: visible;
	transform: translate(0, 0) scale(1) rotate(-4deg);
	transition-delay: 0s;
}

.character:hover a::before,
.character:focus-within a::before {
	opacity: 1;
	visibility: visible;
	transform: scale(1);
	transition-delay: 0s;
}
/* Target the raw SVG to ensure it respects the new fluid div wrapper */
.logo svg {
    width: 100%;
    height: auto;
    display: block;
}

.tagline {
	max-width: 600px;
	line-height: 1.5;
    font-size: 0.85rem;
}

/* --- Light / Dark Theme Toggle --- */

.theme-toggle {
    position: fixed;
    top: 15px;
    left: 20px;
    flex: 0 0 auto;
    width: 35px;
    height: 20px;
    padding: 0;
    border: 2px solid var(--toggle-border);
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    opacity: 0.5;
    appearance: none;
    -webkit-appearance: none;
    transition:
        border-color 0.25s ease,
        opacity 0.25s ease;
}

.theme-toggle:hover {
    opacity: 0.75;
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--color-highlight);
    outline-offset: 4px;
}

.theme-toggle-knob {
    position: absolute;
    top: 0px;
    left: 0;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--toggle-knob);
    transform: translateX(0);
    pointer-events: none;
    transition:
        transform 0.25s ease,
        background-color 0.25s ease;
}

body.dark-mode .theme-toggle-knob {
    transform: translateX(15px);
}

.app-container.internal-view .theme-toggle {
    top: 15px;
    left: 20px;
    margin: 0;
    transform: scale(0.85);
}

@media (prefers-reduced-motion: reduce) {
    body.theme-ready,
    body.theme-ready .brand-zone,
    body.theme-ready .track-nav,
    body.theme-ready .track-btn,
    body.theme-ready .track-scrubber,
    body.theme-ready .scrubber-rail,
    body.theme-ready .scrubber-handle,
    body.theme-ready .ctrl-btn,
    .theme-toggle,
    .theme-toggle-knob {
        transition: none;
    }
}

.visualizer-zone {
	grid-area: visualizer;
	position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
	overflow: hidden;
	opacity: 0;
	transition: opacity 0.4s ease;
	background-color: var(--visualizer-background);
}

.visualizer-zone::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.65);
}

.track-nav {
	grid-area: nav;
	display: flex;
	flex-direction: row;
	justify-content: space-around;
	padding: 2rem;
	border-top: 1px solid var(--interface-border);
	transition: opacity 0.4s ease;
}

/* Normalize track links across mobile and desktop */
.track-btn,
.track-btn:link,
.track-btn:visited {
    background: none;
	border: none;
	font-family: inherit;
	font-size: 1.1rem;
	cursor: pointer;
	padding: 0.5rem;
    color: var(--track-text);
    text-decoration: none;
    -webkit-text-fill-color: currentColor;
}

.track-btn:hover,
.track-btn:focus-visible {
    color: var(--track-hover);
}

.track-btn.active,
.track-btn.active:link,
.track-btn.active:visited {
    color: var(--color-highlight);
}

/* Fullscreen Toggle Button */
.fs-toggle {
	position: absolute;
	top: 20px;
	right: 20px;
	z-index: 10;
	background: transparent;
	border: none;
	color: var(--visualizer-control);
	cursor: pointer;
	font-size: 1.5rem;
    opacity: 0.5;
    transition: all 0.3s ease;
}

.fs-toggle:hover {
    opacity: 1;
}

/* --- State: Internal View (3 Columns) --- */
.app-container.internal-view {
    grid-template-columns: clamp(150px, 10vw, 350px) 1fr 100px;
    height: 100dvh; 
    grid-template-areas: "brand visualizer nav";
}

.app-container.internal-view .brand-zone {
    min-width: 0; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    height: 100%;
}

/* Base internal logo rules */
.app-container.internal-view .logo {
    width: 100%;
    max-width: 200px;
    margin: 0 0 30px 0;
    transition: all 0.3s ease;
}

.app-container.internal-view .visualizer-zone {
  opacity: 1;
}

.app-container.internal-view .visualizer-zone #p5-container {
	width: 100%;
	height: 100%;
}

.app-container.internal-view .brand-zone {
    min-width: 0; 
    container-type: inline-size; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    height: 100%;
}

.app-container.internal-view .track-nav {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-top: none;
    border-left: 1px solid var(--interface-border);
    height: 85dvh; 
    margin: 0 0 0 20px;
    align-self: center; 
}

.app-container.internal-view .track-btn {
	writing-mode: vertical-rl;
	transform: rotate(180deg);
	margin: 1rem 0;
}

/* --- State: Cinema Mode (Full screen visualizer) --- */
.app-container.cinema-mode {
  	grid-template-columns: 0px 1fr 0px;
}

.app-container.cinema-mode .brand-zone,
.app-container.cinema-mode .track-nav {
	opacity: 0;
	pointer-events: none;
}


/* --- Media Controls --- */
.media-controls {
    position: absolute;
    bottom: 10px;
    right: 0;
    z-index: 10;
    display: flex;
	flex-direction: column;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    opacity: 1;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.app-container.internal-view .media-controls {
    pointer-events: auto;
}

.ctrl-btn {
    background: transparent;
    border: none;
    color: var(--visualizer-control);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    opacity: 0.25;
}

.ctrl-btn:hover,
#ctrl-play.is-paused {
    transform: scale(1.1);
    opacity: 1;
}

.track-nav {
    grid-area: nav;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    padding: 2rem;
    border-top: 1px solid var(--interface-border);
    transition: opacity 0.4s ease;
}

.track-btn {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.5rem;
    transition: color 0.2s ease;
}

.track-btn:hover {
    color: var(--track-hover);
}

.track-btn.active {
    color: var(--color-highlight);
}

/* --- Mobile Responsive Rules --- */

@media (max-width: 1024px) {

    /* 1. Internal View Layout Override */
    .app-container.internal-view {
        grid-template-columns: 100%;
        grid-template-rows: auto 1fr auto;
        grid-template-areas: 
            "brand"
            "visualizer"
            "nav";
    }

    /* 2. Top Brand Zone Tweaks */
    .app-container.internal-view .brand-zone {
        border-right: none;
        padding: 1.5rem;
    }

    .app-container.internal-view .logo {
        width: 140px;
        margin: 0;
    }

    /* 3. Bottom Nav Bar Tweaks */
    .app-container.internal-view .track-nav {
        border-left: none;
        border-top: 1px solid var(--interface-border);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 85%;
        margin: 20px auto 0;
        padding: 1.5rem 0;
        height: auto; 
        align-self: auto; 
    }

    .app-container.internal-view .track-btn {
        writing-mode: horizontal-tb;
        transform: none;
        margin: 0.5rem 0;
        font-size: 0.8rem;
    }

    /* 4. Cinema Mode Fix for Mobile */
    .app-container.cinema-mode {
        grid-template-columns: 100%;
        grid-template-rows: 0px 1fr 0px;
    }
}

@media (max-width: 480px) and (orientation: portrait) {

    .app-container .logo {
        width: 50%;
        margin: 0 0 30px 0;
    }

    .app-container.internal-view .logo {
        width: 20%;
        margin: 0 10px 0;
    }

    /* --- 2x2 SCROLLABLE GRID (BOTH VIEWS) --- */
    
    /* Apply the grid layout to both the landing page and internal views */
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        display: grid;
        grid-template-columns: 1fr 1fr; /* 2 even columns */
        grid-auto-rows: min-content; /* Keeps rows hugging the text */
        gap: 1.5rem;
        justify-items: center;
        
        width: 85%;
        margin: 1rem auto 0;
        padding: 1.5rem 0 3rem 0; /* Extra bottom padding for scroll comfort */
        
        /* The scrollable magic */
        height: 100%;
        min-height: 0; /* CRUCIAL: Stops the grid from breaking past the bottom of the screen */
        overflow-y: auto;
    }

    /* Remove the old flex margins so the grid gap handles spacing cleanly */
    .app-container .track-btn,
    .app-container.internal-view .track-btn {
        margin: 0;
    }
    
    /* Optional: Hide the ugly default scrollbar while keeping the swipe-to-scroll functionality */
    .app-container .track-nav::-webkit-scrollbar,
    .app-container.internal-view .track-nav::-webkit-scrollbar {
        display: none;
    }
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    /* --- INTERNAL VIEW PORTRAIT OVERRIDES --- */
    
    .app-container.internal-view {
        /* Row 1: Auto (Brand), Row 2: Auto (Square Visualizer), Row 3: 1fr (Remaining space for Nav) */
        grid-template-rows: auto auto 1fr;
    }

    /* Force the visualizer into a perfect square */
    .app-container.internal-view .visualizer-zone {
        width: 100%;
        aspect-ratio: 4 / 3;
    }

    /* --- CINEMA MODE PORTRAIT OVERRIDES --- */
    
    /* 1. Force the grid to hide the top/bottom rows again */
    .app-container.internal-view.cinema-mode {
        grid-template-rows: 0px 1fr 0px;
    }

    /* 2. Break the visualizer out of the 1:1 square so it fills the screen */
    .app-container.internal-view.cinema-mode .visualizer-zone {
        aspect-ratio: auto;
        height: 100%;
    }
}

/* --- MOBILE LANDSCAPE OVERRIDES --- */
@media (max-height: 600px) and (orientation: landscape) {
    
    /* 1. Landing Page: 50/50 Split */
    .app-container {
        grid-template-columns: 1fr 0px 1fr; /* Left: Brand, Center: Hidden, Right: Nav */
        grid-template-rows: 100dvh;
        grid-template-areas: "brand visualizer nav";
        align-items: center;
    }

    .brand-zone {
        height: 85%;
        border-right: 1px solid var(--interface-border);
        padding: 1.5rem;
    }

    /* Constrain the giant logo */
    .logo {
        width: 30%;
        max-width: 120px; 
        margin: 0 0 30px 0;
    }

    .tagline {
        font-size: 0.65rem;
    }

    .character {
        top: 0;
    }

    /* 2. Track Navigation (Single Column) */
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        border-top: none;
        
        display: grid;
        grid-template-columns: 1fr; /* Forces one item per line */
        grid-auto-rows: min-content;
        gap: 1rem;
        justify-items: center;
        align-content: center; /* Centers the list vertically */
        
        width: 100%;
        height: 100dvh;
        margin: 0;
        padding: 1.5rem;
        min-height: 0; 
        overflow-y: auto;
    }

    /* Hide scrollbars for a clean look */
    .app-container .track-nav::-webkit-scrollbar,
    .app-container.internal-view .track-nav::-webkit-scrollbar {
        display: none;
    }
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .app-container .track-btn,
    .app-container.internal-view .track-btn {
        margin: 0;
        font-size: 0.75rem;
        writing-mode: horizontal-tb;
        transform: none;
    }

    /* 3. Internal View: 3-Column Layout */
    .app-container.internal-view {
        /* 140px Logo | Max space for Visualizer | 180px for 2x2 Nav */
        grid-template-columns: 140px 1fr 180px; 
        grid-template-rows: 100dvh;
        grid-template-areas: "brand visualizer nav";
    }

    .app-container.internal-view .brand-zone {
        border-bottom: none;
        border-right: 1px solid var(--interface-border);
    }

    .app-container.internal-view .logo {
        max-width: 90px;
        margin-top: -40px;
    }

    .app-container.internal-view .track-nav {
        border-left: 1px solid var(--interface-border);
        padding: 1rem 0.5rem;
    }

    /* Break visualizer out of the 1:1 portrait square */
    .app-container.internal-view .visualizer-zone {
        width: 100%;
        height: 100%;
        aspect-ratio: auto; 
    }

    /* 4. Cinema Mode: Fullscreen override */
    .app-container.internal-view.cinema-mode {
        grid-template-columns: 0px 1fr 0px;
    }
}
/* =========================================================
   Shared Track Scrubber + Wrapped Track Navigation
   ========================================================= */

.track-nav {
    position: relative;
}

.track-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    min-width: 0;
    min-height: 0;
}

.track-scrubber {
    --progress: 0%;
    display: none;
    color: var(--scrubber-color);
    user-select: none;
    -webkit-user-select: none;
}

.app-container.internal-view .track-nav {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: flex-start;
    border-left: none;
    padding: 0;
    overflow: visible;
}

.app-container.internal-view .track-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
}

.app-container.internal-view .track-scrubber {
    display: flex;
    position: relative;
    flex: 0 0 24px;
    width: 24px;
    height: 100%;
    flex-direction: column;
    align-items: center;
    z-index: 3;
}

.scrubber-hit-area {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    width: 24px;
    min-height: 0;
    padding: 0 0 0 5px;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
}

.scrubber-rail {
    position: relative;
    width: 1px;
    height: 100%;
    background: var(--scrubber-color);
    overflow: visible;
}

.scrubber-progress {
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: var(--progress);
    transform: translateX(-50%);
    background: var(--color-highlight);
    pointer-events: none;
}

.scrubber-handle {
    position: absolute;
    top: var(--progress);
    left: 50%;
    width: 10px;
    height: 10px;
    padding: 0;
    border: 1px solid var(--color-highlight);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: var(--scrubber-handle-background);
    cursor: grab;
    touch-action: none;
    appearance: none;
    -webkit-appearance: none;
}

.scrubber-handle:active {
    cursor: grabbing;
}

.scrubber-handle:focus-visible {
    outline: 2px solid var(--color-highlight);
    outline-offset: 3px;
}

.scrubber-time {
    flex: 0 0 auto;
    min-width: 46px;
    margin-top: 8px;
    font-size: 0.7rem;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
}

.track-scrubber.is-disabled .scrubber-handle {
    opacity: 0.45;
}

.track-scrubber.is-disabled .scrubber-hit-area {
    cursor: default;
}

/* Tablet and portrait/mobile: horizontal scrubber above track names */
@media (max-width: 1024px) {
    .app-container.internal-view .track-nav {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        border-top: none;
        padding: 0 0 1.5rem;
        overflow: visible;
    }

    .app-container.internal-view .track-list {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .app-container.internal-view .track-scrubber {
        display: flex;
        position: relative;
        flex: 0 0 30px;
        width: 100%;
        height: 30px;
        flex-direction: row;
        align-items: flex-start;
        margin: 0 0 0.5rem;
    }

    .app-container.internal-view .scrubber-hit-area {
        flex: 0 0 auto;
        width: 100%;
        height: 18px;
        min-height: 18px;
        align-items: center;
    }

    .app-container.internal-view .scrubber-rail {
        width: 100%;
        height: 1px;
    }

    .app-container.internal-view .scrubber-progress {
        top: 50%;
        left: 0;
        width: var(--progress);
        height: 2px;
        transform: translateY(-50%);
    }

    .app-container.internal-view .scrubber-handle {
        top: 50%;
        left: var(--progress);
        transform: translate(-50%, -50%);
    }

    .app-container.internal-view .scrubber-time {
        position: absolute;
        right: 0;
        top: 20px;
        min-width: 0;
        margin: 0;
        text-align: right;
    }
}

/* Small portrait: keep the existing 2x2 track layout inside .track-list */
@media (max-width: 480px) and (orientation: portrait) {
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        display: flex;
        grid-template-columns: none;
        grid-auto-rows: auto;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        width: 85%;
        height: 100%;
        min-height: 0;
        margin: 1rem auto 0;
        padding: 0 0 3rem;
        overflow: hidden;
    }

    .app-container .track-list,
    .app-container.internal-view .track-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-auto-rows: min-content;
        gap: 0.25rem;
        align-content: start;
        justify-items: center;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 1.5rem 0 0;
        overflow-y: auto;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .app-container .track-list::-webkit-scrollbar,
    .app-container.internal-view .track-list::-webkit-scrollbar {
        display: none;
    }

    .app-container.internal-view .track-scrubber {
        flex: 0 0 30px;
        width: 100%;
        height: 30px;
        margin-bottom: 0;
    }
}

/* Mobile landscape uses the same vertical scrubber treatment as desktop */
@media (max-height: 600px) and (orientation: landscape) {
    .app-container .track-nav,
    .app-container.internal-view .track-nav {
        display: flex;
        grid-template-columns: none;
        grid-auto-rows: auto;
        flex-direction: row;
        align-items: stretch;
        justify-content: flex-start;
        min-height: 0;
        overflow: visible;
    }

    .app-container .track-list,
    .app-container.internal-view .track-list {
        display: grid;
        flex: 1 1 auto;
        grid-template-columns: 1fr;
        grid-auto-rows: min-content;
        gap: 1rem;
        align-content: center;
        justify-items: center;
        width: auto;
        height: 100%;
        min-height: 0;
        padding: 1rem 0.5rem;
        overflow-y: auto;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .app-container .track-list::-webkit-scrollbar,
    .app-container.internal-view .track-list::-webkit-scrollbar {
        display: none;
    }

    .app-container.internal-view .track-nav {
        width: 100%;
        height: 85dvh;
        margin: auto 0;
        padding: 0;
        border-left: none;
    }

    .app-container.internal-view .track-scrubber {
        display: flex;
        position: relative;
        flex: 0 0 24px;
        width: 24px;
        height: 100%;
        flex-direction: column;
        align-items: center;
        margin: 0 0 0 5px;
    }

    .app-container.internal-view .scrubber-hit-area {
        display: flex;
        flex: 1 1 auto;
        width: 24px;
        height: auto;
        min-height: 0;
        align-items: stretch;
        justify-content: center;
    }

    .app-container.internal-view .scrubber-rail {
        width: 1px;
        height: 100%;
    }

    .app-container.internal-view .scrubber-progress {
        top: 0;
        left: 50%;
        width: 2px;
        height: var(--progress);
        transform: translateX(-50%);
    }

    .app-container.internal-view .scrubber-handle {
        top: var(--progress);
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .app-container.internal-view .scrubber-time {
        position: static;
        min-width: 46px;
        margin-top: 8px;
        text-align: center;
    }

    .app-container.internal-view .character {
        width: 100%;
        bottom: 0;
        left: 0;
        z-index: -1;
    }

    .app-container.internal-view .character img {
        position: absolute;
        width: 30%;
        left: 0;
        right: 0;
        margin: 0 auto;
        bottom: 10px;
    }
}

/* =========================================================
   Portrait Mobile Media Controls
   ========================================================= */

@media (max-width: 480px) and (orientation: portrait) {
    /*
     * Keep the controls attached to the visualizer, but position them just
     * outside its lower edge. The margin reserves space before track-nav.
     */
    .app-container.internal-view:not(.cinema-mode) .visualizer-zone {
        margin-bottom: 64px;
        overflow: visible;
    }

    .app-container.internal-view .media-controls {
        right: 50%;
        bottom: -54px;
        flex-direction: row;
        align-items: center;
        gap: 1.5rem;
        padding: 0.75rem 1rem;
        transform: translateX(50%);
        white-space: nowrap;
    }

    .app-container.internal-view .media-controls .ctrl-btn {
        color: var(--page-text);
    }

    /*
     * Cinema mode removes the reserved space and brings the horizontal
     * controls back inside the visualizer, overlapping its lower edge.
     */
    .app-container.internal-view.cinema-mode .visualizer-zone {
        margin-bottom: 0;
        overflow: hidden;
    }

    .app-container.internal-view.cinema-mode .media-controls {
        right: 50%;
        bottom: 12px;
        transform: translateX(50%);
    }

    .app-container.internal-view.cinema-mode .media-controls .ctrl-btn {
        color: var(--visualizer-control);
    }
}


/* =========================================================
   Mobile orientation reset
   Prevent stale landscape sizing when returning to portrait.
   ========================================================= */

/* Responsive grid templates change shape between portrait and landscape.
   Do not animate those template changes on mobile browsers. */
@media (max-width: 1024px), (max-height: 600px) {
    .app-container {
        transition: none;
    }
}

@media (max-width: 480px) and (orientation: portrait) {
    /* Keep the landing-page rows deterministic after rotation. */
    .app-container:not(.internal-view) {
        grid-template-columns: 100%;
        grid-template-rows: minmax(0, 1fr) 0 auto;
        grid-template-areas:
            "brand"
            "visualizer"
            "nav";
        align-items: stretch;
    }

    /* Explicitly clear the landscape percentage height. */
    .app-container:not(.internal-view) .brand-zone {
        height: auto;
        min-height: 0;
        border-right: none;
    }

    /* Avoid a percentage-height cycle inside the nav's auto-sized grid row. */
    .app-container:not(.internal-view) .track-nav {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .app-container:not(.internal-view) .track-list {
        height: auto;
        min-height: 0;
        overflow: visible;
    }
}

/* =========================================================
   Vertical remaining-time label for vertical scrubbers
   ========================================================= */

/* Desktop: the scrubber rail is vertical. */
@media (min-width: 1025px) {
    .app-container.internal-view .scrubber-time {
        writing-mode: vertical-rl;
        text-orientation: mixed;
        min-width: 0;
        margin: 10px 0 0 5px;
        line-height: 1;
        text-align: start;
    }
}

/* Mobile landscape also switches the scrubber back to vertical. */
@media (max-height: 600px) and (orientation: landscape) {
    .app-container.internal-view .scrubber-time {
        position: static;
        writing-mode: vertical-rl;
        text-orientation: mixed;
        min-width: 0;
        margin: 10px 0 0 5px;
        line-height: 1;
        text-align: start;
    }
}
