:root {
  --bg: #10241d;
  --panel: #f7f8f4;
  --ink: #17201d;
  --muted: #64706a;
  --line: rgba(23, 32, 29, 0.15);
  --felt: #0f6b4e;
  --felt-dark: #084530;
  --red: #d94545;
  --blue: #316fd1;
  --gold: #e0aa3e;
  --card: #fffdf7;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(224, 170, 62, 0.16), transparent 34rem),
    linear-gradient(135deg, #0c1b17, #19342c 54%, #152427);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: #1f3430;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease, box-shadow 140ms ease;
  touch-action: manipulation;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #294a43;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.table-zone {
  display: grid;
  grid-template-rows: auto minmax(460px, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.top-bar,
.hand-panel,
.side-panel section {
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  background: rgba(247, 248, 244, 0.96);
  box-shadow: var(--shadow);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
}

.top-bar p {
  margin-top: 5px;
  color: var(--muted);
}

.room-chip {
  display: grid;
  gap: 2px;
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: right;
  background: #fff;
}

.room-chip span {
  color: var(--muted);
  font-size: 12px;
}

.room-chip strong {
  letter-spacing: 1px;
  font-size: 20px;
}

.table-wrap {
  min-height: 460px;
}

.table-felt {
  position: relative;
  min-height: 100%;
  height: clamp(460px, calc(100vh - 260px), 720px);
  overflow: hidden;
  border: 8px solid #3a271b;
  border-radius: 44px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.08), transparent 36%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 8px),
    var(--felt);
  box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0.06), var(--shadow);
}

.table-felt::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 34px;
  pointer-events: none;
}

.score-board {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 88px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  transform: translateX(-50%);
  background: rgba(6, 42, 30, 0.88);
  color: #fff;
}

.score-board div {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  text-align: center;
}

.score-board div + div {
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.score-board span {
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
}

.score-board strong {
  font-size: 22px;
}

.seats {
  position: absolute;
  inset: 0;
}

.seat {
  position: absolute;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: min(210px, 28vw);
  min-height: 70px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  padding: 9px;
  color: #fff;
  background: rgba(7, 37, 29, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  animation: seatIn 180ms ease both;
  transition: opacity 160ms ease, transform 160ms ease, box-shadow 160ms ease, outline-color 160ms ease;
}

.seat.active {
  outline: 3px solid var(--gold);
  box-shadow: 0 0 0 6px rgba(224, 170, 62, 0.16), 0 14px 32px rgba(0, 0, 0, 0.26);
  animation: seatIn 260ms ease both, activeSeatPulse 1350ms ease-in-out infinite;
}

.seat.finished {
  opacity: 0.74;
}

.seat.empty {
  color: rgba(255, 255, 255, 0.78);
  border-style: dashed;
}

.seat-pos-0 {
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
}

.seat-pos-1 {
  right: 22px;
  bottom: 27%;
}

.seat-pos-2 {
  right: 16%;
  top: 72px;
}

.seat-pos-3 {
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
}

.seat-pos-4 {
  left: 16%;
  top: 72px;
}

.seat-pos-5 {
  left: 22px;
  bottom: 27%;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
}

.team-red .avatar,
.tag-red {
  background: var(--red);
}

.team-blue .avatar,
.tag-blue {
  background: var(--blue);
}

.seat-main {
  min-width: 0;
}

.seat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.seat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

.seat-meta span {
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.13);
}

.center-pile {
  position: absolute;
  left: 50%;
  top: 52%;
  display: grid;
  justify-items: center;
  gap: 9px;
  width: min(460px, 68vw);
  transform: translate(-50%, -50%);
  color: #fff;
  text-align: center;
}

.table-message {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.82);
}

.combo-label {
  border-radius: 999px;
  padding: 6px 12px;
  color: #1a241f;
  background: #f7d57b;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.14);
  animation: comboPop 180ms ease both;
}

.current-cards,
.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.card {
  position: relative;
  display: grid;
  align-content: space-between;
  width: 54px;
  height: 76px;
  border: 1px solid rgba(23, 32, 29, 0.18);
  border-radius: 7px;
  padding: 6px;
  color: #111;
  background: var(--card);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
  user-select: none;
  touch-action: manipulation;
  transition: transform 150ms ease, box-shadow 150ms ease, outline-color 150ms ease;
}

.current-cards .card {
  animation: cardLand 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 34ms);
}

.card.red-card {
  color: #c6262e;
}

.card .rank {
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

.card .suit {
  align-self: end;
  justify-self: end;
  font-size: 20px;
  line-height: 1;
}

.card.wild {
  outline: 3px solid #f5bc3d;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22), 0 0 0 4px rgba(245, 188, 61, 0.2);
}

.card.selected {
  transform: translateY(-14px);
  outline: 3px solid #1e8fff;
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.28), 0 0 0 4px rgba(30, 143, 255, 0.16);
}

.hand-panel {
  min-width: 0;
  min-height: 154px;
  overflow: hidden;
  padding: 12px;
}

.hand-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  margin-bottom: 12px;
}

.hand-toolbar span {
  margin-left: 7px;
  color: var(--muted);
}

.actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#playBtn {
  background: var(--red);
}

#passBtn {
  background: var(--blue);
}

#hintBtn {
  color: #1d261f;
  background: var(--gold);
}

.hand {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 92px;
  align-items: flex-end;
  justify-content: flex-start;
  overflow-x: auto;
  padding-top: 16px;
  flex-wrap: nowrap;
}

.hand .card {
  flex: 0 0 auto;
  cursor: pointer;
}

.hand .card.new-card {
  animation: cardDeal 240ms ease both;
  animation-delay: calc(var(--i, 0) * 10ms);
}

.hand .card:hover {
  transform: translateY(-6px);
}

.hand .card.selected:hover {
  transform: translateY(-14px);
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.side-panel section {
  padding: 16px;
}

.join-panel,
.rules-panel,
.tribute-panel,
.history-panel {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.rules-panel ul,
.history-panel ol {
  margin: 0;
  padding-left: 20px;
}

.rules-panel li {
  margin: 7px 0;
  color: #34413c;
  line-height: 1.45;
}

.history-panel ol {
  display: grid;
  gap: 9px;
  max-height: 360px;
  overflow: auto;
}

.tribute-panel[hidden] {
  display: none;
}

.tribute-list {
  display: grid;
  gap: 8px;
}

.tribute-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.tribute-item button {
  min-height: 32px;
  padding: 0 10px;
}

.tribute-note {
  color: var(--muted);
  line-height: 1.45;
}

.history-panel li {
  color: #34413c;
  line-height: 1.35;
}

.history-cards {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.mini-card {
  border: 1px solid rgba(23, 32, 29, 0.14);
  border-radius: 4px;
  padding: 1px 4px;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.mini-card.red-card {
  color: #c6262e;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 32, 29, 0.94);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes seatIn {
  from {
    opacity: 0.72;
  }
  to {
    opacity: 1;
  }
}

@keyframes activeSeatPulse {
  0%,
  100% {
    outline-color: rgba(224, 170, 62, 0.9);
  }
  50% {
    outline-color: rgba(255, 225, 134, 1);
  }
}

@keyframes cardDeal {
  from {
    opacity: 0;
    filter: blur(2px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes cardLand {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes comboPop {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    gap: 10px;
    padding: 8px;
  }

  .top-bar,
  .hand-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-bar {
    gap: 10px;
    padding: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .top-bar p {
    font-size: 13px;
  }

  .room-chip {
    min-width: 0;
    grid-template-columns: auto 1fr;
    align-items: baseline;
    text-align: left;
  }

  .table-zone {
    grid-template-rows: auto auto auto;
    gap: 10px;
  }

  .table-wrap {
    min-height: 430px;
  }

  .table-felt {
    height: clamp(430px, 63vh, 540px);
    border-width: 5px;
    border-radius: 26px;
  }

  .table-felt::after {
    inset: 7px;
    border-radius: 20px;
  }

  .score-board {
    top: 10px;
    grid-template-columns: repeat(3, 64px);
  }

  .score-board div {
    padding: 6px 5px;
  }

  .score-board strong {
    font-size: 18px;
  }

  .score-board span {
    font-size: 11px;
  }

  .seat {
    width: min(138px, 38vw);
    min-height: 52px;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 7px;
    padding: 7px;
  }

  .avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .seat-name {
    font-size: 13px;
  }

  .seat-meta {
    gap: 4px;
    margin-top: 3px;
    font-size: 11px;
  }

  .seat-meta span {
    padding: 1px 5px;
  }

  .seat-meta span:nth-child(n + 3) {
    display: none;
  }

  .seat-pos-0 {
    bottom: 84px;
  }

  .seat-pos-1,
  .seat-pos-5 {
    bottom: 34%;
  }

  .seat-pos-2 {
    right: 6px;
    top: 86px;
  }

  .seat-pos-3 {
    top: 68px;
  }

  .seat-pos-4 {
    left: 6px;
    top: 86px;
  }

  .center-pile {
    top: 53%;
    width: calc(100vw - 46px);
    gap: 7px;
  }

  .table-message {
    max-width: 84vw;
    font-size: 13px;
  }

  .combo-label {
    max-width: 84vw;
    overflow: hidden;
    padding: 5px 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  .card {
    width: 43px;
    height: 62px;
    padding: 5px;
  }

  .card .rank {
    font-size: 14px;
  }

  .card .suit {
    font-size: 18px;
  }

  .current-cards {
    max-width: 84vw;
    gap: 4px;
  }

  .hand-panel {
    position: sticky;
    bottom: 0;
    z-index: 12;
    min-height: 132px;
    margin-inline: -2px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-color: rgba(255, 255, 255, 0.8);
  }

  .hand-toolbar {
    gap: 8px;
    margin-bottom: 6px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .actions button {
    min-width: 0;
    width: 100%;
    padding-inline: 8px;
  }

  .hand {
    min-height: 76px;
    gap: 5px;
    padding-top: 13px;
    padding-bottom: 3px;
    scroll-padding-inline: 10px;
  }

  .hand .card {
    width: 42px;
    height: 60px;
  }

  .side-panel {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .side-panel section {
    padding: 12px;
  }

  .button-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-row button {
    min-width: 0;
  }

  .history-panel ol {
    max-height: 220px;
  }
}

@media (max-width: 420px) {
  .seat {
    width: 124px;
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .avatar {
    width: 30px;
    height: 30px;
  }

  .seat-pos-2,
  .seat-pos-4 {
    top: 92px;
  }

  .seat-pos-1,
  .seat-pos-5 {
    bottom: 32%;
  }

  .current-cards .card {
    width: 38px;
    height: 55px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
  .side-panel {
    grid-template-columns: 1fr;
  }
}
