body {
    font-family: 'Arial', sans-serif;
    display: flex;
    flex-direction: column; /* Stack main containers vertically */
    align-items: center; /* Center containers horizontally */
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 20px 0; /* Add some padding to top/bottom of body */
    box-sizing: border-box;
    color: #333;
    text-align: center;
}

#page-title-container {
    width: 90%;
    max-width: 800px;
    margin-bottom: 20px;
    text-align: center;
}

#page-title-container h1 {
    color: #fff; /* White title against gradient background */
    font-size: 2.8em;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
    margin: 0; /* Remove default h1 margin if page-title-container handles spacing */
}


#saved-sets-container,
#editor-container,
#game-container {
    background-color: rgba(255, 255, 255, 0.9);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 800px;
    margin-bottom: 30px; /* Space between containers */
    text-align: left; /* Default for container content, can be overridden */
}

#saved-sets-container h2,
#editor-container h2, /* Already styled but good to group */
#game-container h2 {
    color: #3a3a3a;
    text-align: center;
    margin-top: 0; /* Remove top margin if padding handles it */
    margin-bottom: 20px;
    font-size: 2em;
}


.controls-container {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    gap: 15px; /* Space between grid settings and button if they wrap */
}

.grid-settings,
.pre-show-settings {
    display: flex;
    align-items: center;
    gap: 10px;
}

.grid-settings label,
.pre-show-settings label {
    font-size: 1em;
    color: #555;
}

.grid-settings input[type="number"],
.pre-show-settings input[type="number"] {
    width: 60px;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #ddd;
    font-size: 1em;
    text-align: center;
}

#restart-button {
    background-color: #ff6b6b;
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.1em;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    /* margin-bottom: 25px; Removed as .controls-container now handles bottom margin */
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

#restart-button:hover {
    background-color: #ee5253;
    transform: translateY(-2px);
}

#restart-button:active {
    transform: translateY(1px);
}

#game-board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    perspective: 1000px; /* For 3D flip effect */
}

.card {
    background-color: #48dbfb;
    border-radius: 10px;
    cursor: pointer;
    aspect-ratio: 1 / 1; /* Makes cards square */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5em; /* Default for text, adjust as needed */
    transform-style: preserve-3d;
    transition: transform 0.6s, background-color 0.3s;
    position: relative;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.card.flipped,
.card.matched {
    transform: rotateY(180deg);
    background-color: #feca57; /* Color when flipped */
}

.card.matched {
    background-color: #1dd1a1; /* Color when matched */
    cursor: default;
}


.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden; /* Hides the back of the element during rotation */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    overflow: hidden; /* Ensures content like images don't spill out */
}

.card-front {
    /* Content for the front of the card (visible when flipped) */
    transform: rotateY(180deg); /* Initially rotated */
    padding: 10px; /* Padding for content inside the card */
    box-sizing: border-box; /* Includes padding in width/height */
}

.card-back {
    /* Content for the back of the card (visible initially) */
    /* Optionally, add a pattern or logo here */
    background-color: #48dbfb; /* Default back color, same as initial card */
    font-size: 2.5em; /* Larger for a question mark or similar */
    color: white;
}

.card-content-text {
    font-size: 0.8em; /* Adjust based on card size and text length */
    word-wrap: break-word;
    text-align: center;
}

.card-content-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain; /* Scales image to fit within bounds while preserving aspect ratio */
    border-radius: 5px; /* Slight rounding for images */
}

/* Hide card content initially until JS loads it */
.card .card-front > * {
    visibility: hidden;
}

.card.flipped .card-front > *,
.card.matched .card-front > * {
    visibility: visible;
}
/* Card Editor Styles */
#editor-container {
    background-color: rgba(255, 255, 255, 0.85);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 800px;
    margin: 30px auto; /* Center it and add space from game container */
    text-align: left;
}

#editor-container h2,
#editor-container h3 {
    color: #3a3a3a;
    text-align: center;
    margin-bottom: 15px;
}

#toggle-editor-button,
#save-data-button,
#add-item-form button[type="submit"] {
    background-color: #54a0ff;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: block; /* Make buttons take full width or center them */
    margin: 10px auto; /* Center buttons */
}

#toggle-editor-button:hover,
#save-data-button:hover,
#add-item-form button[type="submit"]:hover {
    background-color: #2e86de;
}

#card-editor {
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 20px;
}

#existing-items-editor .existing-item,
#add-item-form .form-group {
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
}

#existing-items-editor .existing-item {
    display: flex;
    flex-direction: column; /* Stack items vertically */
    gap: 10px;
}

.item-pair-details {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.item-pair-details span {
    flex-basis: calc(50% - 5px); /* Two items per row, accounting for gap */
    word-break: break-all;
}


#add-item-form .form-group {
    display: flex;
    flex-direction: column; /* Stack labels and inputs */
    gap: 8px;
}

#add-item-form label {
    font-weight: bold;
    color: #444;
    margin-bottom: 3px;
}

#add-item-form input[type="text"],
#add-item-form select {
    width: calc(100% - 20px); /* Full width minus padding */
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 0.95em;
}

#existing-items-editor .delete-item-button {
    background-color: #ff6b6b;
    color: white;
    border: none;
    padding: 8px 12px;
    font-size: 0.9em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    align-self: flex-end; /* Align button to the right */
    margin-top: 5px;
}

#existing-items-editor .delete-item-button:hover {
    background-color: #ee5253;
}

.editor-note {
    font-size: 0.9em;
    color: #777;
    text-align: center;
    margin-top: 20px;
    font-style: italic;
}
/* Batch Add Text Form Styles */
#batch-add-text-form {
    background-color: #f0f4f8;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px; /* Space from the form above */
    margin-bottom: 20px; /* Space from the save button below */
    border: 1px solid #d1dce5;
}

#batch-add-text-form h3 {
    margin-top: 0;
}

#batch-add-text-form p {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 8px;
}

#batch-add-text-form pre {
    background-color: #e9ecef;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.85em;
    white-space: pre-wrap; /* Wrap long lines */
    word-break: break-all;
    margin-bottom: 10px;
}

.batch-input-group {
    margin-bottom: 15px; /* Space between the two groups */
}

.batch-input-group label {
    display: block; /* Label on its own line */
    font-weight: bold;
    color: #444;
    margin-bottom: 5px;
}

#batch-add-text-form textarea { /* This will style both batch textareas */
    width: calc(100% - 22px); /* Full width minus padding and border */
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 0.95em;
    min-height: 60px; /* Adjusted height for comma-separated lists */
    /* margin-bottom: 10px; Removed, .batch-input-group handles spacing */
}


#generate-from-text-button {
    background-color: #20c997; /* A different color for this button */
    /* Inherits other button styles from the general rule if specific enough,
       or re-declare if needed: */
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: block;
    margin: 10px auto;
}

#generate-from-text-button:hover {
    background-color: #1baa80;
}
/* Saved Sets Styles */
#save-current-set-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

#set-title-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

#save-set-button {
    background-color: #17a2b8; /* Teal color */
    color: white;
    border: none;
    padding: 10px 15px;
    font-size: 1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#save-set-button:hover {
    background-color: #138496;
}

#saved-sets-list {
    list-style-type: none;
    padding: 0;
    margin-top: 10px;
}

#saved-sets-list li {
    background-color: #f8f9fa;
    padding: 10px 15px;
    border-radius: 5px;
    margin-bottom: 10px;
    border: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#saved-sets-list li span {
    font-weight: bold;
    color: #333;
    margin-right: auto; /* Pushes buttons to the right */
    padding-right: 10px; /* Space before buttons */
}

#saved-sets-list .load-set-button,
#saved-sets-list .delete-set-button {
    border: none;
    padding: 8px 12px;
    font-size: 0.9em;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-left: 8px;
}

#saved-sets-list .load-set-button {
    background-color: #28a745; /* Green */
    color: white;
}
#saved-sets-list .load-set-button:hover {
    background-color: #218838;
}

#saved-sets-list .delete-set-button {
    background-color: #dc3545; /* Red */
    color: white;
}
#saved-sets-list .delete-set-button:hover {
    background-color: #c82333;
}