:root {
    --memory-header-height: 62px;
    --memory-primary: #d06ba7;
    --memory-bg-dark: #48213f;
    --memory-bg-mid: #823968;
    --memory-panel: #211620ed;
    --memory-text: #fff;
    --memory-muted: #ead9e5;
}

body[data-memory-room] {
    --game-ui-accent: var(--memory-primary);
    --game-ui-header-background: #40172ff2;
    --game-ui-primary-background: var(--memory-primary);
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    overflow: hidden;
    background: linear-gradient(145deg, var(--memory-bg-dark) 0%, var(--memory-bg-mid) 52%, var(--memory-primary) 100%);
    color: var(--memory-text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: default; }

.memory-header {
    min-height: calc(var(--memory-header-height) + env(safe-area-inset-top, 0px));
    background: #24121fe8;
}

.memory-back,
.memory-brand,
.memory-info { color: #fff; }

.memory-brand {
    font-family: Georgia, serif;
    font-size: clamp(1.35rem, 4vw, 1.8rem);
    font-weight: 800;
    letter-spacing: -.06em;
}

.memory-info { border-color: #fff; }

#memory-app {
    height: calc(100vh - var(--memory-header-height) - env(safe-area-inset-top, 0px));
    height: calc(100dvh - var(--memory-header-height) - env(safe-area-inset-top, 0px));
    overflow: auto;
}

/* Startseite und Lobby */
.memory-panel {
    width: min(440px, calc(100% - 28px));
    margin: clamp(28px, 8vh, 80px) auto 24px;
    padding: clamp(20px, 5vw, 32px);
    border: 1px solid #ffffff2e;
    border-radius: 22px;
    background: var(--memory-panel);
    text-align: center;
    box-shadow: 0 24px 60px #210c1d99;
}

.memory-placeholder-logo {
    min-height: 104px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.memory-placeholder-logo img {
    width: 62px;
    aspect-ratio: 1;
    object-fit: cover;
    border: 3px solid #fff;
    border-radius: 2px;
    filter: drop-shadow(0 8px 12px #0008);
}

.memory-placeholder-logo strong {
    margin-left: -8px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--memory-primary);
    color: #fff;
    font-family: Georgia, serif;
    font-size: clamp(1.8rem, 8vw, 2.75rem);
    line-height: 1;
    letter-spacing: -.07em;
    transform: rotate(2deg);
    box-shadow: 0 8px 20px #0006;
}

.memory-panel h1 { margin: 8px 0; font-size: clamp(1.45rem, 6vw, 2rem); }
.memory-panel p { color: var(--memory-muted); }

.memory-form,
.memory-form label { display: grid; gap: 8px; }
.memory-form { margin-top: 22px; text-align: left; }
.memory-form label,
.memory-lobby-form > label { color: var(--memory-muted); font-size: .82rem; font-weight: 700; }

.memory-form input,
.memory-share input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #d5a7c7;
    border-radius: 10px;
    outline: none;
    background: #fffafc;
    color: #32162b;
}

.memory-form input:focus,
.memory-share input:focus { border-color: var(--memory-primary); box-shadow: 0 0 0 3px #d06ba744; }

.memory-primary,
.memory-secondary,
.memory-link-button {
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 10px;
}

.memory-primary {
    border: 1px solid #efbddd;
    background: var(--memory-primary);
    color: #fff;
    font-weight: 800;
}

.memory-primary:disabled { opacity: .42; }

.memory-kicker {
    display: block;
    margin-bottom: 13px;
    color: #fff;
    font-size: .72rem;
    font-weight: 900;
    letter-spacing: .15em;
    text-transform: uppercase;
}

.memory-lobby-form { display: grid; gap: 13px; margin-top: 24px; text-align: left; }
.memory-lobby-form > label { display: grid; gap: 6px; }
.memory-share { display: flex; gap: 8px; align-items: center; }
.memory-share input { flex: 1; min-width: 0; border-radius: 3px; }

.memory-secondary {
    border: 0;
    border-radius: 3px;
    background: #693058;
    color: #fff;
}

.memory-icon-button { width: 44px; min-width: 44px; padding: 10px; display: grid; place-items: center; }
.memory-icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.memory-player-shares { display: grid; gap: 8px; }
.memory-player-share { align-items: center; }
.memory-player-share-info {
    height: 44px;
    padding: 0 11px;
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    gap: 10px;
    border: 1px solid #d5a7c7;
    border-radius: 3px;
    background: #fffafc;
    color: #32162b;
}

.memory-avatar { width: 31px; height: 31px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--memory-primary); color: #fff; font-weight: 900; }
.memory-player-share-info > span:last-child { display: grid; min-width: 0; gap: 1px; }
.memory-player-share-info strong,
.memory-player-share-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memory-player-share-info small { color: #77566e; font-size: .72rem; }

.memory-house-rules { margin: 0; padding: 12px; border: 1px solid #d5a7c7; border-radius: 10px; text-align: left; }
.memory-house-rules legend { padding: 0 5px; color: #fff; font-weight: 700; }
.memory-house-rules label { display: flex; gap: 8px; align-items: center; margin: 9px 0; color: #fff; font-size: .88rem; }
.memory-house-rules input { accent-color: var(--memory-primary); }

.memory-link-button { border: 0; background: transparent; color: var(--memory-muted); text-decoration: underline; text-underline-offset: 3px; }

.memory-recent { width: min(560px, calc(100% - 28px)); margin: 0 auto 40px; }
.memory-recent h2 { margin: 0 0 10px; color: var(--memory-muted); font-size: .86rem; font-weight: 500; }
.memory-recent-session { margin-bottom: 8px; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 12px; border: 1px solid #ffffff25; border-radius: 12px; background: #211620dd; }
.memory-recent-session > div { min-width: 0; display: grid; gap: 4px; }
.memory-recent-session strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memory-recent-session small { color: var(--memory-muted); }
.memory-recent-players { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 5px; }
.memory-recent-players button { padding: 5px 9px; border: 1px solid #d5a7c7; border-radius: 7px; background: #693058; color: #fff; font-size: .75rem; }
.memory-delete-session { width: 34px; height: 34px; padding: 7px; border: 0; background: transparent; color: #f2bfdc; }
.memory-delete-session svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }

/* Spielfeld */
#memory-app > .memory-board {
    width: min(900px, 100%);
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    overflow: hidden;
}

.memory-board.busy button { pointer-events: none; }
.memory-turn { margin: 0; color: #fff; font: 700 1.15rem Georgia, serif; text-align: center; }

.memory-grid {
    width: min(760px, calc(100vw - 28px), calc(100dvh - var(--memory-header-height) - 230px));
    max-width: 100%;
    aspect-ratio: 1;
    margin: 0 auto;
    display: grid;
    flex: 0 1 auto;
    gap: clamp(4px, 1vw, 10px);
}

.memory-grid-16 { grid-template-columns: repeat(4, 1fr); }
.memory-grid-36 { grid-template-columns: repeat(6, 1fr); }
.memory-grid-64 { grid-template-columns: repeat(8, 1fr); }

.memory-tile {
    padding: 0;
    border: 0;
    background: transparent;
    aspect-ratio: 1;
    perspective: 900px;
    cursor: pointer;
}

.memory-tile:disabled { cursor: default; }
.memory-tile > span { position: relative; display: block; width: 100%; height: 100%; min-width: 7px; transform-style: preserve-3d; }
.memory-tile.open > span { transform: rotateY(180deg); }
.memory-tile i { position: absolute; inset: 0; display: block; overflow: hidden; border: 3px solid #fff; border-radius: 1px; backface-visibility: hidden; box-shadow: 5px 4px 0 #542044, 0 7px 10px #0004; }
.memory-tile-back { background: var(--memory-primary) url('/public/img/memory/back.jpg') center / cover; }
.memory-tile-front { background: #fff; transform: rotateY(180deg); }
.memory-tile-front img { width: 100%; height: 100%; object-fit: cover; }

.memory-tile.memory-flip-card > span { animation: memory-tile-reveal 1s ease-in-out both; will-change: transform; }
.memory-tile.memory-closing-card > span { animation: memory-card-hide 1s ease-in-out both; will-change: transform; }

@keyframes memory-tile-reveal {
    from { transform: rotateY(0); }
    to { transform: rotateY(180deg); }
}

@keyframes memory-card-hide {
    from { transform: rotateY(180deg); }
    to { transform: rotateY(0); }
}

.memory-pair-stack { width: 100%; display: grid; gap: 5px; color: #fff; }
.memory-pair-stack.opponent { justify-items: start; }
.memory-pair-stack.own { justify-items: end; text-align: right; }
.memory-pair-stack header { display: flex; gap: 8px; align-items: baseline; }
.memory-pair-stack.own header { justify-content: end; }
.memory-pair-stack small { color: #fff; font-size: .78rem; }
.memory-pair-stack div { min-height: 36px; display: flex; gap: 4px; }
.memory-pair-stack.own div { justify-content: end; }
.memory-pair-stack img { width: 34px; height: 34px; object-fit: cover; border: 2px solid #fff; border-radius: 2px; background: #fff; }

/* Regeln und Status */
.memory-rules-overlay { position: fixed; inset: 0; z-index: 2000; padding: 18px; display: grid; place-items: center; overflow-y: auto; background: #170b15c7; backdrop-filter: blur(5px); }
.memory-rules-card { position: relative; width: min(420px, 100%); max-height: min(720px, calc(100dvh - 36px)); padding: 24px; overflow-y: auto; border: 1px solid #ffffff35; border-radius: 18px; background: #291724; color: #fff; text-align: left; box-shadow: 0 24px 70px #000a; }
.memory-rules-card h2 { margin: 0 0 18px; color: var(--memory-primary); font: 2rem Georgia, serif; }
.memory-rules-card p { color: var(--memory-muted); font-size: .9rem; line-height: 1.5; }
.memory-rules-close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border: 0; background: transparent; color: #fff; font-size: 1.7rem; }

#memory-status { position: fixed; z-index: 3000; right: 14px; bottom: 14px; max-width: min(360px, calc(100vw - 28px)); padding: 10px 13px; border: 1px solid #efbddd; border-radius: 10px; background: #291724f2; color: #fff; opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .18s ease, transform .18s ease; }
#memory-status.visible { opacity: 1; transform: none; }

@media (max-width: 540px) {
    .memory-header { padding-inline: 10px; }
    .memory-panel { margin-top: 22px; padding: 20px; }
    #memory-app > .memory-board { padding: 8px 6px; gap: 8px; }
    .memory-grid { width: min(calc(100vw - 12px), calc(100dvh - var(--memory-header-height) - 180px)); gap: 3px; }
    .memory-tile i { border-width: 2px; box-shadow: 3px 3px 0 #542044, 0 4px 6px #0004; }
    .memory-pair-stack img { width: 28px; height: 28px; }
}

@media (max-height: 680px) {
    #memory-app > .memory-board { padding-block: 5px; gap: 5px; }
    .memory-grid { width: min(620px, calc(100vw - 16px), calc(100dvh - var(--memory-header-height) - 155px)); }
    .memory-pair-stack div { min-height: 28px; }
    .memory-pair-stack img { width: 26px; height: 26px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
