        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 16px;
            padding: 40px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
        }

        h1 {
            color: #2d3748;
            margin-bottom: 10px;
            font-size: 2.5em;
        }

        .subtitle {
            color: #718096;
            margin-bottom: 40px;
            font-size: 1.1em;
        }

        .input-section {
            background: #f7fafc;
            padding: 30px;
            border-radius: 12px;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #2d3748;
            font-weight: 600;
        }

        input[type="text"] {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e2e8f0;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input[type="text"]:focus {
            outline: none;
            border-color: #667eea;
        }

        select {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e2e8f0;
            border-radius: 8px;
            font-size: 16px;
            background: white;
            color: #2d3748;
            cursor: pointer;
            transition: border-color 0.3s;
            appearance: auto;
        }

        select:focus {
            outline: none;
            border-color: #667eea;
        }

        .checkbox-group {
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
        }

        .checkbox-item {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        input[type="checkbox"] {
            width: 20px;
            height: 20px;
            cursor: pointer;
        }

        button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 14px 32px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
        }

        button:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        .loading {
            text-align: center;
            padding: 40px;
            display: none;
        }

        .spinner {
            border: 4px solid #f3f4f6;
            border-top: 4px solid #667eea;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

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

        .results {
            display: none;
        }

        .error {
            background: #fed7d7;
            color: #c53030;
            padding: 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
        }

        .hero-section {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: white;
            padding: 40px;
            border-radius: 12px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(239, 68, 68, 0.3);
        }

        .hero-section.warning {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
        }

        .hero-section.good {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        }

        .hero-title {
            font-size: 1.8em;
            margin-bottom: 10px;
            font-weight: 700;
        }

        .hero-subtitle {
            font-size: 1.2em;
            opacity: 0.95;
            margin-bottom: 20px;
        }

        .hero-stat {
            font-size: 3em;
            font-weight: 800;
            margin: 10px 0;
        }

        .hero-action {
            background: rgba(255, 255, 255, 0.2);
            padding: 15px 20px;
            border-radius: 8px;
            margin-top: 20px;
            border-left: 4px solid white;
        }

        .leaks-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .leak-card {
            background: white;
            border: 2px solid #e2e8f0;
            border-radius: 12px;
            padding: 25px;
            transition: all 0.3s;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .leak-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            transform: scaleX(0);
            transition: transform 0.3s;
        }

        .leak-card:hover::before {
            transform: scaleX(1);
        }

        .leak-card:hover {
            border-color: #667eea;
            transform: translateY(-4px);
            box-shadow: 0 12px 24px rgba(0,0,0,0.15);
        }

        .leak-card.critical {
            border-color: #ef4444;
            background: linear-gradient(135deg, #fef2f2 0%, #ffffff 100%);
        }

        .leak-card.warning {
            border-color: #f59e0b;
            background: linear-gradient(135deg, #fffbeb 0%, #ffffff 100%);
        }

        .leak-card.good {
            border-color: #10b981;
            background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
        }

        .leak-icon {
            font-size: 2.5em;
            margin-bottom: 15px;
        }

        .leak-title {
            font-size: 1.2em;
            font-weight: 700;
            color: #2d3748;
            margin-bottom: 10px;
        }

        .leak-metric {
            font-size: 2.2em;
            font-weight: 800;
            margin: 10px 0;
        }

        .leak-card.critical .leak-metric {
            color: #dc2626;
        }

        .leak-card.warning .leak-metric {
            color: #d97706;
        }

        .leak-card.good .leak-metric {
            color: #059669;
        }

        .leak-description {
            color: #718096;
            font-size: 0.95em;
            line-height: 1.5;
        }

        .insights-section {
            background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
            padding: 30px;
            border-radius: 12px;
            margin-bottom: 30px;
        }

        .insight-item {
            background: white;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 15px;
            border-left: 4px solid #667eea;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }

        .insight-item.critical {
            border-left-color: #ef4444;
        }

        .insight-item.warning {
            border-left-color: #f59e0b;
        }

        .insight-item.tip {
            border-left-color: #3b82f6;
        }

        .insight-header {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 10px;
        }

        .insight-badge {
            padding: 4px 12px;
            border-radius: 4px;
            font-size: 0.85em;
            font-weight: 600;
        }

        .insight-badge.critical {
            background: #fee2e2;
            color: #991b1b;
        }

        .insight-badge.warning {
            background: #fef3c7;
            color: #92400e;
        }

        .insight-badge.tip {
            background: #dbeafe;
            color: #1e40af;
        }

        .insight-text {
            color: #2d3748;
            line-height: 1.6;
            font-size: 1.05em;
        }

        .study-recommendations {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 12px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
        }

        .study-card {
            background: rgba(255, 255, 255, 0.95);
            color: #2d3748;
            padding: 24px;
            border-radius: 8px;
            margin-bottom: 15px;
            transition: transform 0.2s;
        }

        .study-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 16px rgba(0,0,0,0.1);
        }

        .study-priority {
            display: inline-block;
            background: #ef4444;
            color: white;
            padding: 4px 12px;
            border-radius: 4px;
            font-size: 0.85em;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .study-priority.medium {
            background: #f59e0b;
        }

        .study-title {
            font-size: 1.3em;
            font-weight: 700;
            margin-bottom: 10px;
        }

        .study-impact {
            background: #fef3c7;
            color: #92400e;
            padding: 10px 15px;
            border-radius: 6px;
            margin: 10px 0;
            font-weight: 600;
        }

        .study-resources {
            display: flex;
            gap: 10px;
            margin-top: 15px;
            flex-wrap: wrap;
        }

        .resource-link {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: #667eea;
            color: white;
            padding: 8px 16px;
            border-radius: 6px;
            text-decoration: none;
            font-weight: 600;
            font-size: 0.9em;
            transition: all 0.2s;
        }

        .resource-link:hover {
            background: #5a67d8;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
        }

        .resource-link.article {
            background: #10b981;
        }

        .resource-link.article:hover {
            background: #059669;
        }

        .resource-link.lichess {
            background: #b58863;
        }

        .resource-link.lichess:hover {
            background: #9a7350;
        }

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .section-title {
            font-size: 1.8em;
            color: #2d3748;
            font-weight: 700;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 40px;
        }

        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 24px;
            border-radius: 12px;
            text-align: center;
        }

        .stat-value {
            font-size: 2.5em;
            font-weight: bold;
            margin-bottom: 8px;
        }

        .stat-label {
            font-size: 0.9em;
            opacity: 0.9;
        }

        .chart-container {
            background: #f7fafc;
            padding: 30px;
            border-radius: 12px;
            margin-bottom: 30px;
        }

        .chart-title {
            font-size: 1.4em;
            color: #2d3748;
            margin-bottom: 20px;
            font-weight: 600;
        }

        canvas {
            max-height: 400px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background: white;
            border-radius: 8px;
            overflow: hidden;
        }

        th, td {
            padding: 16px;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }

        th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
            font-size: 0.95em;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        tbody tr {
            transition: all 0.2s;
        }

        tbody tr:hover {
            background: #f7fafc;
            transform: scale(1.01);
        }

        .clickable-row {
            cursor: pointer;
            transition: background 0.2s;
        }

        .clickable-row:hover {
            background: #e6f3ff !important;
        }

        .opening-name {
            font-weight: 600;
            color: #2d3748;
            font-size: 1.05em;
        }

        .opening-eco {
            color: #718096;
            font-size: 0.85em;
            margin-top: 4px;
        }

        .stat-number {
            font-weight: 600;
            color: #2d3748;
        }

        .win-rate-high {
            color: #059669;
            font-weight: 700;
        }

        .win-rate-medium {
            color: #d97706;
            font-weight: 700;
        }

        .win-rate-low {
            color: #dc2626;
            font-weight: 700;
        }

        .show-more-btn {
            background: white;
            color: #667eea;
            border: 2px solid #667eea;
            padding: 12px 24px;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            margin-top: 20px;
            width: 100%;
        }

        .show-more-btn:hover {
            background: #667eea;
            color: white;
            transform: translateY(-2px);
        }

        .opening-row-hidden {
            display: none;
        }

        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.7);
            z-index: 1000;
            overflow-y: auto;
        }

        .modal-content {
            background: white;
            max-width: 900px;
            margin: 50px auto;
            padding: 40px;
            border-radius: 16px;
            position: relative;
        }

        .modal-close {
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 28px;
            cursor: pointer;
            color: #718096;
            background: none;
            border: none;
            padding: 0;
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
        }

        .modal-close:hover {
            background: #f7fafc;
            color: #2d3748;
        }

        .game-card {
            background: #f7fafc;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 15px;
            border-left: 4px solid #667eea;
        }

        .game-card.win {
            border-left-color: #10b981;
        }

        .game-card.loss {
            border-left-color: #ef4444;
        }

        .game-card.draw {
            border-left-color: #f59e0b;
        }

        .game-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .game-players {
            font-weight: 600;
            color: #2d3748;
        }

        .game-result {
            padding: 4px 12px;
            border-radius: 4px;
            font-size: 0.9em;
            font-weight: 600;
        }

        .game-result.win {
            background: #d1fae5;
            color: #065f46;
        }

        .game-result.loss {
            background: #fee2e2;
            color: #991b1b;
        }

        .game-result.draw {
            background: #fef3c7;
            color: #92400e;
        }

        .game-details {
            font-size: 0.9em;
            color: #718096;
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
        }

        .game-link {
            margin-top: 10px;
        }

        .game-link a {
            color: #667eea;
            text-decoration: none;
            font-weight: 600;
        }

        .game-link a:hover {
            text-decoration: underline;
        }

        /* Study Plan Styles */
        .study-plan-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 40px;
            border-radius: 12px;
            margin-top: 40px;
            color: white;
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
        }

        .study-plan-intro {
            text-align: center;
            margin-bottom: 30px;
        }

        .study-plan-intro h2 {
            color: white;
            font-size: 2em;
            margin-bottom: 12px;
        }

        .study-plan-intro p {
            opacity: 0.95;
            font-size: 1.1em;
            margin-bottom: 25px;
        }

        .generate-plan-btn {
            background: white;
            color: #667eea;
            padding: 16px 40px;
            font-size: 1.1em;
            font-weight: 700;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        }

        .generate-plan-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.3);
        }

        .generate-plan-btn:disabled {
            opacity: 0.7;
            cursor: not-allowed;
            transform: none;
        }

        #groqApiKey::placeholder {
            color: rgba(255, 255, 255, 0.6);
        }

        #groqApiKey:focus {
            outline: none;
            border-color: rgba(255, 255, 255, 0.6);
            background: rgba(255, 255, 255, 0.15);
        }

        .study-plan-container {
            background: white;
            padding: 40px;
            border-radius: 12px;
            margin-top: 20px;
        }

        .study-plan-header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 3px solid #667eea;
        }

        .analysis-summary {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 25px;
            margin-bottom: 35px;
        }

        .summary-column {
            padding: 25px;
            border-radius: 10px;
            border-left: 5px solid;
        }

        .summary-column.critical {
            background: #fef2f2;
            border-left-color: #ef4444;
        }

        .summary-column.strength {
            background: #f0fdf4;
            border-left-color: #10b981;
        }

        .summary-column h3 {
            color: #2d3748;
            margin-bottom: 15px;
            font-size: 1.3em;
        }

        .summary-column ul {
            list-style: none;
            padding: 0;
        }

        .summary-column ul li {
            padding: 8px 0;
            color: #4a5568;
            font-size: 0.95em;
            line-height: 1.5;
            padding-left: 25px;
            position: relative;
        }

        .summary-column.critical ul li:before {
            content: '\26A0\FE0F';
            position: absolute;
            left: 0;
        }

        .summary-column.strength ul li:before {
            content: '\2705';
            position: absolute;
            left: 0;
        }

        .ai-study-plan {
            background: #f7fafc;
            padding: 35px;
            border-radius: 12px;
            margin-bottom: 30px;
            position: relative;
        }

        .ai-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            display: inline-block;
            font-weight: 600;
            margin-bottom: 20px;
            font-size: 0.9em;
        }

        .plan-content {
            color: #2d3748;
            line-height: 1.8;
        }

        .plan-content h2 {
            color: #2d3748;
            margin-top: 30px;
            margin-bottom: 15px;
            font-size: 1.8em;
            border-bottom: 2px solid #e2e8f0;
            padding-bottom: 10px;
        }

        .plan-content h3 {
            color: #4a5568;
            margin-top: 25px;
            margin-bottom: 12px;
            font-size: 1.4em;
        }

        .plan-content h4 {
            color: #667eea;
            margin-top: 20px;
            margin-bottom: 10px;
            font-size: 1.2em;
        }

        .plan-content strong {
            color: #2d3748;
            font-weight: 700;
        }

        .plan-content em {
            color: #718096;
            font-style: italic;
        }

        .study-plan-link {
            display: inline-block;
            color: #667eea;
            font-weight: 600;
            text-decoration: none;
            border-bottom: 2px solid rgba(102, 126, 234, 0.3);
            padding: 1px 4px;
            border-radius: 3px;
            transition: all 0.2s;
        }

        .study-plan-link:hover {
            color: #5a67d8;
            background: rgba(102, 126, 234, 0.1);
            border-bottom-color: #5a67d8;
        }

        .study-plan-actions {
            display: flex;
            gap: 15px;
            justify-content: center;
            flex-wrap: wrap;
        }

        .action-btn {
            padding: 14px 28px;
            border-radius: 8px;
            font-size: 1em;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            border: none;
        }

        .action-btn.primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .action-btn.secondary {
            background: white;
            color: #667eea;
            border: 2px solid #667eea;
        }

        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
        }

        /* ============================
           WEEKLY ACCURACY DASHBOARD
           ============================ */

        .dashboard-section {
            background: white;
            border-radius: 16px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        .dashboard-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .dashboard-header h2 {
            font-size: 1.8em;
            color: #2d3748;
            margin-bottom: 8px;
        }

        .dashboard-period {
            color: #718096;
            font-size: 1em;
        }

        .dashboard-loading {
            background: white;
            border-radius: 16px;
            padding: 40px;
            text-align: center;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
        }

        .dashboard-loading p {
            color: #718096;
            margin-top: 15px;
        }

        /* Overview cards */
        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 16px;
            margin-bottom: 30px;
        }

        .dash-card {
            background: #f7fafc;
            border-radius: 12px;
            padding: 20px;
            text-align: center;
        }

        .dash-card-label {
            font-size: 0.85em;
            color: #718096;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 8px;
        }

        .dash-card-value {
            font-size: 2em;
            font-weight: 700;
            color: #2d3748;
            margin-bottom: 6px;
        }

        .dash-card-sub {
            font-size: 0.85em;
            color: #a0aec0;
        }

        .dash-card-sub a {
            text-decoration: none;
        }

        /* Accuracy bar */
        .accuracy-bar {
            height: 8px;
            background: #e2e8f0;
            border-radius: 4px;
            overflow: hidden;
            margin-top: 8px;
        }

        .accuracy-bar-fill {
            height: 100%;
            border-radius: 4px;
            transition: width 0.8s ease;
        }

        /* Phase section */
        .dashboard-phase-section,
        .dashboard-color-section,
        .dashboard-quality-section,
        .dashboard-trend-section {
            margin-top: 30px;
        }

        .dashboard-phase-section h3,
        .dashboard-color-section h3,
        .dashboard-quality-section h3,
        .dashboard-trend-section h3 {
            font-size: 1.3em;
            color: #2d3748;
            margin-bottom: 16px;
        }

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

        .phase-card {
            background: #f7fafc;
            border-radius: 12px;
            padding: 24px;
            text-align: center;
        }

        .phase-icon {
            font-size: 2em;
            margin-bottom: 8px;
        }

        .phase-name {
            font-weight: 700;
            color: #2d3748;
            font-size: 1.1em;
            margin-bottom: 4px;
        }

        .phase-moves {
            font-size: 0.8em;
            color: #a0aec0;
            margin-bottom: 12px;
        }

        .phase-accuracy {
            font-size: 2.2em;
            font-weight: 700;
            margin-bottom: 8px;
        }

        .phase-detail {
            font-size: 0.8em;
            color: #a0aec0;
            margin-top: 8px;
        }

        /* Color accuracy */
        .color-accuracy-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
        }

        .color-acc-card {
            background: #f7fafc;
            border-radius: 12px;
            padding: 24px;
            text-align: center;
        }

        .color-acc-label {
            font-size: 1.1em;
            font-weight: 600;
            color: #2d3748;
            margin-bottom: 8px;
        }

        .color-acc-value {
            font-size: 2em;
            font-weight: 700;
            margin-bottom: 4px;
        }

        .color-acc-games {
            font-size: 0.85em;
            color: #a0aec0;
        }

        /* Move quality */
        .quality-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 16px;
        }

        .quality-card {
            border-radius: 12px;
            padding: 20px;
            text-align: center;
        }

        .quality-card.inaccuracy {
            background: #fefcbf;
            border: 2px solid #d69e2e;
        }

        .quality-card.mistake {
            background: #fed7aa;
            border: 2px solid #dd6b20;
        }

        .quality-card.blunder {
            background: #fed7d7;
            border: 2px solid #e53e3e;
        }

        .quality-count {
            font-size: 2em;
            font-weight: 700;
            color: #2d3748;
        }

        .quality-label {
            font-size: 0.9em;
            color: #4a5568;
            font-weight: 600;
            margin-top: 4px;
        }

        /* Trend chart */
        .dashboard-trend-section canvas {
            max-height: 300px;
        }

        @media (max-width: 768px) {
            .dashboard-grid {
                grid-template-columns: repeat(2, 1fr);
            }

            .phase-grid {
                grid-template-columns: 1fr;
            }

            .color-accuracy-grid {
                grid-template-columns: 1fr;
            }

            .quality-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 768px) {
            .analysis-summary {
                grid-template-columns: 1fr;
            }

            .study-plan-actions {
                flex-direction: column;
            }

            .action-btn {
                width: 100%;
            }
        }