/* --- CSS Variables & Base Theme --- */
:root {
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.75);
    --text-accent: #64ffda;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.3);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --glow: 0 0 20px rgba(100, 255, 218, 0.3);
}

/* --- Base Styles --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    height: 100vh; overflow: hidden;
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    cursor: none; /* Hide cursor for TV experience */
}

/* --- Enhanced Dynamic Backgrounds with Animations --- */
body { 
    transition: background 2s ease-in-out;
    position: relative;
}
.morning { 
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 50%, #fbc2eb 100%);
    animation: backgroundShift 20s ease-in-out infinite alternate;
}
.afternoon { 
    background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 50%, #a8c8ec 100%);
    animation: backgroundShift 25s ease-in-out infinite alternate;
}
.evening { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    animation: backgroundShift 30s ease-in-out infinite alternate;
}
.night, body.force-night-mode { 
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
    animation: backgroundShift 35s ease-in-out infinite alternate;
}

/* --- NEW "COOL SLATE" LIGHT THEME --- */
body.force-light-mode {
    background: #e0e5ec !important; 
    animation: none !important;
    --card-bg: #e0e5ec;
    --card-border: rgba(0, 0, 0, 0.05);
    --text-primary: #34495e;
    --text-secondary: #7f8c8d;
    --text-accent: #2980b9;
    --glow: 0 0 20px rgba(41, 128, 185, 0.2);
}

body.force-light-mode .particle {
    filter: blur(1px);
}
body.force-light-mode .particle-type-1 { 
    background: rgba(52, 73, 94, 0.1) !important; 
}
body.force-light-mode .particle-type-2 { 
    background: radial-gradient(circle, rgba(41, 128, 185, 0.12) 0%, transparent 70%) !important; 
}
body.force-light-mode .particle-type-3 { 
    background: rgba(127, 140, 141, 0.08) !important; 
}

body.force-light-mode .current-day {
    background: linear-gradient(135deg, #2980b9, #3498db) !important;
    color: #ffffff !important;
}
body.force-light-mode .control-btn {
    background: #e0e5ec !important;
    border: none !important;
    color: var(--text-primary) !important;
    box-shadow: 3px 3px 6px #a3b1c6, -3px -3px 6px #ffffff !important;
}
body.force-light-mode .control-btn:hover {
    box-shadow: inset 3px 3px 6px #a3b1c6, inset -3px -3px 6px #ffffff !important;
}

body.force-light-mode .card {
    border-radius: 30px; 
    border: none;
    background: var(--card-bg) !important;
    box-shadow: 
        7px 7px 15px #a3b1c6, 
        -7px -7px 15px #ffffff !important;
}
body.force-light-mode .card:hover {
    transform: translateY(-2px) !important;
    box-shadow: 
        10px 10px 20px #a3b1c6, 
        -10px -10px 20px #ffffff !important;
}
body.force-light-mode .card::before {
    background: linear-gradient(90deg, transparent, rgba(52, 73, 94, 0.04), transparent) !important;
}
body.force-light-mode .calendar-header,
body.force-light-mode .weather-description,
body.force-light-mode .smart-status.on {
    color: var(--text-accent) !important;
}
body.force-light-mode .alarm-input {
    background: #dde3ea;
    border: 1px solid #c8d0d9;
    color: var(--text-primary);
}
body.force-light-mode .alarm-btn {
    background: var(--text-accent);
    color: #fff;
}

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

.particles { position: absolute; width: 100%; height: 100%; overflow: hidden; z-index: -1; }
.particle { 
    position: absolute; 
    border-radius: 50%; 
    pointer-events: none; 
    animation-fill-mode: backwards;
}
.particle-type-1 { background: rgba(255, 255, 255, 0.1); animation: float1 25s infinite linear; }
.particle-type-2 { background: radial-gradient(circle, rgba(100, 255, 218, 0.2) 0%, transparent 70%); animation: float2 30s infinite linear; }
.particle-type-3 { background: rgba(255, 255, 255, 0.05); animation: float3 35s infinite linear; }
@keyframes float1 { 0% { transform: translateY(100vh) rotate(0deg); opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; } }
@keyframes float2 { 0% { transform: translateY(100vh) scale(0.5); opacity: 0; } 20% { opacity: 0.8; } 80% { opacity: 0.8; } 100% { transform: translateY(-10vh) scale(0.5); opacity: 0; } }
@keyframes float3 { 0% { transform: translateY(100vh) translateX(0px); opacity: 0; } 25% { transform: translateY(75vh) translateX(20px); } 75% { transform: translateY(25vh) translateX(-20px); } 100% { transform: translateY(-10vh) translateX(0px); opacity: 0; } }

/* FIXED GRID LAYOUT */
.dashboard {
    display: grid;
    grid-template-areas: 
        "time     calendar weather"
        "quote    calendar smart-home"
        "forecast forecast forecast";
    grid-template-columns: 1.6fr 1.2fr 1.2fr;
    grid-template-rows: auto auto 1fr; 
    gap: 2vh;
    padding: 4vh;
    height: 100vh;
}

.card {
    background: var(--card-bg); backdrop-filter: blur(20px); border: 1px solid var(--card-border);
    border-radius: 24px; box-shadow: var(--shadow-soft);
    transition: var(--transition); position: relative; overflow: hidden;
    padding: 2vh;
}
.card::before {
    content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.8s;
}
.card:hover::before { left: 100%; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-soft), var(--glow); border-color: rgba(100, 255, 218, 0.3); }

/* FIXED TIME SECTION: Better proportions and layout */
.time-section { 
    grid-area: time; 
    display: flex; 
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    min-height: 0; /* Important for proper flex sizing */
}

.time-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
}

.clock { 
    font-size: min(10vh, 6vw); 
    font-weight: 200; 
    line-height: 0.9;
    text-shadow: 0 0 30px rgba(100, 255, 218, 0.3);
    animation: pulse 4s ease-in-out infinite;
    margin-bottom: 1vh;
}

@keyframes pulse { 
    0%, 100% { text-shadow: 0 0 30px rgba(100, 255, 218, 0.3); } 
    50% { text-shadow: 0 0 40px rgba(100, 255, 218, 0.6), 0 0 60px rgba(100, 255, 218, 0.2); } 
}

.date { 
    font-size: min(2.8vh, 1.6vw); 
    font-weight: 300; 
    color: var(--text-secondary); 
    margin-bottom: 2vh;
}
.day-highlight { color: var(--text-accent); font-weight: 400; }

/* IMPROVED ALARM WIDGET: Better sized for landscape */
.alarm-widget {
    display: flex;
    align-items: center;
    gap: 1vh;
    padding: 1.2vh 1.5vh;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: var(--transition);
    width: 100%;
    flex-shrink: 0;
    margin-bottom: 1vh; /* Spacing for multiple alarms */
}
.alarm-widget:last-child {
    margin-bottom: 0;
}
.alarm-widget:hover {
    background: rgba(0, 0, 0, 0.15);
    border-color: var(--text-accent);
    box-shadow: 0 0 15px rgba(100, 255, 218, 0.2);
}
.alarm-icon {
    font-size: min(2.2vh, 1.3vw);
    opacity: 0.8;
    flex-shrink: 0;
}
.alarm-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 0.4vh 0.8vh;
    font-family: inherit;
    font-size: min(1.8vh, 1vw);
    width: 70px;
    transition: var(--transition);
    flex-shrink: 0;
}
.alarm-input:focus {
    outline: none;
    border-color: var(--text-accent);
    box-shadow: 0 0 8px rgba(100, 255, 218, 0.3);
}
.alarm-btn {
    background: var(--text-accent);
    color: #0f0f23;
    border: none;
    border-radius: 6px;
    padding: 0.4vh 0.8vh;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: min(1.6vh, 0.9vw);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 40px;
}
.alarm-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--glow);
}
.alarm-status {
    font-size: min(1.6vh, 0.9vw);
    color: var(--text-accent);
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
    margin-left: auto;
}
.alarm-status.visible {
    opacity: 1;
}

.quote-section { grid-area: quote; margin-top: 2vh; display: flex; align-items: center; }
.quote { 
    font-size: min(4.5vh, 2.5vw); font-style: italic; color: var(--text-secondary); 
    opacity: 0; max-width: 90%; animation: fadeInOut 8s ease-in-out infinite;
}
@keyframes fadeInOut { 0%, 100% { opacity: 0; transform: translateY(10px); } 20%, 80% { opacity: 0.8; transform: translateY(0); } }

.calendar-section { 
    grid-area: calendar; 
    display: flex; 
    flex-direction: column; 
    justify-content: space-between;
}
.calendar-header { text-align: center; font-size: min(3vh, 1.8vw); font-weight: 500; color: var(--text-accent); margin-bottom: 2vh; text-shadow: var(--glow); }
.calendar-grid { 
    display: grid; 
    grid-template-columns: repeat(7, 1fr); 
    gap: 1vh; 
    text-align: center;
}
.calendar-weekdays { font-size: min(2vh, 1.2vw); color: var(--text-secondary); opacity: 0.7; }
.calendar-day { font-size: min(2.2vh, 1.4vw); display: flex; justify-content: center; align-items: center; aspect-ratio: 1 / 1; transition: var(--transition); border-radius: 12px; }
.day-in-month {
    box-shadow: none;
}
.day-in-month:hover { 
    background: rgba(255, 255, 255, 0.1); 
    transform: scale(1.1); 
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.current-day { 
    background: linear-gradient(135deg, var(--text-accent), #4fd1c7); 
    color: #0f0f23; font-weight: 700; 
    animation: dayPulse 2s ease-in-out infinite; 
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), var(--glow);
}
@keyframes dayPulse { 0%, 100% { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), var(--glow); } 50% { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 0 30px rgba(100, 255, 218, 0.8); } }

.weather-section { grid-area: weather; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.weather-icon { font-size: min(7vh, 4vw); animation: weatherFloat 3s ease-in-out infinite; }
@keyframes weatherFloat { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-10px); } }
.weather-temp { font-size: min(6vh, 3.5vw); font-weight: 300; }
.weather-location { font-size: min(2.5vh, 1.5vw); color: var(--text-secondary); text-transform: uppercase; }
.weather-description { font-size: min(2.2vh, 1.3vw); color: var(--text-accent); margin-top: 0.5vh; text-transform: capitalize; }

.smart-home-section { 
    grid-area: smart-home; 
    display: flex; 
    flex-direction: column; 
    gap: 1.5vh; 
    justify-content: center; 
}

.smart-item { 
    padding: 1.5vh; border-radius: 16px; background: rgba(0,0,0,0.05); cursor: pointer; transition: var(--transition);
 box-shadow: none;
    display: flex; 
    align-items: center;
    gap: 1vw;
}

.smart-item:hover { 
    background: rgba(0,0,0,0.1); 
    transform: translateX(5px); 
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}
.smart-icon { font-size: min(3vh, 1.8vw); }
.smart-status { 
    margin-left: auto; 
    color: var(--text-secondary); 
    font-weight: 500; 
    white-space: nowrap; 
}
.smart-status.on { color: var(--text-accent); }

/* FIXED FORECAST SECTION: Better card layout */
.forecast-section { 
    grid-area: forecast; 
    display: flex; 
    gap: 1.5vh; 
    align-items: stretch;
    justify-content: space-between;
    overflow: hidden;
}

@keyframes gentleSequenceFloat {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-4px); }
}

.forecast-item { 
    flex: 1;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1vh;
    padding: 2vh 1vh;
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.05);
    transition: var(--transition);
    animation: gentleSequenceFloat 3s ease-in-out infinite;
    min-width: 0; /* Prevents flex items from overflowing */
}

.forecast-item:hover { 
    animation-play-state: paused;
    background: rgba(0,0,0,0.1); 
    transform: translateY(-8px);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
}
.forecast-day { 
    font-size: min(2vh, 1.2vw); 
    color: var(--text-secondary); 
    font-weight: 500;
    text-align: center;
}
.forecast-icon { 
    font-size: min(3.5vh, 2.2vw); 
    margin: 0; 
}
.forecast-temp { 
    font-size: min(2.4vh, 1.5vw); 
    font-weight: 600;
    color: var(--text-primary);
}

.controls { position: fixed; bottom: 3vh; left: 3vh; display: flex; gap: 10px; z-index: 1000; opacity: 0; transition: opacity 0.3s ease; }
body:hover .controls, body.show-controls .controls { opacity: 0.7; }
.control-btn { width: 40px; height: 40px; background: rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 20px; color: white; cursor: pointer; transition: var(--transition); backdrop-filter: blur(10px); }
.control-btn:hover { background: rgba(100, 255, 218, 0.2); border-color: var(--text-accent); transform: scale(1.1); }

.loading { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2000; opacity: 1; transition: opacity 0.5s ease; }
.loading.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 50px; height: 50px; border: 3px solid rgba(255, 255, 255, 0.1); border-top: 3px solid var(--text-accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* IMPROVED ALARM ALERT */
.alarm-alert {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}
.alarm-alert.visible {
    opacity: 1;
    pointer-events: auto;
}
.alarm-box {
    background: var(--card-bg);
    padding: 4vh 6vh;
    border-radius: 32px;
    text-align: center;
    border: 2px solid var(--text-accent);
    animation: alarmPulse 1.5s infinite;
    backdrop-filter: blur(20px);
}
.alarm-box h2 {
    font-size: min(6vh, 4vw);
    color: var(--text-accent);
    margin-bottom: 3vh;
    text-shadow: var(--glow);
}
.alarm-box button {
    background: linear-gradient(135deg, #ff4757, #ff3742);
    color: #fff;
    border: none;
    border-radius: 16px;
    padding: 2vh 4vh;
    font-size: min(2.5vh, 1.5vw);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}
.alarm-box button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 71, 87, 0.6);
}
@keyframes alarmPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(100, 255, 218, 0.4); }
    70% { transform: scale(1.02); box-shadow: 0 0 20px 30px rgba(100, 255, 218, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(100, 255, 218, 0); }
}

@media (orientation: portrait) {
    html, body { height: auto; overflow-y: auto; overflow-x: hidden; cursor: auto; }
    .dashboard { 
        grid-template-columns: 1fr; 
        grid-template-rows: auto; 
        grid-template-areas: "time" "weather" "calendar" "smart-home" "forecast" "quote";
        height: auto; min-height: 100vh; padding: 4vh 5vw; gap: 2.5vh; 
    }
    .time-section, .quote-section { text-align: center; }
    .time-section { align-items: center; }
    .clock { font-size: 20vw; }
    .date { font-size: 6vw; }
    .alarm-widget { justify-content: center; max-width: 350px; margin: 0 auto; }
    .quote-section { justify-content: center; }
    .quote { font-size: 5vw; padding: 2vh 5vw; }
    .forecast-section { flex-direction: column; gap: 1.5vh; }
    .forecast-item { 
        flex-direction: row; 
        justify-content: space-between; 
        padding: 1.5vh 4vw; 
    }
    .controls { opacity: 0.7; }
}
