/* CSS for Matching Game */

.gamesxblock-matching {
    font-family: 'Inter', sans-serif;
    padding: 24px;
    background: var(--white, #FFFFFF);
    border-radius: 8px;
    box-shadow: 0 20px 40px 0 rgba(0, 0, 0, 0.08), 0 8px 48px 0 rgba(0, 0, 0, 0.08);
    display: flex;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    flex-direction: column;
    gap: 24px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Ensure all descendants inherit border-box to avoid external CSS overrides */
.gamesxblock-matching *,
.gamesxblock-matching *::before,
.gamesxblock-matching *::after {
    box-sizing: inherit;
}

.matching-start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    min-height: 400px;
}

.matching-start-title {
    color: var(--primary-500, #00262B);
    text-align: center;
    font-family: Inter;
    font-size: 20px;
    font-style: normal;
    font-weight: 500;
}
.matching-end-screen {
    display: none;
    gap: 32px;
    min-height: 530px;
    position: relative;
    overflow: hidden;
}
.matching-end-screen.active {
    display: flex;
}
.matching-end-screen-content {
    position: relative;
    z-index: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    width: 100%;
}
.matching-end-screen-content > * {
    flex: 0 0 auto; /* prevent children from stretching or squeezing */
    margin: 0;      /* normalize margins to rely on flex gap */
}
.matching-end-title {
    color: var(--primary-500, #00262B);
    text-align: center;
    font-size: 32px;
    font-style: normal;
    font-weight: 700;
    margin-bottom: 32px;
}

.matching-new-best, .matching-prev-best, .matching-non-timer {
    text-align: center;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.matching-new-best.active, .matching-prev-best.active, .matching-non-timer.active {
    display: flex;
}

.matching-new-end-title {
    color: var(--primary-500, #00262B);
    text-align: center;
    font-variant-numeric: lining-nums proportional-nums;
    font-size: 88px;
    font-style: normal;
    font-weight: 600;
    margin-bottom: 32px;
    height: 77px;
}

.matching-new-end-subtitle {
    color: var(--primary-500, #00262B);
    text-align: center;
    font-size: 28px;
    font-style: normal;
    font-weight: 700;
    margin-bottom: 32px;
}

.matching-new-prev-best {
    color: var(--primary-500, #00262B);
    font-size: 18px;
    font-style: normal;
    font-weight: 600;
    border-radius: 8px;
    background: rgba(246, 246, 246);
    padding: 16px;
    text-align: center;
    display: none;
}
.matching-new-prev-best.active {
    display: block;
}

.matching-prev-best-subtitle, .matching-non-timer-subtitle {
    color: var(--primary-500, #00262B);
    text-align: center;
    font-size: 22px;
    font-style: normal;
    font-weight: 500;
    margin-bottom: 32px;
    line-height: 28px;
}
.matching-prev-best-subtitle span {
    color: var(--primary-500, #00262B);
    font-size: 22px;
    font-style: normal;
    font-weight: 700;
}

.matching-prev-best-time {
    display: flex;
    padding: 19px 24px;
    justify-content: center;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    background: rgba(251, 245, 208);
    color: var(--extras-black, #000);
    text-align: center;
    font-size: 22px;
    font-style: normal;
    font-weight: 700;
}

.matching-end-button, .matching-start-button {
    display: inline-flex;
    padding: 10px 16px;
    justify-content: center;
    gap: 8px;
    align-items: center;
    background: var(--primary-500, #00262B);
    color: var(--white, #FFFFFF);
    font-size: 18px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

.matching-start-button:hover:not(:disabled) {
    background: var(--primary-600, #001A1D);
}

.matching-start-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.matching-loading-spinner {
    display: none;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
}
.matching-loading-spinner.active {
    display: flex;
}

.matching-loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--light-400, #E1DDDB);
    border-top-color: var(--primary-500, #00262B);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.matching-header {
    justify-content: flex-start;
    align-items: center;
}

.matching-title {
    color: var(--primary-500, #00262B);
    font-size: 22px;
    font-weight: 700;
    margin: 0;
}

.matching-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
    min-height: 48px;
}

.matching-timer {
    color: var(--primary-500, #00262B);
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -1.96px;
    text-align: center;
    flex: 1;
}

.matching-progress-wrapper {
    position: relative;
    width: 55px;
    height: 55px;
}

.matching-progress-circle {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.matching-progress-bg {
    fill: none;
    stroke: var(--light-400, #E1DDDB);
    stroke-width: 4px;
}

.matching-progress-bar {
    fill: none;
    stroke: var(--success-500, #0D7D4D);
    stroke-width: 4px;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 339.292;
    transition: stroke-dashoffset 0.3s ease;
    stroke-linecap: round;
}

.matching-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--Primary-500, #00262B);
    text-align: center;
    font-variant-numeric: lining-nums tabular-nums;
    font-family: Inter;
    font-size: 17px;
    font-style: normal;
    font-weight: 500;
    letter-spacing: -1.19px;
}

.matching-help-wrapper {
    position: relative;
}

.matching-help-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-500, #00262B);
    cursor: pointer;
    transition: color 0.2s ease;
}

.matching-help-icon:hover {
    color: var(--primary-700, #00171A);
}

.matching-grid {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
}

.matching-grid.active {
    display: grid;
}

.matching-column {
    display: flex;
    flex-direction: column;
}

.matching-box-wrapper {
    width: 100%;
    margin-bottom: 8px;
    height: 85px;
}

.matching-box {
    display: block;
    height: 85px;
    padding: 16px;
    overflow: auto;
    border-radius: 8px;
    border: 2px solid var(--light-300, #F2F0EF);
    background: var(--white, #FFFFFF);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.matching-box:hover {
    border-color: var(--light-500, #E1DDDB);
    background: var(--light-100, #FAFAFA);
}

.matching-box.selected {
    border-color: var(--primary-500, #00262B);
    background: var(--light-200, #F8F8F8);
}

.matching-box.matched {
    border-color: var(--success-500, #0D7D4D);
    background: var(--success-100, #F2FAF7);
    opacity: 0.6;
    pointer-events: none;
}

.matching-box.incorrect {
    animation: shake 0.4s ease;
    border-color: var(--danger-700, #AB0D02);
    background: var(--danger-100, #FCF1F4);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.matching-box-text {
    color: var(--primary-500, #00262B);
    font-size: 14px;
    font-weight: normal;
    display: inline-block;
    vertical-align: middle;
    text-align: center;
    width: 100%;
}

.matching-footer {
    display: none;
    justify-content: space-between;
    align-items: center;
    align-self: stretch;
    margin-top: 24px;
}

.matching-footer.active {
    display: flex;
}


.help-popover {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    border-radius: 4px;
    background: var(--Core-Elm, #00262B);
    color: #fff;
    padding: 4px 8px;
    min-width: 200px;
    max-width: 280px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
    z-index: 1000;
    pointer-events: none;
}
.help-popover-content {
    color: var(--extras-white, #FFF);
    text-align: center;
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
    line-height: 20px;
}
.help-popover-arrow {
    position: absolute;
    top: 100%;
    right: 12px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--primary-500, #00262B);
}
.matching-help-wrapper:hover .help-popover {
    opacity: 1;
    visibility: visible;
}
