:root {
  --ink: #17202a;
  --muted: #667085;
  --panel: #ffffff;
  --line: #d8dee8;
  --felt: #0f8b6f;
  --felt-dark: #0b604f;
  --red: #e84855;
  --yellow: #f6c343;
  --green: #24a66a;
  --blue: #2878d8;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(232, 72, 85, 0.12), transparent 30%),
    linear-gradient(315deg, rgba(40, 120, 216, 0.16), transparent 34%),
    #f4f7fb;
  font-family: Arial, Helvetica, sans-serif;
}

.game {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 16px;
  min-height: 100vh;
  padding: 22px;
}

.game header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
}

.header-top,
.hand-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

#contextLabel {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

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

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.game .header-actions button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
  color: white;
  background: #165c51;
}

.header-actions #oneCardButton {
  color: #17202a;
  background: var(--yellow);
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 6px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
}

.player span {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.player.active {
  border-left-color: var(--felt);
  box-shadow: 0 10px 24px rgba(15, 139, 111, 0.16);
}

.player.one-card {
  border-left-color: var(--red);
}

.table {
  display: grid;
  grid-template-columns: minmax(96px, 130px) minmax(110px, 150px) minmax(210px, 1fr);
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 34px);
  min-height: 260px;
  padding: clamp(16px, 4vw, 30px);
  border: 1px solid rgba(11, 96, 79, 0.3);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 255, 255, 0.14), transparent 42%),
    linear-gradient(140deg, var(--felt), var(--felt-dark));
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.08);
}

.pile,
.card {
  position: relative;
  display: grid;
  width: min(22vw, 128px);
  min-width: 86px;
  aspect-ratio: 2 / 3;
  padding: 10px;
  border: 5px solid white;
  border-radius: 8px;
  color: white;
  background: var(--card-color, #222831);
  box-shadow: 0 16px 30px rgba(23, 32, 42, 0.28);
  overflow: hidden;
}

.pile {
  place-items: center;
  justify-self: end;
  color: white;
  background:
    linear-gradient(135deg, var(--red) 0 24%, var(--yellow) 24% 49%, var(--green) 49% 74%, var(--blue) 74%),
    #222831;
  font-size: 26px;
}

.card::before {
  content: "";
  position: absolute;
  inset: 17% 8%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  transform: rotate(-24deg);
}

.card.wild::before {
  background: conic-gradient(var(--red), var(--yellow), var(--green), var(--blue), var(--red));
}

.card.back::before {
  background: rgba(255, 255, 255, 0.16);
}

.card.back {
  place-items: center;
  font-size: 26px;
  font-weight: 900;
  background: #222831;
}

.corner,
.face,
.active-color {
  position: relative;
  z-index: 1;
}

.corner {
  align-self: start;
  justify-self: start;
  max-width: 42px;
  color: white;
  font-size: 14px;
  line-height: 1;
}

.corner.bottom {
  align-self: end;
  justify-self: end;
  transform: rotate(180deg);
}

.face {
  align-self: center;
  justify-self: center;
  color: var(--card-color, #222831);
  font-size: clamp(24px, 7vw, 46px);
  line-height: 1;
}

.wild .face {
  color: white;
  text-shadow: 0 2px 6px rgba(23, 32, 42, 0.44);
}

.hand .card.playable {
  transform: translateY(-8px);
}

.hand .card:hover:not(:disabled),
.hand .card:focus-visible {
  outline: 3px solid #f6c343;
  outline-offset: 2px;
  transform: translateY(-14px);
}

.discard-wrap {
  display: grid;
  justify-items: center;
  gap: 8px;
}

#directionLabel,
.turn-panel {
  color: white;
  text-shadow: 0 1px 1px rgba(23, 32, 42, 0.28);
}

.turn-panel {
  display: grid;
  gap: 10px;
  justify-self: start;
  max-width: 520px;
  font-size: 18px;
}

.turn-panel p:last-child {
  font-size: 14px;
  opacity: 0.9;
}

.turn-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.color-chip {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.color-chip.red {
  background: var(--red);
}

.color-chip.yellow {
  background: var(--yellow);
}

.color-chip.green {
  background: var(--green);
}

.color-chip.blue {
  background: var(--blue);
}

.turn-banner {
  justify-self: start;
  padding: 4px 12px;
  border-radius: 999px;
  color: #17202a;
  background: var(--yellow);
  font-size: 14px;
  font-weight: 900;
  text-shadow: none;
  text-transform: uppercase;
}

.active-color {
  align-self: end;
  justify-self: center;
  padding: 4px 8px;
  border-radius: 999px;
  color: white;
  background: var(--card-color);
  font-size: 12px;
}

.active-color.red {
  --card-color: var(--red);
}

.active-color.yellow {
  --card-color: #b77900;
}

.active-color.green {
  --card-color: var(--green);
}

.active-color.blue {
  --card-color: var(--blue);
}

.hand-panel {
  display: grid;
  gap: 12px;
  min-height: 210px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

/* 한 줄 가로 스크롤 대신 줄바꿈시켜 카드가 두 줄로 보이도록 한다. */
.hand {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  align-content: flex-start;
  gap: 8px;
  min-height: 158px;
  padding: 14px 4px 4px;
}

.hand .card {
  flex: 0 0 auto;
  width: 96px;
  min-width: 96px;
  transition: transform 140ms ease, outline-color 140ms ease;
}

/* 방금 받은 카드는 정렬된 손패 안에서도 바로 눈에 띄게 한다. */
.hand .card.just-received {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(246, 195, 67, 0.28), 0 16px 30px rgba(23, 32, 42, 0.28);
}

.new-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  padding: 2px 5px;
  border-radius: 999px;
  color: #17202a;
  background: var(--yellow);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
}

.hand p {
  align-self: center;
  color: var(--muted);
}

.color-picker {
  display: flex;
  gap: 8px;
}

.color-picker.hidden {
  display: none;
}

.color-picker button {
  width: 34px;
  height: 34px;
  border: 3px solid white;
  box-shadow: 0 0 0 1px var(--line);
}

.color-picker [data-color="red"] {
  background: var(--red);
}

.color-picker [data-color="yellow"] {
  background: var(--yellow);
}

.color-picker [data-color="green"] {
  background: var(--green);
}

.color-picker [data-color="blue"] {
  background: var(--blue);
}

.result-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10;
  min-width: min(78vw, 380px);
  padding: 28px 34px;
  border: 2px solid var(--yellow);
  border-radius: 8px;
  color: #17202a;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 60px rgba(23, 32, 42, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.result-overlay.hidden {
  display: none;
}

.result-overlay p {
  font-size: clamp(34px, 8vmin, 72px);
  font-weight: 900;
  line-height: 1;
}

@media (max-width: 720px) {
  .game {
    grid-template-rows: auto auto auto 1fr;
    padding: 16px;
  }

  .header-secondary {
    width: 100%;
    justify-content: stretch;
  }

  .header-secondary button {
    flex: 1 1 70px;
    padding-inline: 8px;
  }

  .table {
    grid-template-columns: 1fr 1fr;
    min-height: 0;
  }

  .turn-panel {
    grid-column: 1 / -1;
    justify-self: stretch;
    font-size: 16px;
  }

  .pile,
  .card {
    width: min(34vw, 112px);
  }

  .hand .card {
    width: 82px;
    min-width: 82px;
  }
}
