body {
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background-image: linear-gradient(45deg, #e2e2e2 25%, transparent 25%, transparent 75%, #e2e2e2 75%),
                    linear-gradient(45deg, #e2e2e2 25%, transparent 25%, transparent 75%, #e2e2e2 75%);
    background-size: 60px 60px;
    background-position: 0 0, 30px 30px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    color: #3a5a78;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

h2 {
    font-size: 1.8rem;
    margin: 30px 0 20px;
    color: #3a5a78;
    text-align: center;
}

.container {
    background-color: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid #3a5a78;
}

.input-section {
    margin-bottom: 30px;
}

input, select, button {
    font-size: 1.1rem;
    padding: 10px;
    margin: 5px 0;
    border-radius: 5px;
    border: 1px solid #ccc;
}

input {
    width: calc(100% - 22px);
}

button {
    background-color: #3a5a78;
    color: white;
    border: none;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
    transition: background-color 0.3s;
    position: relative; 
    min-height: 45px; 
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

button:not(:disabled):hover {
    background-color: #4a6a88;
}

.post-button {
    background-color: #2e8b57; /* Sea green color for post button */
    margin: 15px 0;
}

.post-button:not(:disabled):hover {
    background-color: #3aa76a;
}

.result-section {
    margin-top: 30px;
    text-align: center;
    display: none;
}

.result-section.show {
    display: block;
    animation: fadeIn 0.5s;
}

.character-name {
    font-size: 2rem;
    margin-bottom: 20px;
    color: #3a5a78;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.character-image {
    max-width: 100%;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
    border: 3px solid #3a5a78;
    cursor: pointer;
}

.audio-controls {
    margin-top: 20px;
    width: 100%; 
    display: flex; 
    justify-content: center; 
}

audio {
    border-radius: 5px;
}

.loading {
    margin: 20px 0;
    text-align: center;
    font-style: italic;
    color: #666;
    display: none;
}

.loading.show {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.error {
    color: #d12600;
    margin-top: 10px;
    font-weight: bold;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner.show {
    display: inline-block !important;
}

button .button-text,
button .spinner {
    display: inline-block; 
    vertical-align: middle;
}

button:disabled .button-text {
}

.improvement-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin: 20px 0;
    gap: 10px;
}

.improvement-button {
    flex: 1 1 150px;
    margin: 5px; 
    background-color: #5a7a98;
}

.improvement-button:not(:disabled):hover {
    background-color: #6a8aa8;
}

.gallery-section {
    margin-top: 40px;
    border-top: 2px dashed #3a5a78;
    padding-top: 20px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.gallery-item {
    background-color: #f9f9f9;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    border: 1px solid #ddd;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.gallery-image-container {
    width: 100%;
    padding-top: 100%; /* 1:1 Aspect Ratio */
    position: relative;
    overflow: hidden;
}

.gallery-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    cursor: pointer;
}

.gallery-image:hover {
    transform: scale(1.05);
}

.gallery-info {
    padding: 12px;
    background: white;
}

.gallery-name {
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: #3a5a78;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
    max-height: 2.4em;
}

.gallery-user {
    font-size: 0.8rem;
    color: #666;
    display: flex;
    align-items: center;
}

.user-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 5px;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px;
    color: #666;
    font-style: italic;
}

.gallery-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.sort-button {
    padding: 8px 16px;
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #ccc;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: auto;
    width: auto;
}

.sort-button.active {
    background-color: #3a5a78;
    color: white;
}

.sort-button:not(.active):hover {
    background-color: #e0e0e0;
}

.gallery-upvote {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.upvote-button {
    background: none;
    border: 1px solid #ddd;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    color: #666;
    min-height: auto;
    width: auto;
    transition: all 0.2s;
}

.upvote-button:hover {
    border-color: #3a5a78;
    color: #3a5a78;
}

.upvote-button.upvoted {
    background-color: #3a5a78;
    color: white;
    border-color: #3a5a78;
}

.upvote-count {
    font-size: 0.8rem;
    color: #666;
    font-weight: bold;
}

/* Square viewport overlay for showing full-screen image */
#square-viewport-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
}

#square-viewport-overlay img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}