:root {
    --bg-body: #070A12;
    --bg-panel: rgba(255, 255, 255, 0.05);
    --bg-panel-hover: rgba(255, 255, 255, 0.08);
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --primary: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.1);
    --radius: 16px;
    --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 680px;
    /* Slightly wider for the row of dots */
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.btn-back {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}

.btn-back:hover {
    color: var(--text-main);
}

h1 {
    font-size: 24px;
    margin: 0;
    font-weight: 600;
}

/* Identity Section */
.identity-section {
    text-align: center;
    padding: 20px 0;
    animation: fadeIn 0.8s ease-out;
}

.identity-message {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 8px;
    background: linear-gradient(to right, #fff, #a5b4fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.identity-sub {
    font-size: 14px;
    color: var(--text-muted);
}

/* Controls */
.controls {
    display: flex;
    justify-content: flex-end;
}

.btn-add {
    background: var(--bg-panel);
    color: var(--text-muted);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-add:hover {
    background: var(--bg-panel-hover);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Habit List */
.habit-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.habit-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    backdrop-filter: blur(10px);
    transition: background 0.2s;
}

.habit-card:hover {
    background: var(--bg-panel-hover);
}

.habit-info {
    flex: 1;
    min-width: 0;
}

.habit-info h3 {
    margin: 0 0 6px 0;
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.habit-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.habit-cue {
    /* Hidden as per request to remove time field */
    display: none;
}

.streak-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #ffd700;
    display: inline-block;
}

.streak-badge.inactive {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    filter: grayscale(100%);
    opacity: 0.6;
}

.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.habit-card:hover .btn-delete {
    opacity: 1;
}

/* Days Row */
.days-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.day-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    /* Null/Empty State: Dark/Black */
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    transition: all 0.2s ease;
    display: grid;
    place-items: center;
    position: relative;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.5);
    /* Default text color if needed */
    font-size: 14px;
    font-weight: 600;
}

.day-circle:hover {
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

/* States */
.day-circle.completed {
    background: var(--success);
    border-color: var(--success);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
    color: white;
}

.day-circle.skipped {
    /* Blue/Grey for Skip */
    background: #475569;
    /* Slate 600 */
    border-color: #475569;
    box-shadow: none;
    color: rgba(255, 255, 255, 0.9);
}

.day-circle.missed {
    /* Same as null */
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.15);
}

.day-circle.today {
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Tooltip on hover for date */
.day-circle::after {
    content: attr(data-date);
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    background: rgba(0, 0, 0, 0.8);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    color: white;
}

.day-circle:hover::after {
    opacity: 1;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .app-container {
        padding: 16px;
    }

    .habit-card {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 12px;
        position: relative;
        /* For absolute delete btn */
    }

    /* Compact Header: Title + Streak inline */
    .habit-info {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
        padding-right: 24px;
        /* Space for delete button */
        width: 100%;
    }

    .habit-info h3 {
        margin: 0;
        font-size: 16px;
    }

    .habit-meta {
        margin: 0;
        min-height: 0 !important;
        /* Override inline style */
    }

    .btn-delete {
        position: absolute;
        top: 12px;
        right: 12px;
        opacity: 1;
        /* Always visible on mobile (no hover) */
        padding: 8px;
    }

    /* Adjusted Dots Row */
    .days-row {
        width: 100%;
        justify-content: space-between;
        /* Spread to fill width */
        gap: 4px;
        margin-top: 4px;
        /* Slight separation from title */
    }

    .day-circle {
        width: 36px;
        /* Larger touch targets, fits with space-between */
        height: 36px;
        font-size: 14px;
    }

    /* Adjust for 30/90 day views on mobile */
    .days-row.view-30 .day-circle {
        width: 24px;
        height: 24px;
        font-size: 9px;
    }

    .days-row.view-90 .day-circle {
        width: 12px;
        height: 12px;
    }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #151922;
    padding: 24px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal h2 {
    margin: 0;
    font-size: 20px;
}

input,
select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    color: white;
    font-family: inherit;
    width: 100%;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 13px;
    color: var(--text-muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.btn-cancel {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.btn-submit {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    cursor: pointer;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* View Toggles */
.view-toggles {
    display: flex;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
    margin-right: auto;
    /* Push left in controls */
}

.btn-view {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view:hover {
    color: var(--text-main);
}

.btn-view.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

/* Extended Views (30 & 90 Days) */
.habit-card:has(.view-30),
.habit-card:has(.view-90) {
    flex-wrap: wrap;
}

.days-row.view-30,
.days-row.view-90 {
    flex-basis: 100%;
    order: 3;
    /* Move below title and delete button */
    margin-top: 16px;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
}

/* Ensure title and delete button stay on top row */
.habit-card:has(.view-30) .habit-info,
.habit-card:has(.view-90) .habit-info {
    order: 1;
}

.habit-card:has(.view-30) .btn-delete,
.habit-card:has(.view-90) .btn-delete {
    order: 2;
}

/* 30 Day Specifics */
.days-row.view-30 .day-circle {
    width: 28px;
    height: 28px;
    font-size: 10px;
}

/* 90 Day Specifics */
.days-row.view-90 {
    gap: 4px;
}

.days-row.view-90 .day-circle {
    width: 16px;
    height: 16px;
    font-size: 0;
    /* Hide text/check */
    border-radius: 4px;
    position: relative;
    z-index: 5;
}

.days-row.view-90 .day-circle.completed {
    background: var(--success);
    box-shadow: none;
    /* Too busy for grid */
}

/* Hide checks in small view */


/* 30+ Day Streak (Goal Met) Treatment */
.habit-card.goal-met {
    border-color: rgba(255, 215, 0, 0.4);
    background: linear-gradient(to right, rgba(255, 215, 0, 0.05), rgba(255, 255, 255, 0.05));
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.1);
}

.habit-card.goal-met .streak-badge {
    background: rgba(255, 215, 0, 0.15);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.3);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.2);
    animation: glow 2s infinite alternate;
}

@keyframes glow {
    from {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.2);
    }

    to {
        box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
    }
}