/* Keep the playing cards readable on phones without changing game rules. */
#durak-card-layer {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  clip-path: inset(100%);
}
#durak-card-layer:empty { display: none; }
.durak-emotes-active .durak-tray { grid-template-columns: 133px minmax(0, 1fr); }
.durak-emote-layer { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
.durak-emote-layer [hidden] { display: none; }
.durak-emote-trigger, .durak-emote-picker, .durak-emote-bubble { position: absolute; }
.durak-emote-trigger, .durak-emote-picker { pointer-events: auto; }
.durak-emote-trigger {
  display: flex; align-items: center; gap: 5px; min-height: 44px; padding: 0 8px; border: 1px solid #adbdfe;
  border-radius: 12px; background: #edf1ff; color: #1738b9; font: 750 12px/1 system-ui, sans-serif; cursor: pointer;
}
.durak-emote-trigger span { font-size: 19px; }
.durak-emote-trigger[aria-expanded="true"] { background: #2449e9; color: #fff; }
.durak-emote-picker {
  z-index: 3; width: min(320px, calc(100vw - 24px)); box-sizing: border-box; padding: 10px; border: 1px solid #d4defb;
  border-radius: 18px; background: #fcfdff; color: #171d37; box-shadow: 0 12px 30px #0d1b6452;
}
.durak-emote-picker header { display: flex; align-items: center; justify-content: space-between; padding-left: 3px; font-weight: 750; }
.durak-emote-picker button { border: 0; color: inherit; cursor: pointer; }
.durak-emote-picker header button { width: 44px; height: 44px; border-radius: 12px; background: transparent; font-size: 24px; }
.durak-emote-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.durak-emote-options button {
  display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 67px; padding: 3px;
  border-radius: 12px; background: transparent; text-align: center; font: 650 10px/1.1 system-ui, sans-serif;
}
.durak-emote-picker button:hover { background: #e0e7ff; }
.durak-emote-layer button:focus-visible { outline: 2px solid #1748f8; outline-offset: 2px; }
.durak-emote-layer img { display: block; width: 100%; object-fit: contain; pointer-events: none; }
.durak-emote-layer picture { display: block; width: 100%; min-width: 0; }
.durak-emote-options img { height: 39px; }
.durak-emote-bubble {
  display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; width: clamp(58px, 17vw, 74px);
  height: clamp(58px, 17vw, 74px); animation: durak-emote-pop 180ms ease-out both;
}
.durak-emote-bubble img { height: 100%; filter: drop-shadow(0 3px 3px #0e195e70); }
.durak-emote-announcement { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
@keyframes durak-emote-pop { from { opacity: .2; transform: translateY(5px) scale(.85); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .durak-emote-bubble { animation: none; } }

.durak-live {
  grid-template-rows: auto auto minmax(min-content, 1fr) auto;
  align-content: start;
  gap: 5px;
}
.durak-live .durak-status .eyebrow { margin: 0; font-size: 10px; }
.durak-live .durak-status h1 { margin: 3px 0 0; font-size: clamp(20px, 5.5vw, 28px); }
.durak-live .durak-opponents { padding-top: 3px; }
.durak-live .durak-opponents:has(.ward-hat) { padding-top: 10px; }
.durak-opponent > strong, .durak-self h2 {
  padding: 6px 5px;
  margin-block: -6px;
}
.durak-player-badge { display: grid; }
.durak-finish .ward-game-list { margin: 8px 0 16px; }
@media (max-width: 480px) {
  .durak-live .durak-opponent { flex: 1 1 0; max-width: 106px; }
}
.durak-live .durak-table {
  --table-tools-height: 70px;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: var(--table-tools-height) minmax(min-content, 1fr);
  align-self: stretch;
  align-content: start;
  gap: 12px;
  min-height: 0;
  padding: 8px 14px 4px;
}
.durak-live .durak-pairs,
.durak-live .durak-empty { grid-column: 1 / -1; grid-row: 2; align-self: end; }
.durak-live .durak-pairs {
  grid-template-columns: repeat(3, minmax(0, 134px));
  justify-content: center;
  gap: 18px 14px;
  width: 100%;
  padding-top: 5px;
}
.durak-live .durak-table[data-pair-count="1"] .durak-pairs { grid-template-columns: minmax(0, 134px); }
.durak-live .durak-table[data-pair-count="2"] .durak-pairs { grid-template-columns: repeat(2, minmax(0, 134px)); }
.durak-live .durak-pair { width: 100%; max-width: none; padding: 0 14px 24px 0; }
.durak-live .durak-pair:only-child { grid-column: 1; }
.durak-live .durak-cover-card { width: calc(100% - 14px); top: 18px; right: 0; transform: rotate(4deg); }
.durak-live .durak-empty { display: grid; place-items: center; min-height: 174px; margin: 0; }
.durak-live .durak-stock,
.durak-live .durak-discard { display: flex; align-items: center; gap: 9px; }
.durak-live .durak-stock { grid-column: 1; grid-row: 1; justify-self: start; }
.durak-live .durak-discard { grid-column: 2; grid-row: 1; justify-self: end; flex-direction: row-reverse; }
.durak-live .durak-pile-count { font-size: clamp(23px, 6vw, 28px); }
.durak-live .durak-stock-cards { flex: 0 0 50px; width: 50px; height: 66px; aspect-ratio: auto; }
.durak-live .durak-trump-card {
  width: 42px;
  top: 1px;
  left: 3px;
  transform: rotate(-7deg);
}
.durak-live .durak-stock-cards > .durak-card-back {
  inset: 21px 0 auto auto;
  width: 28px;
  height: 42px;
  transform: rotate(9deg);
  border-radius: 5px;
}
.durak-live .durak-trump-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid #e1e7ff;
  border-radius: 13px;
  background: #f4f7ff;
  color: #28334a;
  box-shadow: 0 3px 10px #17265338;
}
.durak-live .durak-trump-badge > span { font-size: 10px; line-height: 1.1; font-weight: 700; }
.durak-live .durak-trump-suit { font-size: 40px; line-height: 1; }
.durak-live .durak-trump-suit.red-trump { color: #bc243e; }
.durak-live .durak-discard-cards { width: 26px; height: 37px; aspect-ratio: auto; }
.durak-live .durak-discard small { font-size: 11px; }
.durak-live .durak-table.durak-drop-ready::before {
  inset: calc(var(--table-tools-height) + 20px) 8px 0;
}

.durak-live .durak-cards {
  --hand-count: 1;
  --hand-gaps: 1;
  --hand-card: clamp(90px, 26vw, 142px);
  --hand-top: 37px;
  /* Percentages here resolve against the hand's inner width, including on rotation. */
  --card-overlap: max(8px, calc((var(--hand-card) * var(--hand-count) - 100%) / var(--hand-gaps)));
  width: 100%;
  height: calc(var(--hand-card) * .75 + var(--hand-top) + 8px);
  align-items: flex-start;
  overflow: hidden;
  padding: var(--hand-top) 20px 0;
}
/* The app CSP disables inline styles, so hand geometry is selected with data attributes. */
.durak-live .durak-cards[data-hand-count="2"] { --hand-count: 2; --hand-gaps: 1; }
.durak-live .durak-cards[data-hand-count="3"] { --hand-count: 3; --hand-gaps: 2; }
.durak-live .durak-cards[data-hand-count="4"] { --hand-count: 4; --hand-gaps: 3; }
.durak-live .durak-cards[data-hand-count="5"] { --hand-count: 5; --hand-gaps: 4; }
.durak-live .durak-cards[data-hand-count="6"] { --hand-count: 6; --hand-gaps: 5; }
.durak-live .durak-cards.many {
  --card-overlap: 31px;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-padding-inline: 20px;
}
.durak-live .durak-cards.many::-webkit-scrollbar { display: none; }
.durak-live .durak-cards:not(.many) li:first-child { --turn: -7deg; --drop: 7px; }
.durak-live .durak-cards:not(.many) li:nth-child(2) { --turn: -3deg; --drop: 2px; }
.durak-live .durak-cards:not(.many) li:nth-last-child(2):nth-child(n + 3) { --turn: 3deg; --drop: 2px; }
.durak-live .durak-cards:not(.many) li:last-child { --turn: 7deg; --drop: 7px; }
.durak-live .durak-cards:not(.many) li:only-child { --turn: 0deg; --drop: 0px; }
.durak-live .durak-cards .durak-card { border-radius: 9px; }
.durak-live .durak-cards .durak-card:not(.durak-drag-source) { opacity: 1; }
.durak-live .durak-cards:not(.many) button[data-action="durak-select"] { touch-action: pinch-zoom; }
.durak-live .durak-cards button.selected {
  transform: translateY(-23px);
  box-shadow: 0 0 0 3px #b9caff, 0 12px 24px #0b1c36a0;
}
.durak-live .durak-tray {
  min-height: calc(88px + env(safe-area-inset-bottom));
  padding-top: 9px;
  padding-bottom: max(9px, env(safe-area-inset-bottom));
}
.durak-live .durak-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: 64px;
}
.durak-live .durak-feedback {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.durak-live .durak-controls:has(.durak-feedback:not([hidden])) .durak-hint { display: none; }
.durak-live .durak-hint + .durak-actions { margin-top: 0; }

@media (max-height: 740px) and (orientation: portrait) {
  .durak-live .durak-table { row-gap: 8px; padding-block: 4px; }
  .durak-live .durak-stock,
  .durak-live .durak-discard { gap: 5px; }
  .durak-live .durak-cards,
  .durak-live .durak-cards.many { --hand-top: 32px; }
}

@media (max-height: 640px) and (orientation: portrait) {
  .durak-page.durak-page--table { height: 100dvh; }
  .durak-page--table .durak-live {
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }
  .durak-page--table .durak-table { overflow-y: auto; }
  /* On short phones put the stock beside a single pair so both cards and the decision fit. */
  .durak-page--table .durak-table[data-pair-count="1"] {
    grid-template-columns: minmax(0, 1fr) minmax(0, clamp(96px, calc(25dvh - 36px), 124px)) minmax(0, 1fr);
    grid-template-rows: minmax(min-content, 1fr);
    gap: 5px;
  }
  .durak-page--table .durak-table[data-pair-count="1"] .durak-stock { flex-direction: column; justify-self: center; }
  .durak-page--table .durak-table[data-pair-count="1"] .durak-discard { grid-column: 3; flex-direction: column; justify-self: center; }
  .durak-page--table .durak-table[data-pair-count="1"] .durak-pairs { grid-area: 1 / 2; align-self: center; }
  .durak-page--table .durak-table[data-pair-count="1"].durak-drop-ready::before { inset: 3px max(4px, calc(50% - 66px)); }
  .durak-live .durak-empty { min-height: 128px; }
  .durak-live .durak-tray { min-height: calc(68px + env(safe-area-inset-bottom)); }
  .durak-live .durak-controls { min-height: 44px; }
}

@media (max-height: 540px) and (orientation: landscape) {
  .durak-live { gap: 2px; }
  .durak-live .durak-table { padding-block: 8px; }
  .durak-live .durak-cards { --hand-card: 95px; --hand-top: 30px; }
}

@media (max-width: 360px) {
  .durak-live .durak-table { padding-inline: 10px; column-gap: 8px; }
  .durak-live .durak-pairs { column-gap: 10px; }
  .durak-live .durak-discard { gap: 5px; }
}

@media (min-width: 720px) {
  .durak-live .durak-pairs { grid-template-columns: repeat(3, minmax(0, 160px)); }
  .durak-live .durak-table[data-pair-count="1"] .durak-pairs { grid-template-columns: minmax(0, 160px); }
  .durak-live .durak-table[data-pair-count="2"] .durak-pairs { grid-template-columns: repeat(2, minmax(0, 160px)); }
}

/* The hand and the opponents keep their own rows. Only the list of pairs can scroll. */
.durak-page--table:has(.durak-table--multi) { height: 100dvh; }
.durak-page--table .durak-live:has(.durak-table--multi) {
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.durak-page--table .durak-table--multi {
  --table-tools-height: 48px;
  grid-template: var(--table-tools-height) minmax(0, 1fr) / auto minmax(0, 1fr) auto;
  padding: 2px clamp(6px, 2vw, 16px) 3px;
  gap: 3px 5px;
  overflow: visible;
}
.durak-table--multi .durak-stock .durak-stock-cards { width: 33px; height: 43px; flex-basis: 33px; }
.durak-table--multi .durak-stock .durak-trump-card { width: 27px; }
.durak-table--multi .durak-stock-cards > .durak-card-back { width: 18px; height: 27px; inset: 15px 0 auto auto; }
.durak-table--multi .durak-stock .durak-trump-suit { font-size: 25px; }
.durak-table--multi .durak-stock .durak-pile-count { font-size: 18px; }
.durak-page--table .durak-table--multi .durak-discard { grid-column: 3; }
.durak-table-scroll {
  grid-area: 1 / 2;
  justify-self: center;
  min-height: 44px;
  padding: 2px 6px;
  background: transparent;
  border: 0;
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.durak-page--table .durak-table--multi .durak-pairs {
  min-height: 0;
  align-self: stretch;
  align-content: safe center;
  align-items: start;
  grid-template-columns: repeat(3, minmax(0, 144px));
  grid-auto-rows: max-content;
  gap: 10px 6px;
  padding: 7px 5px 10px;
  overflow: hidden auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  container-type: size;
}
.durak-table--multi .durak-pairs .durak-pair {
  --offset: clamp(24px, 26%, 40px);
  display: grid;
  padding: 0;
}
/* Both cards contribute to the row height; the left index of the attack stays exposed. */
.durak-table--multi .durak-pair > .durak-card {
  grid-area: 1 / 1;
  position: relative;
  inset: auto;
  align-self: start;
  width: calc(100% - var(--offset));
  transform: rotate(-1deg);
}
.durak-table--multi .durak-pair > .durak-cover-card {
  justify-self: end;
  margin-top: 14px;
  transform: rotate(1.5deg);
}
@media (max-width: 719px) {
  /* Fit two rows when there is room; keep indices legible and scroll otherwise. */
  .durak-table--multi:is([data-pair-count="4"], [data-pair-count="5"], [data-pair-count="6"]) .durak-pair {
    width: min(100%, clamp(84px, 33cqh, 144px));
  }
}
@media (min-width: 720px) {
  .durak-page--table .durak-table--multi .durak-pairs {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 146px);
  }
  .durak-table--multi .durak-pair:nth-child(4):last-child { grid-column: auto; }
}

/* On a horizontal phone keep the opponents beside the table and the controls beside the hand. */
@media (orientation: landscape) and (max-height: 540px) {
  .durak-page--table:has(.durak-table--multi) { min-height: max(350px, 100dvh); }
  .durak-page--table .durak-live:has(.durak-table--multi) {
    grid-template:
      "status table" auto
      "players table" minmax(0, 1fr)
      "hand hand" auto / clamp(125px, 22%, 185px) minmax(0, 1fr);
    gap: 3px 6px;
  }
  .durak-live:has(.durak-table--multi) .durak-status { grid-area: status; padding-inline: 4px; }
  .durak-live:has(.durak-table--multi) .durak-status h1 { font-size: 18px; }
  .durak-live:has(.durak-table--multi) .durak-opponents {
    grid-area: players;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 6px 3px;
    overflow-y: auto;
  }
  .durak-page--table .durak-table--multi { grid-area: table; }
  .durak-live:has(.durak-table--multi) .durak-hand {
    grid-area: hand;
    grid-template-columns: minmax(0, 1fr) minmax(211px, 35%);
    align-items: end;
  }
  .durak-live:has(.durak-table--multi) .durak-tray { min-height: 74px; padding: 5px 8px max(5px, env(safe-area-inset-bottom)); }
  .durak-live:has(.durak-table--multi) .durak-cards { --hand-top: 26px; }
}

@media (orientation: landscape) and (min-width: 620px) and (max-width: 719px) and (max-height: 540px) {
  .durak-page--table .durak-table--multi .durak-pairs {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 136px);
  }
  .durak-table--multi .durak-pairs .durak-pair { width: 100%; }
  .durak-table--multi .durak-pair:nth-child(4):last-child { grid-column: auto; }
}

.durak-check-pair {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
.durak-check-pair:focus-visible {
  outline: 3px solid #b9caff;
  outline-offset: 2px;
}
.durak-pair[data-checked="true"] > .durak-cover-card::after {
  content: '✓' / '';
  position: absolute;
  inset: auto auto 6% 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 1.45em;
  aspect-ratio: 1;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #17644a;
  color: #fff;
  font: 800 clamp(11px, 16cqi, 17px)/1 system-ui, sans-serif;
  pointer-events: none;
}
.durak-challenge-notice {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  margin: 2px auto 0;
  color: #fff;
  font-size: clamp(14px, 3.6vw, 19px);
  line-height: 1.2;
}
.durak-challenge-notice img { flex: none; width: 38px; height: 38px; object-fit: contain; }
@media (orientation: landscape) and (max-height: 540px) {
  .durak-challenge-notice { gap: 3px; font-size: 12px; }
  .durak-challenge-notice img { width: 28px; height: 28px; }
}
