/* Crazy Eights – only what's specific to this game.
   Header, buttons and the rest come from /css/style.css. */

.c8-pickers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
}

.c8-holder {
  position: relative;
  width: min(100%, 780px);
  --cw: clamp(56px, 10.5vw, 88px);   /* card width */
}

/* ---------- The table ---------- */

.c8-table {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 12px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background:
    radial-gradient(120% 90% at 50% 40%, color-mix(in srgb, var(--game, #e879f9) 14%, transparent), transparent 70%),
    var(--surface);
  overflow: hidden;
}

/* ---------- A card ---------- */

.c8-card {
  position: relative;
  flex: none;
  width: var(--cw);
  aspect-ratio: 5 / 7;
  padding: 0;
  border-radius: calc(var(--cw) * 0.1);
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #fffdf8;
  color: #1c1f26;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), 0 4px 10px rgba(0, 0, 0, 0.1);
  font-family: var(--font-display);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.c8-card.is-red {
  color: #d23a3a;
}

.c8-corner {
  position: absolute;
  top: calc(var(--cw) * 0.05);
  left: calc(var(--cw) * 0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
}

.c8-corner b {
  font-size: calc(var(--cw) * 0.24);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.c8-corner i {
  font-size: calc(var(--cw) * 0.2);
  font-style: normal;
}

.c8-corner.is-flip {
  top: auto;
  left: auto;
  right: calc(var(--cw) * 0.07);
  bottom: calc(var(--cw) * 0.05);
  transform: rotate(180deg);
}

.c8-pip,
.c8-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--cw) * 0.5);
  line-height: 1;
}

.c8-face {
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: calc(var(--cw) * 0.42);
  font-weight: 700;
}

.c8-face i {
  font-size: calc(var(--cw) * 0.26);
  font-style: normal;
}

/* 8s are wild: give them a little shine */
.c8-card.is-eight {
  background:
    linear-gradient(135deg, transparent 0 40%, color-mix(in srgb, var(--game, #e879f9) 22%, transparent) 50%, transparent 60%),
    #fffdf8;
}

.c8-card.is-eight .c8-pip::after {
  content: "wild";
  position: absolute;
  bottom: 25%;
  font-family: var(--font-body);
  font-size: calc(var(--cw) * 0.11);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--game, #e879f9) 75%, #1c1f26);
}

/* The back of a card */
.c8-card.is-back,
.c8-mini span {
  border-color: rgba(0, 0, 0, 0.2);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.35) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 4px, transparent 4px 9px),
    var(--game, #e879f9);
  box-shadow: inset 0 0 0 3px #fffdf8, 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* ---------- Everyone else, across the top ---------- */

.c8-opponents {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.c8-opp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 96px;
  padding: 8px 12px 6px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: var(--surface-2);
  transition: border-color 0.2s, transform 0.2s;
}

.c8-opp.is-turn {
  border-color: var(--seat);
  transform: translateY(-2px);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--seat) 22%, transparent);
}

.c8-opp.is-away {
  opacity: 0.5;
}

.c8-mini {
  display: flex;
  height: 34px;
  padding-left: 14px;
}

.c8-mini span {
  width: 24px;
  height: 34px;
  margin-left: -14px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 0 0 2px #fffdf8;
  background-color: var(--seat, var(--game));
}

.c8-opp-name {
  margin: 2px 0 0;
  font-weight: 600;
  font-size: 14px;
}

.c8-opp-count {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.c8-opp.is-last .c8-opp-count {
  color: var(--warn);
  font-weight: 700;
}

.c8-opp.is-turn .c8-opp-name::after {
  content: " …";
}

.c8-opp.is-winner {
  border-color: var(--accent);
}

/* ---------- The piles in the middle ---------- */

.c8-middle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 4vw, 30px);
}

.c8-pile {
  position: relative;
  display: grid;
  place-items: center;
}

.c8-stock {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: calc(var(--cw) * 0.1);
}

.c8-stock:disabled {
  cursor: default;
}

/* A little stack: two cards peeking out behind */
.c8-stock::before,
.c8-stock::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cw) * 0.1);
  background: var(--game, #e879f9);
  box-shadow: inset 0 0 0 3px #fffdf8, 0 1px 2px rgba(0, 0, 0, 0.25);
  filter: brightness(0.85);
}

.c8-stock::before {
  transform: translate(4px, 4px);
}

.c8-stock::after {
  transform: translate(2px, 2px);
}

.c8-stock .c8-card {
  z-index: 1;
}

.c8-stock.is-empty::before,
.c8-stock.is-empty::after {
  display: none;
}

.c8-stock:not(:disabled):hover .c8-card {
  transform: translateY(-3px);
}

.c8-stock.is-ready .c8-card {
  animation: c8-nudge 1.4s ease-in-out infinite;
}

.c8-stock:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 6px;
}

.c8-count {
  position: absolute;
  z-index: 2;
  right: -10px;
  bottom: -10px;
  min-width: 28px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.c8-discard .c8-card {
  transform: rotate(-3deg);
}

.c8-suit {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 12px;
  line-height: 1.25;
  color: var(--text-muted);
}

.c8-suit b {
  color: var(--text);
  font-size: 14px;
}

.c8-suit-sym {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fffdf8;
  color: #1c1f26;
  font-size: 24px;
}

.c8-suit-sym.is-red {
  color: #d23a3a;
}

/* An 8 just changed the suit: make it obvious */
.c8-suit.is-changed {
  background: color-mix(in srgb, var(--game, #e879f9) 22%, var(--surface-2));
  animation: c8-pop 0.4s ease-out;
}

.c8-status {
  min-height: 1.5em;
  margin: 0;
  font-size: 16px;
  text-align: center;
}

/* ---------- Your hand ---------- */

.c8-hand {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: calc(var(--cw) * 1.4 + 16px);
  padding-top: 14px;
}

.c8-hand .c8-card {
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.c8-hand .c8-card.is-playable {
  transform: translateY(-10px);
  box-shadow: 0 0 0 3px var(--game, #e879f9), 0 8px 16px rgba(0, 0, 0, 0.18);
}

.c8-hand .c8-card.is-playable:hover,
.c8-hand .c8-card.is-playable:focus-visible {
  transform: translateY(-18px);
  z-index: 2;
  outline: none;
}

.c8-hand .c8-card.is-dim {
  opacity: 0.55;
  cursor: not-allowed;
}

.c8-hand .c8-card.is-new {
  animation: c8-in 0.35s ease-out;
}

.c8-hand .c8-card.is-nope {
  animation: c8-shake 0.3s;
}

.c8-actions {
  display: flex;
  justify-content: center;
  min-height: 0;
}

.c8-actions .btn[hidden] {
  display: none;
}

/* The card that's flying between places */
.c8-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
}

/* ---------- Picking a suit after an 8 ---------- */

.c8-picker {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--overlay);
  animation: c8-fade 0.15s ease-out;
}

.c8-picker[hidden] {
  display: none;
}

.c8-picker-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.c8-picker-suits {
  display: flex;
  gap: 12px;
}

.c8-suit-btn {
  position: relative;
  width: 68px;
  height: 84px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: #fffdf8;
  color: #1c1f26;
  font-size: 40px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.c8-suit-btn.is-red {
  color: #d23a3a;
}

.c8-suit-btn:hover,
.c8-suit-btn:focus-visible {
  transform: translateY(-3px);
  outline: none;
  border-color: var(--game, #e879f9);
}

/* How many of that suit you hold, as a hint */
.c8-suit-btn::after {
  content: attr(data-count);
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
}

.c8-suit-btn.is-best {
  border-color: var(--game, #e879f9);
}

.c8-picker-cancel {
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- End of a hand ---------- */

.c8-result {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  border-radius: 22px;
  background: var(--overlay);
  text-align: center;
  animation: c8-fade 0.25s ease-out;
}

.c8-result[hidden] {
  display: none;
}

.c8-result .game-status {
  margin: 0;
  font-size: 26px;
}

.c8-result p {
  margin: 0;
  max-width: 420px;
}

.c8-keys kbd {
  font-size: 12px;
}

@media (pointer: coarse) {
  .c8-keys {
    display: none;
  }
}

/* ---------- Animations ---------- */

@keyframes c8-in {
  from { transform: translateY(-30px) scale(0.85); opacity: 0; }
}

@keyframes c8-shake {
  25% { translate: -5px 0; }
  75% { translate: 5px 0; }
}

@keyframes c8-pop {
  50% { transform: scale(1.08); }
}

@keyframes c8-fade {
  from { opacity: 0; }
}

@keyframes c8-nudge {
  50% { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
  .c8-hand .c8-card,
  .c8-suit.is-changed,
  .c8-stock.is-ready .c8-card {
    animation: none;
    transition: none;
  }
}

/* ---------- Phones ---------- */

@media (max-width: 560px) {
  .c8-table {
    gap: 10px;
    padding: 12px 8px;
  }
  .c8-opp {
    min-width: 0;
    padding: 6px 8px 4px;
  }
  .c8-opp-name {
    font-size: 13px;
  }
  .c8-suit {
    min-width: 0;
    padding: 6px 8px;
  }
  .c8-suit span:last-child {
    display: none;
  }
  .c8-suit-btn {
    width: 58px;
    height: 72px;
    font-size: 34px;
  }
}

/* Phone held sideways: fit the screen height (see css/style.css) */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --land-side: 236px; }
  .c8-holder {
    width: var(--play-w);
    --cw: clamp(44px, calc((var(--play-h) - 150px) / 2.2), 70px);
  }
  .c8-table {
    gap: 6px;
    padding: 8px;
    min-height: var(--play-h);
  }
  .c8-mini {
    height: 24px;
  }
  .c8-mini span {
    width: 17px;
    height: 24px;
    margin-left: -11px;
  }
  .c8-opp {
    padding: 4px 8px;
    flex-direction: row;
    gap: 6px;
  }
  .c8-opp-name {
    margin: 0;
  }
  .c8-hand {
    padding-top: 10px;
    min-height: calc(var(--cw) * 1.4 + 12px);
  }
  .c8-status {
    font-size: 14px;
  }
  .c8-pickers {
    flex-direction: column;
    align-items: center;
  }
}
