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

:root {
    --color-tone-1: #000000;
    --color-tone-2: #787c7e;
    --color-tone-3: #d3d6da;
    --color-tone-4: #edeff1;
    --color-tone-5: #ffffff;
    --color-success: #6aaa64;
    --color-warning: #c9b458;
    --color-error: #787c7e;
    --border-color: #d3d6da;
}

body {
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-tone-5);
    color: var(--color-tone-1);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
}

.container {
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--color-tone-1);
    margin: 0;
    text-align: center;
}

.centered-buttons-row {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-top: 10px;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 24px;
    font-weight: 700;
    color: var(--color-tone-1);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.1s ease;
}

.icon-btn:hover {
    background: var(--color-tone-4);
}

main {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding: 20px;
    max-width: 100%;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
    width: 100%;
}

.secret-code-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: var(--color-tone-4);
    border-radius: 20px;
    width: fit-content;
}

.secret-code {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.secret-peg {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--color-tone-3);
    background: var(--color-tone-5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--color-tone-2);
    transition: all 0.3s ease;
    min-width: 40px; /* Minimum width to prevent squishing */
    min-height: 40px; /* Minimum height to prevent squishing */
}

/* Responsive adjustments for different numbers of slots */
.secret-code.slots-6 .secret-peg,
.secret-code.slots-7 .secret-peg,
.secret-code.slots-8 .secret-peg {
    width: 40px;
    height: 40px;
    font-size: 18px;
}

.secret-code.slots-7 .secret-peg,
.secret-code.slots-8 .secret-peg {
    width: 36px;
    height: 36px;
    font-size: 16px;
}

.secret-code.slots-8 .secret-peg {
    width: 32px;
    height: 32px;
    font-size: 14px;
}

.secret-peg.hidden {
    background: var(--color-tone-5);
}

.secret-peg.revealed {
    animation: revealPeg 0.5s ease-out;
}

@keyframes revealPeg {
    0% {
        transform: scale(0.8) rotate(0deg);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
        opacity: 1;
    }
}

.moves-counter {
    font-size: 14px;
    color: var(--color-tone-1);
    font-weight: 600;
    letter-spacing: 0.5px;
}

#movesCount {
    color: var(--color-tone-1);
    font-size: 18px;
    font-weight: 700;
}

.game-board {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 80px;
    width: 100%;
    max-width: 100vw; /* Allow to use full viewport width */
    overflow-x: auto; /* Allow horizontal scrolling if needed */
    padding: 4px 0; /* Add some padding */
}

.guess-row {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 0;
    animation: slideDown 0.3s ease-out;
    transform-origin: top;
    position: relative;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.guess-row.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: var(--color-tone-1);
    border-radius: 2px;
}

.guess-colors {
    display: flex;
    gap: 8px;
    min-width: 340px;
    justify-content: center;
}

.guess-peg {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--color-tone-3);
    background: var(--color-tone-5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 40px; /* Minimum width to prevent squishing */
    min-height: 40px; /* Minimum height to prevent squishing */
}

/* Responsive adjustments for different numbers of slots */
.guess-row .guess-colors {
    min-width: auto; /* Allow it to be smaller when needed */
}

.guess-row.slots-6 .guess-peg,
.guess-row.slots-7 .guess-peg,
.guess-row.slots-8 .guess-peg {
    width: 40px;
    height: 40px;
    font-size: 18px;
}

.guess-row.slots-7 .guess-peg,
.guess-row.slots-8 .guess-peg {
    width: 36px;
    height: 36px;
    font-size: 16px;
}

.guess-row.slots-8 .guess-peg {
    width: 32px;
    height: 32px;
    font-size: 14px;
}

.guess-peg:hover {
    border-color: var(--color-tone-2);
    transform: scale(1.05);
}

.guess-peg.filled {
    border-color: transparent;
}

.guess-peg.active-slot {
    border-color: var(--color-tone-1);
    border-width: 3px;
}

.feedback {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    width: 24px;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

/* Adjust feedback position for more slots to prevent overlap */
.guess-row.slots-6 .feedback {
    right: 10px; /* Slightly more space */
}

.guess-row.slots-7 .feedback {
    right: 8px; /* More space for 7 slots */
}

.guess-row.slots-8 .feedback {
    right: 6px; /* More space for 8 slots */
}

.feedback-peg {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-error);
}

.color-palette {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: var(--color-tone-4);
    border-radius: 12px;
    width: fit-content;
}

.color-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.15s ease;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: var(--color-tone-1);
}

.color-option.selected {
    border-color: var(--color-tone-1);
    box-shadow: 0 0 0 2px var(--color-tone-5), 0 0 0 4px var(--color-tone-1);
}

.btn-submit {
    padding: 14px 48px;
    border: none;
    background: var(--color-tone-1);
    color: var(--color-tone-5);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: block;
    margin: 20px auto 0 auto; /* Center the button horizontally */
}

.btn-submit:hover:not(:disabled) {
    background: var(--color-tone-2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-submit:disabled {
    background: var(--color-tone-3);
    color: var(--color-tone-5);
    cursor: not-allowed;
    opacity: 0.5;
}

.message {
    text-align: center;
    margin-top: 20px;
    padding: 12px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 14px;
}

.message.success {
    background: var(--color-success);
    color: var(--color-tone-5);
}

.message.error {
    background: var(--color-error);
    color: var(--color-tone-5);
}

.message.info {
    background: var(--color-tone-4);
    color: var(--color-tone-1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
}

.modal-content {
    background-color: var(--color-tone-5);
    margin: 60px auto;
    padding: 32px;
    width: 90%;
    max-width: 500px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.close {
    color: var(--color-tone-2);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--color-tone-1);
}

.instructions h2 {
    margin-bottom: 16px;
    font-size: 20px;
}

.instructions h3 {
    margin-top: 20px;
    margin-bottom: 8px;
    font-size: 16px;
}

.instructions p {
    line-height: 1.6;
    color: var(--color-tone-1);
    margin-bottom: 16px;
}

.instructions ul {
    margin-left: 20px;
    color: var(--color-tone-1);
    line-height: 1.8;
}

.instructions li {
    margin-bottom: 8px;
}

kbd {
    background: var(--color-tone-4);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    border: 1px solid var(--border-color);
}

.feedback-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

/* Settings Form */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 20px;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-row label {
    font-weight: 600;
    color: var(--color-tone-1);
}

.setting-row input {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 16px;
    width: 100%;
    max-width: 200px;
}

.setting-row input:focus {
    outline: none;
    border-color: var(--color-tone-1);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

#applySettings {
    padding: 12px 24px;
    background: var(--color-tone-1);
    color: var(--color-tone-5);
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-start;
    margin-top: 10px;
    transition: background-color 0.15s ease;
}

#applySettings:hover {
    background: var(--color-tone-2);
}

@media (max-width: 600px) {
    h1 {
        font-size: 24px; /* Smaller font size on mobile */
        padding-right: 50px; /* Adjust padding for smaller screens */
        padding-left: 50px;
    }

    .header-buttons {
        right: 10px; /* Move buttons closer to the edge on mobile */
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .guess-slot {
        width: 52px;
        height: 52px;
    }

    .guess-peg {
        width: 38px;
        height: 38px;
    }

    .color-option {
        width: 36px;
        height: 36px;
    }

    main {
        padding: 16px;
    }
}

/* Screen reader only class for accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* SEO content styling - make content visible to search engines but hidden for users */
.seo-content {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    /* This hides the content visually but keeps it accessible to screen readers and search engines */
}

/* No additional styling needed since the content is visually hidden */

/* Performance optimizations */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Mobile responsiveness improvements */
@media (max-width: 600px) {
    .container {
        max-width: 100%;
        padding: 0;
    }

    h1 {
        font-size: 24px; /* Smaller font size on mobile */
        padding: 0 20px; /* Adjust padding for smaller screens */
    }

    .centered-buttons-row {
        padding: 0 10px;
    }

    .header-buttons {
        gap: 6px; /* Reduce gap between buttons */
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    main {
        padding: 16px 12px;
    }

    .secret-code-container {
        padding: 16px;
        margin: 0 10px;
    }

    .secret-peg {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .guess-peg {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .guess-row.slots-6 .guess-peg,
    .guess-row.slots-7 .guess-peg,
    .guess-row.slots-8 .guess-peg {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .color-palette {
        padding: 12px;
        margin: 0 10px;
        gap: 8px;
    }

    .color-option {
        width: 36px;
        height: 36px;
    }

    .btn-submit {
        padding: 12px 32px;
        font-size: 15px;
        margin: 16px auto 0 auto;
    }

    .modal-content {
        margin: 40px auto;
        padding: 24px;
        width: 95%;
        max-width: 480px;
    }

    .instructions h2 {
        font-size: 18px;
    }

    .instructions h3 {
        font-size: 15px;
    }

    .seo-content {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* Extra small screens - when the collision is most likely to happen */
@media (max-width: 400px) {
    h1 {
        font-size: 20px; /* Even smaller font on very small screens */
        padding: 0 15px;
    }

    .header-buttons {
        gap: 4px; /* Reduce gap between buttons */
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .secret-peg {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .guess-peg {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .color-option {
        width: 32px;
        height: 32px;
    }

    .modal-content {
        margin: 30px auto;
        padding: 20px;
        width: 98%;
    }

    .seo-content {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* Performance optimizations for animations */
.guess-peg,
.icon-btn,
.color-option {
    will-change: transform;
}

@supports (backdrop-filter: blur(10px)) {
    .modal {
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(10px);
    }
}
