:root {
  --bg: #f4f1ea;
  --panel: #fffaf2;
  --ink: #1f2a36;
  --accent: #b85c38;
  --accent-2: #2b6f77;
  --ok: #2b8a3e;
  --warn: #b02a37;
  --line: #d8cec0;
  --card-face-a: #ffffff;
  --card-face-b: #f8f5ee;
  --card-line: #b8aa94;
  --muted: #5f6974;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #f3ede2, #e8dfd1);
  color: var(--ink);
}

.title-row {
  position: relative;
  justify-content: center;
  align-items: center;
}

.title-actions {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  justify-content: flex-end;
}

.main-title {
  width: 100%;
  text-align: center;
  margin: 0;
}

.title-divider {
  height: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0 12px;
}

@media (max-width: 760px) {
  .title-row {
    justify-content: space-between;
    align-items: flex-start;
  }
  .main-title {
    width: auto;
    text-align: left;
  }
  .title-actions {
    position: static;
    transform: none;
  }
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

h1, h2, h3 { margin: 0 0 8px; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

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

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1.2fr 1fr;
  grid-template-areas:
    "round hand"
    "log melds";
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "round"
      "hand"
      "log"
      "melds";
  }
}

#gameArea > .card:nth-child(1) { grid-area: round; }
#gameArea > .card:nth-child(2) { grid-area: hand; }
#gameArea > .card:nth-child(3) { grid-area: melds; }
#gameArea > .card:nth-child(4) { grid-area: log; }

.score-bar {
  width: 100%;
}

.scores-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.score-chip {
  white-space: nowrap;
}

.spectators-row {
  margin-top: 8px;
  font-size: 0.95rem;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 7px 10px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: #9c4f31;
}

button.secondary {
  background: var(--accent-2);
  color: white;
  border-color: #235b61;
}

button.ok {
  background: var(--ok);
  color: white;
  border-color: #247533;
}

button.warn {
  background: var(--warn);
  color: white;
  border-color: #8f212c;
}

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

input[type="text"], input[type="number"], select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--panel);
  color: var(--ink);
}

.status {
  display: block;
  gap: 0;
  font-size: 0.95rem;
}

.round-banner {
  display: inline-block;
  background: #efe6d7;
  border: 1px solid #dccfb7;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.pill {
  display: inline-block;
  background: #efe6d7;
  border: 1px solid #dccfb7;
  border-radius: 999px;
  padding: 3px 9px;
  margin-right: 6px;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.cards.hand-pending-reveal {
  position: relative;
}

.hand-reveal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 20, 0.16);
  border-radius: 10px;
  pointer-events: none;
}

.hand-reveal-overlay button {
  pointer-events: auto;
}

.flip-card {
  width: 72px;
  height: 102px;
  perspective: 900px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  animation: handFlipReveal 560ms ease-out forwards;
  animation-delay: var(--flip-delay, 0ms);
}

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-front {
  transform: rotateY(180deg);
}

.flip-back {
  transform: rotateY(0deg);
}

.flip-back .card-back,
.flip-front.playing-card {
  width: 72px;
  height: 102px;
}

@keyframes handFlipReveal {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(180deg);
  }
}

.playing-card {
  position: relative;
  width: 72px;
  height: 102px;
  border: 1px solid var(--card-line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--card-face-a), var(--card-face-b));
  padding: 6px;
  font-weight: 700;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.playing-card.selectable {
  cursor: pointer;
}

.playing-card .corner-top {
  font-size: 0.95rem;
  line-height: 1;
}

.playing-card .corner-bottom {
  font-size: 0.95rem;
  line-height: 1;
  transform: rotate(180deg);
  align-self: flex-end;
}

.playing-card .center {
  text-align: center;
  font-size: 1.4rem;
  line-height: 1;
}

.playing-card.red { color: #af1f2d; }
.playing-card.black { color: #1e2c3f; }

.playing-card input {
  position: absolute;
  top: 4px;
  right: 4px;
}

.playing-card.disabled {
  opacity: 0.7;
}

.playing-card.in-draft-meld {
  box-shadow: 0 0 0 2px rgba(43, 138, 62, 0.42), 0 3px 10px rgba(43, 138, 62, 0.22);
  background: linear-gradient(180deg, #f2fff4, #e2f7e6);
  border-color: #5fa66e;
}

.playing-card.layoff-candidate::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #d11b2c;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 0 6px rgba(209, 27, 44, 0.45);
  pointer-events: none;
}

.playing-card.next-player-layoff-candidate::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #1f6ad6;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 0 6px rgba(31, 106, 214, 0.45);
  pointer-events: none;
}

.pile-area {
  margin-top: 6px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.players-board {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.player-figure {
  position: relative;
  width: 96px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff7ea;
  padding: 6px 6px 8px;
  text-align: center;
}

.player-icons {
  min-height: 18px;
  margin-bottom: 2px;
}

.player-icon {
  display: inline-block;
  font-size: 0.72rem;
  border-radius: 999px;
  border: 1px solid #ccbca3;
  background: #f6ebd9;
  padding: 1px 6px;
  margin: 0 2px;
}

.figure-head {
  position: relative;
  width: 16px;
  height: 16px;
  margin: 0 auto;
  border: 2px solid #41556b;
  border-radius: 50%;
  background: #f8dcc1;
  margin-bottom: -1px;
}

.figure-head.met-head {
  background: #ffe6c8;
}

.figure-head .face-eye {
  position: absolute;
  top: 5px;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #2d3a4c;
}

.figure-head .face-eye.eye-left {
  left: 4px;
}

.figure-head .face-eye.eye-right {
  right: 4px;
}

.figure-head .face-smile {
  position: absolute;
  left: 4px;
  bottom: 3px;
  width: 6px;
  height: 3px;
  border-bottom: 2px solid #2d3a4c;
  border-radius: 0 0 6px 6px;
}

.figure-body {
  position: relative;
  width: 0;
  height: 28px;
  margin: 0 auto;
  border-left: 2px solid #41556b;
}

.figure-body::before,
.figure-body::after {
  content: "";
  position: absolute;
  top: 8px;
  width: 11px;
  border-top: 2px solid #41556b;
}

.figure-body::before { left: -11px; }
.figure-body::after { left: 0; }

.figure-legs {
  position: relative;
  width: 0;
  height: 13px;
  margin: -1px auto 0;
}

.figure-legs span {
  position: absolute;
  top: 0;
  width: 0;
  height: 13px;
  border-left: 2px solid #41556b;
  transform-origin: top;
}

.figure-legs span:first-child { left: -2px; transform: rotate(24deg); }
.figure-legs span:last-child { left: 2px; transform: rotate(-24deg); }

.player-name {
  margin-top: 4px;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-hand-count {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid #ccbca3;
  background: #f6ebd9;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #36495c;
}

.player-figure.you {
  border-color: #1c7c54;
  background: #e9f7ef;
}

.player-figure.met {
  border-color: #b02a37;
  background: #ffe8eb;
}

.player-figure.current {
  box-shadow: 0 0 0 2px rgba(43, 111, 119, 0.28);
}

.pile-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #f7f0e4;
  min-width: 120px;
}

.pile-title {
  font-size: 0.8rem;
  color: #5f6974;
  margin-bottom: 6px;
}

.pile-box .playing-card {
  margin: 0 auto;
}

.pile-box .card-back {
  margin: 0 auto;
}

#lastDiscardTakenBox .mini-discard-card {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 6px;
}

#lastDiscardTakenBox .playing-card {
  width: 52px;
  height: 74px;
  padding: 4px;
}

#lastDiscardTakenBox .playing-card .corner-top,
#lastDiscardTakenBox .playing-card .corner-bottom {
  font-size: 0.68rem;
}

#lastDiscardTakenBox .playing-card .center {
  font-size: 0.9rem;
}

.playing-card.discard-changed {
  animation: discardPulse 450ms ease-out;
}

.playing-card.discard-layoff-hint::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  margin-top: -5px;
  border-radius: 50%;
  background: #1f9d3a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 0 6px rgba(31, 157, 58, 0.45);
  pointer-events: none;
}

@keyframes discardPulse {
  0% {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 0 0 0 rgba(184, 92, 56, 0.35), 0 2px 6px rgba(0,0,0,0.08);
  }
  60% {
    transform: translateY(0) scale(1.01);
    box-shadow: 0 0 0 9px rgba(184, 92, 56, 0), 0 6px 14px rgba(0,0,0,0.15);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  }
}

.card-transfer-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3500;
}

.card-transfer-item {
  position: fixed;
  width: 72px;
  height: 102px;
  left: 0;
  top: 0;
  transform: translate(0, 0) scale(1);
  opacity: 1;
  transition: transform 1000ms ease-in-out, opacity 1000ms ease-in-out;
}

.card-transfer-item .playing-card,
.card-transfer-item .card-back {
  width: 72px;
  height: 102px;
}

.card-back {
  width: 72px;
  height: 102px;
  border-radius: 10px;
  border: 1px solid #41556b;
  background-color: #355c7d;
}

.back-style-1 {
  background:
    linear-gradient(45deg, #355c7d 25%, transparent 25%),
    linear-gradient(-45deg, #355c7d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #355c7d 75%),
    linear-gradient(-45deg, transparent 75%, #355c7d 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
}

.back-style-2 {
  background:
    radial-gradient(circle at 25% 25%, #f5d76e 2px, transparent 3px),
    radial-gradient(circle at 75% 75%, #f5d76e 2px, transparent 3px),
    linear-gradient(#7f1d1d, #7f1d1d);
  background-size: 16px 16px, 16px 16px, 100% 100%;
}

.back-style-3 {
  background:
    linear-gradient(135deg, #0b5d3b 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(225deg, #0b5d3b 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(315deg, #0b5d3b 25%, transparent 25%) 0px 0/16px 16px,
    linear-gradient(45deg, #0b5d3b 25%, transparent 25%) 0px 0/16px 16px,
    #dcefe5;
}

.back-style-4 {
  background:
    repeating-linear-gradient(45deg, #2d3a8c 0 6px, #1f2963 6px 12px);
}

.back-style-5 {
  background:
    radial-gradient(circle, rgba(255,255,255,0.22) 1px, transparent 2px),
    linear-gradient(180deg, #5b2a86, #2e1452);
  background-size: 10px 10px, 100% 100%;
}

.card-back-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card-back-option {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  background: #fff;
  cursor: pointer;
}

.card-back-option.selected {
  border-color: #2b6f77;
  box-shadow: 0 0 0 2px rgba(43, 111, 119, 0.25);
}

.card-back-option .card-back {
  width: 48px;
  height: 66px;
}

.card-back-option .tiny {
  text-align: center;
  margin-top: 3px;
}

.meld-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

#tableMelds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#tableMelds .meld-item {
  margin-bottom: 0;
}

#tableMelds .meld-cards {
  gap: 4px;
}

#tableMelds .playing-card {
  width: 56px;
  height: 80px;
  padding: 4px;
}

#tableMelds .playing-card .corner-top,
#tableMelds .playing-card .corner-bottom {
  font-size: 0.72rem;
}

#tableMelds .playing-card .center {
  font-size: 1rem;
}

@media (max-width: 700px) {
  #tableMelds {
    grid-template-columns: 1fr;
  }
}

.muted { color: #5f6974; }
.log {
  max-height: 260px;
  overflow: auto;
  background: #f7f1e7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.9rem;
}

.log p { margin: 0 0 6px; }
.chat-feed {
  max-height: 140px;
}
.split { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; } }

.draft-item, .meld-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fffdf8;
  margin-bottom: 6px;
}

.tiny { font-size: 0.85rem; }

option.meld-option-eligible {
  color: #1f6ad6;
  font-weight: 700;
}

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

.lobby-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff8ed;
  padding: 8px;
}

.lobby-title {
  font-weight: 700;
}

.lobby-meta {
  font-size: 0.86rem;
  color: #5f6974;
  margin: 4px 0;
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 900px) {
  .leaderboard-list {
    grid-template-columns: 1fr;
  }
}

.leaderboard-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8ed;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.leaderboard-table th,
.leaderboard-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.leaderboard-table th {
  background: #f3ebdf;
}

.leaderboard-table tr:nth-child(even) td {
  background: #fff8ed;
}

.trophy-icon {
  display: inline-block;
  margin-right: 4px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 3000;
}

.modal-card {
  width: min(980px, 100%);
  max-height: 85vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  padding: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
}

.round-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.round-summary-player {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  padding: 8px;
}

.summary-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.summary-line {
  font-size: 0.88rem;
  margin: 4px 0;
}

body[data-theme="dark"] .round-summary-player {
  background: #1f2a38;
}

body[data-theme="dark"] {
  --bg: #11151c;
  --panel: #1c2430;
  --ink: #e8edf5;
  --accent: #cc6d45;
  --accent-2: #3d8c95;
  --ok: #3da55b;
  --warn: #c54855;
  --line: #334153;
  --card-face-a: #233143;
  --card-face-b: #1c2736;
  --card-line: #3b4a5d;
  --muted: #aab6c5;
  background: linear-gradient(135deg, #0d1117, #1b2533);
}

body[data-theme="dark"] .card,
body[data-theme="dark"] .lobby-item,
body[data-theme="dark"] .leaderboard-item,
body[data-theme="dark"] .draft-item,
body[data-theme="dark"] .meld-item,
body[data-theme="dark"] .player-figure,
body[data-theme="dark"] .pile-box,
body[data-theme="dark"] .round-banner,
body[data-theme="dark"] .pill,
body[data-theme="dark"] .log {
  background: #1f2a38;
}

body[data-theme="dark"] .muted,
body[data-theme="dark"] .lobby-meta,
body[data-theme="dark"] .pile-title,
body[data-theme="dark"] .tiny {
  color: var(--muted);
}

body[data-theme="dark"] .playing-card.red { color: #ff7e8e; }
body[data-theme="dark"] .playing-card.black { color: #e2ebf8; }
body[data-theme="dark"] .playing-card.in-draft-meld {
  box-shadow: 0 0 0 2px rgba(94, 201, 122, 0.5), 0 4px 12px rgba(20, 130, 60, 0.22);
  background: linear-gradient(180deg, #244136, #1d342b);
  border-color: #5ec97a;
}

body[data-theme="dark"] .leaderboard-table th {
  background: #293548;
}

body[data-theme="dark"] .leaderboard-table td {
  background: #1f2a38;
}
