/* Base styles */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg: #f9fafb;
    --card-bg: #ffffff;
    --text: #111827;
    --text-light: #6b7280;
    --border: #e5e7eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: var(--card-bg);
    border-bottom: 2px solid var(--border);
    padding: 1rem 0;
    margin-bottom: 2rem;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
    color: var(--primary);
}

nav a {
    margin-left: 1.5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    transition: color 0.2s;
}

nav a:hover {
    color: var(--primary);
}

/* Flash messages */
.flash-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 500px;
    width: auto;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.flash {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-weight: 500;
}

.flash.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid var(--success);
}

.flash.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid var(--error);
}

.flash.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

/* Forms */
.form-container {
    max-width: 500px;
    margin: 3rem auto;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    min-height: 120px;
    font-family: inherit;
}

.textarea-lg {
    min-height: 320px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--text-light);
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-danger {
    background: var(--error);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: #059669;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Challenge Grid (Jeopardy-style) */
.challenge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.challenge-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
    position: relative;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.challenge-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
    border-color: rgba(99, 102, 241, 0.35);
}

.challenge-card.solved {
    background: #d1fae5;
    border-color: var(--success);
}

.challenge-card.solved::after {
    content: "✓ SOLVED";
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--success);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
}

.challenge-card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.challenge-card h3 {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
}

.challenge-points {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}

.challenge-tags {
    font-size: 0.8rem;
    color: var(--text-light);
    letter-spacing: 0.02em;
    margin-top: 0.75rem;
}

/* Challenge Detail */
.challenge-detail {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
}

.challenge-detail-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.challenge-detail-header h2 {
    margin: 0;
}

.challenge-points-badge {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    background: rgba(99, 102, 241, 0.12);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    white-space: nowrap;
}

.challenge-detail-tags {
    margin: 0 0 1.5rem 0;
}

/* Markdown Content Styling */
.challenge-description {
    margin: 1.5rem 0;
    line-height: 1.7;
}

.challenge-description h2 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-size: 1.5rem;
    color: var(--text);
}

.challenge-description h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    color: var(--text);
}

.challenge-description h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: var(--text);
}

.challenge-description p {
    margin-bottom: 1rem;
}

.challenge-description a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.challenge-description a:hover {
    border-bottom-color: var(--primary);
}

.challenge-description ul,
.challenge-description ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.challenge-description li {
    margin-bottom: 0.5rem;
}

.challenge-description strong {
    font-weight: 600;
    color: var(--text);
}

.challenge-description em {
    font-style: italic;
    color: var(--text-light);
}

.challenge-description code {
    background: #f3f4f6;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.challenge-description blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-light);
    font-style: italic;
}

.circuit-image {
    max-width: 350px;
    width: 70%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.circuit-image:hover {
    transform: scale(1.05);
}

.circuit-image.zoomed {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
    z-index: 1000;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    cursor: zoom-out;
}

/* Overlay for zoomed image */
.image-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 999;
    cursor: zoom-out;
}

.image-overlay.active {
    display: block;
}

.qasm-code {
    background: #1f2937;
    color: #f9fafb;
    padding: 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 350px;
    margin: 0;
}

/* Side-by-side layout */
.circuit-qasm-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1.5rem;
    margin: 1rem 0;
    align-items: start;
}

.circuit-column {
    display: flex;
    flex-direction: column;
}

.qasm-column {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Responsive: stack on mobile */
@media (max-width: 768px) {
    .circuit-qasm-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .circuit-image {
        max-width: 100%;
    }
}

/* Test Case Tabs */
.exercise-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
    margin: 1.5rem 0 1rem;
}

.exercise-filters select {
    width: auto;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 240px;
    padding: 0.6rem 0.75rem;
    font: inherit;
    color: var(--text);
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.filter-link {
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

.filter-link.selected {
    background: var(--primary);
    color: white;
}

.exercise-intro { color: var(--text-light); margin: 1rem 0; }
.case-editor-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.test-case-card h3 { margin-top: 0; }
.challenge-description { overflow-wrap: anywhere; }
.challenge-description .katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.25rem 0; }
.challenge-description table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 1rem 0; }
.challenge-description th, .challenge-description td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.challenge-description pre { overflow-x: auto; padding: 1rem; background: #f3f4f6; }

.test-case-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border);
    margin: 1.5rem 0 0 0;
    overflow-x: auto;
}

.test-case-tab {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-light);
    transition: all 0.2s;
    white-space: nowrap;
}

.test-case-tab:hover {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.test-case-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.test-case-content {
    display: none;
    animation: fadeIn 0.3s;
}

.test-case-content.active {
    display: block;
}

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

/* Test Case Card */
.test-case-card {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1.5rem 0;
}

.test-case-answer {
    display: inline-block;
    margin: 0 0 1rem 0;
    padding: 0.5rem 0.75rem;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.18);
    border-radius: 999px;
    font-size: 0.9rem;
    color: var(--primary);
}

/* Collapsible Section */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    background: #1f2937;
    color: #f9fafb;
    border-radius: 6px 6px 0 0;
    transition: background 0.2s;
    margin-bottom: 0;
}

.collapsible-header:hover {
    background: #374151;
}

.collapsible-header h4 {
    color: #f9fafb;
}

.collapsible-content {
    display: block;
}

.qasm-wrapper {
    border: 1px solid #1f2937;
    border-radius: 0 0 6px 6px;
    overflow: hidden;
}

/* Info Box */
.info-box {
    background: #dbeafe;
    border-left: 4px solid #3b82f6;
    padding: 1rem;
    border-radius: 6px;
    margin: 1.5rem 0;
}

.info-box strong {
    color: #1e40af;
}

/* Copy Button */
.copy-btn {
    position: relative;
    float: right;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    color: #f9fafb;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

/* Leaderboard */
.leaderboard {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
}

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

.leaderboard th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text);
}

.leaderboard tr:hover {
    background: var(--bg);
}

.rank {
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary);
}

.rank-1 { color: #fbbf24; }
.rank-2 { color: #9ca3af; }
.rank-3 { color: #cd7f32; }

/* Scoreboard (Big Screen) */
.scoreboard {
    padding: 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.scoreboard h1 {
    color: white;
    text-align: center;
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.scoreboard table {
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    overflow: hidden;
}

.scoreboard th,
.scoreboard td {
    padding: 1.5rem;
    font-size: 1.5rem;
}

.scoreboard .rank {
    font-size: 2rem;
}

/* Admin Styles */
.admin-header {
    background: var(--primary);
    color: white;
}

.admin-header h1 {
    color: white;
}

.admin-header nav a {
    color: rgba(255, 255, 255, 0.9);
}

.admin-header nav a:hover {
    color: white;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.stat-card h3 {
    color: var(--text-light);
    font-size: 0.875rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.stat-card .number {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary);
}

.data-table {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 2rem;
    overflow-x: auto;
}

.data-table table {
    width: 100%;
    border-collapse: collapse;
}

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

.data-table th {
    background: var(--bg);
    font-weight: 600;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}
