:root {
    --bg: #0b0f14;
    --panel: #072438;
    --panel-2: #d0e6f6;
    --text: #000000;
    --muted: #9ca3af;
    --accent: #3b82f6;
    --grid-border: #233047;
    --event-radius: 6px;
    --cell-gap: 2px;
    --cell-pad: 8px;
    --event-font: 12px;
}
.calendar-app {
    max-width: 1100px;
    min-width: 0;
    width: 100%;
    padding: 16px;
    box-sizing: border-box;
}
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.toolbar .title { font-weight: 700; font-size: 22px; letter-spacing: 0.2px; }
.spacer { flex: 1; }
.btn {
    background: #ffffff;
    border: 1px solid #243046;
    color: var(--text);
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: 120ms ease;
}
.btn:hover { background: #0b1220; }
.btn:active { transform: translateY(1px); }
.chev { font-size: 16px; line-height: 1; }

.weekday-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 12px;
    user-select: none;
    width: 100%;
    max-width: 100%;
}
.weekday {
    padding: 8px;
    text-align: right;
}

.grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    /*grid-auto-rows: minmax(110px, 1fr);*/
    gap: var(--cell-gap);
    border-top: 1px solid var(--grid-border);
    border-left: 1px solid var(--grid-border);
    background: var(--grid-border);
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.cell {
    background: #ffffff;
    position: relative;
    padding: var(--cell-pad);
    border-right: 1px solid var(--grid-border);
    border-bottom: 1px solid var(--grid-border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 20px;
    min-width: 0;
    overflow: hidden;
    aspect-ratio: 1;
}
.cell:hover { outline: 2px solid rgba(59,130,246,.3); z-index: 1; }

.date-badge {
    position: absolute;
    top: 6px; right: 8px;
    font-size: 12px; font-weight: 600; color: var(--muted);
    background: transparent; padding: 2px 6px; border-radius: 8px;
}
.date-badge.today { color: white; background: var(--accent); }
.moon-phase {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 14px;
    line-height: 1;
    pointer-events: none;
    filter: drop-shadow(0 0 2px rgba(0,0,0,.25));
}
.moon-inline {
    font-size: 12px;
    font-weight: 600;
    color: #3b2f12;
    background: rgba(255, 249, 230, 0.75);
    border-radius: 999px;
    padding: 2px 8px;
    margin-left: 6px;
    white-space: nowrap;
}
.legend-moons {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #111827;
    letter-spacing: 1px;
}
.outside { opacity: 0.8; }

.events { margin-top: 18px; display: flex; flex-direction: column; gap: 4px; }
.event {
    font-size: var(--event-font);
    line-height: 1.2;
    padding: 0px 4px;
    border-radius: var(--event-radius);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.08);
}
.event[data-color="blue"] { background: #1d4ed8; }
.event[data-color="green"] { background: #15803d; }
.event[data-color="purple"]{ background: #6d28d9; }
.event[data-color="orange"]{ background: #c2410c; }
.event[data-color="pink"] { background: #be185d; }
.event[data-color="gray"] { background: #374151; }

.more { font-size: 12px; color: var(--muted); cursor: pointer; }
.more:hover { color: var(--text); text-decoration: underline; }

/* Popover */
.popover {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.45);
    z-index: 20;
    padding: 16px;
}
.popover.open { display: flex; }
.card {
    width: 100%; max-width: 420px;
    background: #c5d6e3;
    border: 2px solid #082439;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.card h3 { margin: 0 0 8px; font-size: 20px; }
.card small { color: var(--muted); }
.card .event { cursor: default; }

.add-inline {
    margin-top: auto;
    display: flex; gap: 8px; align-items: center;
}
.add-inline input, .add-inline select {
    flex: 1;
    background: #eaeff4;
    border: 1px solid #243046;
    color: var(--text);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13px;
}
.legend {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    color: #111827;
    font-size: 12px;
    background: #ffffff;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(180, 200, 230, 0.9);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; vertical-align: middle; margin-right: 6px; }

@media (max-width: 768px) {
    .calendar-app {
        min-width: 0;
        padding: 8px;
    }
    .toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    .grid {
        grid-auto-rows: minmax(0, auto);
    }
    .cell {
        padding: 4px;
        min-height: 0;
    }
    .weekday {
        text-align: center;
        padding: 4px 2px;
        font-size: 11px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .date-badge { right: 2px; top: 2px; font-size: 10px; padding: 1px 3px; }
    .moon-phase { top: 0px; left: 2px; font-size: 10px; }
    .events { margin-top: 14px; }
    .event {
        font-size: 9px;
        padding: 2px 3px;
    }
}