:root {
  color-scheme: light dark;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #e8edf4, #b8c1d4);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1f2430;
}

#app {
  width: min(1100px, 95vw);
  min-height: 80vh;
}

h1, h2, h3 {
  margin: 0;
}

.connection,
.welcome,
.status,
.lobby,
.game {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 24px 28px;
  box-shadow: 0 16px 40px rgba(15, 30, 60, 0.2);
}

.connection p,
.status p {
  margin: 12px 0 0;
  font-size: 1.1rem;
}

.welcome h1 {
  text-align: center;
  margin-bottom: 16px;
}

.panels {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.panel {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 20px;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(30, 40, 80, 0.05);
}

.public-browser {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.public-toggle {
  background: rgba(31, 36, 48, 0.08);
  color: #1f2430;
  border: 1px solid rgba(31, 36, 48, 0.2);
  padding: 8px 22px;
}

.public-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 25, 50, 0.2);
}

.public-list {
  width: min(560px, 95vw);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: 0 18px 36px rgba(20, 30, 60, 0.18);
}

.public-game-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.public-game {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: rgba(67, 100, 247, 0.08);
  border-radius: 14px;
  padding: 12px 16px;
}

.public-game-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.public-game-heading {
  display: flex;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}

.public-game-id {
  font-size: 0.8rem;
  color: rgba(31, 36, 48, 0.65);
  font-weight: 600;
}

.public-game-meta,
.public-game-names {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(31, 36, 48, 0.75);
}

.public-game-names {
  font-size: 0.8rem;
  color: rgba(31, 36, 48, 0.65);
}

.public-join-btn {
  min-width: 92px;
}

.public-error {
  color: #f44336;
  font-weight: 600;
  text-align: center;
}

.public-refresh {
  margin-top: 12px;
}

.public-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: rgba(31, 36, 48, 0.75);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.public-pagination {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.public-page-numbers {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  font-weight: 600;
  gap: 10px;
}

label.checkbox input[type="checkbox"] {
  width: auto;
  height: auto;
  accent-color: #4364f7;
  cursor: pointer;
}

.checkbox-hint {
  font-size: 0.75rem;
  color: rgba(31, 36, 48, 0.6);
  margin: -6px 0 0;
}

input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(60, 70, 100, 0.3);
  font-size: 1rem;
}

button {
  background: linear-gradient(135deg, #4364f7, #6fb1fc);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(67, 100, 247, 0.25);
}

button.danger {
  background: linear-gradient(135deg, #f44336, #ff7a5c);
}

.public-page-btn {
  background: rgba(31, 36, 48, 0.08);
  color: #1f2430;
  border: 1px solid rgba(31, 36, 48, 0.15);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  min-width: 44px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.public-page-btn.nav {
  min-width: 70px;
}

.public-page-btn.active {
  background: linear-gradient(135deg, #4364f7, #6fb1fc);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 20px rgba(67, 100, 247, 0.2);
}

.public-page-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 25, 50, 0.2);
}

.public-page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.messages {
  list-style: none;
  padding: 12px 16px;
  margin: 20px 0 0;
  border-radius: 14px;
  background: rgba(35, 45, 70, 0.08);
  font-size: 0.85rem;
}

.messages li + li {
  margin-top: 6px;
}

.lobby header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.lobby ol {
  padding-left: 18px;
  font-size: 1.1rem;
}

.game header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.game header h1 {
  font-size: 1.6rem;
}

.game .actions {
  display: flex;
  gap: 12px;
}

.layout-shell {
  display: flex;
  gap: 20px;
}

.summary-pane {
  width: 280px;
  background: rgba(255, 255, 255, 0.9);
  border-right: 1px solid rgba(30, 40, 60, 0.1);
  padding: 20px;
  box-shadow: 4px 0 24px rgba(15, 25, 50, 0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
  overflow-y: auto;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.summary-pane h2 {
  font-size: 1.2rem;
}

.summary-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.95rem;
}

.summary-row {
  background: rgba(65, 75, 120, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-row.turn {
  box-shadow: inset 0 0 0 2px rgba(67, 100, 247, 0.4);
}

.summary-row.finished {
  background: rgba(76, 175, 80, 0.18);
}

.summary-row.left {
  background: rgba(244, 67, 54, 0.18);
}

.summary-row .status {
  align-self: flex-start;
  background: linear-gradient(135deg, #4364f7, #6fb1fc);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.summary-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-heading strong {
  font-size: 1rem;
}

.summary-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85rem;
}

.summary-toggle {
  align-self: flex-end;
  background: transparent;
  color: #1f2430;
  border: 1px solid rgba(30, 40, 60, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.summary-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(30, 40, 60, 0.2);
}

.with-summary-visible,
.with-summary-hidden {
  flex: 1 1 auto;
  position: relative;
}

@media (max-width: 980px) {
  .layout-shell {
    flex-direction: column;
  }

  .summary-pane {
    position: relative;
    width: 100%;
    height: auto;
    top: 0;
    box-shadow: none;
    border-right: none;
  }
}

@media (max-width: 560px) {
  .public-game {
    flex-direction: column;
    align-items: stretch;
  }

  .public-game-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .public-join-btn {
    width: 100%;
  }
}

.summary-floating {
  position: fixed;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, #4364f7, #6fb1fc);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(15, 25, 50, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 50;
}

.summary-floating:hover {
  transform: translateY(-50%) translateX(2px);
  box-shadow: 0 16px 32px rgba(15, 25, 50, 0.3);
}

@media (max-width: 980px) {
  .layout-with-summary {
    grid-template-columns: 1fr;
  }

  .summary-pane {
    order: -1;
  }
}


.table-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.table-ring {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.table-middle {
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.table-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.table-side.left {
  align-items: flex-start;
}

.table-side.right {
  align-items: flex-end;
}

.table-ring {
  min-height: 80px;
}

.table-center {
  display: grid;
  gap: 12px;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 18px 36px rgba(20, 30, 60, 0.25);
}

.table-bottom {
  margin-top: 8px;
}

.opponent {
  background: rgba(65, 75, 120, 0.1);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 160px;
  box-shadow: inset 0 0 0 1px rgba(40, 50, 80, 0.05);
}

.opponent.finished {
  background: rgba(76, 175, 80, 0.18);
}

.opponent.left {
  background: rgba(244, 67, 54, 0.18);
}

.pile {
  background: rgba(40, 55, 95, 0.08);
  border-radius: 16px;
  padding: 16px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pile .card.big {
  font-size: 2.4rem;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  background: white;
  border-radius: 18px;
  width: 120px;
  height: 160px;
  box-shadow: 0 10px 24px rgba(10, 20, 40, 0.18);
}

.pile-trail {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  font-size: 1.1rem;
  opacity: 0.8;
  flex-wrap: wrap;
}

.turn-info {
  background: rgba(40, 55, 95, 0.08);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.turn-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.swap-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sort-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.sort-controls button.active {
  box-shadow: inset 0 0 0 2px rgba(67, 100, 247, 0.5);
}

.finish-order {
  margin: 8px 0 0 16px;
  padding: 0;
  font-size: 0.95rem;
}

.hand-zones {
  display: grid;
  gap: 16px;
}

.hand-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.zone h2 {
  margin-bottom: 8px;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 64px;
}

.card {
  width: 60px;
  height: 88px;
  border-radius: 12px;
  background: white;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  box-shadow: 0 6px 16px rgba(10, 20, 40, 0.15);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.card.back {
  background: linear-gradient(135deg, #1c2a52, #455a92);
  color: rgba(255, 255, 255, 0.7);
  align-items: center;
  justify-content: center;
  cursor: default;
}

.card.selected {
  transform: translateY(-6px);
  box-shadow: 0 16px 32px rgba(70, 120, 255, 0.25);
  border: 2px solid rgba(67, 100, 247, 0.6);
}

.card.swap-selected {
  outline: 3px dashed rgba(255, 193, 7, 0.9);
}

.card.face-down-active {
  cursor: pointer;
  outline: 2px solid rgba(255, 193, 7, 0.8);
  box-shadow: 0 12px 24px rgba(255, 193, 7, 0.2);
}

.card .rank {
  font-size: 1.2rem;
  font-weight: 600;
}

.card .suit {
  font-size: 1.4rem;
  text-align: right;
}

.card.red .rank,
.card.red .suit {
  color: #c62828;
}

.card.black .rank,
.card.black .suit {
  color: #1f2430;
}

.card.see-through {
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  border: 1px dashed rgba(31, 36, 48, 0.25);
}

.card.big.see-through {
  background: rgba(255, 255, 255, 0.18);
}

.card-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  margin-right: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}

.pile-trail .card-face:last-child {
  margin-right: 0;
}

.card-face.red {
  color: #c62828;
}

.card-face.black {
  color: #1f2430;
}

.card-face.see-through {
  background: rgba(255, 255, 255, 0.18);
  border: 1px dashed rgba(31, 36, 48, 0.3);
}

.finish-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.finish-dialog,
.rules-dialog {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 20px;
  padding: 28px 32px;
  box-shadow: 0 24px 48px rgba(20, 30, 60, 0.3);
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rules-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.rules-dialog ul {
  margin: 0;
  padding-left: 18px;
  text-align: left;
}

.rules-dialog li + li {
  margin-top: 6px;
}

@media (max-width: 720px) {
  body {
    padding: 24px 12px;
  }

  .panels {
    flex-direction: column;
    align-items: center;
  }

  .summary-floating {
    left: 50%;
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0));
    transform: translateX(-50%);
    padding: 10px 18px;
  }

  .summary-floating:hover {
    transform: translateX(-50%) translateY(-2px);
  }

  .table-middle {
    grid-template-columns: 1fr;
  }

  .table-side {
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }

  .card {
    width: 48px;
    height: 72px;
  }
}
