.ahx-polylex {
    width: 100%;
    max-width: 440px;
    margin: 24px auto;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: #ffffff;
    font-family: Arial, sans-serif;
    touch-action: manipulation;
}

.ahx-polylex,
.ahx-polylex * {
    box-sizing: border-box;
}

.ahx-polylex__title {
    margin: 0 0 8px;
    text-align: center;
    font-size: 24px;
}

.ahx-polylex__status {
    min-height: 24px;
    margin-bottom: 10px;
    text-align: center;
    font-weight: 600;
}

.ahx-polylex__status-action {
    margin-left: 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f3f4f6;
    padding: 3px 8px;
    cursor: pointer;
    font-weight: 600;
}

.ahx-polylex__language {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    flex: 1;
    min-width: 150px;
}

.ahx-polylex__language-select {
    min-width: 120px;
    padding: 4px 8px;
}

.ahx-polylex__board {
    display: grid;
    width: 100%;
    gap: 6px;
    margin-bottom: 16px;
}

.ahx-polylex__row {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.ahx-polylex__cell {
    --ahx-cell-state-bg: #ffffff;
    --ahx-cell-state-border: #c2cad5;
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 3px solid var(--ahx-cell-state-border);
    border-radius: 8px;
    background: var(--ahx-cell-state-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    text-transform: uppercase;
    user-select: none;
    transform-origin: center;
    backface-visibility: hidden;
}

.ahx-polylex__cell:not([data-state]):not(:empty) {
    font-size: 40px;
}

.ahx-polylex__cell--active {
    border-color: #374151;
    box-shadow: 0 0 0 1px #374151;
    font-size: 40px;
}

.ahx-polylex__cell[data-state="correct"] {
    --ahx-cell-state-bg: #22c55e;
    --ahx-cell-state-border: #4ade80;
    background: #22c55e;
    border-width: 3px;
    border-color: var(--ahx-cell-state-border);
    color: #ffffff;
    font-size: 40px;
}

.ahx-polylex__cell[data-state="present"] {
    --ahx-cell-state-bg: #eab308;
    --ahx-cell-state-border: #facc15;
    background: #eab308;
    border-width: 3px;
    border-color: var(--ahx-cell-state-border);
    color: #ffffff;
    font-size: 40px;
}

.ahx-polylex__cell[data-state="absent"] {
    --ahx-cell-state-bg: #6b7280;
    --ahx-cell-state-border: #9ca3af;
    background: #6b7280;
    border-width: 3px;
    border-color: var(--ahx-cell-state-border);
    color: #ffffff;
    font-size: 40px;
}

.ahx-polylex__cell--flip {
    animation-name: ahx-polylex-reveal-flip;
    animation-duration: 700ms;
    animation-delay: var(--flip-delay, 0ms);
    animation-fill-mode: both;
    animation-timing-function: ease;
}

.ahx-polylex__cell--shake {
    animation: ahx-polylex-invalid-shake 420ms ease;
}

@keyframes ahx-polylex-reveal-flip {
    0% {
        transform: rotateY(0deg);
        background: #ffffff;
        border-color: #c2cad5;
        color: #111827;
    }

    49% {
        transform: rotateY(90deg);
        background: #ffffff;
        border-color: #c2cad5;
        color: #111827;
    }

    50% {
        transform: rotateY(90deg);
        background: var(--ahx-cell-state-bg, #ffffff);
        border-color: var(--ahx-cell-state-border, #c2cad5);
        color: #ffffff;
    }

    100% {
        transform: rotateY(0deg);
        background: var(--ahx-cell-state-bg, #ffffff);
        border-color: var(--ahx-cell-state-border, #c2cad5);
        color: #ffffff;
    }
}

@keyframes ahx-polylex-invalid-shake {
    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(6px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ahx-polylex__cell--flip,
    .ahx-polylex__cell--shake {
        animation: none;
    }
}

.ahx-polylex__keys-row {
    display: flex;
    justify-content: center;
    width: 100%;
    gap: 3px;
}

.ahx-polylex__keyboard {
    display: grid;
    --ahx-key-columns: 10;
    --ahx-key-gap: 3px;
    --ahx-key-width: calc((100% - ((var(--ahx-key-columns) - 1) * var(--ahx-key-gap))) / var(--ahx-key-columns));
    gap: 4px;
    padding: 0 1px;
    width: 100%;
    max-width: 100%;
    overflow-x: visible;
    touch-action: manipulation;
}

.ahx-polylex__stats {
    margin-top: 14px;
}

.ahx-polylex__stats-title,
.ahx-polylex__attempts-title {
    margin: 10px 0 8px;
    font-size: 16px;
}

.ahx-polylex__stats-reset {
    margin-bottom: 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f3f4f6;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: 600;
}

.ahx-polylex__stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.ahx-polylex__stat-card {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px;
    background: #f9fafb;
}

.ahx-polylex__stat-label {
    display: block;
    font-size: 12px;
    color: #4b5563;
}

.ahx-polylex__stat-value {
    display: block;
    margin-top: 4px;
    font-size: 20px;
    font-weight: 700;
}

.ahx-polylex__attempts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ahx-polylex__attempts-table th,
.ahx-polylex__attempts-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 6px 4px;
    text-align: left;
}

.ahx-polylex__attempt-bar-wrap {
    width: 100%;
    min-width: 80px;
    height: 10px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}

.ahx-polylex__attempt-bar {
    height: 100%;
    background: #22c55e;
}

.ahx-polylex__countdown {
    margin-top: 12px;
    padding: 8px;
    border-radius: 8px;
    background: #f3f4f6;
    font-weight: 700;
    text-align: center;
}

.ahx-polylex-view--game .ahx-polylex__stats,
.ahx-polylex-view--game .ahx-polylex__countdown {
    display: none;
}

.ahx-polylex-view--stats .ahx-polylex__status,
.ahx-polylex-view--stats .ahx-polylex__board,
.ahx-polylex-view--stats .ahx-polylex__keyboard {
    display: none;
}

.ahx-polylex-help {
    max-width: 440px;
    margin: 24px auto;
    padding: 18px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #ffffff;
    font-family: Arial, sans-serif;
}

.ahx-polylex-help__title {
    margin: 0 0 10px;
    font-size: 20px;
}

.ahx-polylex-help__intro {
    margin: 0 0 14px;
    line-height: 1.5;
    color: #374151;
}

.ahx-polylex-help__section {
    margin: 0 0 14px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.ahx-polylex-help__section-title {
    margin: 0 0 8px;
    font-size: 16px;
}

.ahx-polylex-help__text {
    margin: 0 0 8px;
    line-height: 1.5;
    color: #374151;
}

.ahx-polylex-help__text:last-child {
    margin-bottom: 0;
}

.ahx-polylex-help__legend-list,
.ahx-polylex-help__tips-list {
    margin: 0;
    padding-left: 18px;
}

.ahx-polylex-help__legend-item,
.ahx-polylex-help__tips-list li {
    margin-bottom: 8px;
}

.ahx-polylex-help__tips-list li:last-child {
    margin-bottom: 0;
}

.ahx-polylex-help__swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 6px;
    border-radius: 2px;
    vertical-align: -1px;
}

.ahx-polylex-help__swatch--correct {
    background: #22c55e;
}

.ahx-polylex-help__swatch--present {
    background: #eab308;
}

.ahx-polylex-help__swatch--absent {
    background: #6b7280;
}

.ahx-polylex-help__legend-label {
    font-weight: 700;
}

.ahx-polylex__key {
    flex: 0 0 var(--ahx-key-width);
    width: var(--ahx-key-width);
    min-width: var(--ahx-key-width);
    height: 46px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: #d1d5db;
    color: #000000;
    -webkit-text-fill-color: #000000;
    -webkit-appearance: none;
    appearance: none;
    font-weight: 400;
    font-size: 24px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.ahx-polylex__key--wide {
    flex-basis: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
    width: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
    min-width: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
}

.ahx-polylex__key[data-state="correct"] {
    background: #22c55e;
    border-color: #22c55e;
    color: #000000;
    -webkit-text-fill-color: #000000;
}

.ahx-polylex__key[data-state="present"] {
    background: #eab308;
    border-color: #eab308;
    color: #000000;
    -webkit-text-fill-color: #000000;
}

.ahx-polylex__key[data-state="absent"] {
    background: #6b7280;
    border-color: #6b7280;
    color: #000000;
    -webkit-text-fill-color: #000000;
}

@media (max-width: 520px) {
    .ahx-polylex {
        max-width: 100%;
        margin: 16px auto;
        padding: 0;
        border-radius: 8px;
    }

    .ahx-polylex__title {
        font-size: 20px;
    }

    .ahx-polylex__status {
        min-height: 20px;
        margin-bottom: 8px;
        font-size: 14px;
    }

    .ahx-polylex__language {
        margin-bottom: 8px;
        font-size: 14px;
    }

    .ahx-polylex__stats-grid {
        grid-template-columns: 1fr;
    }

    .ahx-polylex__stat-value {
        font-size: 18px;
    }

    .ahx-polylex__attempts-table {
        font-size: 12px;
    }

    .ahx-polylex__board,
    .ahx-polylex__row {
        gap: 4px;
    }

    .ahx-polylex__keyboard {
        --ahx-key-gap: 1px;
        --ahx-key-width: calc((100% - ((var(--ahx-key-columns) - 1) * var(--ahx-key-gap))) / var(--ahx-key-columns));
        gap: 2px;
        padding: 0 1px;
        width: calc(100% - 12px);
        max-width: calc(100% - 12px);
        margin: 0 auto;
        overflow-x: visible;
    }

    .ahx-polylex__cell {
        font-size: 20px;
    }

    .ahx-polylex__key {
        height: 40px;
        font-size: 18px;
    }

    .ahx-polylex__key--wide {
        flex-basis: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
        width: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
        min-width: calc(var(--ahx-key-width) + (var(--ahx-key-width) / 2) + (var(--ahx-key-gap) / 2));
    }

    .ahx-polylex__keys-row {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 430px) {
    .ahx-polylex__keyboard {
        --ahx-key-gap: 1px;
        gap: 2px;
        padding: 0 1px;
        width: calc(100% - 18px);
        max-width: calc(100% - 18px);
        margin: 0 auto;
    }
}

/* Report button and modal styles */
.ahx-polylex__footer {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    margin-top: 12px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.ahx-polylex--post-game-stats .ahx-polylex__footer {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    padding: 10px 8px;
    overflow-x: auto;
}

.ahx-polylex--post-game-stats .ahx-polylex__language {
    flex: 0 1 auto;
    min-width: max-content;
    gap: 6px;
    font-size: 12px;
}

.ahx-polylex--post-game-stats .ahx-polylex__language label {
    white-space: nowrap;
}

.ahx-polylex--post-game-stats .ahx-polylex__language-select {
    min-width: 96px;
    padding: 3px 6px;
    font-size: 12px;
}

.ahx-polylex__report-button,
.ahx-polylex__stats-reset-footer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    white-space: nowrap;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.ahx-polylex--post-game-stats .ahx-polylex__report-button,
.ahx-polylex--post-game-stats .ahx-polylex__stats-reset-footer {
    padding: 4px 8px;
    font-size: 12px;
}

.ahx-polylex__report-button:hover,
.ahx-polylex__stats-reset-footer:hover {
    background: #e5e7eb;
}

.ahx-polylex__report-button:active,
.ahx-polylex__stats-reset-footer:active {
    background: #d1d5db;
}

.ahx-polylex-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.ahx-polylex-modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.ahx-polylex-modal {
    background: white;
    border-radius: 10px;
    padding: 20px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.95);
    transition: transform 0.2s ease;
    position: relative;
}

.ahx-polylex-modal-overlay.show .ahx-polylex-modal {
    transform: scale(1);
}

.ahx-polylex-modal__title {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.ahx-polylex-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #6b7280;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ahx-polylex-modal__close:hover {
    color: #111827;
}

.ahx-polylex-modal__reason-group {
    margin-bottom: 12px;
}

.ahx-polylex-modal__reason-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.ahx-polylex-modal__reason-label:hover {
    background-color: #f9fafb;
}

.ahx-polylex-modal__reason-label input[type="radio"] {
    cursor: pointer;
}

.ahx-polylex-modal__reason-text {
    margin: 0;
    color: #374151;
    font-size: 14px;
}

.ahx-polylex-modal__actions {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

.ahx-polylex-modal__button {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.ahx-polylex-modal__button--primary {
    background: #2563eb;
    color: white;
}

.ahx-polylex-modal__button--primary:hover {
    background: #1d4ed8;
}

.ahx-polylex-modal__button--secondary {
    background: #e5e7eb;
    color: #374151;
}

.ahx-polylex-modal__button--secondary:hover {
    background: #d1d5db;
}

