/*
 * Fridolins Memory – Harzer Baumkuchen
 * ==================================================
 * Farben aus dem Gestaltungsraster; nutzt die Theme-Variablen (--hb-*), falls vorhanden.
 * Schriften erben vom Theme (Fraunces für Überschriften, Source Sans 3 für Text).
 */

.hb-memory {
    --hb-m-accent: var(--hb-accent, #f3c41b);
    --hb-m-rot: var(--hb-rot, #9b1c20);
    --hb-m-sand: var(--hb-sand, #e7d9c6);
    --hb-m-creme: var(--hb-creme, #faf5ec);
    --hb-m-braun: var(--hb-konturbraun, #2b1b12);
    --hb-m-gruen: #2f7a3b;
    --hb-m-weiss: #fff;
    --hb-m-grau: #7d6e5c;
    --hb-memory-cols: 4;

    position: relative;
    color: var(--hb-m-braun);
}

.hb-memory *,
.hb-memory *::before,
.hb-memory *::after {
    box-sizing: border-box;
}

.hb-memory [hidden] {
    display: none !important;
}

/* Kopf: Titel + Statuszeile */
.hb-memory__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    margin-bottom: 1.25rem;
}

.hb-memory__title {
    margin: 0;
}

.hb-memory__stats {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.25rem;
    font-size: 1rem;
}

.hb-memory__stat {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.hb-memory__value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Buttons */
.hb-memory__button {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.625rem 1.5rem;
    border: 2px solid var(--hb-m-rot);
    background: var(--hb-m-rot);
    color: var(--hb-m-weiss);
    font: inherit;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.hb-memory__button:hover,
.hb-memory__button:focus-visible {
    background: var(--hb-m-braun);
    border-color: var(--hb-m-braun);
    color: var(--hb-m-weiss);
}

.hb-memory__button:focus-visible,
.hb-memory__card:focus-visible,
.hb-memory__sound:focus-visible {
    outline: 3px solid var(--hb-m-accent);
    outline-offset: 2px;
}

.hb-memory__button--outline {
    background: transparent;
    color: var(--hb-m-braun);
    border-color: var(--hb-m-braun);
}

.hb-memory__button--small {
    padding: 0.125rem 0.625rem;
    font-size: 0.8125rem;
    background: transparent;
    color: var(--hb-m-rot);
    border-width: 1px;
}

.hb-memory__button--level {
    min-width: 11rem;
    padding: 0.875rem 1.5rem;
}

.hb-memory__button--level strong {
    font-size: 1.125rem;
}

.hb-memory__button--level span {
    font-size: 0.875rem;
    font-weight: 400;
    opacity: 0.9;
}

/* Ton an/aus */
.hb-memory__sound {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--hb-m-sand);
    border-radius: 50%;
    background: var(--hb-m-weiss);
    color: var(--hb-m-braun);
    cursor: pointer;
}

.hb-memory__sound svg {
    width: 1.375rem;
    height: 1.375rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hb-memory__sound svg path:first-child {
    fill: currentColor;
}

.hb-memory__sound[aria-pressed="true"] {
    color: var(--hb-m-grau);
}

/* Bühne: Startbildschirm, Spielfeld, Gewinn-Fenster */
.hb-memory__stage {
    position: relative;
}

.hb-memory__panel {
    padding: 2rem 1.5rem;
    background: var(--hb-m-weiss);
    border: 1px solid var(--hb-m-sand);
    text-align: center;
}

/* Gewinn-Fenster: steht im Textfluss über dem gelösten Spielfeld, damit auch lange Inhalte
   (Formular + Bestenliste) auf dem Smartphone ohne inneres Scrollen Platz haben */
.hb-memory__panel--result {
    margin-bottom: 1rem;
    border: 2px solid var(--hb-m-accent);
    animation: hb-memory-fade 0.4s ease;
    scroll-margin-top: 1rem;
}

.hb-memory__panel-image {
    width: 120px;
    height: auto;
    margin: 0 auto 0.5rem;
    animation: hb-memory-bounce 0.9s ease;
}

.hb-memory__panel-title {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
}

.hb-memory__panel-text {
    margin: 0 0 1.5rem;
    color: var(--hb-m-grau);
}

.hb-memory__choices {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

.hb-memory__result {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin: 0 0 0.75rem;
    font-size: 1.125rem;
}

.hb-memory__record {
    margin: 0 0 0.5rem;
    padding: 0.25rem 0.75rem;
    background: var(--hb-m-accent);
    color: var(--hb-m-braun);
    font-weight: 700;
}

.hb-memory__best {
    margin: 0 0 1.5rem;
    color: var(--hb-m-grau);
    font-size: 0.9375rem;
}

/* Spielfeld */
.hb-memory__board {
    display: grid;
    grid-template-columns: repeat(var(--hb-memory-cols), minmax(0, 1fr));
    gap: 0.5rem;
    /* Karten nicht größer als ca. 160px, damit das 4 × 4-Feld auf dem Desktop nicht riesig wird */
    max-width: calc(var(--hb-memory-cols) * 10.5rem);
    margin: 0 auto;
}

/* Karte: Button mit 3D-Flip, Rückseite oben, Vorderseite (Motiv) gespiegelt darunter */
.hb-memory__card {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    perspective: 800px;
    -webkit-tap-highlight-color: transparent;
}

.hb-memory__card-inner {
    position: absolute;
    inset: 0;
    display: block;
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(43, 27, 18, 0.18);
}

.hb-memory__card.is-flipped .hb-memory__card-inner {
    transform: rotateY(180deg);
}

.hb-memory__face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.hb-memory__face--front {
    transform: rotateY(180deg);
}

.hb-memory__card:hover:not(.is-flipped) .hb-memory__card-inner,
.hb-memory__card:focus-visible:not(.is-flipped) .hb-memory__card-inner {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(43, 27, 18, 0.22);
}

.hb-memory__card.is-matched {
    cursor: default;
}

.hb-memory__card.is-matched .hb-memory__card-inner {
    box-shadow: 0 0 0 3px var(--hb-m-accent), 0 2px 6px rgba(43, 27, 18, 0.18);
    animation: hb-memory-match 0.5s ease;
}

/* Bestenliste */
.hb-memory__leaderboard {
    margin-top: 1.5rem;
}

.hb-memory__boards {
    display: grid;
    gap: 1.5rem;
    margin-top: 1.25rem;
    text-align: left;
}

.hb-memory__list-title {
    margin: 0 0 0.5rem;
    font-size: 1.0625rem;
}

.hb-memory__list {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 0.9375rem;
    text-align: left;
}

.hb-memory__list th,
.hb-memory__list td {
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--hb-m-sand);
    white-space: nowrap;
}

.hb-memory__list th {
    font-weight: 600;
    color: var(--hb-m-grau);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hb-memory__list td:first-child,
.hb-memory__list th:first-child {
    width: 2.5rem;
    color: var(--hb-m-grau);
}

.hb-memory__list-name {
    width: 100%;
    white-space: normal !important;
    overflow-wrap: anywhere;
    font-weight: 600;
}

.hb-memory__list tr.is-own td {
    background: var(--hb-m-accent);
    color: var(--hb-m-braun);
}

.hb-memory__form {
    max-width: 26rem;
    margin: 0 auto 1.5rem;
}

.hb-memory__label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.hb-memory__form-row {
    display: flex;
    gap: 0.5rem;
}

.hb-memory__input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--hb-m-grau);
    background: var(--hb-m-weiss);
    color: var(--hb-m-braun);
    font: inherit;
}

.hb-memory__input:focus-visible {
    outline: 3px solid var(--hb-m-accent);
    outline-offset: 1px;
    border-color: var(--hb-m-rot);
}

.hb-memory__form-message {
    min-height: 1.25rem;
    margin: 0.5rem 0 0;
    font-size: 0.9375rem;
    color: var(--hb-m-rot);
}

.hb-memory__form-message:empty {
    display: none;
}

/* Seitenaufbau: Spiel links, Downloads rechts (ab 992px), mobil untereinander */
.hb-fridolin {
    display: grid;
    gap: 2rem;
    align-items: start;
    color: var(--hb-konturbraun, #2b1b12);
}

.hb-fridolin__game {
    min-width: 0;
}

.hb-fridolin__aside-title {
    margin: 0 0 1rem;
    font-size: 1.5rem;
}

.hb-fridolin__downloads {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hb-fridolin__download {
    position: relative;
    display: block;
    padding: 1rem 3rem 1rem 1.25rem;
    background: #fff;
    border: 1px solid var(--hb-sand, #e7d9c6);
    border-left: 4px solid var(--hb-accent, #f3c41b);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.hb-fridolin__download:hover,
.hb-fridolin__download:focus-visible {
    border-color: var(--hb-rot, #9b1c20);
    border-left-color: var(--hb-rot, #9b1c20);
    box-shadow: 0 6px 16px -8px rgba(43, 27, 18, 0.35);
    color: inherit;
    text-decoration: none;
    outline: none;
}

.hb-fridolin__download:focus-visible {
    outline: 3px solid var(--hb-accent, #f3c41b);
    outline-offset: 2px;
}

/* Download-Pfeil rechts */
.hb-fridolin__download::after {
    content: '↓';
    position: absolute;
    top: 50%;
    right: 1.125rem;
    transform: translateY(-50%);
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1;
    color: var(--hb-rot, #9b1c20);
}

.hb-fridolin__download-title {
    display: block;
    font-size: 1.125rem;
    font-weight: 700;
}

.hb-fridolin__download-text {
    display: block;
    margin-top: 0.125rem;
    color: #7d6e5c;
}

.hb-fridolin__download-meta {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--hb-rot, #9b1c20);
}

@media (min-width: 992px) {
    .hb-fridolin {
        grid-template-columns: minmax(0, 1fr) 20rem;
        gap: 2.5rem;
    }
}

/* Screenreader-Statuszeile */
.hb-memory__live {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

@keyframes hb-memory-match {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.06); }
    100% { transform: rotateY(180deg) scale(1); }
}

@keyframes hb-memory-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes hb-memory-bounce {
    0% { transform: translateY(12px) scale(0.9); opacity: 0; }
    60% { transform: translateY(-6px) scale(1.03); opacity: 1; }
    100% { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .hb-memory__card-inner,
    .hb-memory__button {
        transition: none;
    }

    .hb-memory__card.is-matched .hb-memory__card-inner,
    .hb-memory__panel--result,
    .hb-memory__panel-image {
        animation: none;
    }
}

/* Smartphone: immer 4 Spalten (bei 6 × 4 werden es 6 Reihen), kompaktere Statuszeile */
@media (min-width: 640px) {
    .hb-memory__boards {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 639px) {
    .hb-memory__board {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.375rem;
    }

    .hb-memory__stats {
        font-size: 0.9375rem;
        gap: 0.375rem 0.875rem;
    }

    .hb-memory__panel {
        padding: 1.5rem 1rem;
    }

    .hb-memory__button--level {
        min-width: 100%;
    }
}
