/* ============================================
   DOPPELGÄNGER
   Game screen. Uses arcade-common.css variables.
   Layout: agents (left) · table + hand (center) · timer + log (right)
   ============================================ */

.dg[hidden],
.dg [hidden] {
    display: none !important;
}

.dg {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-sm) 16px var(--spacing-lg);
}

.dg-label {
    display: block;
    font-family: var(--font-display);
    font-size: 0.55rem;
    color: var(--color-text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* --- Top bar --- */

.dg-top {
    /* Above modal backdrops so Options / Quit always work */
    position: relative;
    z-index: 51;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    border-bottom: var(--border-subtle);
}

.dg-top__title {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--color-gold);
    text-shadow: 0 0 20px var(--color-gold-glow);
}

.dg-top__title span {
    color: var(--color-text-dim);
    font-size: 0.6rem;
    margin-left: 0.5rem;
    text-shadow: none;
}

.dg-top__round {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--color-text);
    text-align: center;
}

.dg-top__round span {
    white-space: nowrap;
}

.dg-top__turn::before {
    content: ' · ';
}

.dg-top__buttons {
    display: flex;
    gap: var(--spacing-xs);
}

.dg-top__quit {
    padding: 0.5rem 1rem;
}

/* --- Three-column layout --- */

.dg-layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr) 280px;
    gap: var(--spacing-md);
    align-items: start;
}

.dg-panel {
    background: var(--color-bg-card);
    border: var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
}

.dg-panel__title {
    font-size: 0.6rem;
    letter-spacing: 2px;
    margin-bottom: var(--spacing-sm);
    text-shadow: none;
}

/* --- Agents (left) --- */

.dg-scores__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.dg-player {
    background: var(--color-bg-mid);
    border: 2px solid transparent;
    border-left: 4px solid var(--player, transparent);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.75rem;
}

/* Just locked in */
.dg-player.is-picked {
    animation: dg-picked 700ms ease;
}

@keyframes dg-picked {
    0%, 100% { background: var(--color-bg-mid); }
    25% { background: rgba(232, 228, 240, 0.28); }
}

.dg-player__top {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.dg-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(10, 8, 18, 0.6);
}

.dg-player__name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg-player.is-me .dg-player__name {
    color: var(--color-gold);
}

.dg-player__score {
    margin-left: auto;
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--color-gold);
}

.dg-player__chips {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.3rem;
}

.dg-player__chips:empty {
    display: none;
}

.dg-chip {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-radius: var(--radius-sm);
    padding: 0.05rem 0.35rem;
    background: var(--color-purple);
    color: var(--color-text);
    flex-shrink: 0;
}

.dg-chip--wait {
    background: var(--color-bg-deep);
    color: var(--color-text-dim);
}

.dg-chip--locked {
    background: var(--color-success);
    color: var(--color-bg-deep);
}

.dg-player__cards {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: 0.45rem;
    min-height: 20px;
}

.dg-back {
    width: 13px;
    height: 19px;
    border-radius: 2px;
    border: 1px solid var(--color-gold-dim);
    background: repeating-linear-gradient(45deg, var(--color-purple) 0 3px, var(--color-bg-card) 3px 6px);
}

.dg-player__count {
    margin-left: 0.35rem;
    font-size: 0.8rem;
    color: var(--color-text-dim);
}

.dg-player__known {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.dg-player__known:empty {
    display: none;
}

/* Small card label: "K♠" */
.dg-tag {
    display: inline-block;
    background: #f4ecd2;
    color: #1a1625;
    border-radius: 3px;
    padding: 0 0.3rem;
    font-weight: 700;
    font-size: 0.75rem;
    line-height: 1.4;
}

.dg-tag.is-red {
    color: #b3262e;
}

/* --- Center --- */

.dg-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    text-align: center;
}

/* Fixed two-line height (title + subtitle) so the table never jumps */
.dg-status {
    font-size: 1.1rem;
    font-weight: 600;
    min-height: 3.2rem;
}

.dg-status.is-my-turn {
    color: var(--color-gold);
}

.dg-status__sub {
    display: block;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--color-text-dim);
}

/* Hidden but still taking up space, for the same reason */
.dg-lock.is-off,
.dg-mini-timer.is-off {
    visibility: hidden;
    transition: none; /* .btn's transition would otherwise delay the hide */
}

.dg-table {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
    background: radial-gradient(ellipse at center, #2f4a3a 0%, #1f3328 70%);
    border: 2px solid rgba(212, 175, 55, 0.35);
    border-radius: 999px;
    padding: var(--spacing-md) var(--spacing-lg);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

.dg-table .dg-label {
    color: rgba(232, 228, 240, 0.7);
    margin-bottom: var(--spacing-xs);
}

.dg-missing {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-right: var(--spacing-md);
    border-right: 1px dashed rgba(232, 228, 240, 0.25);
}

.dg-slots {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
}

.dg-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    width: 100px;
}

.dg-slot__name {
    max-width: 100%;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--player);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dg-slot__tag {
    font-size: 0.72rem;
    color: rgba(232, 228, 240, 0.75);
    min-height: 2.4em;
    line-height: 1.2;
}

/* Nobody's card yet: dashed outline where it will land */
.dg-slot.is-empty .dg-card__inner {
    opacity: 0;
}

.dg-slot.is-empty .dg-card {
    border: 2px dashed rgba(232, 228, 240, 0.25);
    border-radius: var(--radius-md);
}

.dg-slot .dg-card {
    transition: transform 300ms ease;
}

.dg-slot.is-matched .dg-card__front {
    border-color: var(--color-success);
    box-shadow: 0 0 22px rgba(80, 200, 120, 0.7);
}

.dg-slot.is-matched .dg-slot__tag {
    color: var(--color-success);
    font-weight: 700;
}

.dg-slot.is-winner .dg-card__front {
    box-shadow: 0 0 30px var(--color-gold);
}

.dg-slot.is-winner .dg-slot__tag {
    color: var(--color-gold);
    font-weight: 700;
}

.dg-slot.is-returned .dg-card {
    opacity: 0.6;
}

.dg-slot.is-flash .dg-card {
    animation: dg-land 700ms ease 450ms;
}

@keyframes dg-land {
    40% { transform: scale(1.12); }
}

/* --- Cards --- */

.dg-card {
    width: 84px;
    height: 118px;
    perspective: 600px;
    flex-shrink: 0;
}

.dg-card--small {
    width: 64px;
    height: 90px;
}

.dg-card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 600ms ease;
}

.dg-card.is-revealed .dg-card__inner {
    transform: rotateY(180deg);
}

.dg-card__face {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

.dg-card__back {
    background:
        url('../../PixelCrown_32x32.png') center / 32px no-repeat,
        repeating-linear-gradient(45deg, var(--color-purple) 0 8px, var(--color-bg-card) 8px 16px);
    border: 3px solid var(--color-gold-dim);
    image-rendering: pixelated;
}

.dg-card__front {
    background: linear-gradient(160deg, #fbf6e6, #e8dcb8);
    border: 3px solid var(--color-gold);
    color: #1a1625;
    transform: rotateY(180deg);
    transition: box-shadow 300ms ease, border-color 300ms ease;
}

.dg-card__front.is-red {
    color: #b3262e;
}

.dg-card__value {
    font-family: var(--font-display);
    font-size: 1.9rem;
    line-height: 1;
}

.dg-card__suit {
    font-size: 1.3rem;
    line-height: 1.2;
}

.dg-card--small .dg-card__value { font-size: 1.4rem; }
.dg-card--small .dg-card__suit { font-size: 1rem; }

.dg-card__front.is-pair .dg-card__value {
    font-size: 1.3rem;
    letter-spacing: 2px;
}

.dg-card__pair {
    margin-top: 0.2rem;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--color-gold-dim);
}

/* Corner pips */
.dg-card__front::before,
.dg-card__front::after {
    content: attr(data-corner);
    position: absolute;
    font-size: 0.7rem;
    font-weight: 700;
}
.dg-card__front::before { top: 4px; left: 6px; }
.dg-card__front::after { bottom: 4px; right: 6px; transform: rotate(180deg); }

/* --- Card animation --- */

/* Table card has left (removed, or flown back to a hand) */
.dg-slot.is-gone .dg-card__inner {
    opacity: 0;
}

.dg-slot.is-gone .dg-card {
    border: 2px dashed rgba(232, 228, 240, 0.18);
    border-radius: var(--radius-md);
    opacity: 1;
}

/* Fixed-position copy of a card face that flies or bursts away */
.dg-ghost {
    position: fixed;
    z-index: 60;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: linear-gradient(160deg, #fbf6e6, #e8dcb8);
    border: 3px solid var(--color-gold);
    color: #1a1625;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}

.dg-ghost.is-red {
    color: #b3262e;
}

.dg-ghost.is-matched {
    border-color: var(--color-success);
    box-shadow: 0 0 30px rgba(80, 200, 120, 0.85);
}

.dg-ghost::before,
.dg-ghost::after {
    content: attr(data-corner);
    position: absolute;
    font-size: 0.7rem;
    font-weight: 700;
}
.dg-ghost::before { top: 4px; left: 6px; }
.dg-ghost::after { bottom: 4px; right: 6px; transform: rotate(180deg); }

.dg-float {
    position: fixed;
    z-index: 61;
    pointer-events: none;
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--color-success);
    background: rgba(26, 22, 37, 0.9);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.45rem;
    text-shadow: 0 0 8px rgba(80, 200, 120, 0.6);
    white-space: nowrap;
}

/* My card is on the table / flying home: keep its space, hide it */
.dg-hcard.is-away {
    visibility: hidden;
}

.dg-hcard.is-landed {
    animation: dg-pop 450ms ease;
}

@keyframes dg-pop {
    0% { transform: scale(0.85); }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* --- Your hand --- */

.dg-hand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.dg-hand__cards {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
    min-height: 138px;
    padding-top: 12px; /* room for the selected card to lift */
}

.dg-hand__empty {
    align-self: center;
    color: var(--color-text-dim);
}

.dg-hcard {
    position: relative;
    width: 84px;
    height: 118px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 3px solid var(--color-gold-dim);
    background: linear-gradient(160deg, #fbf6e6, #e8dcb8);
    color: #1a1625;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.dg-hcard.is-red {
    color: #b3262e;
}

/* Keyboard number */
.dg-hcard::before {
    content: attr(data-key);
    position: absolute;
    top: 4px;
    left: 7px;
    font-size: 0.65rem;
    font-weight: 700;
    color: rgba(26, 22, 37, 0.45);
}

.dg-hcard__v {
    font-family: var(--font-display);
    font-size: 1.9rem;
    line-height: 1;
}

.dg-hcard__s {
    font-size: 1.4rem;
    line-height: 1.2;
}

.dg-hcard:hover:not(:disabled) {
    transform: translateY(-5px);
    border-color: var(--color-gold);
}

.dg-hcard.is-selected {
    transform: translateY(-12px);
    border-color: var(--color-gold);
    box-shadow: 0 0 0 3px var(--color-gold), 0 10px 22px var(--color-gold-glow);
}

.dg-hcard:disabled {
    cursor: default;
}

.dg-hand__cards.is-idle .dg-hcard {
    opacity: 0.75;
}

/* The card I locked in: lifted and outlined until the reveal */
.dg-hand__cards .dg-hcard.is-played {
    opacity: 1;
    transform: translateY(-12px);
    box-shadow: 0 0 0 3px var(--color-success), 0 10px 22px rgba(80, 200, 120, 0.35);
}

.dg-actions {
    display: flex;
    gap: var(--spacing-xs);
    justify-content: center;
    flex-wrap: wrap;
}

.dg-lock,
.dg-declare {
    min-width: 160px;
}

.dg-lock:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.dg-declare {
    animation: dg-glow 1.4s ease-in-out infinite;
}

@keyframes dg-glow {
    0%, 100% { box-shadow: 0 0 6px var(--color-gold-glow); }
    50% { box-shadow: 0 0 24px var(--color-gold); }
}

.dg-error {
    color: var(--color-danger);
    font-size: 0.9rem;
    min-height: 1.4em;
}

/* --- Timer + log (right) --- */

.dg-side {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.dg-timer {
    background: var(--color-bg-mid);
    border-radius: var(--radius-md);
    padding: var(--spacing-xs) var(--spacing-sm);
    text-align: center;
}

.dg-timer__name {
    font-weight: 600;
    margin-top: 0.2rem;
}

.dg-timer__clock {
    font-family: var(--font-display);
    font-size: 1.6rem;
    color: var(--color-gold);
    margin: 0.3rem 0;
    min-height: 1.2em;
}

.dg-timer__clock.is-idle {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--color-text-dim);
}

.dg-timer.is-low .dg-timer__clock {
    color: var(--color-danger);
}

.dg-timer__bar {
    height: 6px;
    background: var(--color-bg-deep);
    border-radius: 3px;
    overflow: hidden;
}

.dg-timer__fill {
    height: 100%;
    width: 100%;
    background: var(--color-gold);
    transition: width 200ms linear;
}

.dg-timer.is-low .dg-timer__fill {
    background: var(--color-danger);
}

.dg-log {
    list-style: none;
    max-height: 460px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
}

.dg-log li {
    padding: 0.2rem 0.4rem;
    border-left: 2px solid var(--color-purple-light);
}

.dg-log .is-round {
    border-left-color: var(--color-gold);
    color: var(--color-gold);
    font-weight: 600;
    margin-top: 0.4rem;
}

.dg-log .is-turn {
    color: var(--color-text-dim);
}

.dg-log .is-match {
    border-left-color: var(--color-success);
}

.dg-log .is-end {
    border-left-color: var(--color-gold);
}

.dg-log__plays {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.6rem;
    margin-top: 0.15rem;
    color: var(--color-text);
}

.dg-log__plays > span {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.dg-log__plays .is-removed .dg-tag {
    box-shadow: 0 0 0 2px var(--color-success);
}

.dg-log__result {
    margin-top: 0.15rem;
    color: var(--color-text);
    font-weight: 600;
}

.dg-log .is-end .dg-log__result {
    color: var(--color-gold);
}

.dg-log .is-note {
    color: var(--color-text-dim);
    font-style: italic;
}

/* --- Modals (party summary, game over, quit confirm) --- */

.dg-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(26, 22, 37, 0.8);
}

.dg-modal__card {
    width: 100%;
    max-width: 480px;
    background: var(--color-bg-card);
    border: var(--border-accent);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.dg-modal__card h2 {
    margin-bottom: var(--spacing-sm);
}

.dg-modal__text {
    color: var(--color-text-dim);
    margin-bottom: var(--spacing-sm);
}

.dg-results {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--spacing-sm);
}

.dg-results th,
.dg-results td {
    padding: 0.35rem 0.5rem;
    border-bottom: var(--border-subtle);
}

.dg-results th {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.dg-results td:first-child {
    text-align: left;
    white-space: nowrap;
}

.dg-results td:first-child .dg-dot {
    margin-right: 0.4rem;
}

.dg-results__hand .dg-tag {
    margin: 1px;
}

.dg-results .is-winner td {
    color: var(--color-gold);
    font-weight: 700;
}

.dg-results .is-gain {
    color: var(--color-gold);
    font-weight: 700;
}

.dg-results .is-ready {
    color: var(--color-success);
    font-weight: 700;
}

.dg-results .is-waiting {
    color: var(--color-text-dim);
}

.dg-modal__actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.dg-modal__actions .dg-modal__text {
    margin-bottom: 0;
}

.dg-modal__countdown {
    width: 100%;
    font-size: 0.8rem;
}

.dg-ok {
    min-width: 140px;
}

.dg-mini-timer {
    display: none;
    font-family: var(--font-display);
    font-size: 0.8rem;
    color: var(--color-gold);
    margin-top: calc(-1 * var(--spacing-sm));
}

.dg-mini-timer.is-low {
    color: var(--color-danger);
}

/* --- Narrow screens: stack, table first --- */

@media (max-width: 900px) {
    .dg-mini-timer { display: block; }
    .dg-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .dg-center { order: 1; }
    .dg-side { order: 2; }
    .dg-scores { order: 3; }
    .dg-log { max-height: 220px; }
    .dg-top__title span { display: none; }
}

@media (max-width: 600px) {
    .dg-top__title { font-size: 0.75rem; }
    .dg-top__round { font-size: 0.55rem; line-height: 1.6; }
    .dg-top__round span { display: block; }
    .dg-top__turn::before { content: none; }
    .dg-table {
        flex-direction: column;
        gap: var(--spacing-sm);
        border-radius: var(--radius-lg);
        padding: var(--spacing-sm);
    }
    .dg-missing {
        flex-direction: row;
        gap: var(--spacing-sm);
        padding-right: 0;
        padding-bottom: var(--spacing-sm);
        border-right: none;
        border-bottom: 1px dashed rgba(232, 228, 240, 0.25);
    }
    .dg-missing .dg-label { margin-bottom: 0; }
    .dg-card--small { width: 44px; height: 62px; }
    .dg-card--small .dg-card__value { font-size: 1rem; }
    .dg-card--small .dg-card__suit { font-size: 0.75rem; }
    .dg-slots { gap: var(--spacing-xs); }
    .dg-slot { width: 84px; }
    .dg-card { width: 70px; height: 98px; }
    .dg-hcard { width: 58px; height: 82px; }
    .dg-hcard__v { font-size: 1.3rem; }
    .dg-hcard__s { font-size: 1rem; }
    .dg-hand__cards { min-height: 100px; }
}
