body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    color: #333;
}

header {
    background-color: #333;
    color: #fff;
    padding: 1rem 0;
    text-align: center;
}

header h1 {
    margin: 0;
}

main {
    padding: 20px;
    max-width: 900px;
    margin: 20px auto;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

section:last-child {
    border-bottom: none;
}

h2 {
    color: #333;
}

h3 {
    color: #555;
}

ul, ol {
    margin-left: 20px;
}

.explanation-box {
    background-color: #e7f3fe;
    border-left: 6px solid #2196F3;
    margin: 20px 0;
    padding: 10px 20px;
}

.explanation-box h4 {
    margin-top: 0;
    color: #2196F3;
}

.tape-example {
    margin: 10px 0;
    padding: 5px;
    background-color: #f0f0f0;
    border: 1px dashed #ccc;
}

.tape-example .tape-viz {
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    color: #d9534f; /* Reddish color for 1s */
}

.mermaid {
    text-align: center;
    margin-bottom: 20px;
}

.step-by-step-diagrams {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping to next line if not enough space */
    gap: 20px; /* Space between diagram steps */
    margin-bottom: 20px;
    justify-content: center; /* Center items if they don't fill the row */
}

.diagram-step {
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 5px;
    background-color: #f9f9f9;
    flex: 1 1 300px; /* Flex properties: grow, shrink, basis (min-width) */
    min-width: 280px; /* Ensure a minimum width before wrapping */
    box-shadow: 2px 2px 5px rgba(0,0,0,0.05);
}

.diagram-step p {
    margin-top: 0;
    font-size: 0.95em;
    text-align: center;
}

.diagram-step .mermaid {
    margin-bottom: 0; /* Remove default mermaid margin if any */
    padding: 5px;
    background-color: #fff; /* White background for the diagram itself */
    border-radius: 3px;
}


/* Demonstration Specific Styles */
#turing-machine {
    border: 1px solid #ccc;
    padding: 15px;
    background-color: #f9f9f9;
}

#tape-container {
    width: 100%;
    overflow-x: auto; /* Allows horizontal scrolling for long tapes */
    margin-bottom: 15px;
    padding: 10px 0;
    background-color: #e0e0e0;
    border: 1px solid #ccc;
}

#tape {
    display: flex; /* Aligns tape cells in a row */
    min-width: fit-content; /* Ensures tape expands with content */
}

.tape-cell {
    min-width: 30px;
    height: 30px;
    border: 1px solid #bbb;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
    background-color: #fff;
    margin-right: 2px; /* Small gap between cells */
}

.tape-cell.active {
    border: 2px solid blue;
    font-weight: bold;
    background-color: #e6f2ff; /* Light blue highlight for active cell */
}

.tape-cell.written {
    animation: flash-write 0.5s ease-out;
}

@keyframes flash-write {
    0% { background-color: #a8d8ff; } /* Lighter blue */
    50% { background-color: #6cbaff; } /* Brighter blue */
    100% { background-color: #fff; } /* Original or active color if head is still there */
}

.tape-cell.active.written {
    animation: flash-write-active 0.5s ease-out;
}

@keyframes flash-write-active {
    0% { background-color: #a8d8ff; }
    50% { background-color: #6cbaff; }
    100% { background-color: #e6f2ff; } /* Back to active color */
}


#controls button {
    padding: 10px 15px;
    margin-right: 10px;
    background-color: #5cb85c;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 4px;
}

#controls button:hover {
    background-color: #4cae4c;
}

#controls button#reset-btn {
    background-color: #d9534f;
}

#controls button#reset-btn:hover {
    background-color: #c9302c;
}

#controls button#pause-btn {
    background-color: #f0ad4e;
}

#controls button#pause-btn:hover {
    background-color: #ec971f;
}


#info p {
    margin: 5px 0;
    font-size: 1.1em;
}

#info span {
    font-weight: bold;
}

#current-rule-display {
    margin-top: 15px;
    padding: 10px;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#current-rule-display p {
    margin: 0;
}

#current-rule-display #rule-text {
    font-family: 'Courier New', Courier, monospace;
    color: #007bff;
}

footer {
    text-align: center;
    padding: 10px;
    background-color: #333;
    color: #fff;
    margin-top: 20px;
}
