.sv-matchmaker {
    /* Centrale toolkit-tokens uit schoolvoetbal-core; hex-fallback als core niet actief is. */
    --sv-blue: var(--sv-color-primary, #003D7C);
    --sv-blue-soft: var(--sv-color-primary-light, #DEF1FB);
    --sv-green: var(--sv-color-accent, #6CBE57);
    --sv-green-dark: var(--sv-color-accent-dark, #5BA249);
    --sv-red: var(--sv-color-error, #c0392b);
    --sv-red-soft: var(--sv-color-error-light, #fadbd8);
    --sv-card-bg: #ffffff;
    --sv-card-border: #e6ebef;
    --sv-card-border-hover: #bdc3c7;
    --sv-radius: var(--sv-radius-lg, 12px);
    /* Niet doorverwijzen: zelfde naam als core-token zou een self-reference cycle geven. */
    --sv-shadow-sm: 0 2px 8px rgba(0, 61, 124, 0.06);
    --sv-shadow-md: 0 4px 12px rgba(0, 61, 124, 0.10);

    font-family: inherit;
    background-color: transparent;
    margin: 0;
    padding: 10px;
    color: inherit;
    position: relative;
}

.sv-matchmaker,
.sv-matchmaker * {
    box-sizing: border-box !important;
}

/* ===== HUD: timer, moves, progress, hint ===== */
.sv-matchmaker .sv-hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 10px 14px;
    align-items: center;
    background: #fff;
    border: 1px solid var(--sv-card-border);
    border-radius: var(--sv-radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    box-shadow: var(--sv-shadow-sm);
}

.sv-matchmaker .sv-hud-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.1;
}

.sv-matchmaker .sv-hud-label {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #7a8794;
    font-weight: 600;
}

.sv-matchmaker .sv-hud-value {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--sv-blue);
    font-variant-numeric: tabular-nums;
}

.sv-matchmaker .sv-hud-value.sv-best {
    font-size: 0.9em;
    color: #7a8794;
    font-weight: 600;
}

.sv-matchmaker .sv-hud-timer.sv-penalty-flash {
    animation: sv-penalty-flash 0.65s ease-out;
}

.sv-matchmaker .sv-hint-btn {
    grid-column: 4;
    grid-row: 1 / span 2;
    align-self: center;
    background: var(--sv-blue);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sv-matchmaker .sv-hint-btn:hover:not(:disabled) {
    background: #002952;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 61, 124, 0.25);
}

.sv-matchmaker .sv-hint-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sv-matchmaker .sv-progress-bar {
    grid-column: 1 / -1;
    height: 6px;
    background: #eef3f7;
    border-radius: 999px;
    overflow: hidden;
}

.sv-matchmaker .sv-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--sv-green), #8DD978);
    border-radius: 999px;
    transition: width 0.4s ease;
}

/* ===== Start overlay ===== */
.sv-matchmaker .sv-start-overlay {
    display: none;
    justify-content: center;
    padding: 10px 0 14px;
}

.sv-matchmaker .sv-start-overlay.sv-active {
    display: flex;
}

/* Blur + dim the play area while the game has not started yet */
.sv-matchmaker:has(.sv-start-overlay.sv-active) .sv-game-container,
.sv-matchmaker:has(.sv-start-overlay.sv-active) .sv-matched-area {
    filter: blur(4px);
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

/* ===== End banner (inline, replaces overlay) ===== */
.sv-matchmaker .sv-end-banner {
    display: none;
    background: linear-gradient(135deg, var(--sv-green), var(--sv-green-dark));
    color: #fff;
    border-radius: var(--sv-radius);
    padding: 18px 20px;
    margin-bottom: 12px;
    text-align: center;
    box-shadow: var(--sv-shadow-md);
    animation: sv-pop-in 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.sv-matchmaker .sv-end-banner.sv-active { display: block; }

.sv-matchmaker .sv-end-banner h2 {
    margin: 0 0 4px;
    font-size: 2em;
    letter-spacing: 0.02em;
}

.sv-matchmaker .sv-end-stats {
    font-size: 1em;
    margin-bottom: 12px;
    opacity: 0.95;
}

.sv-matchmaker .sv-end-stats strong { font-weight: 700; }

.sv-matchmaker .sv-end-banner .sv-btn {
    background: #fff;
    color: var(--sv-green-dark);
    font-weight: 700;
}

.sv-matchmaker .sv-end-banner .sv-btn:hover { background: #f3f3f3; }

/* ===== Matched strip ===== */
.sv-matchmaker .sv-matched-area {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-height: 44px;
    padding: 8px 10px;
    margin-bottom: 14px;
    background-color: #fff;
    border: 1px solid var(--sv-card-border);
    border-radius: var(--sv-radius);
}

.sv-matchmaker .sv-placeholder {
    color: #94a3b1;
    font-style: italic;
    font-size: 0.9em;
    align-self: center;
}

.sv-matchmaker .sv-matched-pair {
    display: inline-flex;
    align-items: center;
    background: #e8f8f5;
    border: 1px solid #2ecc71;
    border-radius: 999px;
    padding: 3px 10px 3px 4px;
    gap: 8px;
    animation: sv-slide-up 0.4s ease-out;
    height: 36px;
}

.sv-matchmaker .sv-matched-pair .sv-shirt-visual {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}

.sv-matchmaker .sv-matched-pair img {
    max-height: 26px;
    max-width: 90px;
    object-fit: contain;
}

.sv-matchmaker .sv-matched-pair .sv-school-name-text {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--sv-blue);
    white-space: nowrap;
}

/* ===== Game grids ===== */
.sv-matchmaker .sv-game-container {
    display: flex;
    flex-direction: row;
    gap: 12px;
    max-width: 1100px;
    margin: 0 auto;
}

.sv-matchmaker .sv-game-container > .sv-column {
    flex: 1;
    min-width: 0;
}

.sv-matchmaker .sv-column {
    background-color: var(--sv-blue-soft);
    padding: 12px;
    border-radius: var(--sv-radius);
    box-shadow: var(--sv-shadow-sm);
}

.sv-matchmaker .sv-col-title {
    font-weight: bold;
    text-transform: uppercase;
    color: var(--sv-blue);
    font-size: 0.75em;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    padding: 0 4px;
}

/* Shirts grid: square cells. Default sized for 1024px container (~480px column). */
.sv-matchmaker .sv-shirt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 10px;
}

/* Schools grid: landscape cells (3:2). Default sized for 1024px container. */
.sv-matchmaker .sv-school-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

/* ===== Cards ===== */
.sv-matchmaker .sv-card {
    background: var(--sv-card-bg);
    border: 2px solid var(--sv-card-border);
    border-radius: 10px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, border-color 0.2s, background-color 0.2s, box-shadow 0.2s, opacity 0.25s;
    box-shadow: var(--sv-shadow-sm);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    position: relative;
    overflow: hidden;
}

.sv-matchmaker .sv-card:active { cursor: grabbing; }

.sv-matchmaker .sv-card-shirt {
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    padding: 6px;
}

.sv-matchmaker .sv-card-school {
    aspect-ratio: 3 / 2;
    padding: 8px 10px;
}

.sv-matchmaker .sv-school-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
}

.sv-matchmaker .sv-school-name-text {
    font-weight: 600;
    color: var(--sv-blue);
    text-align: center;
    font-size: 0.95em;
    line-height: 1.2;
    pointer-events: none;
}

.sv-matchmaker .sv-shirt-visual {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

/* States */
.sv-matchmaker .sv-card:hover {
    border-color: var(--sv-card-border-hover);
    transform: translateY(-2px);
    box-shadow: var(--sv-shadow-md);
}

.sv-matchmaker .sv-card.sv-selected {
    border-color: var(--sv-blue);
    background-color: var(--sv-blue-soft);
    transform: scale(1.03);
    box-shadow: 0 0 0 3px rgba(0, 61, 124, 0.25);
}

.sv-matchmaker .sv-card.sv-drop-target {
    border-color: var(--sv-green);
    background-color: #eafaf1;
    transform: scale(1.05);
    box-shadow: 0 0 0 3px rgba(108, 190, 87, 0.4);
}

.sv-matchmaker .sv-card.sv-dragging {
    opacity: 0.4;
}

.sv-matchmaker .sv-card.sv-hint {
    animation: sv-hint-pulse 1.2s ease-in-out 2;
}

.sv-matchmaker .sv-card.sv-match-success {
    animation: sv-match-pop 0.45s ease-out;
}

.sv-matchmaker .sv-card.sv-match-error {
    animation: sv-shake 0.45s;
    border-color: var(--sv-red) !important;
    background-color: var(--sv-red-soft) !important;
}

.sv-matchmaker .sv-card.sv-card-removed {
    opacity: 0;
    transform: scale(0.6);
    pointer-events: none;
}

/* Drag ghost: a clone we move with the pointer */
.sv-matchmaker .sv-drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.92;
    transform: translate(-50%, -50%) scale(1.05);
    box-shadow: 0 12px 24px rgba(0, 61, 124, 0.25);
    border-radius: 10px;
    transition: none;
}

/* ===== Inline confetti burst ===== */
.sv-matchmaker .sv-burst {
    position: absolute;
    pointer-events: none;
    z-index: 5;
    width: 0;
    height: 0;
}

.sv-matchmaker .sv-burst-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: sv-burst-out 0.8s ease-out forwards;
}

/* End-game confetti rains over game area */
.sv-matchmaker .sv-confetti-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 4;
}

.sv-matchmaker .sv-confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    border-radius: 2px;
}

/* ===== Buttons ===== */

.sv-matchmaker .sv-btn {
    padding: 10px 22px;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.sv-matchmaker .sv-btn:hover { transform: translateY(-1px); }

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

.sv-matchmaker .sv-btn-primary:hover {
    background-color: var(--sv-green-dark);
    box-shadow: 0 4px 10px rgba(108, 190, 87, 0.3);
}

/* Focus ring: only visible during keyboard navigation, not on mouse click */
.sv-matchmaker .sv-hint-btn:focus-visible,
.sv-matchmaker .sv-btn:focus-visible {
    outline: 2px solid var(--sv-green);
    outline-offset: 2px;
}

/* ===== Animations ===== */
@keyframes sv-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes sv-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-4px); }
}

@keyframes sv-penalty-flash {
    0%   { color: var(--sv-red); transform: scale(1.25); }
    60%  { color: var(--sv-red); transform: scale(1.1); }
    100% { color: var(--sv-blue); transform: scale(1); }
}

@keyframes sv-pop-in {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes sv-match-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(108, 190, 87, 0.5); }
    100% { transform: scale(1); }
}

@keyframes sv-hint-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
    50% { box-shadow: 0 0 0 6px rgba(255, 193, 7, 0.6); border-color: #ffc107; }
}

@keyframes sv-fall {
    0% { transform: translateY(-10%) rotate(0deg); opacity: 1; }
    100% { transform: translateY(120%) rotate(720deg); opacity: 0.6; }
}

@keyframes sv-burst-out {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% {
        transform: translate(var(--sv-burst-x, 0), var(--sv-burst-y, 0)) scale(0.4);
        opacity: 0;
    }
}

/* ===== Responsive ===== */
/* Mid-size: tablet / small desktop — slightly tighter cells */
@media (max-width: 900px) {
    .sv-matchmaker .sv-shirt-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
    .sv-matchmaker .sv-school-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
}

/* Large phone / small tablet: still 2 columns side-by-side, smaller cells */
@media (max-width: 640px) {
    .sv-matchmaker .sv-shirt-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
    .sv-matchmaker .sv-school-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
    .sv-matchmaker .sv-game-container { gap: 8px; }
    .sv-matchmaker .sv-column { padding: 10px; }
}

/* Phones: stack the two grids and tighten HUD */
@media (max-width: 480px) {
    .sv-matchmaker { padding-left: 0; padding-right: 0; }
    .sv-matchmaker .sv-game-container { flex-direction: column; }
    .sv-matchmaker .sv-hud {
        grid-template-columns: repeat(3, 1fr);
        padding: 10px;
    }
    .sv-matchmaker .sv-hint-btn {
        grid-column: 1 / -1;
        grid-row: auto;
        justify-content: center;
        padding: 8px;
    }
    .sv-matchmaker .sv-hud-value { font-size: 1.1em; }
    .sv-matchmaker .sv-shirt-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
    .sv-matchmaker .sv-school-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .sv-matchmaker .sv-end-banner h2 { font-size: 1.5em; }
}

@media (prefers-reduced-motion: reduce) {
    .sv-matchmaker *, .sv-matchmaker *::before, .sv-matchmaker *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .sv-matchmaker .sv-confetti,
    .sv-matchmaker .sv-burst { display: none !important; }
}
