/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: #1e293b;
    background: #f1f5f9;
    min-height: 100vh;
}

a { color: #3b82f6; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }

.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { background: #e2e8f0; color: #475569; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 6px 10px; font-size: 1.1rem; background: #e2e8f0; border-radius: 6px; }
.btn-icon:hover { background: #cbd5e1; }

/* ===== Forms ===== */
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #374151;
    font-size: 0.9rem;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3b82f6;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.form-card {
    background: #fff;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-width: 700px;
}
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e2e8f0;
    color: #475569;
}
.badge-dark { background: #1e293b; color: #f8fafc; }
.badge-light { background: #fef9c3; color: #854d0e; }
.badge-image { background: #dbeafe; color: #1e40af; }

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}
.login-container {
    background: #fff;
    padding: 48px 40px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-container h1 {
    font-size: 2rem;
    color: #1e293b;
    margin-bottom: 4px;
}
.login-container .subtitle {
    color: #64748b;
    margin-bottom: 32px;
}
.login-form .form-group { text-align: left; }

/* ===== Admin Header ===== */
.admin-header {
    background: #fff;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-left h1 { font-size: 1.3rem; color: #1e293b; }
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.username { color: #64748b; font-size: 0.9rem; }
.back-link {
    color: #64748b;
    font-size: 0.9rem;
}

/* ===== Admin Main ===== */
.admin-main {
    max-width: 960px;
    margin: 32px auto;
    padding: 0 24px;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h2 { font-size: 1.4rem; }
.quiz-info { color: #64748b; font-size: 0.9rem; }

/* ===== Quiz Grid ===== */
.quiz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}
.quiz-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s;
}
.quiz-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.quiz-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.quiz-card-header h3 { font-size: 1.15rem; }
.quiz-card-desc {
    color: #64748b;
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.quiz-card-meta {
    display: flex;
    gap: 16px;
    color: #94a3b8;
    font-size: 0.8rem;
    margin-bottom: 16px;
}
.quiz-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Question List ===== */
.question-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.question-item {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    padding: 16px 20px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.question-number {
    font-size: 1.4rem;
    font-weight: 700;
    color: #3b82f6;
    min-width: 36px;
    text-align: center;
}
.question-content { flex: 1; }
.question-text {
    font-weight: 500;
    margin-bottom: 4px;
}
.question-meta {
    display: flex;
    gap: 6px;
}
.question-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ===== Answer Rows (editor) ===== */
.answer-section {
    margin-bottom: 20px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
}
.answer-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    color: #374151;
}
#correct-hint {
    font-weight: 400;
    color: #94a3b8;
    font-size: 0.85rem;
}
.answer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.answer-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #22c55e;
}
.answer-row input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
}
.answer-row input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
}
.tf-options {
    display: flex;
    gap: 24px;
}
.tf-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    cursor: pointer;
}
.tf-option input { accent-color: #3b82f6; width: 18px; height: 18px; }

/* ===== Image Preview ===== */
.image-preview-container {
    margin-bottom: 12px;
    display: inline-block;
    position: relative;
}
.image-preview-container img {
    max-width: 240px;
    max-height: 160px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    display: block;
    margin-bottom: 8px;
    object-fit: cover;
}
.image-remove-btn {
    display: block;
}

/* Image source tabs */
.image-source-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.image-tab {
    opacity: 0.6;
    transition: opacity 0.2s;
}
.image-tab.active {
    opacity: 1;
    background: #3b82f6;
    color: #fff;
}
.image-tab-content {
    display: none;
}
.image-tab-content.active {
    display: block;
}

/* URL input */
.image-url-row,
.image-search-row {
    display: flex;
    gap: 8px;
}
.image-url-row input,
.image-search-row input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
}
.image-url-row input:focus,
.image-search-row input:focus {
    outline: none;
    border-color: #3b82f6;
}

/* Search results grid */
.image-search-results {
    margin-top: 12px;
}
.image-search-loading {
    color: #64748b;
    padding: 12px 0;
    font-size: 0.9rem;
}
.image-search-info {
    color: #64748b;
    font-size: 0.85rem;
    margin-bottom: 10px;
}
.image-search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}
.image-search-item {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.15s;
}
.image-search-item:hover {
    border-color: #3b82f6;
    transform: scale(1.03);
}
.image-search-item img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
}
.current-image {
    margin-bottom: 12px;
}
.current-image img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    display: block;
    margin-bottom: 8px;
}
.remove-image {
    font-size: 0.85rem;
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== Page Header Actions ===== */
.page-header-actions {
    display: flex;
    gap: 8px;
}

/* ===== Source Tabs ===== */
.source-tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.source-tab {
    display: flex;
    flex-direction: column;
    padding: 14px 24px;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    text-decoration: none;
    color: #64748b;
    transition: border-color 0.2s, background 0.2s;
    min-width: 160px;
}
.source-tab:hover {
    border-color: #94a3b8;
    text-decoration: none;
}
.source-tab.active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1e293b;
}
.source-tab strong {
    font-size: 1rem;
    color: inherit;
}
.source-tab span {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* ===== Import Page ===== */
.admin-main-wide {
    max-width: 1100px;
}
.import-filters {
    margin-bottom: 24px;
    max-width: 100%;
}
.import-filters h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}
.import-form-grid {
    display: grid;
    grid-template-columns: 100px 1fr 140px 160px;
    gap: 16px;
    margin-bottom: 16px;
}
.import-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    gap: 12px;
}
.import-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.import-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 2px solid #e2e8f0;
    transition: border-color 0.2s;
}
.import-card:has(.import-checkbox:checked) {
    border-color: #3b82f6;
    background: #f8faff;
}
.import-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    margin-bottom: 10px;
}
.import-checkbox {
    width: 20px;
    height: 20px;
    accent-color: #3b82f6;
    margin-top: 2px;
    flex-shrink: 0;
}
.import-question {
    font-weight: 600;
    font-size: 1.05rem;
    line-height: 1.4;
}
.import-meta {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    padding-left: 32px;
}
.badge-easy { background: #dcfce7; color: #166534; }
.badge-medium { background: #fef9c3; color: #854d0e; }
.badge-hard { background: #fecaca; color: #991b1b; }
.import-answers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 32px;
}
.import-answer {
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
}
.import-answer.correct {
    background: #dcfce7;
    color: #166534;
    font-weight: 600;
}
.import-answer.wrong {
    background: #f1f5f9;
    color: #64748b;
}
.import-image-upload {
    margin-top: 12px;
    padding-left: 32px;
}
.import-image-label {
    cursor: pointer;
}
.import-file-input {
    display: none;
}
.import-image-buttons {
    display: flex;
    gap: 8px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 { margin: 0; }
.modal-body {
    padding: 24px;
    overflow-y: auto;
}
.import-preview {
    margin-top: 10px;
}
.import-preview img {
    max-width: 180px;
    max-height: 120px;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 1.05rem;
}

/* ============================================
   PLAYER / PRESENTATION MODE
   ============================================ */

.player-page {
    overflow: hidden;
}

.screen {
    display: none;
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
}
.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Welcome / End screen */
.welcome-content {
    text-align: center;
    padding: 40px;
    max-width: 800px;
}
.welcome-image {
    max-width: 400px;
    max-height: 300px;
    border-radius: 16px;
    margin-bottom: 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.welcome-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    line-height: 1.2;
}
.welcome-description {
    font-size: 1.3rem;
    opacity: 0.8;
    margin-bottom: 12px;
}
.welcome-info {
    font-size: 1rem;
    opacity: 0.5;
    margin-bottom: 40px;
}
.btn-play {
    padding: 16px 48px;
    font-size: 1.3rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-play:hover {
    transform: scale(1.05);
}
.end-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 32px;
}

/* Question display */
.question-display {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px 48px;
}

.question-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
}
.question-counter {
    font-size: 1.2rem;
    font-weight: 600;
    opacity: 0.6;
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 12px;
}
.timer-display {
    font-size: 2.4rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    min-width: 80px;
    text-align: center;
    transition: color 0.3s;
}
.timer-warning {
    animation: pulse 1s infinite;
}
.timer-expired {
    animation: none;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.btn-timer {
    padding: 8px 18px;
    font-size: 0.85rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

.question-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    overflow-y: auto;
}
.question-image-container img {
    max-width: 500px;
    max-height: 35vh;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.question-title {
    font-size: 2.6rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.3;
    max-width: 900px;
}

.answers-display {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    width: 100%;
    max-width: 800px;
}
.answer-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s, box-shadow 0.3s;
}
.answer-label {
    font-size: 1.5rem;
    font-weight: 800;
    min-width: 40px;
    text-align: center;
}

.question-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
}
.btn-reveal {
    padding: 12px 32px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

/* Fullscreen button */
.btn-fullscreen {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s;
    z-index: 1000;
}
.btn-fullscreen:hover { opacity: 1; }
