:root {
  --bg: oklch(0.965 0.020 205);
  --surface: oklch(0.940 0.018 205);
  --panel: oklch(0.992 0.004 205);
  --ink: oklch(0.20 0.026 248);
  --muted: oklch(0.42 0.025 230);
  --line: oklch(0.835 0.020 220);
  --primary: oklch(0.61 0.150 50);
  --primary-dark: oklch(0.46 0.125 50);
  --accent: oklch(0.56 0.125 198);
  --danger: oklch(0.56 0.17 28);
  --ok: oklch(0.57 0.13 145);
  --table: oklch(0.73 0.078 184);
  --table-deep: oklch(0.54 0.082 184);
  --table-edge: oklch(0.37 0.060 188);
  --wood: oklch(0.52 0.105 58);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 10%, oklch(0.98 0.030 190), transparent 34rem),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 16px;
}

button:hover {
  background: var(--primary-dark);
}

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

.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary:hover {
  background: oklch(0.90 0.010 230);
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid oklch(0.80 0.10 205 / 0.55);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.entry {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 28px;
  padding: 28px;
  background: linear-gradient(180deg, oklch(0.93 0.04 205), white 48%);
}

.brand {
  text-align: center;
}

.logo {
  font-size: 58px;
  line-height: 1;
  font-weight: 950;
  color: oklch(0.67 0.13 205);
}

.logo.small {
  font-size: 30px;
  text-align: left;
}

.brand p,
.topbar p,
.lobby-panel p {
  color: var(--muted);
  margin: 8px 0 0;
}

.entry-grid {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid oklch(1 0 0 / 0.55);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px oklch(0 0 0 / 0.10);
}

.panel h1,
.panel h2 {
  margin: 0 0 14px;
}

.panel h1 {
  font-size: 24px;
}

.panel h2 {
  font-size: 18px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.game {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 10%, oklch(0.98 0.035 190), transparent 38rem),
    linear-gradient(180deg, oklch(0.93 0.024 205), oklch(0.88 0.030 210));
}

.topbar {
  min-height: 76px;
  padding: 14px 22px;
  background: oklch(0.98 0.004 230);
  border-bottom: 1px solid oklch(1 0 0 / 0.45);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.room-actions,
.lobby-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 310px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.players,
.log {
  align-self: start;
}

.player {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.player:first-of-type {
  border-top: 0;
}

.player-row,
.seat-name {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.score-line {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 850;
  background: var(--surface);
  color: var(--muted);
}

.badge.ready {
  background: oklch(0.91 0.08 145);
  color: oklch(0.32 0.10 145);
}

.badge.host {
  background: oklch(0.90 0.07 58);
  color: oklch(0.35 0.10 58);
}

.center {
  min-width: 0;
}

.lobby-panel {
  display: grid;
  gap: 10px;
}

.play-area {
  display: grid;
  gap: 14px;
}

.round-state {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: oklch(0.975 0.004 230);
}

.round-state strong {
  font-size: 18px;
}

.round-state span {
  color: var(--muted);
  font-weight: 750;
}

.round-table {
  position: relative;
  min-height: 760px;
  overflow: visible;
  border-radius: 22px;
  background:
    radial-gradient(ellipse at center, oklch(0.78 0.070 184), var(--table) 54%, var(--table-deep) 55%, var(--table-edge) 68%, oklch(0.30 0.050 188) 69%),
    var(--table);
  border: 10px solid var(--wood);
  box-shadow:
    inset 0 0 0 2px oklch(0.82 0.065 75 / 0.48),
    inset 0 18px 34px oklch(1 0 0 / 0.18),
    0 14px 24px oklch(0.20 0.025 248 / 0.18);
}

.table-center {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(230px, 38%);
  transform: translate(-50%, -50%);
  display: grid;
  gap: 8px;
  justify-items: center;
  z-index: 2;
}

.label {
  margin: 0;
  font-size: 13px;
  font-weight: 850;
  color: oklch(0.24 0.030 200);
  opacity: 0.92;
}

.food-card {
  position: relative;
  width: 100%;
  min-height: 180px;
}

.food-card-pool-item {
  position: absolute;
  left: var(--pool-x);
  top: var(--pool-y);
  width: 100%;
  z-index: var(--pool-z);
  transform: rotate(var(--pool-rotate));
}

.food-card-pool-item:first-child {
  position: relative;
}

.food-card-face {
  min-height: 150px;
  background: oklch(0.88 0.075 202);
  color: var(--ink);
  border: 8px solid white;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: center;
  box-shadow: 0 7px 0 oklch(0.20 0.025 248 / 0.18), 0 12px 16px oklch(0.20 0.025 248 / 0.16);
  animation: cardIn 220ms ease-out;
}

.food-card-face.empty-current {
  min-height: 120px;
  background: oklch(0.94 0.018 205);
  border-style: dashed;
  color: var(--muted);
}

.food-card-face.minus {
  background: oklch(0.90 0.055 28);
}

.food-mark {
  justify-self: start;
  border-radius: 999px;
  padding: 4px 8px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.food-name {
  font-size: 20px;
  font-weight: 950;
}

.food-items {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.food-chip {
  border-radius: 10px;
  padding: 8px 10px;
  background: white;
  font-weight: 900;
}

.table-seats {
  position: absolute;
  inset: 0;
}

.seat {
  position: absolute;
  width: 230px;
  display: grid;
  gap: 7px;
  color: var(--ink);
  z-index: 3;
}

.seat-bottom {
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
}

.seat-top {
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
}

.seat-left {
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
}

.seat-right {
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
}

.seat-far {
  right: 46px;
  top: 44px;
}

.seat-name {
  border-radius: 999px;
  padding: 8px 11px;
  background: oklch(1 0 0 / 0.82);
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px oklch(0.78 0.022 220 / 0.60);
}

.seat-play {
  min-height: 68px;
  display: grid;
  place-items: center;
}

.played-slot {
  width: 56px;
  aspect-ratio: 0.72;
  display: grid;
  place-items: center;
  border: 2px dashed oklch(0.26 0.028 200 / 0.44);
  border-radius: 10px;
  color: oklch(0.24 0.028 200 / 0.72);
  font-size: 12px;
  font-weight: 850;
}

.seat-pile {
  min-height: 62px;
  position: relative;
  overflow: visible;
  z-index: 4;
  isolation: isolate;
}

.empty-pile {
  color: oklch(0.25 0.030 200 / 0.72);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
}

.mini-food {
  position: absolute;
  left: var(--stack-x);
  top: var(--stack-y);
  width: 96px;
  height: 44px;
  border: 4px solid white;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: oklch(0.92 0.055 205);
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
  z-index: var(--z);
  box-shadow: 0 4px 0 oklch(0 0 0 / 0.18);
  transition: left 180ms ease, top 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.mini-food.minus {
  background: oklch(0.92 0.045 28);
}

.seat-pile:hover,
.seat-pile:focus-within {
  z-index: 40;
  min-height: var(--expanded-height);
  padding: 28px 8px 8px;
  border-radius: 12px;
  background: oklch(1 0 0 / 0.82);
  box-shadow: inset 0 0 0 1px oklch(0.78 0.022 220 / 0.62), 0 8px 14px oklch(0.20 0.025 248 / 0.14);
}

.seat-pile:hover .mini-food,
.seat-pile:focus-within .mini-food {
  left: var(--grid-x);
  top: var(--grid-y);
  transform: translateY(0);
  box-shadow: 0 5px 0 oklch(0 0 0 / 0.22);
}

.seat-right .seat-pile:hover .mini-food,
.seat-right .seat-pile:focus-within .mini-food,
.seat-far .seat-pile:hover .mini-food,
.seat-far .seat-pile:focus-within .mini-food {
  left: var(--grid-x);
}

.pile-count {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 999px;
  padding: 4px 8px;
  background: oklch(1 0 0 / 0.82);
  color: var(--ink);
  font-size: 11px;
  font-weight: 850;
  z-index: 25;
}

.seat-pile:hover .pile-count,
.seat-pile:focus-within .pile-count {
  left: 8px;
  top: 7px;
  background: oklch(1 0 0 / 0.94);
  color: var(--ink);
}

.play-history {
  min-height: 28px;
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 2px 0;
}

.history-empty {
  color: oklch(0.25 0.030 200 / 0.62);
  font-size: 11px;
  font-weight: 750;
}

.history-card {
  position: relative;
  width: 22px;
  height: 30px;
  border-radius: 5px;
  border: 2px solid white;
  display: grid;
  place-items: center;
  color: white;
  font-size: 13px;
  font-weight: 950;
}

.history-card.numeric {
  background: oklch(0.66 0.13 220);
}

.history-card.special {
  background: oklch(0.62 0.14 58);
}

.history-card small {
  position: absolute;
  right: -3px;
  bottom: -5px;
  min-width: 12px;
  height: 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: white;
  color: var(--ink);
  font-size: 8px;
  font-weight: 950;
}

.hand-dock {
  display: grid;
  gap: 12px;
  background: oklch(0.985 0.004 230);
}

.hand-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.hand-heading h2 {
  margin: 0;
}

#playedState {
  color: var(--muted);
  font-weight: 800;
}

.target-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 1fr) minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
}

.target-panel strong {
  font-size: 13px;
}

.hand {
  min-height: 122px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: flex-end;
}

.card {
  position: relative;
  width: 66px;
  aspect-ratio: 0.72;
  border-radius: 10px;
  border: 4px solid white;
  color: white;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 950;
  box-shadow: 0 5px 0 oklch(0 0 0 / 0.20);
}

.hand .card {
  width: 74px;
}

.hand-card {
  align-content: center;
  gap: 4px;
  padding: 0;
  transform-origin: 50% 100%;
}

.hand-card small {
  font-size: 10px;
  font-weight: 850;
}

.card.numeric {
  background: oklch(0.66 0.13 220);
}

.card.special {
  background: oklch(0.62 0.14 58);
}

.hand-card.player-blue {
  background: oklch(0.66 0.13 220);
}

.hand-card.player-green {
  background: oklch(0.58 0.13 150);
}

.hand-card.player-purple {
  background: oklch(0.56 0.13 300);
}

.hand-card.player-orange {
  background: oklch(0.67 0.14 55);
}

.hand-card.player-red {
  background: oklch(0.58 0.16 25);
}

.card.back {
  font-size: 14px;
  background: oklch(0.50 0.035 248);
}

.card.playable:hover,
.card.selected {
  transform: translateY(-7px) rotate(-1deg);
}

.card.selected {
  outline: 3px solid oklch(0.83 0.13 90);
  outline-offset: 2px;
}

.table-card {
  animation: playCard 220ms ease-out;
}

.play-order {
  position: absolute;
  right: -7px;
  top: -7px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: white;
  color: var(--ink);
  font-size: 12px;
  font-weight: 950;
}

#log {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 150px);
  overflow: auto;
}

.log-line {
  padding: 10px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 800;
}

@keyframes playCard {
  from {
    opacity: 0.35;
    transform: translateY(24px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: rotate(-2deg) scale(0.94);
  }
  to {
    opacity: 1;
    transform: rotate(0) scale(1);
  }
}

@media (max-width: 1180px) {
  .table {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .log {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .entry-grid,
  .table {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .round-table {
    min-height: 720px;
  }

  .seat {
    width: 180px;
  }

  .seat-left,
  .seat-right {
    top: auto;
    bottom: 150px;
    transform: none;
  }

  .table-center {
    width: min(250px, 66%);
  }

  .round-state,
  .target-panel {
    grid-template-columns: 1fr;
  }

  .card {
    width: 60px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  button,
  .card {
    transition: background-color 160ms ease, transform 160ms ease, opacity 160ms ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
