/* Compact typography polish for short embedded mobile browsers (e.g., Telegram / iMessage / Safari iOS sheets) */
@media (max-height: 640px) and (max-width: 959px) {
  .opp-status-bar { min-height: 12px; }
  .opp-name { font-size: 11px; }
  .opp-score-pill { font-size: 10.5px; padding: 1px 5px; }
  .opp-total-pill { font-size: 9.5px; padding: 1px 4px; }
  .opp-count-badge, .opp-warning-badge, .opp-danger-badge, .opp-closer-badge, .opp-action-badge, .opp-setup-badge {
    font-size: 8.5px;
    padding: 1px 4px;
  }
  .pile-counter { font-size: 9.5px; padding: 1px 5px; }
  .pile-deck-stack .card-pip { display: none; }
  .held-card-tray { padding: 5px 8px; gap: 7px; }
  .held-mini-slot { width: 34px; height: 48px; }
  .held-headline { font-size: 12px; }
  .held-hint { font-size: 10px; }
  .tray-btn { padding: 6px 9px; min-height: 32px; font-size: 11.5px; }
  .player-tag-name { font-size: 12px; }
  .player-revealed-stat { font-size: 11px; }
  .player-revealed-stat #playerRevealedScore { font-size: 13.5px; }
  .triple-clear-pill, .negative-clear-pill, .flip-target-pill, .last-card-pill {
    font-size: 8px;
    padding: 1px 4px;
  }
}

/* Mobile Landscape / Very Short Wide Windows (e.g. rotated phones 667x375, 844x390): Side-by-side 2-column arena */
@media (max-height: 520px) and (min-width: 520px) and (max-width: 959px) {
  #app {
    max-width: none;
    --hdr-h: 36px;
    --opp-row-h: clamp(18px, calc((var(--avail-h) - 190px) * 0.12), 28px);
    --opp-col-w: clamp(22px, calc(var(--opp-row-h) * 0.9), 30px);
    --pile-h: clamp(54px, calc((var(--avail-h) - 180px) * 0.42), 84px);
    --coach-h: 26px;
    --player-hdr-h: 20px;
    --player-pad-y: 5px;
    --player-pad-b: 6px;
    --player-gap: 4px;
    --slot-pad: 2.5px;
    --max-grid-h: max(120px, calc(var(--avail-h) - var(--hdr-h) - var(--coach-h) - var(--player-hdr-h) - 24px));
    --slot-w: clamp(36px, min(78px, calc((var(--avail-w) * 0.56 - 24px) / 4), calc((var(--max-grid-h) / 3 - var(--slot-pad) * 2) / 1.4 + var(--slot-pad) * 2)), 78px);
    --slot-h: calc((var(--slot-w) - var(--slot-pad) * 2) * 1.4 + var(--slot-pad) * 2);
    --avail-w: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    display: grid;
    grid-template-columns: minmax(210px, 44%) minmax(240px, 56%);
    grid-template-rows: var(--hdr-h) auto 1fr;
  }
  #app:has(.opp-tray:only-child) {
    --opp-row-h: clamp(20px, calc((var(--avail-h) - 180px) * 0.13), 30px);
    --opp-col-w: clamp(24px, calc(var(--opp-row-h) * 0.9), 32px);
  }
  header {
    grid-column: 1 / -1;
    grid-row: 1;
    padding: 2px 12px;
  }
  .opponents-section {
    grid-column: 1;
    grid-row: 2;
    padding: 4px 8px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
  .table-center {
    grid-column: 1;
    grid-row: 3;
    padding: 4px 8px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
  .player-section {
    grid-column: 2;
    grid-row: 2 / 4;
    border-radius: 0;
    border-top: none;
    box-shadow: none;
    justify-content: center;
    padding: 5px 10px 6px;
  }
  .coach-bar, .player-header {
    max-width: max(220px, calc(4 * var(--slot-w) + 8px));
  }
}

/* ==========================================================================
   TABLET & WIDESCREEN DESKTOP CARD TABLE LAYOUT
   ========================================================================== */
@media (hover: hover) and (pointer: fine) {
  .nav-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.28);
    color: #fff;
    transform: translateY(-1px);
  }
  .friends-pill-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
  }
  .game-card.clickable:hover:not(.column-clearing):not(.just-flipped):not(.drag-drop-hover) {
    transform: translateY(-3px) scale(1.025);
    box-shadow: var(--shadow-lift);
  }
  .pile-unit:hover .pile-deck-stack .game-card.clickable {
    transform: translateY(-3px) scale(1.03);
    box-shadow: var(--shadow-lift);
  }
  .pile-unit:hover .discard-pile-stack #discardPileCard.clickable:not(.empty-pile-slot) {
    transform:
      translate(
        calc(var(--throw-x, 0px) * var(--pile-scatter, 1)),
        calc(var(--throw-y, 0px) * var(--pile-scatter, 1) - 3px)
      )
      rotate(calc(var(--throw-rot, 0deg) * 0.45))
      scale(1.035);
    box-shadow: var(--shadow-lift);
  }
}

/* Tablet / Medium Window (640px - 959px): Full-width header, unclipped opponents, framed player mat */
@media (min-width: 640px) and (max-width: 959px) and (min-height: 521px) {
  #app {
    max-width: none;
    --avail-w: min(440px, calc(100vw - 32px));
    padding-bottom: 10px;
  }
  header {
    height: var(--hdr-h);
    padding: 6px 24px;
  }
  .opponents-section {
    background: transparent;
    border-bottom: none;
    padding: var(--opp-sec-pad-y) 20px 4px;
    gap: 12px;
  }
  .player-section {
    width: calc(100% - 32px);
    max-width: 440px;
    margin: 0 auto;
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: var(--player-pad-y) 18px var(--player-pad-b);
  }
}

/* Desktop Widescreen Card Table (960px+): Full-table sightlines, 4 opponents side-by-side, side-by-side Deck & Hand arena */
@media (min-width: 960px) {
  body {
    background:
      radial-gradient(ellipse at 50% 0%, rgba(30, 58, 95, 0.35) 0%, transparent 60%),
      radial-gradient(circle at 50% 55%, #162133 0%, #090d15 100%);
  }

  #app {
    max-width: none;
    width: 100%;
    height: 100%;
    --hdr-h: clamp(46px, calc(var(--avail-h) * 0.072), 58px);
    --opp-row-h: clamp(26px, calc((var(--avail-h) - 240px) * 0.088), 48px);
    --opp-col-w: clamp(28px, calc(var(--opp-row-h) * 0.92), 44px);
    --pile-h: clamp(78px, calc((var(--avail-h) - 200px) * 0.2), 120px);
    --coach-h: clamp(34px, calc((var(--avail-h) - 260px) * 0.09), 44px);
    --player-hdr-h: clamp(22px, calc(var(--avail-h) * 0.036), 28px);
    --slot-pad: clamp(3px, calc(var(--avail-h) * 0.0055), 4.5px);
    --slot-w: clamp(44px, calc((var(--avail-h) - var(--hdr-h) - (3 * var(--opp-row-h) + 84px) - var(--coach-h) - var(--player-hdr-h) - 68px) / 4.25), 92px);
    --slot-h: calc((var(--slot-w) - var(--slot-pad) * 2) * 1.4 + var(--slot-pad) * 2);
    display: grid;
    grid-template-columns: minmax(20px, 1fr) minmax(340px, 410px) minmax(380px, 476px) minmax(20px, 1fr);
    grid-template-rows: var(--hdr-h) minmax(4px, 0.75fr) auto auto minmax(6px, 1.25fr);
    column-gap: 28px;
    row-gap: 0;
    padding-bottom: 0;
    align-items: center;
  }
  #app:has(.opp-tray:only-child) {
    --opp-row-h: clamp(28px, calc((var(--avail-h) - 240px) * 0.095), 52px);
    --opp-col-w: clamp(32px, calc(var(--opp-row-h) * 0.92), 48px);
  }

  /* Unified Luxury Casino Felt Arena spanning Deck Station + Player Hand */
  #app::before {
    content: "";
    grid-column: 2 / 4;
    grid-row: 4;
    align-self: stretch;
    border-radius: 30px;
    background:
      radial-gradient(ellipse at 32% 48%, rgba(16, 114, 88, 0.25) 0%, rgba(18, 30, 48, 0.82) 56%, rgba(12, 18, 30, 0.95) 100%);
    border: 1.5px solid rgba(245, 158, 11, 0.28);
    box-shadow:
      inset 0 0 0 6px rgba(9, 14, 24, 0.52),
      inset 0 0 0 7px rgba(255, 255, 255, 0.06),
      inset 0 24px 56px rgba(0, 0, 0, 0.36),
      0 24px 58px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 0;
  }

  header {
    grid-column: 1 / -1;
    grid-row: 1;
    height: var(--hdr-h);
    padding: 0 max(28px, calc(50vw - 560px));
    background: rgba(11, 16, 26, 0.88);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  }

  .brand {
    gap: 10px;
  }
  .brand-crest {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }
  .brand-crest svg {
    width: 18px;
    height: 18px;
  }
  .brand-title {
    font-size: 16px;
    letter-spacing: 0.06em;
  }
  .round-pill {
    font-size: 11.5px;
  }
  .header-actions {
    gap: 8px;
  }
  .nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }
  .friends-pill-btn {
    height: 36px;
    padding: 0 14px;
    font-size: 12.5px;
    border-radius: 10px;
  }

  /* Opponents Row: All 1-4 seats displayed cleanly across the top of the table */
  .opponents-section {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-content: center;
    overflow-x: visible;
    background: transparent;
    border-bottom: none;
    padding: 0 28px;
    margin-bottom: clamp(6px, calc((var(--avail-h) - 520px) * 0.05), 14px);
    gap: 16px;
    z-index: 2;
  }
  .opp-tray,
  .opponents-section:has(.opp-tray:only-child) .opp-tray {
    flex: 0 1 232px;
    min-width: 196px;
    max-width: 244px;
    margin: 0 !important;
    padding: clamp(6px, calc((var(--avail-h) - 520px) * 0.02 + 5px), 10px) 12px;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(26, 37, 56, 0.95), rgba(15, 22, 35, 0.96));
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  }
  .opp-name {
    font-size: 13.5px;
  }
  .opp-total-pill {
    font-size: 11px;
    padding: 2px 6px;
  }
  .opp-score-pill {
    font-size: 12.5px;
    padding: 2px 8px;
  }
  .opp-mini-card {
    font-size: 15px;
    border-radius: 6px;
  }

  /* Left Side of Felt Arena: Center Deck & Discard Station */
  .table-center {
    grid-column: 2;
    grid-row: 4;
    align-self: stretch;
    justify-content: center;
    padding: 22px 24px 22px 32px;
    z-index: 2;
  }
  .table-center::after {
    content: "";
    position: absolute;
    right: -14px;
    top: 13%;
    bottom: 13%;
    width: 1px;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.13) 50%, transparent);
    pointer-events: none;
  }

  .piles-layout {
    gap: 36px;
    margin-bottom: clamp(54px, calc((var(--avail-h) - 520px) * 0.16 + 48px), 82px);
  }
  /* Keep both piles 100% crisp & unblurred on desktop since Held Tray / Results Bar docks cleanly below them */
  .piles-layout.piles-holding,
  .piles-layout.piles-peeking,
  .piles-layout.dragging-reveal-discard {
    transform: none !important;
    opacity: 1 !important;
    filter: none !important;
    pointer-events: auto;
  }
  .pile-unit {
    gap: 8px;
  }
  .pile-tag {
    font-size: 11.5px;
    letter-spacing: 0.06em;
  }
  .pile-deck-stack {
    height: var(--pile-h);
    width: calc(var(--pile-h) / 1.4);
  }
  .pile-deck-stack .card-numeral {
    font-size: clamp(26px, calc(var(--pile-h) * 0.34), 40px);
  }
  .pile-counter {
    font-size: 12px;
    padding: 2px 8px;
  }

  /* Dedicated Held-Card / Round-Results Docking Bay below the Piles (0px layout shift, zero pile occlusion) */
  .held-card-tray,
  .round-results-bar {
    left: calc(50% + 4px);
    top: calc(50% + clamp(58px, calc(var(--pile-h) * 0.72), 84px));
    width: calc(100% - 36px);
    max-width: 368px;
    padding: 9px 13px;
    border-radius: 16px;
  }
  .held-headline {
    white-space: nowrap;
  }

  /* Right Side of Felt Arena: Seamless Player Hand directly on the Casino Felt */
  .player-section {
    grid-column: 3;
    grid-row: 4;
    align-self: center;
    margin: 0;
    padding: clamp(10px, calc((var(--avail-h) - 540px) * 0.06 + 8px), 20px) 32px clamp(10px, calc((var(--avail-h) - 540px) * 0.06 + 8px), 20px) 10px;
    gap: clamp(6px, calc((var(--avail-h) - 540px) * 0.025 + 5px), 10px);
    border-radius: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    z-index: 2;
  }

  .grid-container {
    max-width: calc(4 * var(--slot-w));
  }
  .grid-container .card-numeral {
    font-size: clamp(22px, calc(var(--slot-w) * 0.4), 36px);
  }

  .coach-bar {
    max-width: max(300px, calc(4 * var(--slot-w)));
    font-size: 12.5px;
    border-radius: 12px;
  }
  .player-header {
    max-width: max(300px, calc(4 * var(--slot-w)));
    height: var(--player-hdr-h);
    min-height: var(--player-hdr-h);
    max-height: var(--player-hdr-h);
  }
  .player-tag-name {
    font-size: 14.5px;
    max-width: 130px;
  }
  .turn-status-badge {
    font-size: 11px;
    padding: 3px 9px;
    max-width: 150px;
  }
  .player-revealed-stat {
    font-size: 13px;
  }
  .player-revealed-stat #playerRevealedScore {
    font-size: 16px;
  }

  .welcome-card {
    max-width: 480px;
    padding: 28px 30px;
  }
}
