/* Base styles and CSS reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #003366;
    --accent-color: #CC0000;
    --link-color: #006600;
    --panel-bg: rgba(255, 255, 255, 0.7);
    --font-family: 'Comic Sans MS', cursive, sans-serif;
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    background-size: cover;
    font-family: var(--font-family);
    color: var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 2rem;
    padding-bottom: 2rem;
    position: relative;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Typography */
h1 {
    color: var(--accent-color);
    text-shadow: 1px 1px 0px #fff;
    margin-bottom: 1rem;
}

a {
    color: var(--link-color);
    font-weight: bold;
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    text-decoration: underline;
    color: #004400;
}

/* Form elements */
input[type="text"], input[type="password"], input[type="submit"] {
    padding: 0.6rem;
    margin-top: 0.5rem;
    border-radius: 6px;
    border: 2px solid #88c;
    font-size: 1rem;
    width: 100%;
    max-width: 300px;
}

input[type="submit"] {
    background-color: var(--link-color);
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

input[type="submit"]:hover {
    background-color: #004400;
}

/* Content elements */
pre, code {
    background: var(--panel-bg);
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
}

ul {
    background: var(--panel-bg);
    padding: 1rem;
    border-radius: 10px;
    list-style-type: square;
    margin-bottom: 1rem;
}

li {
    margin-bottom: 0.5rem;
    margin-left: 1.5rem;
}

p {
    background: rgba(255, 255, 255, 0.65);
    padding: 0.8rem;
    border-radius: 8px;
    margin: 0.8rem 0;
    max-width: 100%;
}

/* Main container */
#elfStyle {
    position: relative;
    z-index: 2;
    font-family: var(--font-family);
    color: var(--accent-color);
    font-size: clamp(1rem, 4vw, 2.0rem);
    line-height: 1.3;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    width: 90%;
    max-width: 1200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Navigation elements */
.welcome {
    margin-bottom: 2rem;
    width: 100%;
    margin-top: -50px;
}

.register {
    margin: 2rem 0;
    width: 100%;
}

.register a {
    background-color: rgba(255, 255, 255, 0.8);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    display: inline-block;
    font-size: clamp(1rem, 3vw, 1.8rem);
}

.violation {
    margin-top: 2rem;
    width: 100%;
    font-size: clamp(0.8rem, 1vw, 1rem);
}

/* Session ID display */
.session-id {
    position: fixed;
    bottom: 3rem;
    font-size: clamp(0.7rem, 1.5vw, 0.9rem);
    color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.7);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.warning-message {
    color: var(--accent-color);
    font-weight: bold;
}

/* O login form styles */
.oContainer .login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.oContainer .form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.oContainer .form-group label {
    font-weight: bold;
}

.oContainer .form-group input[type="text"],
.oContainer .form-group input[type="password"] {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: var(--font-family);
}

.oContainer .form-group input[type="submit"] {
    background-color: var(--accent-color);
    color: white;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: bold;
}

.oContainer .form-group input[type="submit"]:hover {
    background-color: #990000;
}

.oContainer .error-message {
    color: var(--accent-color);
    font-weight: bold;
}

.oContainer .info-message {
    color: var(--primary-color);
    font-style: italic;
    margin-bottom: 10px;
    margin-top: 1rem;
    padding: 0.5rem;
    border-radius: 4px;
    background-color: rgba(255, 255, 220, 0.7);
}

/* Report pages styles */
.report-content {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.report-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.violation-list {
    text-align: left;
    margin-bottom: 1rem;
    background: transparent;
    padding: 0;
}

.violation-list li {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.violation-list li:hover {
    white-space: normal;
    overflow: visible;
}

.violation-count {
    font-size: 1.1rem;
    color: var(--accent-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 1rem;
    margin-top: 1rem;
}

/* Termination page styles */
.terminated-title {
    color: var(--accent-color);
    font-weight: bold;
}

.terminated-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    margin: 0 auto;
    border: 3px solid var(--accent-color);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.terminated-container p {
    font-size: 1.2rem;
    background: transparent;
    text-align: center;
}

/* Instructions panel */
#instBtn {
    display: inline;
    background: none;
    padding: 0;
    color: var(--link-color);
    font-weight: bold;
    text-decoration: none;
    transition: color 0.3s ease;
}

#instBtn:hover {
    text-decoration: underline;
    color: #004400;
}

.rules {
    width: 90%;
    max-width: 800px;
    background-color: var(--panel-bg);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 15;
    overflow: hidden; /* Changed from auto to hidden */
    max-height: 90vh;
    padding: 10px;
    padding-bottom: 60px; /* Space for the close button */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Background overlay when rules are visible */
.rules::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.rules.visible {
    opacity: 1;
    visibility: visible;
}

.rules.visible::before {
    opacity: 1;
    visibility: visible;
}

#instructions {
    width: 100%;
    height: auto;
    display: block;
    max-width: 100%;
    max-height: calc(90vh - 80px); /* Subtract space for padding and close button */
    object-fit: contain;
}

.close-instructions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    font-family: var(--font-family);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s ease;
    min-width: 100px; /* Ensure button has enough touch area */
    z-index: 16; /* Ensure button stays above content */
}

.close-instructions:hover, .close-instructions:focus {
    background-color: #990000;
    outline: none;
}

/* Admin and Logs pages styles */
.admin-title {
    color: var(--primary-color);
}

.admin-content {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.admin-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 95%;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.admin-message {
    margin-bottom: 1rem;
    text-align: center;
    font-weight: bold;
}

.admin-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.filter-form {
    flex: 1;
    min-width: 280px;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-group input {
    flex: 1;
    min-width: 120px;
}

.admin-actions {
    display: flex;
    gap: 1rem;
}

.clear-button {
    background-color: var(--accent-color);
    color: white;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.clear-button:hover {
    background-color: #990000;
    text-decoration: none;
    color: white;
}

.logs-container {
    background: rgba(0,0,0,0.05);
    padding: 1em;
    border-radius: 5px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Success page styles */
.success-title {
    color: #006600;
}

.success-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    margin: 0 auto;
    border: 2px solid #006600;
    text-align: center;
}

.action-button {
    display: inline-block;
    background-color: var(--link-color);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    margin: 1rem 0;
    font-weight: bold;
}

.action-button:hover {
    background-color: #004400;
    text-decoration: none;
    color: white;
}

.flag-display {
    color: var(--link-color);
    font-weight: bold;
    font-size: 1.2rem;
    margin-top: 1.5rem;
    text-align: center;
    background-color: rgba(255, 255, 220, 0.8);
    padding: 1rem;
    border-radius: 8px;
}

@media (max-width: 768px) {
    .course-details {
        grid-template-columns: 1fr;
    }
}

/* O pages additional styles */
.feedback-message, .feedback-hash {
    background: rgba(255, 255, 255, 0.6);
    margin: 0.5rem 0;
    padding: 0.8rem;
}

.env-code {
    background: #eeeeee;
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    white-space: pre-wrap;
    font-family: monospace;
    margin-bottom: 1rem;
}

.search-result {
    margin-bottom: 0.5rem;
}

.search-query {
    font-weight: bold;
    background-color: rgba(255, 255, 0, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.student-form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.student-form label {
    font-weight: bold;
}

.student-form input[type="text"] {
    width: 100%;
}

.student-form input[type="submit"] {
    align-self: flex-start;
}

/* Error pages styles */
.error-title {
    color: #4169E1;
    font-weight: bold;
}

.error-content {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.error-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    margin: 0 auto;
    border: 2px solid #4169E1;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* 403 Forbidden styles */
.forbidden-title {
    color: #FF3300;
    font-weight: bold;
}

.forbidden-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    margin: 0 auto;
    border: 2px solid #FF3300;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* 500 Server Error styles */
.server-error-title {
    color: #9932CC;
    font-weight: bold;
}

.server-error-container {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    margin: 0 auto;
    border: 2px solid #9932CC;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.error-path {
    font-family: monospace;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: bold;
    color: var(--accent-color);
}

.error-reasons {
    text-align: left;
    background: transparent;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
}

.error-message {
    font-weight: bold;
    margin-bottom: 0.2rem;
}

@media (max-width: 768px) {
    .error-container, .forbidden-container, .server-error-container {
        width: 95%;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .error-container, .forbidden-container, .server-error-container {
        padding: 0.8rem;
        border-width: 1px;
    }
    
    .error-path {
        font-size: 0.8rem;
        word-break: break-all;
    }
}

@media (max-width: 768px) {
    #elfStyle {
        width: 95%;
        padding: 1rem;
    }
    
    .rules {
        width: 95%;
        max-height: 85vh;
    }
    
    .login-container {
        padding: 1.5rem;
    }
    
    .oContainer {
        padding: 1rem;
        width: 95%;
    }
    
    .report-container {
        padding: 1rem;
        width: 95%;
    }
    
    .terminated-container {
        padding: 1rem;
        width: 95%;
    }
    
    .admin-container, .success-container, .courses-container {
        width: 95%;
        padding: 1rem;
    }
    
    .admin-controls {
        flex-direction: column;
    }
    
    .filter-group {
        flex-direction: column;
    }
    
    .logs-container {
        max-height: 300px;
        font-size: 0.8rem;
    }
    
    .flag-display {
        font-size: 1.1rem;
        padding: 0.8rem;
    }
}

@media (max-width: 480px) {
    body {
        align-items: flex-start;
        padding-top: 2rem;
    }
    
    #elfStyle {
        font-size: 1rem;
    }
    
    .welcome, .register, .violation {
        margin: 1rem 0;
    }
    
    .rules {
        top: 50%;
        width: 98%;
        max-height: 80vh;
        overflow: hidden;
    }
    
    .close-instructions {
        bottom: 10px;
        padding: 6px 15px;
        font-size: 0.9rem;
    }
    
    .login-container {
        padding: 1rem;
        margin-top: 0.5rem;
    }
}

/* Extra small devices */
@media (max-width: 320px) {
    .rules {
        width: 100%;
        height: 100%;
        max-height: none;
        top: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        overflow: hidden;
        padding: 15px;
        padding-bottom: 70px;
    }
    
    #instructions {
        max-width: 100%;
        max-height: calc(100vh - 100px);
        width: auto;
        height: auto;
    }
    
    .close-instructions {
        width: 80%;
        max-width: 200px;
        padding: 10px 15px;
        font-size: 1rem;
    }
    
    .login-form input {
        font-size: 0.9rem;
    }
    
    .session-id {
        font-size: 0.7rem;
        bottom: 2.5rem;
    }
    
    .oContainer {
        padding: 0.8rem;
        border-width: 1px;
    }
    
    .warning-message {
        font-size: 0.9rem;
    }
    
    .report-container {
        padding: 0.8rem;
    }
    
    .violation-list li {
        font-size: 0.9rem;
    }
    
    .violation-count {
        font-size: 1rem;
    }
    
    .terminated-container {
        padding: 0.8rem;
        border-width: 2px;
    }
    
    .terminated-container p {
        font-size: 1rem;
    }
    
    .admin-container, .success-container, .courses-container {
        padding: 0.8rem;
    }
    
    .logs-container {
        padding: 0.7rem;
        max-height: 250px;
        font-size: 0.75rem;
    }
    
    .flag-display {
        font-size: 1rem;
        padding: 0.6rem;
    }
    
    .env-code {
        font-size: 0.8rem;
        padding: 0.8rem;
    }
}
