/**
 * Дурак — glass / aurora, one-screen в центральной колонке.
 */

#durakToastRoot.durak-toast-host {
  position: fixed;
  top: calc(var(--games-safe-top) + 10px);
  right: calc(var(--games-safe-right) + 16px);
  z-index: 520;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - var(--games-safe-left) - var(--games-safe-right) - 32px));
}

.durak-toast {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: rgba(12, 8, 16, 0.92);
  border: 1px solid rgba(167, 139, 250, 0.35);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: none;
  animation: durakToastIn 0.28s ease;
}

@keyframes durakToastIn {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#roomView.is-durak-active .room-col-center {
  position: relative;
  min-height: 0;
  isolation: isolate;
}

#roomView.is-durak-active #gameBoard.games-gameboard,
#roomView.is-durak-active #gameBoard.room-game-board {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

#roomView.is-durak-active .durak-board-root {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.durak-board-root.durak-board--loading {
  pointer-events: none;
  opacity: 0.72;
}

.room-mobile-quick {
  display: none;
  align-items: center;
  gap: 8px;
}

.room-mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 499;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(2px);
}

.room-mobile-backdrop:not([hidden]) {
  display: block;
}

.durak-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 8px 8px;
}

.durak-layout--grid {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.durak-zone {
  border-radius: 14px;
  border: 1px solid rgba(167, 139, 250, 0.18);
  background: linear-gradient(165deg, rgba(99, 102, 241, 0.06), rgba(0, 0, 0, 0.35));
  backdrop-filter: none;
  transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

.durak-zone--active {
  box-shadow:
    0 0 0 1px rgba(139, 92, 246, 0.35),
    0 0 28px rgba(99, 102, 241, 0.22);
  border-color: rgba(167, 139, 250, 0.42);
}

.durak-zone--opp {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  min-height: 72px;
}

.durak-opp-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.durak-opp-name {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.durak-opp-badges {
  font-size: 11px;
  color: var(--muted);
}

.durak-hand-backs {
  display: flex;
  flex-direction: row-reverse;
  margin-left: auto;
}

.durak-card-back {
  width: 36px;
  height: 50px;
  border-radius: 7px;
  margin-right: -22px;
  background:
    #1a1028 url('/assets/cards/kenney-playing-cards/png/card_back.png') center / cover no-repeat;
  border: 1px solid rgba(139, 92, 246, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.durak-hand-backs .durak-card-back:last-child {
  margin-right: 0;
}

.durak-zone--table {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: visible;
}

.durak-deck-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.durak-deck-stack {
  position: relative;
  width: 54px;
  height: 76px;
}

.durak-deck-stack .durak-card-back,
.durak-deck-stack .durak-deck-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 54px;
  height: 76px;
  margin: 0;
}

.durak-deck-stack .durak-deck-layer:nth-of-type(1) {
  transform: translate(0, 0);
  z-index: 0;
}
.durak-deck-stack .durak-deck-layer:nth-of-type(2) {
  transform: translate(2px, -2px);
  z-index: 1;
}
.durak-deck-stack .durak-deck-layer:nth-of-type(3) {
  transform: translate(4px, -4px);
  z-index: 2;
}
.durak-deck-stack .durak-deck-layer:nth-of-type(4) {
  transform: translate(6px, -6px);
  z-index: 3;
}
.durak-deck-stack .durak-deck-layer:nth-of-type(5) {
  transform: translate(8px, -8px);
  z-index: 4;
}

.durak-deck-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: linear-gradient(145deg, #7c3aed, #5b21b6);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.55);
  z-index: 10;
}

.durak-trump-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: -6px;
}

.durak-trump-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.durak-trump-card {
  transform: none;
  transform-origin: center center;
}

.durak-table-pairs {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 18px 20px;
  align-content: center;
  overflow-x: auto;
  overflow-y: visible;
  padding: 10px 8px 12px;
}

.durak-pair {
  position: relative;
  /* Контейнер шире/выше смещения + размера карты — иначе обрезается карта отбоя */
  width: 86px;
  height: 126px;
  flex-shrink: 0;
  overflow: visible;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease;
  animation: none;
}

.durak-pair .playing-card {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 64px;
  height: 92px;
  padding: 6px 7px;
  border-radius: 11px;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease;
}

.durak-pair .playing-card__cr {
  font-size: 13px;
}

.durak-pair .playing-card__mid {
  font-size: 40px;
}

.durak-pair .playing-card--defend {
  left: 18px;
  bottom: 30px;
  z-index: 2;
}

.durak-zone--self {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
}

.durak-self-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  min-height: 108px;
}

.durak-hand-fan {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0 8px 4px;
}

.durak-hand-fan .playing-card {
  margin-left: -36px;
  transition:
    transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.2s ease,
    opacity 0.18s ease;
}

.durak-hand-fan .playing-card:first-child {
  margin-left: 0;
}

.durak-hand-fan button.playing-card {
  display: block;
  font: inherit;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

@media (hover: hover) {
  .durak-hand-fan .playing-card:hover:not(:disabled) {
    transform: translateY(-10px) scale(1.03);
    z-index: 5;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
    will-change: transform;
  }
}

.durak-hand-fan.durak-hand-fan--opp-turn button.playing-card:not(:disabled) {
  opacity: 0.62;
  /* Избегаем тяжёлого фильтра в fan-анимациях */
}

.durak-hand-fan .playing-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.durak-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.durak-actions--await-auto {
  min-height: 8px;
}

.durak-btn {
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  backdrop-filter: none;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    background-color 0.18s ease,
    opacity 0.18s ease,
    box-shadow 0.18s ease;
}

.durak-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.durak-btn--bito {
  border-color: rgba(52, 211, 153, 0.55);
  background: rgba(52, 211, 153, 0.18);
  color: #a7f3d0;
}

.durak-btn--bito:not(:disabled):hover {
  box-shadow: 0 0 24px rgba(52, 211, 153, 0.35);
}

.durak-btn--take {
  border-color: rgba(251, 146, 60, 0.6);
  background: rgba(251, 146, 60, 0.18);
  color: #fed7aa;
}

.durak-btn--take:not(:disabled):hover {
  box-shadow: 0 0 24px rgba(251, 146, 60, 0.32);
}

@keyframes durakBtnPulse {
  0%,
  100% {
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.15);
  }
  50% {
    box-shadow:
      0 0 22px rgba(52, 211, 153, 0.45),
      0 0 36px rgba(99, 102, 241, 0.2);
  }
}

.durak-btn--pulse.durak-btn--bito:not(:disabled) {
  animation: none;
}

@keyframes durakBtnPulseTake {
  0%,
  100% {
    box-shadow: 0 0 12px rgba(251, 146, 60, 0.2);
  }
  50% {
    box-shadow:
      0 0 24px rgba(251, 146, 60, 0.5),
      0 0 32px rgba(234, 88, 12, 0.2);
  }
}

.durak-btn--pulse.durak-btn--take:not(:disabled) {
  animation: none;
}

/* Карты (CSS) */
.playing-card {
  width: 56px;
  height: 80px;
  border-radius: 10px;
  background: linear-gradient(165deg, #ffffff 0%, #f8f6ff 100%);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.25),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 5px 6px;
  font-family: Inter, sans-serif;
  user-select: none;
  cursor: pointer;
  color: #0a0a0a;
  position: relative;
  overflow: hidden;
  transition:
    transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.2s ease,
    opacity 0.18s ease;
  transform: translateZ(0);
}

.playing-card--red {
  color: #ff453a;
}

.playing-card__asset {
  position: absolute;
  inset: 1px;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #fff;
  border-radius: inherit;
  pointer-events: none;
  user-select: none;
}

.playing-card__fallback {
  display: contents;
}

.playing-card--asset-loaded .playing-card__fallback {
  display: none;
}

.playing-card--asset-error .playing-card__fallback {
  display: contents;
}

.playing-card__cr {
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.playing-card__cr--br {
  transform: rotate(180deg);
  align-self: end;
  justify-self: end;
}

.playing-card__mid {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  line-height: 1;
}

.durak-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 4, 10, 0.72);
  backdrop-filter: none;
  border-radius: inherit;
}

.durak-overlay-box {
  max-width: 360px;
  width: 100%;
  padding: 22px;
  text-align: center;
  border-radius: 16px;
  border: 1px solid rgba(167, 139, 250, 0.28);
  background: linear-gradient(165deg, rgba(99, 102, 241, 0.14), rgba(0, 0, 0, 0.5));
}

.durak-overlay-box h3 {
  font-size: 17px;
  margin-bottom: 10px;
  color: var(--accent-color);
}

.durak-overlay-box p {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.45;
}

@media (max-width: 699px) {
  .room-mobile-backdrop {
    top: var(--games-top-offset);
    right: calc(var(--games-shell-pad-right) + var(--games-safe-right));
    bottom: var(--games-bottom-offset);
    left: calc(var(--games-shell-pad-left) + var(--games-safe-left));
    border-radius: 18px;
  }

  #roomView.is-durak-active {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  #roomView.is-durak-active .layout-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
    grid-template-columns: unset;
    grid-template-rows: unset;
  }

  #roomView.is-durak-active .room-col-center {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    order: 0;
    width: 100%;
    overflow: hidden;
  }

  #roomView.is-durak-active .room-center-toolbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  #roomView.is-durak-active .room-mobile-quick {
    display: flex;
    margin-left: auto;
    margin-right: 4px;
  }

  #roomView.is-durak-active .room-col-left {
    position: fixed;
    left: calc(var(--games-shell-pad-left) + var(--games-safe-left));
    top: var(--games-top-offset);
    bottom: var(--games-bottom-offset);
    width: min(88vw, 380px);
    max-width: 100%;
    z-index: 500;
    transform: translateX(-105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: auto;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  #roomView.is-durak-active .room-col-chat {
    position: fixed;
    right: calc(var(--games-shell-pad-right) + var(--games-safe-right));
    top: var(--games-top-offset);
    bottom: var(--games-bottom-offset);
    width: min(88vw, 380px);
    max-width: 100%;
    z-index: 500;
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: auto;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
  }

  #roomView.is-durak-active.room-mobile-panel-left .room-col-left {
    transform: translateX(0);
  }

  #roomView.is-durak-active.room-mobile-panel-right .room-col-chat {
    transform: translateX(0);
  }

  #roomView.is-durak-active #gameBoard.games-gameboard,
  #roomView.is-durak-active #gameBoard.room-game-board {
    overflow: auto;
    padding-bottom: calc(10px + var(--games-safe-bottom));
  }

  #roomView.is-durak-active .durak-board-root {
    overflow: visible;
  }

  .durak-layout {
    gap: 6px;
    padding: 4px 4px 0;
  }

  .durak-zone--opp {
    gap: 8px;
    padding: 8px 10px;
    min-height: 60px;
  }

  .durak-card-back {
    width: 30px;
    height: 42px;
    margin-right: -18px;
  }

  .durak-zone--table {
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
    padding: 6px 8px;
    overflow-y: hidden;
  }

  .durak-deck-block {
    gap: 4px;
  }

  .durak-deck-stack {
    width: 44px;
    height: 62px;
  }

  .durak-deck-stack .durak-card-back,
  .durak-deck-stack .durak-deck-layer {
    width: 44px;
    height: 62px;
  }

  .durak-table-pairs {
    gap: 12px 10px;
    align-content: flex-start;
    padding: 4px 2px 8px;
  }

  .durak-pair {
    width: 72px;
    height: 106px;
  }

  .durak-pair .playing-card {
    width: 54px;
    height: 78px;
    padding: 5px 6px;
  }

  .durak-pair .playing-card__cr {
    font-size: 11px;
  }

  .durak-pair .playing-card__mid {
    font-size: 32px;
  }

  .durak-pair .playing-card--defend {
    left: 14px;
    bottom: 22px;
  }

  .durak-hand-fan .playing-card {
    margin-left: -40px;
    width: 46px;
    min-height: 68px;
    flex-shrink: 0;
  }

  .durak-self-row {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    min-height: 88px;
  }

  .durak-zone--self {
    gap: 6px;
    padding: 8px 8px calc(8px + var(--games-safe-bottom));
  }

  .durak-hand-fan {
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 2px 2px;
    scrollbar-width: none;
  }

  .durak-hand-fan::-webkit-scrollbar {
    display: none;
  }

  .durak-actions {
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .durak-btn {
    min-height: 44px;
    padding: 9px 12px;
  }
}

@media (max-width: 430px) {
  #durakToastRoot.durak-toast-host {
    right: calc(var(--games-safe-right) + 12px);
    left: calc(var(--games-safe-left) + 12px);
    max-width: none;
  }

  .durak-zone--opp {
    min-height: 56px;
    padding: 7px 8px;
  }

  .durak-zone--table {
    gap: 8px;
    padding: 6px;
  }

  .durak-table-pairs {
    gap: 10px 8px;
  }

  .durak-pair {
    width: 68px;
    height: 100px;
  }

  .durak-pair .playing-card {
    width: 50px;
    height: 74px;
  }

  .durak-pair .playing-card--defend {
    left: 12px;
    bottom: 20px;
  }

  .durak-hand-fan .playing-card {
    margin-left: -38px;
    width: 44px;
    min-height: 64px;
  }

  .durak-btn {
    font-size: 12px;
    padding: 8px 10px;
  }
}

/* Dark Glassmorphism — тема колоды (#durakBoard) */
#durakBoard.durak-board-root.durak-deck-theme--glass .playing-card {
  background: linear-gradient(
    155deg,
    rgba(28, 24, 38, 0.82) 0%,
    rgba(12, 10, 20, 0.72) 45%,
    rgba(22, 18, 32, 0.88) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: rgba(248, 246, 255, 0.96);
}

#durakBoard.durak-board-root.durak-deck-theme--glass .playing-card--red {
  color: rgba(255, 120, 132, 0.95);
  text-shadow: 0 0 12px rgba(255, 80, 100, 0.25);
}

#durakBoard.durak-board-root.durak-deck-theme--glass .playing-card__mid {
  filter: none;
}

#durakBoard.durak-board-root.durak-deck-theme--glass .durak-card-back {
  background: linear-gradient(
    128deg,
    rgba(18, 12, 32, 0.95) 0%,
    rgba(8, 6, 16, 0.9) 50%,
    rgba(26, 18, 44, 0.92) 100%
  );
  border: 1px solid rgba(167, 139, 250, 0.28);
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#durakBoard.durak-board-root.durak-deck-theme--glass .durak-deck-stack .durak-card-back {
  background: repeating-linear-gradient(
    -18deg,
    rgba(30, 22, 48, 0.92) 0px,
    rgba(30, 22, 48, 0.92) 3px,
    rgba(18, 14, 32, 0.95) 3px,
    rgba(18, 14, 32, 0.95) 6px
  );
}

#durakBoard.durak-board-root.durak-deck-theme--glass .durak-trump-card.playing-card {
  box-shadow:
    0 0 0 1px rgba(167, 139, 250, 0.45),
    0 6px 16px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#durakBoard.durak-board-root.durak-deck-theme--glass .durak-hand-fan button.playing-card:hover:not(:disabled) {
  box-shadow: 0 5px 12px rgba(99, 102, 241, 0.16);
  border-color: rgba(255, 255, 255, 0.2);
}

@media (prefers-reduced-motion: reduce) {
  .durak-hand-fan .playing-card,
  .playing-card,
  .durak-btn {
    transition: none !important;
  }
}

@supports not (backdrop-filter: blur(1px)) {
  .durak-zone,
  .durak-overlay,
  #durakBoard.durak-board-root.durak-deck-theme--glass .playing-card,
  #durakBoard.durak-board-root.durak-deck-theme--glass .durak-card-back {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
