:root {
    /* Dark theme colors based on render.im with tint hue variables */
    --tint-hue: 210; /* Default hue, will be overridden by JS */
    --tint-saturation: 50%;
    --tint-lightness: 45%;
    
    --background-color: #121212;
    --surface-color: #1e1e1e;
    --surface-color-hover: #2d2d2d;
    --surface-color-active: #333333;
    --primary-text: #ffffff;
    --secondary-text: #bbbbbb;
    --muted-text: #888888;
    --border-color: #3d3d3d;
    --shadow-color: rgba(0, 0, 0, 0.5);
    
    /* Dynamic colors that use the tint hue */
    --primary-button: hsl(var(--tint-hue), var(--tint-saturation), var(--tint-lightness));
    --primary-button-hover: hsl(var(--tint-hue), var(--tint-saturation), 35%);
    --success-button: hsl(var(--tint-hue), 60%, 40%);
    --success-button-hover: hsl(var(--tint-hue), 50%, 30%);
    --danger-button: #e53935; /* Keeping red for danger */
    --danger-button-hover: #c62828;
    --correct-color: hsl(var(--tint-hue), 60%, 40%);
    --incorrect-color: #e53935;
    --correct-bg: hsla(var(--tint-hue), 50%, 15%, 0.4);
    --incorrect-bg: #3e1515;
    
    /* Blur and transparency settings */
    --blur-amount: 8px;
    --container-bg-opacity: 0.7;
    --sidebar-bg-opacity: 0.7;
    --inner-element-opacity: 0.6;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--primary-text);
    min-height: 100vh;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

header {
    background-color: var(--surface-color);
    color: var(--primary-text);
    padding: 1rem 2rem;
    box-shadow: 0 2px 5px var(--shadow-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    position: relative;
}

.header-content {
    display: flex;
    align-items: center;
}

.logo {
    height: 2rem;
    margin-right: 1rem;
}

main {
    display: flex;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.admin-panel {
    flex: 2;
    margin-right: 2rem;
}

.preview {
    flex: 1;
    background-color: rgba(30, 30, 30, var(--container-bg-opacity));
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px var(--shadow-color);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
}

h1, h2, h3 {
    margin-top: 0;
    color: var(--primary-text);
}

.section-manager,
.category-manager,
.question-manager,
.admin-section {
    background-color: rgba(30, 30, 30, var(--container-bg-opacity));
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px var(--shadow-color);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
}

form {
    margin-top: 1rem;
}

input[type="text"],
textarea,
select {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-color);
    color: var(--primary-text);
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-button);
}

textarea {
    min-height: 100px;
}

button {
    background-color: var(--primary-button);
    color: var(--primary-text);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

button:hover:not(:disabled) {
    background-color: var(--primary-button-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px var(--shadow-color);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

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

#save-questions {
    background-color: var(--success-button);
    padding: 0.75rem 1.5rem;
    font-size: 1.1em;
    margin-top: 1rem;
}

#save-questions:hover {
    background-color: var(--success-button-hover);
}

.secondary-button {
    background-color: var(--surface-color-active);
    color: var(--primary-button);
    border: 1px solid var(--primary-button);
    padding: 0.75rem 1.5rem;
    font-size: 1.1em;
    margin-top: 1rem;
}

.danger-button {
    background-color: var(--danger-button);
    color: var(--primary-text);
}

.danger-button:hover {
    background-color: var(--danger-button-hover);
}

.edit-button, .delete-button {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.edit-button {
    background-color: var(--primary-button);
}

.delete-button {
    background-color: var(--danger-button);
}

.question-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

#questions-list {
    max-height: 400px; /* Increased height for better visibility */
}

.list-container {
    max-height: 400px; /* Increase from 200px */
    overflow-y: auto;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-color);
}

.list-item {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--secondary-text);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    transition: background-color 0.2s;
}

.list-item:hover {
    background-color: var(--surface-color-hover);
}

.list-item.active {
    background-color: var(--selection-active-bg);
    border-left: 3px solid var(--selection-border);
    color: var(--primary-text);
    padding-left: calc(0.5rem - 3px);
}

.list-item-text {
    flex: 1;
    min-width: 50%;
    max-width: 100%;
    white-space: normal; /* Allow text to wrap */
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.list-item-actions {
    display: flex;
    gap: 0.25rem;
    margin-left: auto; /* Push to the right */
    flex-shrink: 0; /* Prevent shrinking */
    align-self: flex-start; /* Align to top of text */
}

.question-item {
    padding: 0.75rem 1rem;
}

/* Responsive adjustments for question list */
@media (min-width: 901px) {
    .list-item-text {
        max-width: 50%; /* Limit width on larger screens */
    }
}

.answer-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.answer-text {
    flex: 1;
    margin-right: 1rem;
    margin-bottom: 0 !important;
}

.answer-correct {
    margin-right: 0.5rem;
    accent-color: var(--success-button);
}

#answers-container {
    margin-bottom: 1rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-color-hover);
}

#add-answer {
    background-color: var(--muted-text);
    margin-bottom: 1rem;
}

#add-answer:hover {
    background-color: var(--secondary-text);
}

.preview-answer {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-color-hover);
}

.preview-answer.correct {
    background-color: var(--correct-bg);
    border-color: var(--correct-color);
    color: var(--correct-color);
}

/* Make sure the hidden class is very explicit */
.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#admin-content:not(.hidden) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Authentication UI */
.full-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--background-color);
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-button);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.login-container {
    background-color: rgba(30, 30, 30, var(--container-bg-opacity));
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 10px var(--shadow-color);
    width: 100%;
    max-width: 400px;
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--secondary-text);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color-hover);
    color: var(--primary-text);
    border-radius: 4px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-button);
}

.error-message {
    color: var(--incorrect-color);
    margin-top: 1rem;
    text-align: center;
}

.user-info {
    display: flex;
    align-items: center;
}

#user-name {
    margin-right: 1rem;
    color: var(--secondary-text);
}

#logout-button {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    padding: 0.25rem 0.5rem;
}

#logout-button:hover {
    background-color: var(--surface-color-hover);
}

/* Session Timeout Warning */
.timeout-warning {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--surface-color);
    border: 2px solid var(--danger-button);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 10px var(--shadow-color);
    z-index: 2000;
    max-width: 350px;
    transition: opacity 0.3s, transform 0.3s;
}

.timeout-warning.hidden {
    opacity: 0;
    transform: translateY(30px);
    pointer-events: none;
    visibility: hidden;
}

.timeout-content h3 {
    color: var(--danger-button);
    margin-top: 0;
    margin-bottom: 10px;
}

.timeout-content p {
    margin-bottom: 15px;
}

#timeout-countdown {
    font-weight: bold;
    color: var(--danger-button);
}

/* Fix header styling for admin page */
#admin-content header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    width: 100%;
    background-color: var(--surface-color);
    box-shadow: 0 2px 5px var(--shadow-color);
}

#admin-content .header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#admin-content .header-content h1 {
    margin: 0;
    font-size: 1.5rem;
    white-space: nowrap;
}

#admin-content .logo {
    height: 2.5rem;
    width: auto;
    margin-right: 1rem;
}

#admin-content .user-info {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

#admin-content #logout-button {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    padding: 0.5rem 1rem;
    margin: 0 0 0 1rem;
}

#admin-content main {
    display: flex;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Animation Editor Styles */
.animation-editor {
    background-color: var(--surface-color);
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    margin: 1rem 0;
}

/* Animation Settings Panel */
.animation-settings {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--surface-color-hover);
}

.animation-settings h4 {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.settings-group {
    flex: 1;
    min-width: 200px;
}

.frame-size-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.frame-size-controls input {
    width: 70px;
}

.grid-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.grid-size-setting {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.grid-size-setting input {
    width: 60px;
}

.animation-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.animation-objects {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.5rem;
}

.animation-timeline {
    flex: 2;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 0.5rem;
}

.object-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    padding: 0.5rem;
    background-color: var(--surface-color-hover);
    border-radius: 3px;
}

.object-item {
    width: 60px;
    height: 60px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: var(--surface-color-active);
    border-radius: 3px;
    position: relative;
    padding: 5px;
    transition: all 0.2s ease;
}

.object-item:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 5px var(--shadow-color);
}

.object-item.selected {
    border: 2px solid var(--primary-button);
}

.object-item img, .object-item svg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.object-item .object-name {
    position: absolute;
    bottom: -20px;
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.timeline-container {
    height: 50px;
    background-color: var(--surface-color-hover);
    position: relative;
    margin-top: 1rem;
    border-radius: 3px;
    overflow-x: auto;
}

.timeline-mark {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background-color: var(--border-color);
}

.timeline-mark.active {
    background-color: var(--primary-button);
}

.timeline-mark .time-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
}

.animation-preview-container {
    display: flex;
    margin: 1rem 0;
    gap: 1rem;
}

.animation-preview {
    flex: 2;
    height: 400px;
    background-color: var(--surface-color-hover);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}

.animation-properties {
    flex: 1;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 5px;
    max-width: 250px;
}

.property-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.property-group {
    margin-bottom: 0.5rem;
}

.position-controls {
    display: flex;
    gap: 0.5rem;
}

.position-controls input {
    width: 60px;
}

.animation-json {
    margin-top: 1rem;
}

.animation-json textarea {
    width: 100%;
    font-family: monospace;
    background-color: var(--surface-color-hover);
}

.timeline-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.timeline-controls input {
    width: 60px;
}

/* Animation object in preview */
.animation-object {
    position: absolute;
    cursor: move;
    /* Add default fixed dimensions to prevent size changes */
    min-width: 50px;
    min-height: 50px;
    box-sizing: border-box;
}

.animation-object.selected {
    outline: 2px dashed var(--primary-button);
}

.animation-object img, .animation-object svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
    object-fit: contain; /* Ensure images maintain aspect ratio */
}

.danger-btn {
    background-color: var(--danger-button);
    color: var(--primary-text);
}

.danger-btn:hover {
    background-color: var(--danger-button-hover);
}

.background-selector {
    width: 100%;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--primary-text);
}

/* Form actions */
.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.form-actions button {
    flex: 1;
}

/* Responsive design for mobile */
@media (max-width: 900px) {
    main {
        flex-direction: column;
        padding: 1rem;
    }
    
    .admin-panel {
        margin-right: 0;
        margin-bottom: 2rem;
    }
    
    .preview {
        width: 100%;
    }
    
    header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }
    
    .header-content h1 {
        font-size: 1.2rem;
    }
}

@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .user-info {
        width: 100%;
        justify-content: space-between;
    }
    
    .section-manager,
    .category-manager,
    .question-manager {
        padding: 1rem;
    }
    
    .list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .list-item-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .animation-controls {
        flex-direction: column;
    }
    
    .animation-preview-container {
        flex-direction: column;
    }
    
    .animation-preview {
        height: 300px;
    }
    
    .animation-properties {
        max-width: 100%;
    }
    
    .frame-size-controls {
        flex-wrap: wrap;
    }
    
    .settings-row {
        flex-direction: column;
    }
    
    button {
        padding: 0.75rem 1rem;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions button {
        width: 100%;
    }
}
