﻿:root {
  --felt-1: #0d5c30;
  --felt-2: #0a4a27;
  --felt-3: #1e7a45;
  --line: #d9c27a;
  --panel: rgba(6, 20, 12, 0.72);
  --text: #f6f0dd;
  --accent: #ffd166;
  --danger: #ff7a7a;
  --card-w: 64px;
  --card-h: 92px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text);
  font-family: "Trebuchet MS", "Lucida Sans", sans-serif;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.08), transparent 35%),
    radial-gradient(circle at 85% 75%, rgba(255, 255, 255, 0.07), transparent 30%),
    linear-gradient(140deg, var(--felt-1), var(--felt-2));
}

.table {
  position: relative;
  min-height: 100vh;
  overflow: visible;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  padding: 14px 14px 24px;
}

.table.lobby-mode .npcs {
  display: none;
}

.table.lobby-mode .center-area {
  margin-top: 0;
  min-height: 220px;
}

.table.lobby-mode .controls,
.table.lobby-mode .player-area {
  display: none;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid rgba(255, 209, 102, 0.3);
  border-radius: 14px;
  padding: 10px 14px;
}

.header-bar h1 {
  margin: 0;
  letter-spacing: 1px;
}

.online-panel {
  background: rgba(4, 17, 10, 0.72);
  border: 1px solid rgba(255, 209, 102, 0.26);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.online-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.online-row input {
  min-width: 130px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.8rem;
}

.online-row input::placeholder {
  color: rgba(246, 240, 221, 0.65);
}

.online-status {
  font-size: 0.82rem;
  color: #ffe6a4;
}

.online-status.error {
  color: #ffb0b0;
}

.online-players {
  font-size: 0.78rem;
  color: #f6f0dd;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.online-chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.deck-info {
  font-size: 0.95rem;
  text-align: center;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

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

.npcs {
  position: absolute;
  inset: 86px 14px 250px 14px;
  pointer-events: none;
}

.npc {
  position: absolute;
  width: 172px;
  background: rgba(5, 20, 11, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 8px;
  font-size: 0.9rem;
}

.npc-top-left {
  top: 0;
  left: 2%;
}

.npc-top {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.npc-top-right {
  top: 0;
  right: 2%;
}

.npc-right {
  top: 40%;
  right: 0;
}

.npc-hand {
  display: flex;
  margin-top: 8px;
}

.back-card {
  width: 26px;
  height: 38px;
  margin-left: -12px;
  border-radius: 4px;
  border: 1px solid #c5a753;
  background:
    linear-gradient(135deg, #442600, #7f5025),
    repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255, 255, 255, 0.08) 4px, rgba(255, 255, 255, 0.08) 8px);
}

.npc .back-card:first-child {
  margin-left: 0;
}

.center-area {
  margin-top: 90px;
  background: rgba(5, 20, 11, 0.58);
  border: 1px solid rgba(255, 209, 102, 0.26);
  border-radius: 16px;
  padding: 12px;
  min-height: 360px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  overflow: visible;
}

.turn-status {
  font-weight: 700;
}

.table-melds {
  position: relative;
  min-height: 260px;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
}

.table-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.8;
}

.meld {
  position: absolute;
  left: var(--pile-x, 50%);
  top: var(--pile-y, 50%);
  transform: translate(-50%, -50%) rotate(var(--pile-r, 0deg));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 6px 6px 5px;
  background: rgba(0, 0, 0, 0.16);
  cursor: pointer;
  z-index: var(--pile-z, 1);
  backdrop-filter: blur(1px);
}

.meld.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.3);
  z-index: 40;
}

.meld-title {
  font-size: 0.72rem;
  margin-bottom: 4px;
  color: #ffe6a4;
  line-height: 1.1;
  opacity: 0.9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.meld-cards {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  overflow: visible;
  padding-bottom: 1px;
}

.card {
  width: 48px;
  height: 69px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  margin-right: -29px;
  flex: 0 0 auto;
  transform: translateY(var(--fan-y, 0px)) rotate(var(--fan-r, 0deg));
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.meld-cards .card:last-child {
  margin-right: 0;
}

.meld-cards .card:hover {
  transform: translateY(calc(var(--fan-y, 0px) - 4px)) rotate(var(--fan-r, 0deg));
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.log {
  display: none;
  min-height: 48px;
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 8px;
}

.controls {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selection-info {
  color: #fff6db;
  font-size: 0.86rem;
}

.rules-note {
  color: #f7d9a1;
  font-size: 0.8rem;
  line-height: 1.25;
}

.player-area {
  background: rgba(5, 20, 11, 0.9);
  border: 1px solid rgba(255, 209, 102, 0.35);
  border-radius: 14px;
  padding: 10px;
}

.player-area h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.player-hand {
  display: flex;
  align-items: flex-end;
  overflow-x: auto;
  padding-bottom: 4px;
}

.player-card {
  position: relative;
  z-index: 1;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  margin-right: -30px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  background: rgba(255, 255, 255, 0.07);
}

.player-card:last-child {
  margin-right: 0;
}

.player-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.player-card:hover {
  transform: translateY(-6px);
  z-index: 1;
}

.player-card.selected {
  transform: translateY(-12px);
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 1;
}

.player-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dead {
  color: var(--danger);
}

.winner {
  color: #90ff90;
}

.winner-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(2, 8, 5, 0.72);
  z-index: 120;
}

.winner-modal.show {
  display: flex;
}

.winner-modal-card {
  width: min(520px, 100%);
  background: linear-gradient(160deg, rgba(6, 26, 15, 0.96), rgba(4, 14, 9, 0.96));
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
  padding: 16px;
}

.winner-modal-card h2 {
  margin: 0 0 8px;
  color: #ffe6a4;
}

.winner-subtitle {
  margin: 0 0 10px;
  color: #f6f0dd;
}

.winner-detail {
  max-height: 240px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
}

.winner-line {
  margin: 0 0 4px;
}

.winner-line:last-child {
  margin-bottom: 0;
}

.winner-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.controls button {
  font-size: 0.82rem;
  padding: 6px 10px;
}

@media (max-width: 900px) {
  .npcs {
    inset: 76px 8px 230px 8px;
  }

  .npc {
    width: 136px;
    font-size: 0.78rem;
    padding: 6px;
  }

  .npc-top {
    left: 50%;
    transform: translateX(-50%);
  }

  .npc-right {
    top: 38%;
    right: 0;
  }

  .center-area {
    margin-top: 78px;
    padding: 8px;
    min-height: 320px;
  }

  .table-melds {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 33vh;
    overflow-y: auto;
  }

  .meld {
    position: static;
    left: auto;
    top: auto;
    transform: none;
    z-index: auto;
  }

  .meld-cards {
    overflow-x: auto;
    padding-bottom: 3px;
    padding-right: 10px;
  }

  .player-card {
    width: 54px;
    height: 78px;
    margin-right: -22px;
  }
}
