/* ========== Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-night: #0a0e27;
    --bg-dawn: #1a1040;
    --bg-day: #4a90d9;
    --bg-sunset: #e8734a;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.12);
    --card-hover: rgba(255, 255, 255, 0.12);
    --accent-gold: #f4c430;
    --accent-blue: #5b9bd5;
    --accent-orange: #e8734a;
    --accent-purple: #9b59b6;
    --suhoor-color: #7c6ee6;
    --iftar-color: #e8734a;
    --sunrise-color: #f4c430;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-night);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 2s ease;
}

#app {
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* ========== Pages ========== */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: var(--bg-night);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#main-page {
    z-index: 1;
    transform: translateX(0);
    opacity: 1;
}

#settings-page {
    z-index: 2;
    transform: translateX(100%);
    pointer-events: none;
}

#settings-page.active {
    transform: translateX(0);
    pointer-events: auto;
}

/* ========== Header ========== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(12px + var(--safe-top)) 20px 12px;
    position: relative;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.location-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--card-hover);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ========== Main Content ========== */
main {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Date Navigation */
.date-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.date-nav-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 10px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.date-nav-btn:hover {
    background: var(--card-hover);
}

.date-nav-btn:active {
    transform: scale(0.92);
}

/* Date Display */
.date-display {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.hijri-date {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-gold);
}

.gregorian-date {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
}

/* Day Context Banner */
.day-context {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(124, 110, 230, 0.15);
    border: 1px solid rgba(124, 110, 230, 0.35);
    border-radius: 12px;
    animation: fade-in 0.3s ease both;
}

.day-context-text {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    flex: 1;
}

.today-btn {
    background: var(--suhoor-color);
    border: none;
    border-radius: 8px;
    padding: 6px 14px;
    color: white;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.today-btn:active {
    transform: scale(0.95);
    opacity: 0.85;
}

/* Outside Ramadan message */
.outside-ramadan {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 18px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    text-align: center;
    justify-content: center;
    animation: fade-in 0.4s ease both;
}

.outside-ramadan-icon {
    font-size: 28px;
}

.outside-ramadan-text {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Eid Banner */
.eid-banner {
    background: linear-gradient(135deg, rgba(164, 84, 123, 0.25), rgba(138, 68, 134, 0.25));
    border: 1px solid rgba(164, 84, 123, 0.4);
    border-radius: 14px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: fade-in 0.5s ease both;
}

.eid-banner-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.eid-prayer-line {
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 28px;
}

.eid-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* ========== Sky Container / Canvas ========== */
.sky-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 220px;
    border-radius: 20px;
    overflow: hidden;
    background: linear-gradient(180deg, #0a0e27 0%, #1a1a4e 100%);
}

#sky-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.time-display {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
    font-variant-numeric: tabular-nums;
}

/* ========== Time Cards ========== */
.times-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.time-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.time-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 0 2px 2px 0;
}

.time-card.suhoor::before {
    background: var(--suhoor-color);
}

.time-card.sunrise::before {
    background: var(--sunrise-color);
}

.time-card.iftar::before {
    background: var(--iftar-color);
}

.time-card.active {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.time-card.active.suhoor {
    box-shadow: 0 0 20px rgba(124, 110, 230, 0.15);
}

.time-card.active.iftar {
    box-shadow: 0 0 20px rgba(232, 115, 74, 0.15);
}

.time-card-icon {
    font-size: 28px;
    flex-shrink: 0;
    width: 40px;
    text-align: center;
}

.time-card-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.time-card-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.time-card-time {
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.time-card-countdown {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ========== Next Event Banner ========== */
.next-event-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(124, 110, 230, 0.2), rgba(232, 115, 74, 0.2));
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.next-event-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.next-event-countdown {
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ========== Settings Page ========== */
.settings-content {
    padding: 10px 20px calc(20px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.settings-section h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 600;
}

/* Radio Cards */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-option {
    cursor: pointer;
}

.radio-option input[type="radio"] {
    display: none;
}

.radio-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    transition: all 0.25s ease;
}

.radio-option input:checked + .radio-card {
    background: rgba(124, 110, 230, 0.15);
    border-color: var(--suhoor-color);
}

.radio-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.radio-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.radio-text strong {
    font-size: 15px;
    font-weight: 600;
}

.radio-text span {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Language Switcher */
.lang-switcher {
    display: flex;
    gap: 10px;
}

.lang-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
}

.lang-btn:active {
    transform: scale(0.97);
}

.lang-btn.active {
    background: rgba(124, 110, 230, 0.15);
    border-color: var(--suhoor-color);
}

.lang-flag {
    font-size: 22px;
}

/* Select */
.settings-select {
    width: 100%;
    padding: 14px 16px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='rgba(255,255,255,0.5)' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

.settings-select option {
    background: #1a1a2e;
    color: #fff;
}

/* Toggle */
.toggle-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    font-size: 14px;
}

.toggle-option:last-child {
    border-bottom: none;
}

.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-minutes {
    font-size: 12px;
    color: var(--text-muted);
}

.toggle-input {
    display: none;
}

.toggle-slider {
    width: 48px;
    height: 28px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    position: relative;
    transition: background 0.3s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
}

.toggle-input:checked ~ .toggle-slider {
    background: var(--suhoor-color);
}

.toggle-input:checked ~ .toggle-slider::after {
    transform: translateX(20px);
}

/* File Upload */
.file-upload-area {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.upload-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    background: var(--card-bg);
    border: 1px dashed var(--card-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-btn:hover {
    background: var(--card-hover);
    border-color: var(--suhoor-color);
}

.file-name {
    font-size: 12px;
    color: var(--text-muted);
}

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* ========== Animations ========== */
@keyframes pulse-glow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.time-card {
    animation: fade-in 0.5s ease both;
}

.time-card:nth-child(1) { animation-delay: 0.1s; }
.time-card:nth-child(2) { animation-delay: 0.2s; }
.time-card:nth-child(3) { animation-delay: 0.3s; }

/* ========== Responsive ========== */
@media (max-height: 667px) {
    .sky-container {
        max-height: 170px;
    }
    .time-display {
        font-size: 28px;
    }
    .time-card {
        padding: 12px;
    }
    .time-card-time {
        font-size: 20px;
    }
    .time-card-icon {
        font-size: 24px;
    }
    main {
        gap: 10px;
    }
}

@media (min-width: 500px) {
    main {
        max-width: 480px;
        margin: 0 auto;
    }
    .settings-content {
        max-width: 480px;
        margin: 0 auto;
    }
}
