body[data-schwarzer-peter-room] {
    --game-ui-accent: #ef8e9c;
    --game-ui-header-background: #0d714c;
    --game-ui-header-color: #fff;
    --game-ui-surface: #fffdf9e8;
    --game-ui-surface-text: #5d5061;
    --game-ui-surface-muted: #8b7a92;
    --game-ui-primary-background: #ec90a0;
    --game-ui-primary-color: #fff;
    --game-ui-secondary-background: #e7dcf2;
    --game-ui-secondary-color: #5b4b63;
    --peter-card-width: clamp(68px, min(13vw, 16dvh), 132px);
    --peter-card-height: calc(var(--peter-card-width) * 1.3449);
}

* { box-sizing: border-box; }
body[data-schwarzer-peter-room] {
    min-height: 100dvh;
    margin: 0;
    overflow-x: hidden;
    color: #5a4b61;
    background-color: #7fe0b3;
    font-family: Arial, Helvetica, sans-serif;
}
body[data-schwarzer-peter-room]::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .28;
    background-image: radial-gradient(#fff 1.4px, transparent 1.7px);
    background-size: 19px 19px;
}
.peter-header { border-bottom-color: #095a3d; box-shadow: 0 2px 13px #06462f52; }
.peter-add-player { display: grid; grid-template-columns: 1fr 44px; align-items: end; gap: 9px; }
.peter-add-player label { min-width: 0; }
.peter-lobby-marker { width: 30px; height: 30px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #fff; background: #a6d8ca; }

body.game-ui-in-game { overflow: hidden; }
body.game-ui-in-game main { height: calc(100dvh - var(--game-ui-header-height) - env(safe-area-inset-top, 0px)); min-height: 0; margin-top: calc(var(--game-ui-header-height) + env(safe-area-inset-top, 0px)); overflow: hidden; }
.peter-board {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: clamp(16px, 2.5dvh, 24px) max(8px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 5px;
    isolation: isolate;
    overflow: hidden;
}
.peter-board.busy,.peter-board.peter-dealing { pointer-events: none; }

.peter-opponents { width: min(100%, 1100px); min-width: 0; margin-inline: auto; display: grid; grid-template-columns: repeat(var(--opponents), minmax(0, 1fr)); align-items: start; gap: clamp(6px, 1.5vw, 22px); overflow: hidden; }
.peter-opponent { min-width: 0; padding: 3px 5px 0; transition: transform .2s; }
.peter-opponent.target { transform: translateY(3px); }
.peter-opponent header,.peter-own header { min-width: 0; display: flex; align-items: center; gap: 8px; }
.peter-opponent header > span:nth-child(2),.peter-own header > span:first-child { min-width: 0; display: grid; }
.peter-opponent strong,.peter-own strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peter-opponent small,.peter-own small { color: #9a889d; font-size: .68rem; }
.peter-turn-indicator { width: 0; height: 0; display: inline-block; margin: 0 5px 1px 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid #0d714c; vertical-align: middle; filter: drop-shadow(0 1px 0 #fff); }
.peter-avatar { width: 28px; height: 28px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #fff; background: #f1abb9; font-weight: 900; }
.peter-hidden-hand { min-width: 0; height: calc(var(--peter-card-height) + 12px); margin-top: 3px; padding-top: 12px; display: flex; justify-content: safe center; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.peter-hidden-hand .peter-card { width: var(--peter-card-width); height: var(--peter-card-height); }

.peter-table { min-height: 0; display: grid; grid-template-rows: 44px minmax(0, 1fr); place-items: center; gap: 7px; }
.peter-phase { max-width: min(100%, 56ch); height: 44px; padding: 5px 10px; display: grid; place-items: center; overflow: hidden; border-radius: 999px; color: #6f6075; background: #fffdf9b8; font-size: clamp(.68rem, 1.8vw, .84rem); line-height: 1.2; text-align: center; }
.peter-phase-placeholder { visibility: hidden; }
.peter-discard { position: relative; width: calc(var(--peter-card-width) * 1.75); height: calc(var(--peter-card-height) * 1.25); display: flex; justify-content: center; align-items: center; }
.peter-discard .peter-card { position: absolute; z-index: var(--discard-index); transform: translate(var(--discard-x), var(--discard-y)) rotate(var(--discard-rotation)); transition: transform .2s ease; }
.peter-empty-stack { width: var(--peter-card-width); height: var(--peter-card-height); display: block; background: url('/public/img/schwarzer-peter/cards/back.png') center / contain no-repeat; opacity: .58; }

.peter-card { position: relative; width: var(--peter-card-width); height: var(--peter-card-height); flex: 0 0 auto; padding: 0; border: 0; color: inherit; background: transparent; transform-origin: 50% 100%; }
button.peter-card { appearance: none; }
.peter-card img { display: block; width: 100%; height: 100%; object-fit: contain; }
.peter-card.clickable { cursor: pointer; transition: transform .16s ease; touch-action: pan-x pan-y; -webkit-touch-callout: none; user-select: none; }
.peter-own-hand .peter-card.peter-pair-hint { transform: translateY(-12px) rotate(-3deg); }
@media (hover: hover) and (pointer: fine) { .peter-card.clickable:hover, .peter-own-hand .peter-card.peter-pair-hint.clickable:hover { transform: translateY(-12px) rotate(0); } }
.peter-card.clickable:focus-visible { transform: translateY(-12px) rotate(0); }
.peter-card.clickable:focus-visible { outline: 2px solid #0d714c; outline-offset: 2px; }
.peter-card.selected, .peter-own-hand .peter-card.peter-pair-hint.selected { transform: translateY(-18px) rotate(0); }
.peter-card.peter-draw-flight { position: fixed; z-index: 180; margin: 0; pointer-events: none; transform-origin: center; }

.peter-own { min-width: 0; max-width: 1100px; width: 100%; margin-inline: auto; padding: 0 8px; align-self: end; }
.peter-own header { justify-content: space-between; padding: 0 2px 9px; }
.peter-own-hand { min-width: 0; min-height: calc(var(--peter-card-height) + 24px); display: flex; justify-content: safe center; align-items: end; padding: 24px clamp(3px, 2vw, 16px) 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.peter-own-hand::-webkit-scrollbar,.peter-hidden-hand::-webkit-scrollbar { display: none; }
.peter-own-hand .peter-card + .peter-card,
.peter-hidden-hand .peter-card + .peter-card { margin-left: clamp(calc(var(--peter-card-width) * -.46), -5vw, calc(var(--peter-card-width) * -.32)); }
.peter-own-hand.peter-fit-compact .peter-card + .peter-card,
.peter-hidden-hand.peter-fit-compact .peter-card + .peter-card { margin-left: calc(var(--peter-card-width) * -.55); }
.peter-own-hand.peter-fit-tight .peter-card + .peter-card,
.peter-hidden-hand.peter-fit-tight .peter-card + .peter-card { margin-left: calc(var(--peter-card-width) * -.65); }
.peter-own-hand.is-shuffling .peter-card { animation: peter-hand-shuffle .58s cubic-bezier(.2,.75,.2,1) both; animation-delay: calc(var(--card-index, 0) * 12ms); }
@media (min-width: 901px) and (min-height: 561px) {
    .peter-own.peter-spread { max-width: none; }
    .peter-opponents.peter-spread { width: 100%; }
    .peter-spread .peter-own-hand, .peter-spread .peter-hidden-hand { overflow-x: hidden; }
    .peter-spread .peter-own-hand .peter-card + .peter-card,
    .peter-spread .peter-hidden-hand .peter-card + .peter-card { margin-left: var(--peter-hand-spacing, 0px); }
}
@media (max-width: 900px), (max-height: 560px) {
    .game-ui-control.peter-hand-spread-toggle:not([hidden]) { display: none !important; }
}
.peter-reaction { max-width: 160px; margin-left: auto; padding: 5px 8px; overflow: hidden; border-radius: 10px 10px 10px 2px; color: #69546b; background: #fff6d9; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }

.peter-result-overlay { position: fixed; z-index: 150; inset: 0; padding: 20px; display: grid; place-items: center; background: #e9d9eea6; backdrop-filter: blur(8px); }
.peter-result { width: min(420px, 100%); padding: 32px; border: 3px solid #fff; border-radius: 28px; color: #67536c; background: #fffdf8; box-shadow: 0 25px 80px #98729452; text-align: center; }
.peter-result > span { display: block; color: #ef9eae; font-size: 4rem; }
.peter-result h2 { margin: 5px 0 10px; font: 2rem/1.05 Georgia,serif; }
.peter-result p { color: #8b748e; line-height: 1.5; }

.peter-deal-layer { position: fixed; z-index: 160; inset: 0; overflow: hidden; pointer-events: none; }
.peter-deal-layer .peter-deal-flight { position: fixed; margin: 0; transform-origin: center; }
.peter-rules { position: fixed; z-index: 180; top: calc(var(--game-ui-header-height) + 10px); right: 12px; width: min(390px, calc(100vw - 24px)); max-height: calc(100dvh - var(--game-ui-header-height) - 24px); padding: 25px; overflow: auto; border: 3px solid #fff; border-radius: 24px; color: #67536c; background: #fffdf8; box-shadow: 0 24px 70px #a77c9b45; }
.peter-rules h2 { margin: 0 30px 12px 0; font-family: Georgia,serif; }
.peter-rules p { color: #8a738d; line-height: 1.55; }
.peter-rules > button { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 1.6rem; cursor: pointer; }

@keyframes peter-hand-shuffle {
    0%,100% { transform: translate(0,0) rotate(0); }
    35% { transform: translate(calc((var(--cards) / 2) * -2px), -22px) rotate(-5deg); }
    70% { transform: translate(calc((var(--cards) / 2) * 2px), -7px) rotate(4deg); }
}

@media (max-width: 600px) {
    body[data-schwarzer-peter-room] { --peter-card-width: clamp(62px, min(20vw, 13dvh), 82px); }
    .peter-board { padding-inline: max(5px, env(safe-area-inset-left)) max(5px, env(safe-area-inset-right)); }
    .peter-opponents { gap: 4px; }
    .peter-opponent { padding: 3px 2px 0; }
    .peter-opponent header { gap: 4px; }
    .peter-avatar { width: 22px; height: 22px; font-size: .72rem; }
    .peter-opponent small { display: none; }
    .peter-table { min-height: 104px; }
    .peter-own { padding-inline: 7px; }
}

@media (max-height: 560px) and (orientation: landscape) {
    body[data-schwarzer-peter-room] { --peter-card-width: clamp(54px, 11dvh, 74px); }
    .peter-board { grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1.5fr); grid-template-rows: minmax(0, 1fr); gap: 7px 12px; padding-top: 10px; padding-bottom: max(5px, env(safe-area-inset-bottom)); }
    .peter-opponents { grid-column: 1; grid-row: 1; align-content: start; }
    .peter-opponent { min-width: 0; }
    .peter-table { grid-column: 2; grid-row: 1; }
    .peter-own { grid-column: 3; grid-row: 1; align-self: end; }
    .peter-own-hand { min-height: 96px; max-height: 176px; }
}

@media (prefers-reduced-motion: reduce) {
    .peter-card,.peter-opponent { transition: none; }
    .peter-deal-layer { display: none; }
    .peter-own-hand.is-shuffling .peter-card { animation: none; }
}
