body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin: 0;
    padding: 20px;
    background-color: #eef1f5; /* Light grayish blue background */
    min-height: 100vh;
    color: #333;
}

.container {
    background-color: #ffffff;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    display: flex;
    gap: 35px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 1000px; /* Max container width */
}

.main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    color: #2c3e50; /* Dark blue */
    margin-bottom: 20px;
}

.flag-display-area {
    width: 450px; /* 3:2 aspect ratio for typical flags */
    height: 300px;
    border: 3px solid #bdc3c7; /* Medium gray border */
    background-color: #f0f0f0; 
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
    border-radius: 4px; /* Slightly rounded corners for the display area */
}

#flag {
    width: 100%;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box; /* Add this for correct border rendering */
    /* Dynamic styles (display, flex-direction, background-color, position, clip-path) are set by JS */
}

.controls {
    width: 380px; /* Slightly wider controls */
    display: flex;
    flex-direction: column;
    gap: 18px; /* Increased gap */
}

.controls h2 {
    margin-top: 0;
    margin-bottom: 15px;
    text-align: center;
    color: #34495e; /* Another shade of dark blue */
    font-size: 1.8em;
}

.controls h3 {
    margin-top: 5px;
    margin-bottom: 10px;
    color: #2980b9; /* Blue for subheadings */
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.control-group {
    padding: 15px;
    border: 1px solid #e0e0e0; /* Lighter border */
    border-radius: 6px;
    background-color: #fdfdfd; /* Almost white */
}

.control-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600; /* Slightly bolder */
    color: #555;
    font-size: 0.95em;
}

.control-group input[type="color"],
.control-group input[type="number"],
.control-group input[type="range"],
.control-group select {
    width: 100%;
    padding: 10px;
    margin-bottom: 12px; /* More space below inputs */
    border: 1px solid #d1d1d1; /* Slightly darker border for inputs */
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1em;
}

.control-group input[type="color"] {
    padding: 2px; /* Color pickers often handle their own internal padding */
    height: 45px; 
}
.control-group input[type="number"] {
    max-width: 100px; /* Numbers don't need full width */
}

.star-controls {
    margin-top: 10px;
    margin-bottom: 15px;
    display: none; /* Initially hidden */
}

.star-controls label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #555;
    font-size: 0.95em;
}

.star-controls input[type="number"],
.star-controls select {
    width: 100%;
    padding: 10px;
    margin-bottom: 12px;
    border: 1px solid #d1d1d1;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1em;
}

.crescent-controls {
    margin-top: 10px;
    margin-bottom: 15px;
    display: none; /* Initially hidden */
}

.crescent-controls label {
    display: inline-block; /* Use inline-block for checkbox label */
    margin-right: 10px; /* Space between label and checkbox */
    font-weight: 600;
    color: #555;
    font-size: 0.95em;
}

.crescent-controls input[type="checkbox"] {
    vertical-align: middle; /* Align checkbox with text */
    margin-bottom: 0; /* Remove bottom margin */
    width: auto; /* Auto width for checkbox */
    padding: 0; /* Remove padding for checkbox */
}

#stripeColorsContainer {
    margin-top: 10px;
}

#stripeColorsContainer .stripe-color-picker-group {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px dashed #eaeaea; /* Lighter dash */
    display: flex;
    align-items: center;
    gap: 10px;
}
#stripeColorsContainer .stripe-color-picker-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

#stripeColorsContainer label {
    font-weight: normal;
    flex-shrink: 0; /* Prevent label from shrinking */
}
#stripeColorsContainer input[type="color"] {
    width: 60px; /* Smaller color pickers for stripes */
    height: 30px;
    margin-bottom: 0; /* Remove margin as it's handled by group */
}

.triangle-control {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #f9f9f9;
}

.triangle-control h4 {
    margin: 0 0 10px 0;
    color: #333;
}

.triangle-control label {
    display: block;
    margin-bottom: 8px;
}

.triangle-control input[type="range"] {
    width: 100%;
    margin: 5px 0;
}

.triangle-control input[type="color"] {
    width: 60px;
    height: 30px;
    padding: 0;
    margin: 5px 0;
}

.triangle-control .remove-triangle {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    margin-top: 5px;
    width: 100%;
}

.triangle-control .remove-triangle:hover {
    background-color: #c0392b;
}

#addTriangleButton {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 10px;
    width: 100%;
}

#addTriangleButton:hover {
    background-color: #2980b9;
}

#triangleControlsContainer {
    margin-top: 10px;
}

button#resetButton {
    padding: 12px 20px;
    background-color: #e74c3c; /* Red */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em; /* Larger font */
    font-weight: bold;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease;
    margin-top: 10px; /* Space above reset button */
}

button#resetButton:hover {
    background-color: #c0392b; /* Darker red */
}
button#resetButton:active {
    transform: translateY(1px); /* Click effect */
}

#downloadButton {
    padding: 12px 20px;
    background-color: #2ecc71; /* Green */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease;
    margin-top: 10px;
}

#downloadButton:hover {
    background-color: #27ae60; /* Darker green */
}

#downloadButton:active {
    transform: translateY(1px); /* Click effect */
}

button#postFlagButton {
    padding: 12px 20px;
    background-color: #3498db; /* Blue */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease, opacity 0.2s ease;
    margin-top: 10px;
}

button#postFlagButton:hover {
    background-color: #2980b9; /* Darker blue */
}
button#postFlagButton:active {
    transform: translateY(1px);
}
button#postFlagButton:disabled {
    background-color: #bdc3c7; /* Gray when disabled */
    cursor: not-allowed;
    opacity: 0.7;
}

button#viewPostsButton {
    padding: 12px 20px;
    background-color: #9b59b6; /* Purple */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease;
    margin-top: 10px;
}

button#viewPostsButton:hover {
    background-color: #8e44ad; /* Darker purple */
}
button#viewPostsButton:active {
    transform: translateY(1px);
}

.symbol {
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    /* Other styles (color, fontSize, line-height, pointer-events) are set by JS */
}

.symbol-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* Prevent symbols from blocking clicks */
}

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 25px;
    border: 1px solid #888;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative; /* For close button positioning */
}

.gallery-modal-content {
    max-width: 800px; /* Wider for gallery */
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal h2 {
    margin-top: 0;
    color: #2c3e50;
    text-align: center;
    margin-bottom: 20px;
}

.modal .control-group {
    margin-bottom: 15px;
    padding: 0; /* Override general control group padding if not desired here */
    border: none; /* Override general control group border */
}

.modal label {
    font-weight: bold;
    margin-bottom: 5px;
    display: block;
}

.modal input[type="text"],
.modal textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1em;
}

.modal textarea {
    resize: vertical;
}

.message-area {
    margin-top: 10px;
    margin-bottom: 15px;
    color: red;
    font-size: 0.9em;
    min-height: 1.2em; /* Reserve space */
}

.modal-action-button {
    background-color: #2ecc71; /* Green */
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.2s ease;
    width: 100%;
    margin-top: 10px;
}

.modal-action-button:hover {
    background-color: #27ae60; /* Darker green */
}

.modal-action-button-secondary {
    background-color: #e74c3c; /* Red */
    color: white;
    padding: 10px 18px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: background-color 0.2s ease;
    width: 100%;
    margin-top: 10px;
}

.modal-action-button-secondary:hover {
    background-color: #c0392b; /* Darker red */
}

#galleryContent {
    max-height: 70vh; /* Limit height and allow scrolling */
    overflow-y: auto;
    padding: 10px;
    background-color: #f9f9f9;
    border-radius: 6px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); /* Responsive grid */
    gap: 20px;
}

.gallery-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gallery-item img {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2; /* Maintain flag aspect ratio */
    object-fit: contain; /* Use contain to ensure whole flag is visible */
    border: 1px solid #eee;
    border-radius: 4px;
    margin-bottom: 10px;
}

.gallery-item h4 {
    margin-top: 0;
    margin-bottom: 5px;
    font-size: 1.1em;
    color: #333;
    text-align: center;
    word-break: break-word;
}

.gallery-item p {
    font-size: 0.9em;
    color: #666;
    text-align: center;
    word-break: break-word;
    max-height: 60px; /* Limit description height */
    overflow-y: auto; /* Scroll for long descriptions */
}

.delete-flag-button {
    background-color: #e74c3c; /* Red color */
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}

.delete-flag-button:hover {
    background-color: #c0392b; /* Darker red on hover */
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.grid-line {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.3);
}

.grid-line.horizontal {
    width: 100%;
    height: 1px;
}

.grid-line.vertical {
    height: 100%;
    width: 1px;
}

.draggable-symbol {
    cursor: move;
    user-select: none;
    pointer-events: auto !important;
}

.symbol-position-controls {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.position-slider {
    width: 100%;
    margin: 5px 0;
}

.grid-toggle {
    margin-top: 10px;
    padding: 8px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}