.c-red {
  --cc: #d7413b;
}

.c-yellow {
  --cc: #e6a817;
}

.c-green {
  --cc: #2f9e5f;
}

.c-blue {
  --cc: #2f6fd0;
}

.c-wild {
  --cc: #23232b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #f7f4ea;
  background: radial-gradient(ellipse 120% 90% at 50% -10%, rgba(255, 255, 255, 0.1), transparent 55%), radial-gradient(ellipse 140% 120% at 50% 115%, rgba(0, 0, 0, 0.42), transparent 60%), repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.016) 0 2px, transparent 2px 6px), linear-gradient(165deg, #1d7a4f 0%, #11563a 38%, #0b3d26 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.12));
  border-bottom: 1px solid rgba(242, 201, 76, 0.25);
}

.brand {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  margin: 0;
  font-weight: 800;
  color: #f2c94c;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}
.brand span {
  color: #f7f4ea;
  font-weight: 400;
  margin-left: 4px;
}

.scoreboard {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}
.scoreboard .score b {
  color: #f2c94c;
  font-size: 1.1rem;
  margin-left: 4px;
}
.scoreboard .round {
  margin-left: 8px;
  opacity: 0.85;
}
.scoreboard .score-sep {
  opacity: 0.5;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn {
  font: inherit;
  font-weight: 700;
  color: #1c1c22;
  background: linear-gradient(180deg, rgb(95.9852941176%, 83.3235294118%, 44.7205882353%), #b8860b);
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(1px);
}
.btn.ghost {
  background: transparent;
  color: #f2c94c;
  border: 1px solid rgba(242, 201, 76, 0.5);
  box-shadow: none;
}
.btn.gold {
  font-size: 1.15rem;
  padding: 12px 28px;
}

button:focus-visible,
.card.playable:focus-visible {
  outline: 3px solid #f2c94c;
  outline-offset: 2px;
}

.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 16px 16px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.zone-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(242, 201, 76, 0.4);
  color: #f2c94c;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 999px;
  min-width: 34px;
  text-align: center;
}

.card {
  width: var(--cw, 84px);
  height: var(--ch, 122px);
  border-radius: 12px;
  position: relative;
  background: linear-gradient(160deg, #ffffff 0%, #f7f4ea 70%, #e9e4d4 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 0 0 3px var(--cc, #999);
  flex: 0 0 auto;
  overflow: hidden;
  padding: 0;
  font-family: inherit;
  color: var(--cc, #333);
}
.card .idx {
  position: absolute;
  font-weight: 900;
  font-size: calc(var(--cw, 84px) * 0.22);
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.card .idx i {
  font-style: normal;
  font-size: 0.55em;
  opacity: 0.9;
}
.card .idx.tl {
  top: 6px;
  left: 7px;
}
.card .idx.br {
  bottom: 6px;
  right: 7px;
  transform: rotate(180deg);
}
.card .face {
  position: absolute;
  inset: 16% 10%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: calc(var(--cw, 84px) * 0.52);
  font-style: italic;
  color: var(--cc);
  background: radial-gradient(ellipse at center, var(--cc) 0%, transparent 72%);
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.92) 0 58%, transparent 60%), radial-gradient(ellipse at center, var(--cc) 0 74%, transparent 78%);
  -webkit-background-clip: text;
  background-clip: text;
}
.card .face.wildface {
  background: conic-gradient(from 40deg, #d7413b 0 90deg, #e6a817 90deg 180deg, #2f9e5f 180deg 270deg, #2f6fd0 270deg 360deg);
  border-radius: 50%;
  inset: 26% 22%;
  box-shadow: inset 0 0 0 6px #23232b, 0 0 0 4px rgba(255, 255, 255, 0.9);
}
.card .shape-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--cw, 84px) * 1.15);
  color: var(--cc);
  opacity: 0.12;
  pointer-events: none;
}
.card.c-wild {
  background: linear-gradient(160deg, #34343e, #17171d);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55), inset 0 0 0 3px #0e0e12, inset 0 0 0 6px rgba(255, 255, 255, 0.25);
}
.card.c-wild .idx, .card.c-wild .face {
  color: #fff;
}
.card.c-wild .shape-mark {
  color: #fff;
  opacity: 0.1;
}
.card.c-wild.v-draw4 .face {
  font-size: calc(var(--cw, 84px) * 0.42);
  font-style: italic;
}
.card.back {
  background: radial-gradient(circle at 50% 50%, rgba(242, 201, 76, 0.16) 0 26%, transparent 27%), repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.06) 0 3px, transparent 3px 9px), linear-gradient(160deg, #7a1f2b, #471019 70%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), inset 0 0 0 3px #e8dcc0, inset 0 0 0 6px #7a1f2b;
  display: grid;
  place-items: center;
}
.card.back .back-mark {
  font-weight: 900;
  font-style: italic;
  color: #f2c94c;
  font-size: calc(var(--cw, 84px) * 0.3);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  transform: rotate(-18deg);
}

.cpu-zone {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fan {
  display: flex;
  padding-left: 30px;
}

.cpu-fan {
  --cw: 60.48px;
  --ch: 87.84px;
}
.cpu-fan .cpu-back {
  margin-left: -26px;
  transform: rotate(calc(var(--i, 0) * 1.6deg - 5deg));
  transition: transform 0.3s ease;
}
.cpu-fan .cpu-back:first-child {
  margin-left: 0;
}

.mid-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 5vw, 56px);
  padding: 6px 0;
}

.pile {
  position: relative;
  width: 84px;
  height: 122px;
  flex: 0 0 auto;
}

#draw-btn {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
#draw-btn .pile-inner {
  position: absolute;
  inset: 0;
  display: block;
}
#draw-btn .pile-inner::before, #draw-btn .pile-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
}
#draw-btn .pile-inner::before {
  transform: translate(5px, 5px);
  background: linear-gradient(160deg, #5c1622, #3c0d15);
  box-shadow: inset 0 0 0 3px #e8dcc0;
}
#draw-btn .pile-inner::after {
  background: radial-gradient(circle at 50% 50%, rgba(242, 201, 76, 0.16) 0 26%, transparent 27%), repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.06) 0 3px, transparent 3px 9px), linear-gradient(160deg, #7a1f2b, #471019 70%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55), inset 0 0 0 3px #e8dcc0, inset 0 0 0 6px #7a1f2b;
}
#draw-btn .draw-count {
  position: absolute;
  z-index: 2;
  inset: auto 0 0 0;
  text-align: center;
  font-weight: 900;
  font-size: 1.3rem;
  color: #f2c94c;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  font-variant-numeric: tabular-nums;
}
#draw-btn:hover:not(.off) {
  transform: translateY(-2px);
}
#draw-btn {
  transition: transform 0.15s ease, filter 0.2s ease;
}
#draw-btn.off {
  cursor: default;
  filter: saturate(0.6) brightness(0.85);
}

.discard .under {
  position: absolute;
  inset: 0;
  transform: rotate(-3deg) translate(-3px, 2px);
  opacity: 0.9;
}
.discard .top {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.discard .top.flip {
  animation: flip-in 0.45s cubic-bezier(0.2, 0.8, 0.3, 1.15) both;
  transform-origin: center left;
}

@keyframes flip-in {
  0% {
    transform: rotateY(-92deg) scale(0.92);
    filter: brightness(0.4);
  }
  55% {
    transform: rotateY(18deg) scale(1.04);
    filter: brightness(1.15);
  }
  100% {
    transform: rotateY(0deg) scale(1);
    filter: brightness(1);
  }
}
.color-chip {
  min-width: 96px;
  text-align: center;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.3)), var(--cc, #555);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 52px;
}

.turn-pill {
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.turn-pill.you {
  background: linear-gradient(180deg, #2b8f5d, #17663e);
  border-color: rgba(242, 201, 76, 0.55);
  box-shadow: 0 0 18px rgba(46, 204, 113, 0.35);
}
.turn-pill.cpu {
  background: linear-gradient(180deg, #8a5a12, #5c3a08);
  animation: breathe 1.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}
.btn.pass {
  font-size: 0.95rem;
}

.uno-btn {
  font: inherit;
  font-weight: 900;
  font-size: 1.5rem;
  font-style: italic;
  color: #fff;
  text-shadow: 0 2px 0 #a33;
  background: radial-gradient(circle at 30% 30%, #ff9d3c, #d5232b 70%);
  border: 3px solid #f2c94c;
  border-radius: 999px;
  padding: 10px 34px;
  min-height: 52px;
  cursor: pointer;
  animation: pulse 0.9s ease-in-out infinite;
  box-shadow: 0 0 26px rgba(255, 160, 40, 0.65);
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}
.log {
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  font-size: 0.82rem;
  opacity: 0.75;
  max-width: 380px;
  text-align: right;
}
.log li {
  padding: 1px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hand-zone {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hand-fan {
  --cw: 84px;
  --ch: 122px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 10px;
  gap: 0;
}
.hand-fan button.card {
  margin-left: -34px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.2s ease;
  transform: translateY(0);
}
.hand-fan button.card:first-child {
  margin-left: 0;
}
.hand-fan button.card.playable {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45), inset 0 0 0 3px var(--cc), 0 0 0 2px rgba(242, 201, 76, 0.85), 0 0 14px rgba(242, 201, 76, 0.4);
  z-index: 1;
}
.hand-fan button.card.playable:hover, .hand-fan button.card.playable:focus-visible {
  transform: translateY(-18px) scale(1.06);
  z-index: 5;
}
.hand-fan button.card.dim {
  cursor: not-allowed;
  filter: grayscale(0.8) brightness(0.62);
  transform: translateY(4px);
}
.hand-fan button.card.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% {
    translate: 0 0;
  }
  25% {
    translate: -4px 0;
  }
  75% {
    translate: 4px 0;
  }
}
.toasts {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 40;
  pointer-events: none;
  width: min(92vw, 480px);
}

.toast {
  background: rgba(10, 28, 20, 0.92);
  border: 1px solid rgba(242, 201, 76, 0.35);
  color: #f7f4ea;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  animation: drop 0.25s ease both;
  max-width: 100%;
  text-align: center;
}
.toast.big {
  font-size: 1.35rem;
  font-weight: 900;
  font-style: italic;
  color: #f2c94c;
  border-color: #f2c94c;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}
.toast.warn {
  border-color: rgba(224, 86, 75, 0.8);
}
.toast.bye {
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.4s ease;
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.modal, .overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 14, 9, 0.72);
  display: grid;
  place-items: center;
  z-index: 60;
  backdrop-filter: blur(3px);
}

.modal-box, .overlay-box {
  background: linear-gradient(165deg, #1d7a4f, #0b3d26);
  border: 2px solid rgba(242, 201, 76, 0.6);
  border-radius: 18px;
  padding: 26px 30px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  text-align: center;
  max-width: min(92vw, 520px);
}
.modal-box h2, .overlay-box h2 {
  margin: 0 0 16px;
  color: #f2c94c;
}
.modal-box p, .overlay-box p {
  margin: 0 0 20px;
  line-height: 1.5;
}

.color-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 12px;
}

.color-btn {
  font: inherit;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(0, 0, 0, 0.25)), var(--cc);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  padding: 18px 10px;
  min-height: 64px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.12s ease;
}
.color-btn span {
  font-size: 1.3rem;
}
.color-btn:hover {
  transform: scale(1.05);
}

@media (max-width: 700px) {
  .card {
    --cw: 62px;
    --ch: 92px;
  }
  .hand-fan {
    --cw: 62px;
    --ch: 92px;
    padding-left: 18px;
  }
  .hand-fan button.card {
    margin-left: -22px;
  }
  .cpu-fan .cpu-back {
    --cw: 40px;
    --ch: 58px;
    margin-left: -16px;
  }
  .pile {
    width: 62px;
    height: 92px;
  }
  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }
  .brand {
    font-size: 1.1rem;
  }
  .scoreboard .score b {
    font-size: 1rem;
  }
  .table {
    padding: 8px 8px 12px;
  }
  .log {
    display: none;
  }
  .uno-btn {
    font-size: 1.2rem;
    padding: 8px 24px;
  }
  .toasts {
    top: 96px;
  }
}
@media (max-width: 380px) {
  .topbar-actions .btn {
    padding: 10px 10px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
