* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Alata', Arial, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
    padding: 20px;
    direction: ltr;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #1a5f7a, #159895);
    color: white;
    padding: 30px;
    text-align: center;
}

h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.content {
    padding: 30px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.form-section {
    background: #f9f9f9;
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #1a5f7a;
    box-shadow: 4px 4px 0 #1a5f7a;
    transition: all 0.25s ease-in-out;
}

.form-section:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #1a5f7a;
}

.section-title {
    font-size: 1.3rem;
    margin-bottom: 15px;
    color: #1a5f7a;
    padding-bottom: 8px;
    border-bottom: 2px solid #eaeaea;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #444;
}

input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #1a5f7a;
    border-radius: 8px;
    font-family: 'Alata', Arial, sans-serif;
    font-size: 1rem;
    background-color: #f0f4f8;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 0 #1a5f7a;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: #159895;
    background-color: #ffffff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(21, 152, 149, 0.2);
}

input[type="text"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #1a5f7a;
}

textarea {
    height: 200px;
    resize: vertical;
}

#equations {
    width: 100%;
    height: 280px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: 'Alata', Arial, sans-serif;
    color: #111;
    background-color: #fffef8;
    border: 2px solid #1a5f7a;
    border-radius: 10px;
    box-shadow: inset 2px 2px 6px rgba(0,0,0,0.15);
    line-height: 1.6;
    resize: vertical;
    white-space: pre;
    word-break: normal;
    overflow-x: auto;
    overflow-y: auto;
}

#equations::selection {
    background: rgba(21, 152, 149, 0.45);
    color: #000;
}

#equations:focus {
    outline: none;
    border-color: #159895;
    box-shadow: 0 0 10px rgba(21, 152, 149, 0.5);
    background-color: #fffce8;
}

.controls {
    background: #f0f4f8;
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
    border: 2px solid #1a5f7a;
    box-shadow: 4px 4px 0 #1a5f7a;
    transition: all 0.25s ease-in-out;
}

.controls:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 #1a5f7a;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 15px;
}

.control-group {
    flex: 1;
    min-width: 200px;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 12px;
    margin-bottom: 7px;
}

.hint {
    color: #666;
    font-size: 0.9rem;
    margin-top: 10px;
    line-height: 1.5;
}

.button-group {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 25px;
}

button {
    font-size: 1rem;
    padding: 14px 25px;
    border-radius: 12px;
    border: 2px solid #1a5f7a;
    background: #fff;
    color: #1a5f7a;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 3px 3px 0 #1a5f7a;
    position: relative;
    overflow: hidden;
    min-width: 180px;
    font-family: 'Alata', Arial, sans-serif;
}

button:hover {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #1a5f7a;
}

button:active {
    transform: translate(3px, 3px);
    box-shadow: 0 0 0 #1a5f7a;
}

.generate-btn {
    background: linear-gradient(to bottom, #57cc99, #c7f9cc);
    border: 2px solid #1a5f7a;
    color: #1a5f7a;
    font-size: 1.1em;
    padding: 16px 30px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 3px 3px 0px #1a5f7a;
    transition: all 0.2s ease-in-out;
}

.download-btn {
    background: linear-gradient(to bottom, #27a745, #1e7e34);
    color: white;
    border: 2px solid #1a5f7a;
    text-decoration: none;
    text-align: center;
}

.back-home-container {
    text-align: center;
    margin-bottom: 20px;
}

.back-home-btn {
    background: linear-gradient(to bottom, #57cc99, #c7f9cc);
    border: 2px solid #1a5f7a;
    color: #1a5f7a;
    font-weight: bold;
    font-family: 'Alata', Arial, sans-serif;
    font-size: 1rem;
    padding: 12px 25px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 3px 3px 0 #1a5f7a;
    transition: all 0.2s ease;
}

.back-home-btn:hover {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #1a5f7a;
    background: linear-gradient(to bottom, #c7f9cc, #57cc99);
}

/* Worksheet Styling */
.worksheet-container {
    margin-top: 30px;
    display: flex;
    justify-content: center;
}

.worksheet {
    background: white;
    border: 2px solid #1a5f7a;
    width: 100%;
    max-width: 794px;
    min-height: 1123px;
    padding: 40px;
    box-shadow: 3px 3px 0 #1a5f7a;
    border-radius: 12px;
}

.meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    font-size: clamp(14px, 2vw, 18px);
    flex-wrap: wrap;
    gap: 10px;
}

.columns {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.column {
    flex: 1;
    min-width: 0;
}

.equation {
    display: flex;
    align-items: center;
    margin: 8px 0;
    padding: 5px;
    border-radius: 6px;
    transition: background-color 0.2s;
    font-size: clamp(14px, 2vw, 18px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.equation:hover {
    background-color: #f0f4f8;
}

.equation-text {
    flex-shrink: 0;
    min-width: 200px;
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.equation-number {
    font-size: 0.8em;
    color: #666;
    margin-right: 5px;
}

.dots-space {
    display: inline-block;
    color: #1a5f7a;
    font-weight: bold;
    font-size: 18px;
    letter-spacing: 2px;
    margin: 0 5px;
    min-width: 60px;
    text-align: center;
}

#scoreDisplay {
    font-size: clamp(14px, 2vw, 18px);
    color: #222;
    font-weight: bold;
}

.footer {
    text-align: center;
    font-size: clamp(12px, 1.5vw, 14px);
    margin-top: 40px;
    color: #777;
}

.footer a {
    color: #0073aa;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.status-message {
    margin: 15px 0;
    padding: 10px;
    border-radius: 4px;
    display: none;
}

.status-message.success {
    background: #e8f5e9;
    color: #4ba924;
    border: 1px solid #4ba924;
    display: block;
}

.status-message.error {
    background: #ffebee;
    color: #b93f05;
    border: 1px solid #b93f05;
    display: block;
}

.loading {
    display: none;
    margin: 15px 0;
}

.loading.active {
    display: block;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #1a5f7a;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.recommendation-box {
    margin-top: 25px;
    background: linear-gradient(to bottom right, #e3f2fd, #bbdefb);
    border: 2px solid #1a5f7a;
    border-radius: 12px;
    padding: 18px 22px;
    box-shadow: 3px 3px 0 #1a5f7a;
    color: #222;
    font-family: 'Alata', Arial, sans-serif;
    line-height: 1.6;
}

.recommendation-box h3 {
    font-size: 1.15rem;
    color: #1a5f7a;
    margin-bottom: 10px;
    text-align: center;
}

.recommendation-box ul {
    list-style-type: "✔ ";
    margin: 10px 0 10px 20px;
    padding: 0;
}

.recommendation-box li {
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.features-box {
    margin-top: 30px;
    background: linear-gradient(to bottom right, #e3f2fd, #bbdefb);
    border: 2px solid #1a5f7a;
    border-radius: 14px;
    padding: 25px 28px;
    box-shadow: 3px 3px 0 #1a5f7a;
    color: #222;
    font-family: 'Alata', Arial, sans-serif;
    line-height: 1.7;
}

.features-box h3 {
    font-size: 1.3rem;
    color: #1a5f7a;
    text-align: center;
    margin-bottom: 18px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #1a5f7a;
    display: inline-block;
    padding-bottom: 5px;
}

.features-box ul {
    list-style-type: "⭐ ";
    margin: 0;
    padding: 0 0 0 25px;
}

.features-box li {
    font-size: 1rem;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.features-box li:hover {
    color: #000;
    transform: translateX(4px);
}

/* زر التحميل والعداد المبسط */
.download-section {
    margin-top: 30px;
    text-align: center;
    display: none;
}

.download-section.visible {
    display: block;
}

.simple-download-btn {
    background: linear-gradient(to bottom, #ff4444, #cc0000);
    color: white;
    border: 2px solid #1a5f7a;
    border-radius: 12px;
    padding: 16px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 3px 3px 0 #1a5f7a;
    transition: all 0.2s ease;
    font-family: 'Alata', Arial, sans-serif;
    margin-bottom: 15px;
    min-width: 200px;
}

.simple-download-btn:hover {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #1a5f7a;
}

.simple-download-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: 3px 3px 0 #1a5f7a;
}

.simple-countdown {
    font-size: 1.1rem;
    color: #ff4444;
    font-weight: bold;
    margin-top: 10px;
    padding: 8px 15px;
    background: #fff5f5;
    border-radius: 8px;
    border: 1px solid #ffcccc;
    display: inline-block;
}

/* Manual input controls */
.manual-controls {
    background: #e8f4f8;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    border: 1px solid #1a5f7a;
}

.manual-controls h4 {
    color: #1a5f7a;
    margin-bottom: 10px;
    font-size: 1rem;
}

.manual-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.manual-btn {
    padding: 8px 12px;
    background: #57cc99;
    border: 1px solid #1a5f7a;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Alata', Arial, sans-serif;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.manual-btn:hover {
    background: #38b2ac;
    transform: translateY(-1px);
}

/* Operation buttons */
.operation-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.operation-btn {
    padding: 6px 10px;
    background: #ffd166;
    border: 1px solid #1a5f7a;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Alata', Arial, sans-serif;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.operation-btn:hover {
    background: #ffb347;
    transform: translateY(-1px);
}

/* Mode toggle */
.mode-toggle {
    display: flex;
    background: #e8f4f8;
    border-radius: 8px;
    padding: 5px;
    margin-bottom: 15px;
    border: 1px solid #1a5f7a;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Alata', Arial, sans-serif;
    font-weight: bold;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: #57cc99;
    color: #1a5f7a;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mode-btn:not(.active):hover {
    background: #c7f9cc;
}

/* Manual mode specific */
.manual-mode .auto-controls {
    display: none;
}

.auto-mode .manual-controls {
    display: none;
}

.equation-counter {
    text-align: right;
    font-size: 0.9rem;
    color: #666;
    margin-top: 5px;
}

.equation-counter.warning {
    color: #ff4444;
    font-weight: bold;
}

/* Responsive Design */
@media (max-width: 900px) {
    .worksheet {
        padding: 30px;
    }
    
    .columns {
        gap: 15px;
    }
    
    .column {
        flex: 1 1 calc(50% - 10px);
    }
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .control-group {
        min-width: 100%;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
    }
    
    .worksheet {
        padding: 20px;
    }
    
    .column {
        flex: 1 1 100%;
    }
    
    .meta {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .equation {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .worksheet {
        padding: 15px;
    }
    
    .equation {
        font-size: 14px;
    }
    
    .button-group {
        flex-direction: column;
        align-items: center;
    }
    
    button {
        min-width: 100%;
        width: 100%;
    }
    
    .simple-download-btn {
        min-width: 100%;
    }
}

@media (max-width: 360px) {
    .worksheet {
        padding: 10px;
    }
    
    .equation {
        font-size: 13px;
    }
    
    .content {
        padding: 15px;
    }
}