:root {
  color-scheme: dark;
  --bg: #0b0e12;
  --panel: #121922;
  --panel-strong: #17212b;
  --ink: #eef3ef;
  --muted: #9caaa8;
  --line: #2b3945;
  --accent: #61d394;
  --accent-strong: #31ad6c;
  --red: #ff7575;
  --gold: #f2c66d;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(97, 211, 148, 0.13), transparent 28rem),
    linear-gradient(135deg, #0b0e12 0%, #121821 54%, #090c10 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 13px;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(940px, calc(100vw - 18px));
  margin: 0 auto;
  padding: 6px 0 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 8px;
}

.top-bar {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 25, 34, 0.9);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.8vw, 2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 0.98rem;
  line-height: 1.15;
}

.meta-row,
.action-row,
.panel-heading,
.zone-title {
  display: flex;
  align-items: center;
}

.meta-row {
  justify-content: end;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1218;
  color: var(--ink);
  font-weight: 850;
  white-space: nowrap;
}

.table-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 7px;
}

.pile-panel,
.player-panel,
.panel-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 25, 34, 0.9);
  box-shadow: var(--shadow);
}

.pile-panel,
.player-panel {
  padding: 8px;
}

.panel-heading {
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.panel-heading.compact {
  margin-bottom: 7px;
}

#stockCount {
  color: var(--gold);
  font-size: 0.82rem;
  white-space: nowrap;
}

.pile-cards {
  min-height: 48px;
  margin-top: 7px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(97, 211, 148, 0.08), transparent 44%),
    #0d1319;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.pile-cards .card {
  width: 32px;
  height: 45px;
}

.pile-more {
  min-width: 42px;
  min-height: 45px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  place-items: center;
  font-weight: 900;
  text-align: center;
}

.rule-text,
.status-text,
.hint,
.rules-block p {
  color: var(--muted);
  line-height: 1.45;
}

.rule-text {
  min-height: 18px;
  margin: 6px 0 0;
  font-weight: 750;
}

.status-text {
  min-height: 18px;
  margin: 0 0 6px;
  color: var(--ink);
  font-weight: 780;
}

.action-row {
  margin-top: 6px;
  gap: 6px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  min-height: 30px;
  border-radius: 8px;
  padding: 0 10px;
  font-weight: 900;
}

.primary-button {
  color: #06130d;
  border: 1px solid var(--accent-strong);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.ghost-button {
  color: var(--ink);
  border: 1px solid var(--line);
  background: #0c1218;
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

.card-zones {
  display: grid;
  gap: 6px;
}

.zone {
  min-width: 0;
}

.zone-title {
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 850;
}

.zone-title small {
  color: var(--muted);
  font-weight: 700;
}

.cards {
  min-height: 58px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1319;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.card {
  width: 38px;
  height: 54px;
  border: 1px solid #d9dfd9;
  border-radius: 6px;
  background: linear-gradient(145deg, #fff, #dfe7df);
  color: #11171a;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24);
  display: grid;
  place-items: center;
  position: relative;
  user-select: none;
}

.card.clickable {
  cursor: pointer;
}

.card.red {
  color: #b71f2d;
}

.card.selected {
  outline: 2px solid var(--accent);
  transform: translateY(-2px);
}

.card.unplayable {
  opacity: 0.46;
}

.card.back {
  border-color: #42605c;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%) 0 0 / 12px 12px,
    linear-gradient(135deg, transparent 75%, rgba(255, 255, 255, 0.08) 75%) 0 0 / 12px 12px,
    #12312b;
}

.rank {
  font-size: 0.9rem;
  font-weight: 950;
}

.suit {
  position: absolute;
  right: 5px;
  bottom: 3px;
  font-size: 0.78rem;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.side-panel {
  min-width: 0;
  display: grid;
  gap: 8px;
  align-content: start;
  position: sticky;
  top: 8px;
}

.panel-block {
  padding: 8px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

select {
  min-height: 30px;
  width: 100%;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1218;
  padding: 5px 8px;
}

.hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
}

.player-list {
  display: grid;
  gap: 5px;
}

.player-row {
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1218;
}

.player-row.active {
  border-color: var(--accent);
}

.player-row.out {
  opacity: 0.55;
}

.player-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
  font-weight: 900;
}

.mini-cards {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.mini-card {
  min-width: 19px;
  min-height: 26px;
  padding: 2px;
  border-radius: 4px;
  background: #f5f7f2;
  color: #11171a;
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 950;
}

.mini-card.red {
  color: #b71f2d;
}

.mini-card.back {
  background: #12312b;
  color: #dff8ec;
}

.rules-block p {
  margin-bottom: 5px;
  font-size: 0.78rem;
}

.rules-block p:last-child {
  margin-bottom: 0;
}

.rules-strip {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px 12px;
  box-shadow: none;
}

.rules-strip p {
  margin: 0;
}

.celebration {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
}

.celebration-message {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 28px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(12, 18, 24, 0.92);
  box-shadow: var(--shadow);
  font-size: 1.05rem;
  font-weight: 950;
  text-align: center;
  animation: message-pop 2100ms ease forwards;
}

.confetti-piece {
  position: absolute;
  top: -36px;
  font-size: 1.3rem;
  animation: confetti-fall 3600ms linear forwards;
}

@keyframes confetti-fall {
  from {
    transform: translate3d(0, -20px, 0) rotate(0deg);
    opacity: 1;
  }
  to {
    transform: translate3d(var(--drift), 110vh, 0) rotate(720deg);
    opacity: 0;
  }
}

@keyframes message-pop {
  0% {
    transform: translateX(-50%) scale(0.92);
    opacity: 0;
  }
  14%,
  78% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateX(-50%) scale(0.98);
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(760px, calc(100vw - 24px));
  }

  .side-panel {
    position: static;
  }

  .rules-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .top-bar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-bar,
  .meta-row,
  .action-row {
    justify-content: stretch;
  }

  .chip,
  .primary-button,
  .ghost-button {
    width: 100%;
    text-align: center;
  }

  .card {
    width: 48px;
    height: 68px;
  }

  .rules-strip {
    grid-template-columns: 1fr;
  }
}
