/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #d32f2f;
    --primary-dark: #b71c1c;
    --primary-light: #ffcdd2;
    --secondary-color: #1976d2;
    --accent-color: #ff5722;
    --background: #f5f5f5;
    --surface: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-muted: #9e9e9e;
    --border-color: #e0e0e0;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.2s ease-in-out;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Container */
.container {
    max-width: 100vw;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--background);
    display: flex;
    flex-direction: column;
}

/* Calendar Section (nav + calendar grid) */
.calendar-section {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Install Button */
.install-button {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-elevated);
}

.install-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.hidden {
    display: none !important;
}

/* ===== Traditional Chinese Calendar Header ===== */
.header {
    background: linear-gradient(160deg, #c62828 0%, #b71c1c 60%, #8d1010 100%);
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* Subtle paper-grain texture overlay */
.header::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.025) 3px, rgba(0,0,0,0.025) 4px);
    pointer-events: none;
    z-index: 0;
}

.header > * {
    position: relative;
    z-index: 1;
}

/* Top band: title + festival tags */
.cal-top-band {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px 12px;
    background: rgba(0, 0, 0, 0.18);
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.cal-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid #000000;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.cal-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 4px;
    opacity: 0.92;
    flex-shrink: 0;
}

.cal-festival-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    flex: 1;
}

.cal-festival-tags .festival-tag {
    background: rgba(255, 255, 255, 0.18) !important;
    color: rgba(255, 255, 255, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.35) !important;
    font-size: 14px;
    padding: 4px 12px;
}

/* Main page body */
.cal-page-body {
    display: flex;
    align-items: center;
    padding: 32px 24px 24px;
    gap: 0;
    flex: 1;
}

/* Left block: solar date big number */
.cal-left-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding-right: 24px;
    min-width: 140px;
}

.cal-big-day {
    font-size: 140px;
    font-weight: 900;
    line-height: 0.9;
    letter-spacing: -3px;
    color: white;
    text-shadow: 2px 4px 16px rgba(0, 0, 0, 0.4);
    font-variant-numeric: tabular-nums;
}

.cal-weekday-badge {
    font-size: 20px;
    font-weight: 600;
    margin-top: 10px;
    opacity: 0.88;
    letter-spacing: 1.5px;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 14px;
    border-radius: 24px;
}

.cal-solar-ym {
    font-size: 16px;
    opacity: 0.65;
    margin-top: 8px;
    letter-spacing: 0.8px;
}

/* Vertical divider */
.cal-vdivider {
    width: 1px;
    background: rgba(255, 255, 255, 0.22);
    margin: 0;
    align-self: stretch;
    flex-shrink: 0;
}

/* Right block: lunar + ganzhi */
.cal-right-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding-left: 24px;
}

.cal-lunar-top {
    display: flex;
    align-items: stretch;
    gap: 12px;
}

.cal-lunar-day-num {
    font-size: 60px;
    font-weight: 700;
    line-height: 1;
    color: white;
    text-shadow: 1px 2px 8px rgba(0, 0, 0, 0.3);
}

.cal-lunar-month-name {
    font-size: 28px;
    font-weight: 500;
    opacity: 0.88;
}

.cal-lunar-year-line {
    font-size: 20px;
    opacity: 0.72;
    letter-spacing: 2px;
}

.cal-hdivider {
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    margin: 8px 0;
}

.cal-ganzhi-line {
    font-size: 20px;
    opacity: 0.88;
    letter-spacing: 1.5px;
}

.cal-meta-line {
    font-size: 18px;
    opacity: 0.78;
}

.cal-sep {
    margin: 0 6px;
    opacity: 0.5;
}

.cal-jieqi-line {
    font-size: 16px;
    opacity: 0.65;
    margin-top: 4px;
}

/* Yi / Ji strip */
.cal-yiji-strip {
    display: flex;
    background: rgba(0, 0, 0, 0.22);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px 24px;
    gap: 0;
}

.cal-yi-block,
.cal-ji-block {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 6px;
}

.cal-yiji-sep {
    width: 1px;
    background: rgba(255, 255, 255, 0.18);
    margin: 0 20px;
    flex-shrink: 0;
}

.cal-yiji-label {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 4px;
    opacity: 0.55;
}

.cal-yiji-value {
    font-size: 16px;
    line-height: 1.6;
}

.cal-yi-block .cal-yiji-value {
    color: #f9c841;
}

.cal-ji-block .cal-yiji-value {
    color: #ffcdd2;
}

/* Navigation */
.nav-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 100;
}

.nav-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.nav-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    transform: scale(1.05);
}

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

/* Inline year/month pickers */
.inline-pickers {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.picker-wrap {
    position: relative;
}

.inline-picker {
    display: flex;
    align-items: center;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
}

.spin-btn {
    width: 32px;
    height: 36px;
    border: none;
    background: none;
    color: var(--primary-color);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.spin-btn:hover {
    background: var(--primary-light);
}

.spin-btn:active {
    transform: scale(0.9);
}

.spin-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 48px;
    text-align: center;
    user-select: none;
    letter-spacing: 0.5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 2px;
    transition: var(--transition);
}

.spin-label:hover {
    color: var(--primary-color);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Dropdown panel */
.spin-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    z-index: 500;
    overflow: hidden;
    animation: fadeIn 0.15s ease;
}

.spin-dropdown.hidden {
    display: none;
}

/* Year list */
#year-dropdown {
    width: 110px;
    max-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.year-item {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.year-item:last-child { border-bottom: none; }

.year-item:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

.year-item.active {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
}

/* Month grid */
#month-dropdown {
    width: 168px;
    padding: 8px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.month-item {
    padding: 9px 4px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition);
    color: var(--text-primary);
}

.month-item:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

.month-item.active {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Today button - Ghost style in header */
.today-btn {
    background: transparent;
    color: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.today-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-1px);
}

/* CTA Button - Prominent style in nav-actions */
.cal-cta-btn {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #f5c518, #c8960c);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    border-radius: 20px;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(245, 197, 24, 0.4);
    transition: all 0.3s ease;
    text-align: center;
    white-space: nowrap;
}

.cal-cta-btn:hover {
    background: linear-gradient(135deg, #ffd700, #d4a915);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 197, 24, 0.6);
}

.cal-cta-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(245, 197, 24, 0.4);
}

/* Calendar Container */
.calendar-container {
    background: var(--surface);
    margin: 16px 16px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Weekdays */
.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.weekday {
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    color: #555555;
    font-size: 14px;
}

/* Calendar Grid */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

/* Calendar Day */
.calendar-day {
    position: relative;
    background: transparent;
    padding: 6px 4px;
    min-height: 64px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.calendar-day:hover::before {
    border: 2px solid var(--primary-color);
}

.calendar-day.selected::before {
    background: var(--primary-color);
}

.calendar-day.today::before {
    background: linear-gradient(135deg, #f5c518, #c8960c);
}

.calendar-day.other-month {
    opacity: 0.35;
}

/* Circle drawn as a pseudo-element behind number + lunar */
.calendar-day::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    pointer-events: none;
}

.day-number {
    position: relative;
    z-index: 1;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 1px;
    line-height: 1;
    padding-top: 6px;
}

/* Holiday indicator dot */
.holiday-dot {
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    background: #f5c518;
    border-radius: 50%;
    z-index: 2;
    box-shadow: 0 0 3px rgba(245, 197, 24, 0.8);
}

.day-lunar {
    position: relative;
    z-index: 1;
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
}

.calendar-day.selected .day-number,
.calendar-day.today .day-number {
    color: white;
}

.calendar-day.selected .day-lunar,
.calendar-day.today .day-lunar {
    color: rgba(255, 255, 255, 0.9);
}

.day-festival {
    position: relative;
    z-index: 1;
    font-size: 9px;
    color: #1976d2;
    font-weight: 500;
    margin-top: 1px;
    text-align: center;
    line-height: 1;
}

.calendar-day.selected .day-festival,
.calendar-day.today .day-festival {
    color: white;
}

/* Day Details — removed; content now lives in header */

.festival-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.6;
}

.festival-tag.priority-1 {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
}

.festival-tag.priority-2 {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.festival-tag.priority-3 {
    background: #f3e5f5;
    color: #6a1b9a;
    border: 1px solid #ce93d8;
}

.festival-tag.term {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius);
    font-size: 14p;
    z-index: 1000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .nav-controls {
        padding: 12px;
    }
    
    .nav-title {
        font-size: 16px;
    }
    
    .calendar-container {
        margin: 0 8px 8px;
    }
    
    .calendar-day {
        min-height: 50px;
        padding: 6px 2px;
    }
    
    .day-number {
        font-size: 14px;
    }
    
    .day-lunar {
        font-size: 9px;
    }
    
    .day-festival {
        font-size: 8px;
    }
    
    .install-button {
        top: 10px;
        right: 10px;
        padding: 6px 12px;
        font-size: 13px;
    }
}

@media (max-width: 360px) {
    .calendar-day {
        min-height: 45px;
        padding: 4px 2px;
    }
    
    .day-number {
        font-size: 13px;
    }
    
    .day-lunar {
        font-size: 8px;
    }
    
    .weekday {
        padding: 8px 4px;
        font-size: 13px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 100vw;
        padding: 0;
        flex-direction: row;
        align-items: stretch;
    }
    
    .header {
        width: 60%;
        min-width: 500px;
        max-width: 800px;
        min-height: 100vh;
        max-height: 100vh;
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.35);
        justify-content: center;
    }
    
    .install-button {
        left: 520px;
    }
    
    .cal-page-body {
        flex-direction: column;
        padding: 40px 32px;
        gap: 20px;
    }
    
    .cal-left-block {
        padding-right: 0;
        min-width: auto;
        width: 100%;
        padding-bottom: 20px;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    }
    
    .cal-vdivider {
        display: none;
    }
    
    .cal-hdivider {
        display: none;
    }
    
    .cal-right-block {
        padding-left: 0;
        width: 100%;
        align-items: center;
    }
    
    .calendar-section {
        flex: 1;
        overflow-y: auto;
        background: var(--background);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 40px 0;
    }
    
    .nav-controls {
        position: relative;
        z-index: 100;
        width: 100%;
        max-width: 900px;
        margin-bottom: 20px;
        border-radius: var(--border-radius);
        overflow: hidden;
    }
    
    .calendar-container {
        margin: 0 20px;
        max-width: 900px;
        width: 100%;
    }
    
    .calendar-day {
        min-height: 110px;
        padding: 12px 8px;
    }

    .calendar-day::before {
        width: 76px;
        height: 76px;
        top: 6px;
    }
    
    .day-number {
        font-size: 19px;
        padding-top: 8px;
    }
    
    .day-lunar {
        font-size: 13px;
    }
    
    .day-festival {
        font-size: 11px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --surface: #1e1e1e;
        --text-primary: #ffffff;
        --text-secondary: #b3b3b3;
        --text-muted: #666666;
        --border-color: #333333;
    }
}

/* Responsive: header on small screens */
@media (max-width: 480px) {
    .cal-icon {
        width: 24px;
        height: 24px;
    }
    .cal-title {
        font-size: 14px;
        letter-spacing: 3px;
    }
    .cal-festival-tags .festival-tag {
        font-size: 11px;
        padding: 3px 8px;
    }
    .cal-big-day {
        font-size: 90px;
    }
    .cal-weekday-badge {
        font-size: 16px;
        padding: 3px 10px;
    }
    .cal-solar-ym {
        font-size: 13px;
    }
    .cal-lunar-day-num {
        font-size: 40px;
    }
    .cal-lunar-month-name {
        font-size: 20px;
    }
    .cal-lunar-year-line {
        font-size: 16px;
    }
    .cal-ganzhi-line {
        font-size: 16px;
    }
    .cal-meta-line {
        font-size: 14px;
    }
    .cal-jieqi-line {
        font-size: 13px;
    }
    .cal-page-body {
        padding: 20px 16px 16px;
    }
    .cal-left-block {
        min-width: 100px;
        padding-right: 16px;
    }
    .cal-right-block {
        padding-left: 16px;
        gap: 6px;
    }
    .cal-yiji-strip {
        padding: 12px 16px;
    }
    .cal-yiji-label {
        font-size: 12px;
    }
    .cal-yiji-value {
        font-size: 14px;
    }
    .today-btn {
        font-size: 11px;
        padding: 3px 8px;
    }
    .cal-cta-btn {
        font-size: 13px;
        padding: 7px 16px;
    }
}

@media (min-width: 768px) {
    .cal-icon {
        width: 36px;
        height: 36px;
    }
    .cal-title {
        font-size: 20px;
        letter-spacing: 5px;
    }
    .cal-festival-tags .festival-tag {
        font-size: 14px;
        padding: 4px 12px;
    }
    .cal-big-day {
        font-size: 200px;
    }
    .cal-weekday-badge {
        font-size: 28px;
        padding: 6px 20px;
        margin-top: 12px;
    }
    .cal-solar-ym {
        font-size: 20px;
        margin-top: 10px;
        order: -1;
    }
    .cal-lunar-day-num {
        font-size: 60px;
    }
    .cal-lunar-month-name {
        font-size: 28px;
    }
    .cal-lunar-year-line {
        font-size: 20px;
    }
    .cal-ganzhi-line {
        font-size: 20px;
    }
    .cal-meta-line {
        font-size: 18px;
    }
    .cal-jieqi-line {
        font-size: 16px;
    }
    .cal-yiji-strip {
        padding: 18px 32px;
    }
    .cal-yiji-label {
        font-size: 14px;
        letter-spacing: 4px;
    }
    .cal-yiji-value {
        font-size: 15px;
    }
    .today-btn {
        font-size: 14px;
        padding: 4px 12px;
    }
    .cal-cta-btn {
        font-size: 15px;
        padding: 10px 24px;
    }
}

