/* ========== CSS Variables (Dark default) ========== */
:root {
    --bg-primary: #0a0e14;
    --bg-secondary: #12171e;
    --bg-tertiary: #1a2129;
    --bg-card: rgba(26, 33, 41, 0.85);
    --bg-card-border: rgba(56, 66, 78, 0.6);
    --text-primary: #eef2f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #60a5fa;
    --accent-dim: rgba(96, 165, 250, 0.18);
    --accent-hover: #93c5fd;
    --success: #34d399;
    --success-light: #6ee7b7;
    --warning: #fbbf24;
    --danger: #f87171;
    --glass-bg: rgba(26, 33, 41, 0.9);
    --glass-border: rgba(75, 85, 99, 0.4);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 14px 36px rgba(0, 0, 0, 0.55);
    --input-bg: rgba(17, 24, 32, 0.95);
    --heatmap-0: #1a2129;
    --heatmap-1: #064e3b;
    --heatmap-2: #047857;
    --heatmap-3: #059669;
    --heatmap-4: #10b981;
    --chart-grid: rgba(56, 66, 78, 0.5);
    --chart-text: #9ca3af;
    --tooltip-bg: #1a2129;
    --tooltip-border: rgba(56, 66, 78, 0.7);
}

[data-theme="light"] {
    --bg-primary: #f6f8fa;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-border: rgba(31, 35, 40, 0.12);
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #8c959f;
    --accent: #0969da;
    --accent-dim: rgba(9, 105, 218, 0.12);
    --accent-hover: #0550ae;
    --success: #1a7f37;
    --success-light: #2da44e;
    --warning: #9a6700;
    --danger: #cf222e;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(31, 35, 40, 0.15);
    --shadow: 0 8px 24px rgba(31, 35, 40, 0.15);
    --shadow-hover: 0 12px 32px rgba(31, 35, 40, 0.2);
    --input-bg: rgba(255, 255, 255, 0.95);
    --heatmap-0: #ebedf0;
    --heatmap-1: #9be9a8;
    --heatmap-2: #40c463;
    --heatmap-3: #30a14e;
    --heatmap-4: #216e39;
    --chart-grid: rgba(31, 35, 40, 0.15);
    --chart-text: #656d76;
    --tooltip-bg: #ffffff;
    --tooltip-border: rgba(31, 35, 40, 0.15);
}

/* ========== Base ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
    animation: fadeIn 0.4s ease-out;
}

/* Smooth theme transitions */
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
    transition: background-color 0.3s ease, 
                color 0.3s ease, 
                border-color 0.3s ease,
                box-shadow 0.3s ease !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ========== Modal ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay:not([aria-hidden="true"]) .modal {
    animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-overlay[aria-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal {
    position: relative;
    max-width: 380px;
    width: 100%;
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
}

.modal-close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s;
}

.modal-close-btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.modal-close-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
    transform: scale(1.04);
}

.modal-title {
    margin: 0 0 1.25rem;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-subtitle {
    margin: -0.8rem 0 1.15rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-form input {
    font: inherit;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--bg-card-border);
    background: var(--input-bg);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-form input::placeholder {
    color: var(--text-muted);
}

.modal-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn-primary {
    font: inherit;
    font-weight: 600;
    width: 100%;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-primary:active {
    transform: scale(0.98);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.btn-secondary {
    font: inherit;
    font-weight: 500;
    padding: 0.6rem 1rem;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.btn-secondary:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
    color: var(--accent);
}

.btn-edit-handles {
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.btn-edit-handles:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ========== App layout ========== */
.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

/* ========== Header ========== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.greeting {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* Theme toggle */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    transition: background 0.3s, border-color 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                background 0.3s ease,
                box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: var(--accent);
    box-shadow: 0 2px 6px rgba(88, 166, 255, 0.4);
}

.toggle:hover .toggle-slider::before {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ========== Main ========== */
.last-updated {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0 0 1.5rem;
}

/* ========== Glass cards ========== */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    transition: border-color 0.3s ease, 
                box-shadow 0.3s ease, 
                background 0.3s ease, 
                transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
    animation-delay: calc(var(--card-index, 0) * 0.05s);
    will-change: transform;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glass-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--glass-border);
}

[data-theme="dark"] .glass-card,
:root:not([data-theme="light"]) .glass-card {
    border-color: rgba(75, 85, 99, 0.45);
}

[data-theme="dark"] .glass-card:hover,
:root:not([data-theme="light"]) .glass-card:hover {
    border-color: rgba(96, 165, 250, 0.25);
}

@media (prefers-reduced-motion: reduce) {
    .glass-card {
        animation: none;
        transition: none;
    }
    
    .glass-card:hover {
        transform: none;
    }
}

.card {
    padding: 1.5rem;
}

.card-title {
    margin: 0 0 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
}

/* ========== Dashboard grid ========== */
.dashboard {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.chart-card {
    min-height: 260px;
}

.chart-wrap {
    position: relative;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-wrap-bar {
    height: 240px;
}

.chart-wrap-line {
    height: 280px;
}

.full-width {
    grid-column: span 2;
}

/* ========== Streak card ========== */
.streak-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    text-align: center;
}

.streak-card:has(.streak-wrap) {
    grid-column: span 2;
}

.streak-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1;
    margin: 0.5rem 0;
    transition: transform 0.3s ease;
}

.streak-card:hover .streak-value {
    transform: scale(1.05);
}

.streak-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.streak-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    overflow: hidden;
    border-radius: 10px;
}

.streak-img {
    max-width: 100%;
    height: auto;
    min-height: 100px;
    object-fit: contain;
    border-radius: 8px;
    transition: opacity 0.3s ease;
}

/* ========== Heatmap ========== */
.heatmap-card {
    grid-column: span 2;
}

.heatmap-layout {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 0.5rem;
}

.heatmap-header {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
}

.heatmap-header-spacer {
    width: 32px;
}

.heatmap-months {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    font-size: 0.7rem;
    color: var(--text-muted);
    column-gap: 2px;
}

.heatmap-month-label {
    text-align: left;
    white-space: nowrap;
}

.heatmap-body {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    column-gap: 0.5rem;
}

.heatmap-days {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding-top: 2px;
    padding-bottom: 2px;
}

.heatmap-days span {
    line-height: 1;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-swatches {
    display: flex;
    gap: 2px;
}

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
}

.swatch[data-level="0"] { background: var(--heatmap-0); }
.swatch[data-level="1"] { background: var(--heatmap-1); }
.swatch[data-level="2"] { background: var(--heatmap-2); }
.swatch[data-level="3"] { background: var(--heatmap-3); }
.swatch[data-level="4"] { background: var(--heatmap-4); }

.heatmap-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 2px;
}

.heatmap-cell {
    aspect-ratio: 1;
    min-width: 12px;
    max-width: 18px;
    border-radius: 3px;
    background: var(--heatmap-0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.2s ease,
                box-shadow 0.2s ease,
                filter 0.2s ease;
    cursor: pointer;
    will-change: transform;
    position: relative;
}

.heatmap-cell:hover {
    transform: scale(1.3);
    z-index: 10;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    filter: brightness(1.15);
}

.heatmap-cell[data-level="0"]:hover {
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.15);
    filter: brightness(1.3);
}

/* Enhanced tooltip */
.heatmap-cell::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: var(--tooltip-bg);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: pre-line;
    text-align: center;
    line-height: 1.4;
    border: 1px solid var(--tooltip-border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    z-index: 100;
    min-width: 140px;
    max-width: 200px;
    font-family: 'JetBrains Mono', monospace;
    backdrop-filter: blur(8px);
}

.heatmap-cell:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.heatmap-cell::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--tooltip-bg);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 101;
}

.heatmap-cell:hover::before {
    opacity: 1;
    visibility: visible;
}

.heatmap-cell[data-level="1"] { background: var(--heatmap-1); }
.heatmap-cell[data-level="2"] { background: var(--heatmap-2); }
.heatmap-cell[data-level="3"] { background: var(--heatmap-3); }
.heatmap-cell[data-level="4"] { background: var(--heatmap-4); }

/* ========== Tag Analysis ========== */
.tag-analysis-card {
    grid-column: 1 / -1;
}

.tag-analysis-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
}

.tag-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tag-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.tag-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tag-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--accent-dim);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tag-item:hover {
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tag-item-weak {
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.2);
}

.tag-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.tag-bar-container {
    flex: 1;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.tag-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 3px;
    transition: width 0.6s ease;
}

.tag-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    min-width: 2rem;
    text-align: right;
}

.tag-empty {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 0;
    padding: 1rem;
    text-align: center;
}

@media (max-width: 768px) {
    .tag-analysis-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* ========== Recent Submissions ========== */
.submissions-card.full-width {
    grid-column: 1 / -1;
}

.submissions-wrap {
    max-height: 320px;
    overflow-y: auto;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
}

.submissions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.submissions-table th,
.submissions-table td {
    padding: 0.65rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.submissions-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
}

.submissions-table tbody tr {
    transition: background 0.15s ease;
}

.submissions-table tbody tr:hover {
    background: var(--accent-dim);
    transform: translateX(2px);
    transition: background 0.15s ease, transform 0.15s ease;
}

[data-theme="dark"] .header,
:root:not([data-theme="light"]) .header {
    border-bottom-color: rgba(75, 85, 99, 0.4);
}

.submissions-table .problem-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease, text-decoration 0.2s ease;
}

.submissions-table .problem-link:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

.submissions-table .platform-badge {
    display: inline-block;
    padding: 0.2em 0.5em;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
}

.platform-codeforces { background: rgba(68, 95, 157, 0.2); color: #445f9d; }
.platform-leetcode { background: rgba(255, 161, 22, 0.2); color: #ffa116; }

.submissions-table .difficulty {
    font-size: 0.85rem;
    font-weight: 500;
}

.difficulty-easy { color: var(--success); }
.difficulty-medium { color: var(--warning); }
.difficulty-hard { color: var(--danger); }

.submissions-table .time-ago {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .chart-card,
    .streak-card,
    .heatmap-card {
        grid-column: span 1;
    }

    .heatmap-grid {
        grid-template-columns: repeat(26, 1fr);
    }
}

@media (max-width: 480px) {
    .app {
        padding: 1rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .submissions-table th,
    .submissions-table td {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}
