/* Base Styles and Variables */
:root {
    --primary-color: #6aaa64;
    --secondary-color: #c9b458;
    --background-light: #ffffff;
    --text-light: #1a1a1b;
    --background-dark: #121213;
    --text-dark: #d7dadc;
    --tile-border-light: #d3d6da;
    --tile-border-dark: #3a3a3c;
    --keyboard-light: #d3d6da;
    --keyboard-dark: #818384;
    --absent-color: #787c7e;
    --correct-color: #6aaa64;
    --present-color: #c9b458;
    --font-family: 'Arial', sans-serif;
    --border-radius: 4px;
    --transition-speed: 0.3s;
}

/* Global Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.light-mode {
    background-color: var(--background-light);
    color: var(--text-light);
}

body.dark-mode {
    background-color: var(--background-dark);
    color: var(--text-dark);
}

.hidden {
    display: none !important;
}

/* Header Styles */
header {
    padding: 1rem;
    border-bottom: 1px solid var(--tile-border-light);
    transition: border-color var(--transition-speed);
}

body.dark-mode header {
    border-color: var(--tile-border-dark);
}

.header-container {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.theme-toggle button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: inherit;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color var(--transition-speed);
}

.theme-toggle button:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

body.dark-mode .theme-toggle button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Main Content Styles */
main {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

#game-container {
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
}

.mode-container {
    width: 100%;
    padding: 1rem;
}

h2, h3 {
    margin-bottom: 1rem;
    text-align: center;
}

/* Form Elements */
.input-container {
    margin-bottom: 1.5rem;
    position: relative;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

input, textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--tile-border-light);
    border-radius: var(--border-radius);
    font-size: 1rem;
    line-height: 1.6;
    background-color: var(--background-light);
    color: var(--text-light);
    transition: border-color var(--transition-speed), background-color var(--transition-speed), color var(--transition-speed);
}

body.dark-mode input, 
body.dark-mode textarea {
    border-color: var(--tile-border-dark);
    background-color: var(--background-dark);
    color: var(--text-dark);
}

input:focus, 
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Style for the icon button SPECIFICALLY inside an input-container */
.input-container > .icon-btn {
    position: absolute;
    right: 0;
    bottom: 0;
    height: calc(3.1rem + 4px); /* Calculated height matching input */
    width: 3rem;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    z-index: 1;
}

/* Adjust input padding ONLY when its container has a direct child icon button */
.input-container:has(> .icon-btn) input {
    padding-right: 3rem; /* Make space for the button */
}

/* Buttons */
button {
    cursor: pointer;
    font-family: var(--font-family);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.primary-btn, 
.secondary-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1rem;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: #5a9054;
}

.secondary-btn {
    background-color: transparent;
    border: 2px solid var(--absent-color);
    color: var(--absent-color);
}

.secondary-btn:hover {
    background-color: rgba(120, 124, 126, 0.1);
}

/* Share Container */
.share-link-container {
    display: flex;
    align-items: stretch; /* Make input and button same height */
    margin-bottom: 1rem;
}

.share-link-container input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--tile-border-light);
    border-right: none;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    font-size: 1rem;
    line-height: 1.6;
}

body.dark-mode .share-link-container input {
    border-color: var(--tile-border-dark);
    border-right: none;
}

/* Style the copy button specifically using its ID */
#copy-link-btn {
    /* Ensure it stays in the flex flow */
    position: relative; 
    flex-shrink: 0; /* Prevent shrinking */
    /* Styling for appearance */
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
    padding: 0 1rem;
    background-color: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-color);
    border-left: none;
    /* Center the icon */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
}

.social-share {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.social-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    border: none;
}

#share-whatsapp {
    background-color: #25D366;
}

#share-twitter {
    background-color: #1DA1F2;
}

#share-facebook {
    background-color: #4267B2;
}

#share-email {
    background-color: #DB4437;
}

/* Game Board */
#game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    margin-bottom: 2rem;
}

.board-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
}

.tile {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    border: 2px solid var(--tile-border-light);
    border-radius: var(--border-radius);
    transition: transform 0.2s, border-color var(--transition-speed);
}

body.dark-mode .tile {
    border-color: var(--tile-border-dark);
}

.tile.filled {
    border-color: var(--absent-color);
}

.tile.correct {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.tile.present {
    background-color: var(--present-color);
    border-color: var(--present-color);
    color: white;
}

.tile.absent {
    background-color: var(--absent-color);
    border-color: var(--absent-color);
    color: white;
}

.tile.pop {
    transform: scale(1.1);
}

.tile.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0% { transform: translateX(0); }
    10% { transform: translateX(-5px); }
    30% { transform: translateX(5px); }
    50% { transform: translateX(-5px); }
    70% { transform: translateX(5px); }
    90% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}

/* Keyboard */
#keyboard {
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 1rem;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.key {
    height: 58px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--keyboard-light);
    border: none;
    border-radius: var(--border-radius);
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    user-select: none;
    transition: background-color var(--transition-speed);
}

body.dark-mode .key {
    background-color: var(--keyboard-dark);
}

.key-letter {
    flex: 1;
    min-width: 29px;
}

.key-wide {
    flex: 1.5;
    font-size: 0.8rem;
}

.key.correct {
    background-color: var(--correct-color);
    color: white;
}

.key.present {
    background-color: var(--present-color);
    color: white;
}

.key.absent {
    background-color: var(--absent-color);
    color: white;
}

/* Game Message */
#game-message {
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    text-align: center;
    margin-bottom: 1rem;
    animation: fadeIn 0.5s;
}

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

/* Results Container */
#results-grid {
    margin: 1rem 0;
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    max-width: 200px;
    margin: 0 auto 1rem auto;
}

.results-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.results-tile {
    width: 20px;
    height: 20px;
    border-radius: 2px;
}

#time-taken {
    text-align: center;
    margin-bottom: 1rem;
    font-weight: bold;
}

/* Footer */
footer {
    padding: 1rem;
    text-align: center;
    border-top: 1px solid var(--tile-border-light);
    transition: border-color var(--transition-speed);
}

body.dark-mode footer {
    border-color: var(--tile-border-dark);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--background-light);
    color: var(--text-light);
    padding: 2rem;
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

body.dark-mode .modal-content {
    background-color: var(--background-dark);
    color: var(--text-dark);
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.5rem;
    cursor: pointer;
}

.instructions ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.tile-examples {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 1rem;
}

.tile-examples .tile {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
}

/* Custom Message Display */
#custom-message-display {
    background-color: rgba(106, 170, 100, 0.1);
    border-left: 4px solid var(--primary-color);
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: var(--border-radius);
}

/* Responsive Design */
@media (max-width: 480px) {
    .key {
        height: 50px;
    }
    
    .key-letter {
        min-width: 20px;
    }
    
    .tile {
        font-size: 1.5rem;
    }
}

@media (max-width: 350px) {
    .key {
        height: 45px;
        font-size: 0.8rem;
    }
    
    .key-wide {
        font-size: 0.7rem;
    }
}
