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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ZX Spectrum Background Canvas */
#bg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    pointer-events: none;
    z-index: 0;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.header {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
    border-bottom: 2px solid #e0e0e0;
}

.header-left {
    display: flex;
    gap: 20px;
}

.nav-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
    transition: color 0.2s;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
}

.nav-link:hover {
    color: #764ba2;
}

.nav-link.active {
    color: #764ba2;
    border-bottom-color: #764ba2;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #333;
    font-weight: 500;
}

.avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #667eea;
    background-color: #667eea;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
    text-transform: uppercase;
    user-select: none;
}

.container {
    padding: 40px 20px;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.page-title {
    color: #000;
    font-size: 48px;
    text-align: center;
    margin-bottom: 40px;
    text-shadow: none;
    font-weight: 700;
}

.loading {
    color: #333;
    font-size: 24px;
    text-align: center;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.error {
    background-color: #f44336;
    color: white;
    padding: 20px;
    border-radius: 8px;
    font-size: 18px;
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
}

.info-card {
    background: white;
    border-radius: 12px;
    padding: 32px;
    border: 2px solid #667eea;
    margin-bottom: 32px;
    max-width: 1400px;
}

.info-card h1 {
    font-size: 36px;
    font-weight: 700;
    color: #333;
    margin: 0 0 20px 0;
    border-bottom: 3px solid #667eea;
    padding-bottom: 12px;
}

.info-card-content {
    color: #333;
    line-height: 1.6;
    font-size: 16px;
}

.info-card-content p {
    margin-bottom: 16px;
}

.info-card-content h2 {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 24px 0 12px 0;
}

.info-card-content strong {
    font-weight: 600;
    color: #222;
}

.info-card-content code {
    background-color: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    color: #d63384;
}

.challenges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
    gap: 24px;
    max-width: 1400px;
}

.challenge-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 2px solid #e0e0e0;
    transition: border-color 0.2s, transform 0.2s;
    cursor: pointer;
}

.challenge-card:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.challenge-card.solved {
    background: #e8f5e9;
    border-color: #c8e6c9;
}

.challenge-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 16px;
}

.challenge-name {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.challenge-id {
    background: #667eea;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
}

.challenge-description {
    color: #666;
    font-size: 16px;
    line-height: 1.5;
    margin: 0;
}

.play-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    position: relative;
}

.play-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.play-button:active {
    transform: scale(0.98);
}

.play-button:disabled {
    opacity: 0.8;
    cursor: wait;
}

.play-button:disabled::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 12px;
    margin-top: -8px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.open-button {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    transition: opacity 0.2s, transform 0.1s;
    display: inline-block;
}

.open-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.check-button {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.check-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.check-button:active {
    transform: scale(0.98);
}

.stop-button {
    background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.stop-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.stop-button:active {
    transform: scale(0.98);
}

.stop-button:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-in-out;
}

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

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 32px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #333;
}

.modal-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.modal-action-button {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    border: none;
    text-decoration: none;
    display: inline-block;
}

.modal-action-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.modal-action-button:active {
    transform: scale(0.98);
}

.modal-close {
    background: none;
    border: none;
    font-size: 36px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
    background-color: #f5f5f5;
    color: #333;
}

.modal-body {
    padding: 32px;
    overflow-y: auto;
    flex: 1;
}

/* Markdown content styling */
.markdown-content {
    color: #333;
    line-height: 1.6;
}

.markdown-content h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 16px;
    color: #222;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.markdown-content h2 {
    font-size: 26px;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 12px;
    color: #333;
}

/* Remove top margin from first element to avoid double padding */
.markdown-content > *:first-child {
    margin-top: 0;
}

.markdown-content h3 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 10px;
    color: #444;
}

.markdown-content p {
    margin-bottom: 16px;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-content li {
    margin-bottom: 8px;
}

.markdown-content code {
    background-color: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    color: #d63384;
}

.markdown-content pre {
    background-color: #f5f5f5;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: #333;
    font-size: 14px;
}

.markdown-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 16px;
    margin: 16px 0;
    color: #666;
    font-style: italic;
}

.markdown-content a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content strong {
    font-weight: 600;
    color: #222;
}

.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.markdown-content table th,
.markdown-content table td {
    border: 1px solid #e0e0e0;
    padding: 12px;
    text-align: left;
}

.markdown-content table th {
    background-color: #f5f5f5;
    font-weight: 600;
}

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

/* Check Result Modal */
.check-result-modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-in-out;
}

.check-result-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
}

.check-result-header {
    padding: 24px 32px;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.check-result-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    flex: 1;
}

.check-result-header .modal-close {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.check-result-header .modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.check-result-icon {
    font-size: 32px;
}

.check-result-body {
    padding: 32px;
    color: #333;
    line-height: 1.6;
}

.check-result-body p {
    margin: 0;
    font-size: 16px;
}

.check-result-footer {
    padding: 20px 32px;
    background: #f5f5f5;
    display: flex;
    justify-content: flex-end;
}

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

.check-result-button:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.check-result-button:active {
    transform: scale(0.98);
}

/* Scoreboard styles */
.scoreboard-container {
    max-width: 800px;
    margin: 0 auto;
}

.scoreboard-table {
    width: 100%;
    background: white;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    overflow: hidden;
    border-collapse: collapse;
}

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

.scoreboard-table th {
    padding: 16px;
    text-align: left;
    font-weight: 600;
    font-size: 16px;
}

.scoreboard-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: background-color 0.2s;
}

.scoreboard-table tbody tr:last-child {
    border-bottom: none;
}

.scoreboard-table tbody tr:hover {
    background-color: #f5f5f5;
}

.scoreboard-table td {
    padding: 16px;
    font-size: 16px;
}

.rank-cell {
    font-weight: 600;
    color: #667eea;
    width: 80px;
    text-align: center;
}

.player-cell {
    color: #333;
    font-weight: 500;
}

.solves-cell {
    color: #666;
    font-weight: 600;
    width: 100px;
    text-align: center;
}
