body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* Prevent text selection globally */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

#welcome-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

#logo {
    width: 128px;
    height: auto;
    margin-bottom: 10px;
}

#script-list {
    list-style-type: none;
    padding: 0;
    margin: 24px auto;
    width: 90%;
    max-width: 1200px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    padding-bottom: 120px; /* space for floating import button */
}

#script-list li.script-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 16px;
    padding-bottom: 56px; /* space for bottom-right button */
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    cursor: pointer;
    text-align: center;
    transition: transform 120ms ease, box-shadow 120ms ease;
    min-height: 200px;
}

#script-list li.script-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.script-card .card-title {
    font-weight: 600;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: center;
    position: relative;
}

.script-card .script-icon {
    width: 120px;
    height: 120px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 8px;
    background: rgba(255,255,255,0.8);
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.script-card .script-title-text {
    font-size: 11px;
    color: #666;
    text-align: center;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* role select inside cards */
.script-card .role-select {
    margin-top: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 10px;
    background: #fff;
}

#script-list li .statistics-btn {
    position: absolute;
    left: 12px;
    bottom: 12px;
    padding: 6px 10px;
    background-color: #1976d2;
    border: none;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    z-index: 2; /* ensure above select */
    pointer-events: auto;
    font-size: 12px;
}

#script-list li .statistics-btn:hover {
    background-color: #1565c0;
}

#script-list li .delete-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 6px 10px;
    background-color: #e53935;
    border: none;
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    z-index: 2; /* ensure above select */
    pointer-events: auto;
}

#script-list li .delete-btn:hover {
    background-color: #c62828;
}

#upload-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(20px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none; /* allow clicks only on button */
}

#upload-button {
    font-size: 16px;
    padding: 12px 20px;
    cursor: pointer;
    background: linear-gradient(135deg, #1976d2, #42a5f5);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 8px 20px rgba(25, 118, 210, 0.35);
    transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
    pointer-events: auto; /* re-enable click */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    text-align: center;
    min-height: 44px; /* iOS recommended touch target */
    min-width: 44px;
    line-height: 1;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
}

#upload-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(25, 118, 210, 0.45);
}

#upload-button:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

/* Mobile touch states */
#upload-button:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Enhance touch feedback on mobile */
@media (pointer: coarse) {
    #upload-button {
        min-height: 48px; /* Larger touch target for mobile */
        padding: 14px 24px;
    }
}

#upload-hint {
    margin-top: 0;
    color: #666;
    font-size: 0.9em;
    background: rgba(255,255,255,0.85);
    padding: 6px 10px;
    border-radius: 8px;
    backdrop-filter: blur(6px);
    pointer-events: none;
}

#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* back button removed */

#controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* allow wrapping on narrow screens */
    width: 100%;
    padding: 12px 14px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    color: #111;
}

#controls label {
    margin: 0 4px 0 12px;
    font-size: 0.95em;
    color: #555;
}

.label-short { display: none; }
.label-full { display: inline; }

#controls select, #controls input[type="checkbox"] {
    margin: 0 6px;
}

#controls select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #d0d0d0;
    background: #fff;
    color: #111;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

#controls select:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}

.toggle-button {
    margin: 0 6px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #424242, #5a5a5a);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
.toggle-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.toggle-button:active { filter: brightness(0.95); }
.toggle-button.active {
    background: linear-gradient(135deg, #0b7, #12b886);
}

#script-container {
    flex-grow: 1;
    overflow-y: auto;
    width: 100%;
    padding: 20px;
    padding-bottom: 80px; /* space for rehearsal nav buttons */
    background-color: #f9f9f9;
    box-sizing: border-box;
    /* Ensure no text selection in script area */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent text cursor */
    cursor: default;
    /* iOS-specific touch improvements */
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Rehearsal Navigation Buttons */
#rehearsal-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-evenly;
    gap: 8px;
    padding: 12px;
    background: linear-gradient(to top, rgba(255,255,255,0.98), rgba(255,255,255,0.92));
    backdrop-filter: blur(8px);
    border-top: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
    z-index: 100;
}

#rehearsal-nav button {
    flex: 1;
    max-width: 150px;
    padding: 12px 16px;
    font-size: 0.95em;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    -webkit-tap-highlight-color: transparent;
    outline: none; /* Prevent focus outline */
    -webkit-user-select: none;
    user-select: none;
}

#rehearsal-nav button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#rehearsal-nav button:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(102, 126, 234, 0.3);
}

#rehearsal-nav button:focus {
    outline: none; /* Ensure no focus ring after touch */
}

#rehearsal-nav #back-to-scene {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    box-shadow: 0 2px 8px rgba(240, 147, 251, 0.3);
}

#rehearsal-nav #back-to-scene:hover {
    box-shadow: 0 4px 12px rgba(240, 147, 251, 0.4);
}

/* nav buttons removed */

#back-to-main {
    padding: 8px 12px;
    background: linear-gradient(135deg, #757575, #9e9e9e);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    font-size: 16px;
    margin-right: 8px;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

#back-to-main:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#burger-button {
    margin-left: auto;
    font-size: 18px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #424242, #5a5a5a);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
}

#burger-menu {
    position: absolute;
    top: calc(100% + 8px); /* sit below toolbar regardless of its height */
    right: 10px;
    background: rgba(255,255,255,0.98);
    color: #111;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 14px 16px;
    display: none;
    z-index: 1000;
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
    min-width: 280px;
    max-width: 90vw;
    font-size: 0.95em;
}

#burger-menu .menu-row {
    display: flex;
    align-items: center;
    margin: 8px 0;
}

#burger-menu .menu-row label {
    color: #222;
    font-weight: 600;
    margin-right: 10px;
    min-width: 72px;
}

#burger-menu select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid #d0d0d0;
    background: #fff;
    color: #111;
}

#burger-menu input[type="checkbox"] {
    transform: scale(1.1);
}

body.dark #burger-menu {
    background: #111;
    border-color: #333;
}
body.dark #burger-menu .menu-row label {
    color: #fff;
}
body.dark #burger-menu select {
    border-color: #555;
    background: #1f1f1f;
    color: #fff;
}

/* Dark mode styles for cards */
body.dark #script-list li.script-card {
    background: #1b1b1b;
    border-color: #333;
    color: #eee;
}
body.dark #script-list li .statistics-btn {
    background-color: #0d47a1;
}
body.dark #script-list li .statistics-btn:hover {
    background-color: #0b3d91;
}
body.dark #script-list li .delete-btn {
    background-color: #b71c1c;
}
body.dark #script-list li .delete-btn:hover {
    background-color: #8d1414;
}

/* Dark mode for upload footer */
body.dark #upload-button {
    background: linear-gradient(135deg, #0d47a1, #1565c0);
    box-shadow: 0 8px 20px rgba(13, 71, 161, 0.45);
}
body.dark #upload-hint {
    background: rgba(0,0,0,0.6);
    color: #bbb;
}

/* Dark mode inputs in controls */
body.dark #controls select {
    background: #1f1f1f;
    color: #eee;
    border-color: #333;
}
body.dark #burger-button {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
}
body.dark #back-to-main {
    background: linear-gradient(135deg, #424242, #616161);
}

/* Responsive tweaks for small phones (e.g., Pixel 7) */
@media (max-width: 480px) {
    #controls { padding: 8px 8px; gap: 6px; }
    #controls label { margin: 0 2px 0 6px; font-size: 0.9em; }
    .label-full { display: none; }
    .label-short { display: inline; }
    #controls select { padding: 6px 10px; border-radius: 8px; font-size: 0.95em; }
    .toggle-button { padding: 6px 10px; font-size: 0.9em; }
    #burger-button { padding: 6px 10px; }
    #script-container { padding: 12px; }
    .scene-title { font-size: 1.25em; }
}

.scene-title {
    font-size: 1.5em;
    margin: 20px 0;
    /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

.stage-hint {
    font-style: italic;
    color: gray;
    margin: 10px 0; /* Add vertical space */
    /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

.dialogue {
    margin: 10px 0; /* Add vertical space */
    /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

.bold {
    font-weight: bold;
    color: red; /* Change the style as desired */
    font-size: larger;
}

/* Highlight background for selected role's dialogue */
.highlighted {
    background-color: #ffcccc; /* Light red */
}

/* Add more margin after each scene */
.scene-end {
    margin-bottom: 40px;
}

/* Hide stage directions toggle */
.hide-stage .stage-hint {
    display: none;
}

/* Dark mode */
body.dark {
    background-color: #111;
    color: #eee;
}
body.dark #controls {
    background: rgba(0, 0, 0, 0.6);
    color: #ddd;
    border-bottom-color: rgba(255,255,255,0.06);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
body.dark #script-container {
    background-color: #181818;
}
body.dark .highlighted {
    background-color: #333f44;
}
body.dark #rehearsal-nav {
    background: linear-gradient(to top, rgba(24,24,24,0.98), rgba(24,24,24,0.92));
    border-top-color: rgba(255,255,255,0.12);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
}

/* Update notification */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #4CAF50;
    color: white;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1000;
    max-width: 300px;
    animation: slideIn 0.3s ease-out;
}

.notification-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#update-dismiss {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

#update-dismiss:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Rehearsal help button */
#rehearsal-help {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

#rehearsal-help:hover {
    background: #0056b3;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

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

.modal-header h2 {
    margin: 0;
    color: #333;
    font-size: 1.4em;
}

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

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

.modal-body {
    padding: 20px 24px 24px;
    line-height: 1.6;
}

.modal-body h3 {
    color: #333;
    margin: 20px 0 12px;
    font-size: 1.1em;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin: 12px 0;
    color: #555;
}

.modal-body ol, .modal-body ul {
    margin: 12px 0;
    padding-left: 20px;
}

.modal-body li {
    margin: 8px 0;
    color: #555;
}

.modal-body strong {
    color: #333;
}

.modal-body em {
    color: #666;
    font-style: italic;
}

/* Dark mode for modal and notification */
body.dark .modal-content {
    background: #2c2c2c;
    color: #eee;
}

body.dark .modal-header {
    border-bottom-color: #444;
}

body.dark .modal-header h2 {
    color: #eee;
}

body.dark .modal-close {
    color: #ccc;
}

body.dark .modal-close:hover {
    background-color: #444;
    color: #fff;
}

body.dark .modal-body h3 {
    color: #eee;
}

body.dark .modal-body p,
body.dark .modal-body li {
    color: #ccc;
}

body.dark .modal-body strong {
    color: #eee;
}

body.dark .modal-body em {
    color: #aaa;
}

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

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

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

/* Mobile responsive adjustments for modal */
@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 20px 0;
    }
    
    .modal-header {
        padding: 16px 20px 12px;
    }
    
    .modal-header h2 {
        font-size: 1.2em;
    }
    
    .modal-body {
        padding: 16px 20px 20px;
    }
    
    .notification {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    #rehearsal-help {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}

/* Loading indicator styles */
#loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 300px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}

.loading-message {
    font-size: 16px;
    color: #333;
    font-weight: 500;
}

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

/* Dark mode for loading indicator */
body.dark .loading-content {
    background: #333;
    color: #fff;
}

body.dark .loading-message {
    color: #fff;
}

/* iOS touch improvements for script elements */
.line, .scene-title {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Improve touch responsiveness */
    cursor: pointer;
}

/* Rehearsal mode specific improvements */
body #script-container.rehearsal-mode {
    /* Add substantial bottom padding to ensure we can always scroll enough
       to keep content in the top 2/3 of the screen */
    padding-bottom: 60vh; /* 60% of viewport height as padding */
}

body #script-container.rehearsal-mode .line,
body #script-container.rehearsal-mode .scene-title {
    /* Better touch feedback in rehearsal mode */
    transition: background-color 0.1s ease;
}

body #script-container.rehearsal-mode .line:active,
body #script-container.rehearsal-mode .scene-title:active {
    background-color: rgba(25, 118, 210, 0.05);
}

/* Statistics Page Styles */
#statistics-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #f9f9f9;
}

#statistics-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
}

#statistics-title {
    flex: 1;
}

#back-to-scripts {
    padding: 8px 12px;
    background: linear-gradient(135deg, #757575, #9e9e9e);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    font-size: 16px;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

#back-to-scripts:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#clear-stats-btn {
    padding: 8px 12px;
    background: linear-gradient(135deg, #e53935, #c62828);
    color: #fff;
    border: none;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    font-size: 14px;
    transition: transform 120ms ease, box-shadow 120ms ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

#clear-stats-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    background: linear-gradient(135deg, #c62828, #b71c1c);
}

#statistics-title {
    margin: 0;
    font-size: 1.5em;
    color: #333;
}

#statistics-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

#statistics-summary {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

#statistics-summary h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3em;
}

#summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.stat-item {
    text-align: center;
    padding: 20px 16px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 2.2em;
    font-weight: bold;
    color: #1976d2;
    display: block;
    line-height: 1.1;
}

.stat-label {
    font-size: 0.85em;
    color: #666;
    margin-top: 6px;
    line-height: 1.3;
}

#heatmap-container {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

#heatmap-container h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3em;
}

#heatmap-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8em;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}

.legend-no-data {
    background-color: #e9ecef;
}

.legend-good {
    background-color: #28a745;
}

.legend-medium {
    background-color: #ffc107;
}

.legend-poor {
    background-color: #dc3545;
}

#heatmap {
    overflow-x: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.heatmap-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 400px;
    font-size: 0.8em;
}

.heatmap-table th,
.heatmap-table td {
    padding: 2px 4px;
    text-align: center;
    border: 1px solid #ddd;
    font-size: 0.75em;
    line-height: 1.2;
}

.heatmap-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #333;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 4px 2px;
}

.heatmap-table th:first-child {
    width: 80px;
    max-width: 80px;
    text-align: left;
    padding-left: 8px;
}

.heatmap-table th:not(:first-child) {
    width: 30px;
    max-width: 30px;
}

.heatmap-table .scene-header {
    background-color: #e9ecef;
    font-weight: 600;
    text-align: left;
    padding: 2px 8px;
    white-space: nowrap;
    width: 80px;
    max-width: 80px;
}

.heatmap-cell {
    width: 20px;
    height: 20px;
    position: relative;
    cursor: pointer;
    transition: transform 0.1s ease;
    padding: 0;
}

.heatmap-cell:hover {
    transform: scale(1.1);
    z-index: 5;
}

.heatmap-cell.no-data {
    background-color: #e9ecef;
}

.heatmap-cell.good {
    background-color: #28a745;
}

.heatmap-cell.medium {
    background-color: #ffc107;
}

.heatmap-cell.poor {
    background-color: #dc3545;
}

/* Dark mode for statistics */
body.dark #statistics-page {
    background-color: #181818;
}

body.dark #statistics-controls {
    background: rgba(0, 0, 0, 0.6);
    color: #ddd;
    border-bottom-color: rgba(255,255,255,0.06);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

body.dark #statistics-title {
    color: #eee;
}

body.dark #back-to-scripts {
    background: linear-gradient(135deg, #424242, #616161);
}

body.dark #clear-stats-btn {
    background: linear-gradient(135deg, #b71c1c, #8d1414);
}

body.dark #clear-stats-btn:hover {
    background: linear-gradient(135deg, #8d1414, #6d1010);
}

body.dark #statistics-summary,
body.dark #heatmap-container {
    background: #2c2c2c;
    color: #eee;
}

body.dark #statistics-summary h3,
body.dark #heatmap-container h3 {
    color: #eee;
}

body.dark .stat-item {
    background: #1f1f1f;
    border-color: #444;
    color: #eee;
}

body.dark .stat-label {
    color: #ccc;
}

body.dark #heatmap-legend {
    background: #1f1f1f;
    color: #eee;
}

body.dark .heatmap-table th {
    background-color: #1f1f1f;
    color: #eee;
    border-color: #444;
}

body.dark .heatmap-table .scene-header {
    background-color: #333;
    color: #eee;
}

body.dark .heatmap-table td {
    border-color: #444;
}

body.dark #heatmap {
    border-color: #444;
}

/* Tablet responsive adjustments for statistics */
@media (max-width: 768px) {
    #statistics-container {
        padding: 16px;
    }
    
    #statistics-summary,
    #heatmap-container {
        padding: 20px;
    }
    
    #summary-stats {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
    }
    
    .stat-item {
        padding: 16px 12px;
    }
    
    .stat-value {
        font-size: 1.8em;
    }
    
    .stat-label {
        font-size: 0.8em;
    }
    
    #statistics-title {
        font-size: 1.3em;
    }
    
    .heatmap-table th,
    .heatmap-table td {
        padding: 2px 3px;
        font-size: 0.7em;
    }
    
    .heatmap-table .scene-header {
        width: 70px;
        max-width: 70px;
        padding: 2px 6px;
    }
    
    .heatmap-table th:first-child {
        width: 70px;
        max-width: 70px;
        padding-left: 6px;
    }
    
    .heatmap-table th:not(:first-child) {
        width: 28px;
        max-width: 28px;
    }
    
    .heatmap-cell {
        width: 18px;
        height: 18px;
    }
}

/* Mobile responsive adjustments for statistics */
@media (max-width: 480px) {
    #statistics-controls {
        padding: 8px 12px;
        gap: 8px;
    }
    
    #statistics-title {
        font-size: 1.1em;
    }
    
    #clear-stats-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    #statistics-container {
        padding: 12px;
    }
    
    #statistics-summary,
    #heatmap-container {
        padding: 16px;
        margin-bottom: 16px;
    }
    
    #statistics-summary h3,
    #heatmap-container h3 {
        font-size: 1.1em;
        margin-bottom: 16px;
    }
    
    #summary-stats {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .stat-item {
        padding: 16px;
    }
    
    .stat-value {
        font-size: 1.8em;
    }
    
    .stat-label {
        font-size: 0.8em;
    }
    
    #heatmap-legend {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    
    .legend-item {
        font-size: 0.75em;
    }
    
    .heatmap-table {
        font-size: 0.7em;
        min-width: 350px;
    }
    
    .heatmap-table th,
    .heatmap-table td {
        padding: 1px 2px;
        font-size: 0.65em;
    }
    
    .heatmap-table .scene-header {
        padding: 1px 4px;
        font-size: 0.6em;
        width: 50px;
        max-width: 50px;
    }
    
    .heatmap-table th:first-child {
        width: 50px;
        max-width: 50px;
        padding-left: 4px;
        font-size: 0.6em;
    }
    
    .heatmap-table th:not(:first-child) {
        width: 22px;
        max-width: 22px;
        font-size: 0.6em;
    }
    
    .heatmap-cell {
        width: 16px;
        height: 16px;
    }
}
