/* App Reset & Mobile Lock */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body, html {
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevents vertical bouncing on mobile browser */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Set background */
body {
	background-image: url("../images/overlay.png"), url("../images/bg.jpg");
	background-repeat: repeat, no-repeat;
	background-size: auto, 100% 100%;
	background-attachment: fixed;
	overflow-y: auto;
}

/* Headers */
h1 {
/*		font-size: clamp(1.2rem, 2.5vw, 2.2rem); */
        font-size: calc((100dvw + 100dvh) / 75);
        padding: 5px;
		letter-spacing: -0.015em;
		font-family: 'nasalization', sans-serif;
		color: #ffffff;
		text-shadow: 0 0 5px #000000;
	}
h2 {
		font-size: calc((100dvw + 100dvh) / 50);
        padding: 10px;
		letter-spacing: -0.015em;
		font-family: 'nasalization', sans-serif;
		color: #ffffff;
		text-shadow: 0 0 calc((100dvw + 100dvh) / 200) #ffffff;
	}
h3 {
		font-size: calc((100dvw + 100dvh) / 75);
        padding: 10px;
		letter-spacing: -0.015em;
		font-family: 'nasalization', sans-serif;
		color: #ffffff;
		text-shadow: 0 0 10px #ffffff;
	}



/* Horizontal Swipe Container */
.app-container {
    display: flex;
    width: 100%;
    height: calc(100% - 60px); /* Leaves room for bottom nav */
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory; /* Forces touch swiping to stick to tab boundaries */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.app-container::-webkit-scrollbar {
    display: none;
    height: 0;
}

/* Individual Tab Setup */
.tab-view {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    scroll-snap-align: start;
    overflow-y: auto; /* Allows independent vertical scrolling inside a tab */
    padding: 20px;
}

#Home {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: calc(100% - 40px);
}

.home-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    width: 100%;
    max-width: 1080px;
    flex-wrap: wrap;
}

.home-head img {
    display: block;
    width: 100%;
    height: auto;
}

.home-logo {
    order: 0;
    flex: 0 0 auto;
    width: min(250px, 55vw);
}

.home-avatar {
    order: 1;
    flex: 0 0 auto;
    width: min(150px, 30vw);
}

@media (max-width: 800px), (orientation: portrait) {
    .home-head {
        flex-direction: column;
    }
    .home-logo {
        order: 1;
        width: min(250px, 70vw);
    }
    .home-avatar {
        order: 0;
        width: min(150px, 40vw);
    }
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: rgba(17, 17, 17, 0.95);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}
.bottom-nav::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent 50%);
    pointer-events: none;
}
.nav-item {
    position: relative;
    z-index: 1;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 14px;
    padding: 0 14px;
    line-height: 1;
    min-width: 0;
    transition: color 0.2s ease;
}
.nav-item.active {
    color: #ffffff;
}
.nav-item:hover {
    color: #b8dcff;
}

.nav-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    width: 0;
    background: linear-gradient(90deg, #3bb4ff, #007aff);
    border-radius: 2px 2px 0 0;
    transition: transform 0.25s ease, width 0.25s ease;
    z-index: 0;
}

/* ========================================== */
/* ADAPTIVE ORIENTATION LAYOUTS              */
/* ========================================== */





/* --- Google Docs Tab / Book Reader --- */
.docs-layout {
    display: grid;
    grid-template-rows: 3fr 1fr; /* Portrait: Docs take up most of the screen */
    gap: 15px;
    padding: 10px;
}

.docs-viewer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.docs-viewer iframe {
    width: 100%;
    height: 100%;
    border: none;
    min-height: 45vh;
}

.docs-sidebar {
    text-align: center;
    position: relative; /* Anchor UTFOF help/edit buttons to sidebar */
}


.utfof-header {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 10px;
}

.utfof-titleblock {
    flex: 0 1 80vw;
    min-width: 0;
    text-align: center;
}

.utfof-title {
    color: #fff;
    font-family: 'nasalization', sans-serif;
    text-shadow: 0 0 10px #fff;
    font-size: clamp(1rem, 1.8vw, 1.3rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70vw;
    margin: 0 auto;
    padding: 10px;
    text-align: center;
}

.utfof-subtitle {
    color: rgba(255,255,255,0.85);
    margin-top: 0px;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.utfof-nav-btn, .utfof-counter {
    color: rgba(255,255,255,0.9);
    font-size: 0.95rem;
    margin-top: 3px;
    padding: 0.35rem 0.6rem;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 10px;
    background: rgba(0,0,0,0.25);
    vertical-align: middle;

}
.utfof-nav-btn {
    cursor: pointer;
    color: #fff;
}

.utfof-controls {
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    align-items: center;
    gap: 10px;
}

.utfof-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.utfof-audio-wrap audio {
    width: 100%;
}

		/* UTFOF: top-left ? hover popup (top-left of book panel) */
		#UTFOF{ position:relative; }
		#UTFOF .utfof-quest{

			position:absolute;
			top:0px;
			margin:0;
			border-radius:50%;
			background:rgba(0,0,0,0.0);
			color:#fff;
			display:flex;
			align-items:center;
			justify-content:center;
			font-size:18px;
			font-weight:700;
			z-index:5;
			cursor:help;
			transition: color 150ms ease-in-out, text-shadow 150ms ease-in-out;
		}

		/* Ensure the help button remains circular even on small screens */
		#UTFOF .utfof-quest{
			width:26px !important;
			min-width:26px !important;
			height:26px !important;
			padding:0 !important;
			display:inline-flex !important;
			align-items:center !important;
			justify-content:center !important;
			box-sizing:border-box !important;
		}

		#UTFOF .utfof-quest:hover,
		#UTFOF .utfof-quest:focus{
			color:#fff;
			text-shadow: 0 0 8px rgba(255,255,255,0.95), 0 0 16px rgba(255,255,255,0.65);
		}

		/* Prevent the "?" button from staying visually "hovered" after closing the modal.
		   Likely caused by focus being returned to the button. */
		#UTFOF .utfof-quest:focus:not(:hover){
			color:#fff;
			text-shadow:none;
		}


		#UTFOF .utfof-edit{
			position:absolute;
			top:0px;
			margin:0;
			border-radius:50%;
			background:rgba(0,0,0,0.0);
			color:#fff;
			display:flex;
			align-items:center;
			justify-content:center;
			font-size:12px;
			font-weight:700;
			z-index:5;
			cursor:pointer;
			transition: color 150ms ease-in-out, text-shadow 150ms ease-in-out;
		}

		/* Ensure the help button remains circular even on small screens */
		#UTFOF .utfof-edit{
			width:26px !important;
			min-width:26px !important;
			height:26px !important;
			padding:0 !important;
			display:inline-flex !important;
			align-items:center !important;
			justify-content:center !important;
			box-sizing:border-box !important;
		}

		#UTFOF .utfof-edit:hover,
		#UTFOF .utfof-edit:focus{

			color:#fff;
			text-shadow: 0 0 8px rgba(255,255,255,0.95), 0 0 16px rgba(255,255,255,0.65);
		}
		#UTFOF #utfof-quest{ left:10px; }
		#UTFOF #utfof-edit{ right:0px; }

		/* Modal overlay that covers the viewport and centers the modal box */
		#utfof-modal-overlay,
		#book .utfof-modal-overlay{
			position:fixed;
			inset:0;
			display:none;
			align-items:center;
			justify-content:center;
			background:rgba(0,0,0,0.0);
			z-index:9999;
		}

		/* Modal opened */
		#utfof-modal-overlay.visible{
			display:flex;
			background:rgba(0,0,0,0.35);
		}

		/* If JS closes via hidden attribute, ensure it can be reopened */
		#utfof-modal-overlay[hidden]{
			display:none !important;
		}
		#utfof-modal-overlay:not([hidden]).visible{
			display:flex !important;
		}



		#utfof-modal{
			background:#222;
			color:#ffffff;
			padding:1.25em;
			border-radius:8px;
			max-width:42em;
			width:calc(100% - 40px);
			box-shadow:0 10px 30px rgba(0,0,0,0.5);
			border:1px solid rgba(255,255,255,0.12);
		}

		#utfof-modal h3{ margin:0 0 .5em 0; font-size:1.2em; }
		#utfof-modal .utfof-modal-content{ font-size:1em; line-height:1.4; margin-bottom:1em; }
		#utfof-modal .utfof-modal-actions{ text-align:right; }
		#utfof-modal .utfof-modal-actions .button{ background:#444; color:#fff; padding:.45em .9em; border-radius:4px; border:0; cursor:pointer; }
		#utfof-modal .utfof-modal-actions .button:hover{ background:#555; }







        
/* --- MP3 Player Tab --- */
.player-layout {
    display: grid;
    grid-template-rows: 1fr auto; /* Portrait: Stacked vertically */
    gap: 20px;
    align-items: center;
    min-height: 0;
}
.player-art {
    display: flex;
    justify-content: center;
    min-height: 0;
}
.album-disc {
    width: 200px;
    height: 200px;
    background: #333;
    border-radius: 50%;
}

/* ========================================== */
/* LANDSCAPE MODE CONTROLS (Flipped Sideways) */
/* ========================================== */
@media (orientation: landscape) {
    .app-container {
        height: calc(100% - 50px); /* Tighter nav for landscape */
    }
    .bottom-nav {
        height: 50px;
    }

    /* Change layouts to 50/50 split side-by-side */
    .docs-layout, .player-layout {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr;
        align-items: center;
    }
    
    .docs-viewer, .player-art {
        height: 100%;
    }

    /* --- TCM: landscape reflow (image left, text right) --- */
    #TCM .tcm-layout {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-start;
        justify-content: center;
    }

    #TCM .tcm-media,
    #TCM .tcm-copy {
        width: 50%;
        flex: 0 0 50%;
    }

    #TCM .tcm-media {
        padding: 0 10px 0 0;
    }

    #TCM .tcm-copy {
        padding: 0 0 0 10px;
    }
}

/* --- TCM: portrait layout defaults (image above, text below) --- */
#TCM .tcm-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1980px;
    gap: 20px;
    align-items: center;
}

#TCM .tcm-media {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 10px;
}

#TCM .tcm-media .image.fit {
    display: inline-flex;
    justify-content: center;
    width: auto;
}

#TCM .tcm-media img {
    width: min(90%, 1220px);
    max-width: 100%;
    height: auto;
    display: block;
    box-shadow: 0 22px 40px rgba(0, 0, 0, 0.15);
}

#TCM .tcm-copy {
    padding: 0 10px;
    line-height: 1.3em;
    text-align: justify;
    max-width: 700px;
    background: #1111118e;
    border-radius: 1dvh;
    box-shadow: 0 22px 40px rgba(0, 0, 0, 0.15);
    color: #aaaaaa;
    overflow: hidden; /* helps the fit-text logic prevent spillover */
}


#TCM .tcm-copy p {
    margin: 0;
    padding: 24px;
    font-size: clamp(0.95rem, 0.6rem + 0.15vw, 1.15rem);
    line-height: 1.55;
}

#TCM h2 {
    width: 100%;
    text-align: center;
    margin-bottom: 18px;
}

#TCM .tcm-copy strong {
    font-weight: 700;
    color: #ddd;
}

/* --- TBA: portrait layout defaults (artwork above, controls below) --- */
#TBA {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    height: auto;
    overflow: visible;
}

#TBA #tba-player {
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
    max-width: none;
    gap: 20px;
    align-items: center;
    min-height: 0;
    height: auto;
    overflow: visible;
}

#TBA .player-art {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 90px 10px;
    min-height: 0;
    min-width: 0;
    max-height: 55vh;
    overflow: hidden;
    box-sizing: border-box;
}

#TBA .player-art img {
    width: auto;
    max-width: 100%;
    max-height: 40vh;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 2dvh;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

#tba-meta:empty {
    display: none;
}

#TBA .player-controls {
    width: 100%;
    padding: 0 10px;
    max-width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    overflow: hidden;
    overscroll-behavior: contain;
    box-sizing: border-box;
}

#TBA .tba-playlist-wrap {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#TBA .tba-content-box,
#TBA .tba-tab-content,
#TBA #tba-playlist,
#TBA #tba-playlist li {
}

#TBA #tba-playlist {
    list-style: none;
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.7) transparent;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.03);
    box-sizing: border-box;
}

#TBA #tba-playlist li {
    margin-bottom: 4px;
    padding: 6px 12px !important;
}

#TBA,
#TBA .tba-content-box,
#TBA .tba-tab-content {
}

#TBA #tba-playlist::-webkit-scrollbar {
    width: 10px;
}
#TBA #tba-playlist::-webkit-scrollbar-track {
    background: transparent;
}
#TBA #tba-playlist::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.35);
    border-radius: 6px;
}
#TBA #tba-playlist::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.55);
}

/* --- TBA: Theme scrollbars for tab content box --- */
#TBA .tba-tab-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 132, 255, 0.75) rgba(0, 0, 0, 0);
}

#TBA .tba-tab-content::-webkit-scrollbar {
    width: 10px;
}

#TBA .tba-tab-content::-webkit-scrollbar-track {
    background: transparent;
}

#TBA .tba-tab-content::-webkit-scrollbar-thumb {
    background: rgba(0, 132, 255, 0.35);
    border-radius: 6px;
    border: 2px solid rgba(0, 0, 0, 0);
    background-clip: content-box;
}

#TBA .tba-tab-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 132, 255, 0.55);
}


/* --- TBA: landscape reflow (artwork left, controls right) --- */
@media (orientation: landscape) {
    #TBA #tba-player {
        display: flex !important;
        flex-direction: row !important;
        align-items: stretch;
        justify-content: center;
    }

    #TBA .player-art,
    #TBA .player-controls {
        width: calc(50% - 10px);
        flex: 1 1 calc(50% - 10px);
        min-width: 0;
        min-height: 0;
        box-sizing: border-box;
    }

    #TBA .player-art {
        margin: auto 0;
    }

    #TBA .player-art {
        padding: 20px 10px;
        max-height: 55vh;
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    #TBA .player-controls {
        padding: 0 0 0 10px;
        box-sizing: border-box;
        overflow: hidden;
        min-height: 0;
    }

    #TBA .player-art img {
        max-width: 100%;
        max-height: 100%;
        height: auto;
    }

    #TBA #tba-time {
        min-width: 55px;
        font-size: 0.85em;
    }
}

/* --- TBA: Playlist active state --- */
#TBA #tba-playlist li.active {
    background-color: #0084ff !important;
    color: #fff;
}

#TBA #tba-playlist li.active div {
    color: #fff;
}

/* --- TBA: Tab styles --- */
.tba-content-box {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    box-sizing: border-box;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

@media (orientation: landscape) {
    #TBA .player-art,
    #TBA .player-controls,
    #TBA .tba-content-box {
        min-width: 0;
        max-width: 100%;
    }
    #TBA .player-controls {
        overflow: visible;
    }
}

.tba-tabs {
    display: flex;
    border-bottom: 1px solid #444;
    background: #1a1a1a;
}

.tba-tab-btn {
    flex: 1;
    padding: 4px 8px;
    border: none;
    background: transparent;
    color: #888;
    cursor: pointer;
    text-align: center;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    transition: color 0.2s, border-color 0.2s;
}

.tba-tab-btn.tba-tab-active {
    color: #eee;
    border-bottom-color: #0084ff;
}

.tba-tab-btn:hover {
    color: #aaa;
}

.tba-tab-content {
    padding: 0 8px;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    display: none;
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 0.9em;
    color: #ccc;
}

.tba-tab-content.tba-tab-active { 
    display: block;
}

/* --- TBA: Prev/Play/Next button theme --- */
#TBA #tba-prev,
#TBA #tba-play,
#TBA #tba-next {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(0, 132, 255, 0.65);
    background: rgba(0, 132, 255, 0.12);
    color: #eaf4ff;
    border-radius: 8px;
    padding: 5px 10px; /* smaller + tighter */
    font-size: 0.95em;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.05s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 0 0 rgba(0, 132, 255, 0);
}


#TBA #tba-prev:hover,
#TBA #tba-play:hover,
#TBA #tba-next:hover {
    background: rgba(0, 132, 255, 0.22);
    border-color: rgba(0, 132, 255, 0.95);
    box-shadow: 0 0 18px rgba(0, 132, 255, 0.25);
}

#TBA #tba-prev,
#TBA #tba-play,
#TBA #tba-next {
    min-height: 28px;
    min-width: 28px;
    height: 28px;
}

#TBA #tba-prev:active,
#TBA #tba-play:active,
#TBA #tba-next:active {
    transform: translateY(1px);
}


#TBA #tba-prev:focus-visible,
#TBA #tba-play:focus-visible,
#TBA #tba-next:focus-visible {
    outline: none;
    border-color: rgba(59, 180, 255, 1);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.35);
}

#TBA #tba-prev:disabled,
#TBA #tba-play:disabled,
#TBA #tba-next:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

