/* --- Themes (Skins) --- */
:root {
    color-scheme: light;
    forced-color-adjust: none;
}
/* Royal Biblical (Default) */
body, body.theme-royal {
    color-scheme: light;
    forced-color-adjust: none;
    --bg-dark: #FDFBF7; /* Bright Parchment Background */
    --card-bg: #FFFFFF; /* White Cards */
    --accent-gold: #C5A059; /* Royal Gold */
    --accent-gold-glow: rgba(197, 160, 89, 0.3);
    --accent-blue: #004B87; /* Tekhelet Royal Blue */
    --text-main: #2C1E16; /* Deep Brown/Black */
    --text-muted: #6B5B4C;
    --border-color: rgba(197, 160, 89, 0.4);
    
    /* Dynamic Theme Gradients */
    --theme-title-gradient: linear-gradient(
        to top,
        #1e40af 0%,
        #1d4ed8 25%,
        #172554 50%,
        #1e3a8a 75%,
        #1e40af 100%
    );
}

/* Theme: Royal Red */
body.theme-red {
    --accent-gold: #FFD700;
    --accent-blue: #991b1b;
    --border-color: rgba(255, 215, 0, 0.4);
    --theme-title-gradient: linear-gradient(
        to top,
        #7f1d1d 0%,   /* Dark Red */
        #b91c1c 25%,  /* Red */
        #450a0a 50%,  /* Deepest Red */
        #991b1b 75%,
        #7f1d1d 100%
    );
}

/* Theme: Emerald Green */
body.theme-green {
    --accent-gold: #FFD700;
    --accent-blue: #166534;
    --border-color: rgba(255, 215, 0, 0.4);
    --theme-title-gradient: linear-gradient(
        to top,
        #14532d 0%,   /* Dark Green */
        #15803d 25%,  /* Green */
        #052e16 50%,  /* Deepest Green */
        #166534 75%,
        #14532d 100%
    );
}

/* Theme: Silver Gray */
body.theme-gray {
    --accent-gold: #e2e8f0; /* Silver instead of Gold */
    --accent-gold-glow: rgba(226, 232, 240, 0.3);
    --accent-blue: #334155; /* Slate */
    --border-color: rgba(226, 232, 240, 0.4);
    --theme-title-gradient: linear-gradient(
        to top,
        #334155 0%,   /* Slate 700 */
        #475569 25%,  /* Slate 600 */
        #0f172a 50%,  /* Deepest Slate */
        #1e293b 75%,
        #334155 100%
    );
}

/* Modern Dark */
body.theme-modern-dark {
    --bg-dark: #0F172A; /* Slate 900 */
    --card-bg: #1E293B; /* Slate 800 */
    --accent-gold: #38BDF8; /* Neon Blue */
    --accent-gold-glow: rgba(56, 189, 248, 0.3);
    --accent-blue: #38BDF8;
    --text-main: #F8FAFC; /* Slate 50 */
    --text-muted: #94A3B8; /* Slate 400 */
    --border-color: rgba(56, 189, 248, 0.2);
}
body.theme-modern-dark header {
    background-image: none !important;
    background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%) !important;
    border-bottom: 2px solid var(--accent-gold);
}
body.theme-modern-dark .skin-royal-only { display: none !important; }

/* Classic Light */
body.theme-classic-light {
    --bg-dark: #F1F5F9; /* Slate 100 */
    --card-bg: #FFFFFF; /* White */
    --accent-gold: #0284C7; /* Sky 600 */
    --accent-gold-glow: rgba(2, 132, 199, 0.1);
    --accent-blue: #0369A1; /* Sky 700 */
    --text-main: #0F172A; /* Slate 900 */
    --text-muted: #64748B; /* Slate 500 */
    --border-color: #CBD5E1; /* Slate 300 */
}
body.theme-classic-light header {
    background-image: none !important;
    background: #FFFFFF !important;
    border-bottom: 1px solid var(--border-color);
}
body.theme-classic-light .skin-royal-only { display: none !important; }

/* Base Styles */
html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden; /* Force perfectly compressed fit without scrollbars */
}

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

body {
    /* Leather Parchment Gradient + Texture */
    background: 
        url("data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E"),
        radial-gradient(circle at center, #Fdf3e1 0%, #Ecd4a8 60%, #D1a76b 100%);
    background-blend-mode: multiply, normal;
    color: var(--text-light);
    font-family: 'Frank Ruhl Hofshi', serif;
    overflow: hidden; /* No scrolling for 24/7 TV display */
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Settings Button */
#settings-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: rgba(128, 128, 128, 0.05);
    color: rgba(128, 128, 128, 0.3);
    font-size: 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}
#settings-btn:hover {
    background: rgba(128, 128, 128, 0.2);
    color: rgba(128, 128, 128, 0.8);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
}
.modal-overlay.hidden {
    display: none !important;
}
.modal-content {
    background: var(--card-bg);
    padding: 4vmin;
    border-radius: 2vmin;
    text-align: center;
    border: 2px solid var(--accent-gold);
    color: var(--text-main);
}
.announcements-feed {
    text-align: center;
    background: var(--card-bg);
    padding: 3vmin;
    border-radius: 2vmin;
    border: 2px solid var(--border-color);
    font-size: 3.5vmin;
    font-weight: 700;
    color: var(--text-main);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    width: 100%;
    word-break: break-word;
}
.theme-options {
    display: flex;
    flex-direction: column;
    gap: 2vmin;
    margin: 3vmin 0;
}
.theme-btn {
    background: var(--bg-dark);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 2vmin;
    font-size: 3vmin;
    border-radius: 1vmin;
    cursor: pointer;
    font-family: inherit;
}
.theme-btn:hover {
    background: var(--accent-gold);
    color: #fff;
}
.close-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 2.5vmin;
    cursor: pointer;
}

/* Rotate Button - Barely visible but clickable */
#rotate-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.05);
    color: rgba(0, 0, 0, 0.3);
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 9999;
}
#rotate-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.8);
}

#rotate-wrapper {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;
    transform-origin: center center;
    transition: transform 0.5s ease;
}

#rotate-wrapper.rotated {
    width: 100vh;
    height: 100vw;
    transform: rotate(90deg);
}

#board-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 2.5vmin;
    transition: transform 0.5s ease; /* For pixel shifting */
    position: relative;
}

/* --- Header Section --- */
header {
    background: transparent;
    box-shadow: none; /* Removed shadow */
    border: transparent;
    padding: 4vmin 6vmin;
    position: relative;
    border-radius: 0 0 3vmin 3vmin; /* Rounded only at the bottom */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000; /* Extremely high z-index to stay above everything */
}

/* New overlay for the curtain */
.top-curtain-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto; /* Automatically scales based on the image's dimensions */
    z-index: 1000 !important; /* Above everything including header */
    pointer-events: none;
}

.header-content {
    position: relative;
    z-index: 2;
    text-align: center;
    display: flex;
    flex-direction: column; /* Stack vertically */
    align-items: center;
    justify-content: center;
    gap: 0.5vmin; /* Reduced gap */
}

.logo {
    height: 10vmin; /* Reduced logo size slightly to save space */
    object-fit: contain;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.9)); /* Light white glow */
}

.synagogue-info {
    display: flex;
    flex-direction: column;
    gap: 1vmin;
    text-align: center;
    margin-top: 0;
}

.synagogue-info .verse {
    font-size: 2.5vmin;
    color: var(--accent-blue);
    font-style: italic;
    font-weight: 700;
}

.synagogue-info h1 {
    font-size: 6.5vmin; 
    line-height: 1.2;
    margin: 0;
    transform: translateY(3vh); /* Move down visually without pushing layout */
    font-weight: 900;
    
    /* Shimmering Animated Gradient */
    background-image: var(--theme-title-gradient);
    background-size: 100% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    
    animation: moveGradient 6s ease-in-out infinite alternate;
    
    /* Simple soft shadow for readability */
    /* Note: text-shadow with transparent color might show under the gradient in some browsers, but keeping it soft */
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.2));
}

@keyframes moveGradient {
    0% {
        background-position: 0% 0%;
    }
    100% {
        background-position: 0% 100%;
    }
}

.datetime-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2vmin;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.05) 100%);
    box-shadow: inset 0 0 10px rgba(255,255,255,0.4), 0 4px 10px rgba(92, 60, 20, 0.1);
    padding: 2vmin;
    border-radius: 1.5vmin;
    border: 1px solid rgba(184, 134, 11, 0.2);
}

.day-name, .hebrew-date {
    font-size: 3.5vmin;
    font-weight: 700;
    color: var(--text-light);
}

.clock {
    font-size: 4vmin;
    font-weight: 900;
    color: var(--accent-blue);
    font-variant-numeric: tabular-nums;
}

.separator {
    font-size: 3vmin;
    color: var(--accent-gold);
}

.parasha-banner {
    text-align: center;
    padding: 3vmin !important;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.parasha-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    justify-items: center;
    width: 100%;
}

.parasha-star {
    height: 6vmin; /* Matches the text size exactly */
    width: auto;
    object-fit: contain;
}

.parasha-title {
    font-size: 5vmin !important; /* Reduced from 6vmin */
    color: var(--accent-blue) !important;
    font-weight: 900;
    margin-bottom: 0 !important;
}

.haftarah-title {
    font-size: 2.5vmin !important; /* Reduced from 3vmin */
    color: var(--text-muted) !important;
    font-weight: 700;
    border-bottom: none !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    position: absolute;
    bottom: 1.5vmin;
}
.haftarah-title::after {
    display: none;
}

/* --- Main Grid Section --- */
/* --- Layout Grid --- */
.grid-container {
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
    flex: 1;
    padding: 0 3vmin 3vmin 3vmin;
}

.two-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5vmin;
}

.half-col {
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
}

.full-col {
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
    flex-grow: 1;
}

/* --- Cards --- */
.card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.1) 100%);
    backdrop-filter: blur(10px);
    border-radius: 2vmin;
    padding: 2vmin; 
    box-shadow: 0 8px 32px 0 rgba(0,0,0, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Shabbat Decoration Image */
.shabbat-decoration {
    position: absolute;
    bottom: -1vmin;
    left: -1vmin;
    height: 16vmin;
    object-fit: contain;
    z-index: 5;
    filter: drop-shadow(2px 2px 5px rgba(0,0,0,0.2));
}

/* Royal Biblical Card Immersive Style */
body.theme-royal .card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.1) 100%);
    box-shadow: inset 0 0 20px rgba(255,255,255,0.5), 0 10px 30px rgba(92, 60, 20, 0.15);
    border: none;
}

.card h3 {
    font-size: 3vmin; /* Reduced from 3.5vmin */
    color: var(--accent-blue);
    margin-bottom: 2vmin;
    text-align: center;
    font-weight: 700;
    position: relative;
    padding-bottom: 1.5vmin;
    transition: opacity 0.3s ease;
}

/* Custom elegant underline for headers instead of borders */
.card h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--accent-gold), transparent);
}

/* Important Text Utilities */
.glow-text {
    color: var(--accent-blue);
    font-weight: 900;
}

/* Lists and Items */
ul {
    list-style: none;
}

.time-row, .prayer-item, .zmanim-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 3vmin;
    padding: 1.5vmin 1vmin;
    border-bottom: 1px solid rgba(184, 134, 11, 0.15); /* Very subtle divider */
}

.time-row:last-child, .prayer-item:last-child, .zmanim-list li:last-child {
    border-bottom: none;
}

/* Announcements & Shabbat */
.shabbat-card {
    flex: 0 0 auto;
}

.announcements-card {
    flex-grow: 1;
}

.announcement-feed {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1vmin;
    overflow: hidden;
}

.announcement-text {
    font-size: 4vmin;
    font-weight: 700;
    line-height: 1.5;
    color: var(--text-light);
    transition: opacity 0.5s ease;
}

.fade-out {
    opacity: 0;
}

.dedication-plaque {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background: url('dedication-banner.png') no-repeat center bottom;
    background-size: contain;
    color: #C5A059; /* Always keep original gold color regardless of theme */
    padding: 6vmin 12% 0 12%; /* Increased top padding to push text further down */
    text-align: center;
    z-index: 100;
    width: 75%;
    height: 14vmin;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: none;
    box-shadow: none;
}

.dedication-plaque h4 {
    font-size: 2.5vmin;
    margin-bottom: 0.5vmin;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.1vmin;
}

/* Prayers & Slider */
.slider-container {
    position: relative;
    flex: 1;
    min-height: 0;
}

.prayer-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.prayer-slide.active-slide {
    opacity: 1;
    pointer-events: auto;
}

/* Staggered item animation */
.prayer-slide .prayer-item {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.prayer-slide.active-slide .prayer-item {
    opacity: 1;
    transform: translateY(0);
}

.prayer-slide.active-slide .prayer-item:nth-child(1) { transition-delay: 0.1s; }
.prayer-slide.active-slide .prayer-item:nth-child(2) { transition-delay: 0.2s; }
.prayer-slide.active-slide .prayer-item:nth-child(3) { transition-delay: 0.3s; }
.prayer-slide.active-slide .prayer-item:nth-child(4) { transition-delay: 0.4s; }
.prayer-slide.active-slide .prayer-item:nth-child(5) { transition-delay: 0.5s; }
.prayer-slide.active-slide .prayer-item:nth-child(6) { transition-delay: 0.6s; }
.prayer-slide.active-slide .prayer-item:nth-child(7) { transition-delay: 0.7s; }
.prayer-slide.active-slide .prayer-item:nth-child(8) { transition-delay: 0.8s; }
.prayer-slide.active-slide .prayer-item:nth-child(9) { transition-delay: 0.9s; }
.prayer-slide.active-slide .prayer-item:nth-child(10) { transition-delay: 1.0s; }
.prayer-slide.active-slide .prayer-item:nth-child(11) { transition-delay: 1.1s; }
.prayer-slide.active-slide .prayer-item:nth-child(12) { transition-delay: 1.2s; }

/* ---------------------------------
   HORIZONTAL LAYOUT OVERRIDES
   --------------------------------- */
.layout-horizontal .grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto auto auto 1fr;
    grid-template-areas:
        "datetime datetime datetime"
        "zmanim-ticker zmanim-ticker zmanim-ticker"
        "announcements prayers parasha"
        "announcements prayers parasha-filler"
        "announcements prayers shabbat";
    gap: 2vmin;
    padding: 0 2vmin 2vmin 2vmin;
    flex: 1;
    min-height: 0;
}

.layout-horizontal .datetime-banner {
    grid-area: datetime;
}

/* Unwrap containers so cards become direct grid items */
.layout-horizontal .two-cols,
.layout-horizontal .half-col {
    display: contents;
}

/* Hide fillers in horizontal mode for prayers, but show parasha-filler */
.layout-horizontal .prayers-filler {
    display: none;
}
.parasha-filler {
    display: none; /* Hidden in vertical by default */
}
.layout-horizontal .parasha-filler {
    display: flex;
    justify-content: center;
    align-items: center;
    grid-area: parasha-filler;
    height: 8vmin; /* Small fixed height */
    margin: 1vmin 0;
    align-items: center;
}
.layout-horizontal .parasha-filler .filler-img {
    height: 100%;
    width: auto;
    max-width: 60%;
}

/* Map cards to grid areas */
.layout-horizontal .zmanim-card { 
    grid-area: zmanim-ticker; 
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-top: -1vmin;
}
.layout-horizontal .zmanim-card h3 { display: none; }
.layout-horizontal .zmanim-list {
    display: flex;
    flex-direction: row;
    gap: 3vmin;
    justify-content: center;
    width: 100%;
}
.layout-horizontal .zmanim-list li {
    padding: 0;
    border: none;
    flex-direction: row;
    gap: 1vmin;
}
.layout-horizontal .zmanim-name,
.layout-horizontal .zmanim-list .glow-text {
    font-size: 1.8vmin !important;
}
.layout-horizontal .zmanim-list .prayer-time {
    color: var(--accent-gold);
    font-weight: 700;
}
.layout-horizontal .zmanim-list .prayer-name {
    color: var(--text-main);
}
.layout-horizontal .prayers-card { grid-area: prayers; }
.layout-horizontal .parasha-banner { grid-area: parasha; }
.layout-horizontal .shabbat-card { grid-area: shabbat; }
.layout-horizontal .shabbat-decoration {
    height: 22vmin; /* Made a little bit bigger */
    bottom: -1vmin;
    left: 0vmin;
}
.layout-horizontal .announcements-card { 
    grid-area: announcements; 
    /* min-height removed because spanning two rows handles height beautifully */
}
.layout-horizontal .dedication-plaque {
    grid-area: dedication;
    position: absolute; /* Changed to absolute to stick to bottom of page */
    bottom: 0;
    width: 35vw; /* Adjust width because it's absolute now */
    height: 12vmin; /* Fixed height so it doesn't blow up */
    right: 0; /* Align perfectly flush to the right */
    transform: none;
    padding-top: 5.5vmin; /* Bring up names a little */
    z-index: 50;
}

.layout-horizontal .card {
    height: 100%;
}

.layout-horizontal .top-curtain-overlay {
    width: 100vw;
    height: auto;
    max-height: none; /* Let the image dictate its natural height based on width */
    object-fit: unset; /* Remove any distortion or cropping */
    left: 0;
    top: 0;
}


.layout-horizontal .dedication-plaque h4 {
    font-size: 2vh;
    margin: 0 0 0.5vh 0;
}
.layout-horizontal #current-dedication {
    font-size: 2vh !important;
}

/* Header Compression */
.layout-horizontal header {
    padding: 1vmin 6vmin; /* Significantly reduce top/bottom padding */
    margin-bottom: -2vmin; /* Pull content up slightly */
}
.layout-horizontal .logo {
    height: 7vmin; /* Shrink logo */
}
.layout-horizontal .synagogue-info h1 {
    font-size: 5vmin; /* Shrink title */
    transform: none; /* Remove downward shift */
}
.layout-horizontal .synagogue-info p {
    font-size: 2vmin;
    margin-bottom: 0;
}

/* Parasha Compression */
.layout-horizontal .parasha-banner {
    padding: 1vmin !important;
    height: auto;
    min-height: 0;
    align-self: start; /* Prevents it from stretching to match announcements row height */
}
.layout-horizontal .parasha-header h1 {
    font-size: 4vmin; /* Shrink parasha font */
    margin: 0 1vmin;
}
.layout-horizontal .parasha-star {
    width: 3vmin;
    height: 3vmin;
}

.prayer-item {
    font-size: 2.8vmin;
    padding: 1.5vmin 1vmin;
}

.prayer-name {
    font-weight: 700;
}

.prayers-filler {
    margin-top: auto; /* Pushes to the very bottom of the card */
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-top: 2vmin;
}

.filler-img {
    width: 100%;
    max-height: 14vmin; /* Constrain height so it doesn't break layout */
    object-fit: contain;
    opacity: 0.9;
}

/* Zmanim */
.zmanim-card {
    height: 100%;
}

.zmanim-list {
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    height: 100%;
}

.zmanim-name {
    color: var(--text-light);
    font-size: 3vmin; /* Explicitly set slightly smaller */
}

/* --- Universal Responsive Fit Locks --- */
#rotate-wrapper, #board-container, .grid-container, .half-col {
    min-height: 0; /* Forces flex children to compress instead of bursting out */
    min-width: 0;
}

.zmanim-list, .prayer-times {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly; /* Distributes compressed space evenly */
}

.zmanim-list li, .prayer-item {
    min-height: 0; /* Allow items to shrink vertically */
    padding: clamp(0.5vmin, 2vmin, 20px) 1vmin; /* Dynamic padding */
}

img {
    flex-shrink: 0; /* Never deform images */
}
