body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, #f1f5f9 0, #f8fafc 40%, #eef2ff 100%);
}

* {
  caret-color: transparent;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #0f172a;
  background: radial-gradient(circle at 20% 20%, #f1f5f9 0, #f8fafc 40%, #eef2ff 100%);
  min-height: 100vh;
}

.masthead {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 12px;
  color: #6b7280;
  margin: 0;
}

.masthead h1 {
  margin: 0;
  font-size: 2.6rem;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 4px 0 0;
  color: #475569;
}

.game-meta {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 220px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.theme-toggle {
  align-self: flex-start;
  display: flex;
  gap: 8px;
}

.ghost.danger {
  color: #b91c1c;
  border-color: #b91c1c;
}

.ghost.danger:hover {
  background: rgba(185, 28, 28, 0.1);
  color: #991b1b;
  border-color: #991b1b;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 14px;
}

.meta-line strong {
  color: #fff;
}

.alert {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecdd3;
  box-shadow: 0 10px 24px rgba(190, 24, 93, 0.12);
  display: none;
}

.alert.visible {
  display: block;
}

.panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.panel.nested {
  box-shadow: none;
  background: #f8fafc;
}

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

label {
  font-weight: 600;
  color: #0f172a;
}

input {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  caret-color: transparent;
}

input:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

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

button {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  background: #e2e8f0;
  color: #0f172a;
  font-weight: 600;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.15);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

button.accent {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
}

button.accent:disabled {
  background: #e2e8f0;
  color: #475569;
}

button.bold {
  background: #0f172a;
  color: #fff;
}

button.block {
  width: 100%;
  text-align: center;
}

button.ghost {
  background: #f8fafc;
}

.info-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  align-items: stretch;
}

.action-card {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: space-between;
  min-height: 180px;
  position: relative;
  overflow: hidden;
}

.action-card h3 {
  margin: 4px 0;
}

.action-card .hint {
  color: #475569;
  margin: 0;
}

.create-card {
  background: linear-gradient(145deg, #0f172a, #1e293b);
  color: #e2e8f0;
  border-color: #0f172a;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.3);
}

.create-card .hint {
  color: #cbd5e1;
}

.join-card {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
}

.start-card {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  display: none;
}

body.joined .start-card {
  display: flex;
}

body.joined .create-card,
body.joined .join-card {
  display: none;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.turn-progress {
  color: #475569;
  font-size: 14px;
}

.board {
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: 12px;
  align-items: center;
}

.piles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.pile {
  padding: 10px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.1s ease;
}

.pile:hover {
  transform: translateY(-1px);
}

.pile.on-fire {
  border-color: #ef4444;
  background: #fff1f2;
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.35), 0 12px 22px rgba(239, 68, 68, 0.25);
}

.pile.locked {
  opacity: 0.55;
  pointer-events: none;
  cursor: not-allowed;
}

.pile.selected {
  border-color: #7c3aed;
  background: #ede9fe;
}

.pile.hint {
  border-color: #0ea5e9;
  box-shadow: inset 0 0 0 2px rgba(14, 165, 233, 0.3);
}

.pile.muted {
  opacity: 0.5;
}

.pile .label {
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 4px;
}

.pile .top {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.pile .top.on-fire-top,
.pile .top.on-fire-top .top-old,
.pile .top.on-fire-top .top-new {
  color: #b91c1c;
}

.pile .top-old {
  color: #475569;
  animation: pileOld 1.3s ease forwards;
}

.pile .top-new {
  color: inherit;
  animation: pileNew 1.3s ease forwards;
}

.pile.pile-change {
  animation: pileHighlight 2s ease;
}

.pile.pile-backwards {
  position: relative;
  overflow: hidden;
  animation: backwardsFlash 2.55s ease-in-out;
}

.pile.pile-backwards::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 14px;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  opacity: 0;
  animation: backwardsBorder 2.55s ease-in-out;
  pointer-events: none;
  z-index: 1;
}

@keyframes backwardsFlash {
  0% {
    background: rgba(34, 197, 94, 0.18);
    box-shadow: inset 0 0 0 0 rgba(34, 197, 94, 0.4);
  }
  60% {
    background: rgba(34, 197, 94, 0.28);
    box-shadow: inset 0 0 0 4px rgba(34, 197, 94, 0.45);
  }
  100% {
    background: transparent;
    box-shadow: inset 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes backwardsBorder {
  0% {
    opacity: 0;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.0);
  }
  60% {
    opacity: 1;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.55);
  }
  100% {
    opacity: 0;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes pileHighlight {
  0% {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.6);
  }
  70% {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

@keyframes pileOld {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-10px);
  }
}

@keyframes pileNew {
  0% {
    opacity: 0;
    transform: translateX(10px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

.pile .count {
  font-weight: 600;
  font-size: 12px;
  color: #475569;
}

.fire-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 14px rgba(239, 68, 68, 0.3);
}

.pile.asc .label { color: #16a34a; }
.pile.desc .label { color: #ef4444; }

.deck {
  justify-self: end;
  text-align: center;
}

.card {
  padding: 12px 10px;
  background: #0f172a;
  color: #fff;
  border-radius: 10px;
  display: inline-block;
  min-width: 72px;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.2);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 24px rgba(15, 23, 42, 0.18);
}

.card.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: #e2e8f0;
  color: #475569;
}

.card.selected {
  outline: 3px solid #7c3aed;
  background: #6d28d9;
}

.card.hint {
  outline: 2px solid #0ea5e9;
}

.card.muted {
  opacity: 0.5;
}

.card.on-fire-card {
  background: linear-gradient(135deg, #b91c1c, #ef4444);
  color: #fff7ed;
  box-shadow: 0 12px 24px rgba(239, 68, 68, 0.3);
}

.card.on-fire-card.disabled {
  background: #fecdd3;
  color: #7f1d1d;
  opacity: 0.9;
  box-shadow: none;
}

.card.drawn {
  background: #e0f2fe;
  color: #0f172a;
}

.card.card-enter {
  opacity: 0;
  transform: translateY(12px) scale(0.9);
  animation: card-enter-pop 1.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes card-enter-pop {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.9);
  }
  70% {
    opacity: 1;
    transform: translateY(0) scale(1.03);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card.ghost {
  background: #cbd5e1;
  color: #0f172a;
  box-shadow: none;
}

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

.hand-panel {
  margin-top: 4px;
}

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

.turn-controls {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.turn-actions {
  display: flex;
  gap: 8px;
}

#selection {
  color: #334155;
}

.subturn-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

button.small {
  padding: 6px 10px;
  font-size: 12px;
}

.side-panel {
  display: none;
}

.players ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.players li {
  padding: 6px 0;
}

.turn-notice {
  margin: 6px 0 10px;
  font-weight: 800;
  font-size: 20px;
  color: #0ea5e9;
}

.turn-notice.me {
  color: #16a34a;
}

.turn-notice.other {
  color: #f97316;
}

.not-your-turn .gameplay-action {
  opacity: 0.6;
  pointer-events: none;
  cursor: not-allowed !important;
}

.not-your-turn .gameplay-action:hover {
  transform: none;
  box-shadow: none;
}

.not-your-turn .gameplay-click {
  pointer-events: none;
  opacity: 0.55;
  cursor: not-allowed !important;
}

.subturn-log ul {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
}

.subturn-log li {
  padding: 6px 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 14px;
}

.pill {
  display: inline-block;
  background: #0f172a;
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 4px;
  font-weight: 700;
}

.pill.good-play {
  background: #16a34a;
  color: #0f172a;
}

.pill.on-fire-pill {
  background: #ef4444;
  color: #fff7ed;
  box-shadow: 0 10px 18px rgba(239, 68, 68, 0.35);
}

.pill-small {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.15);
}

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

.status-banner {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 700;
}

.status-win {
  background: #dcfce7;
  color: #166534;
}

.status-lose {
  background: #f0fdf4;
  color: #15803d;
}

.status-detail {
  margin-top: 8px;
  font-size: 14px;
  color: #475569;
}

.remaining-row {
  margin-top: 20px;
}

.remaining-hands {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
}

.remaining-hands li {
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.remaining-player {
  font-weight: 700;
  color: #0f172a;
  display: inline-flex;
}

.remaining-none {
  color: #94a3b8;
  font-style: italic;
}

.remaining-label {
  margin: 20px 0 6px;
}

.remaining-hands .pill-row {
  margin-top: 0;
}

@media (max-width: 960px) {
  .masthead {
    flex-direction: column;
    align-items: flex-start;
  }
  .game-meta {
    width: 100%;
  }
  .board {
    grid-template-columns: 1fr;
  }
}

body.theme-dark {
  background: radial-gradient(circle at 15% 15%, #0f172a 0, #0b1220 45%, #090f1b 100%);
  color: #e2e8f0;
}

/* Dark theme overrides */
.theme-dark .page {
  color: #e2e8f0;
  background: radial-gradient(circle at 15% 15%, #0f172a 0, #0b1220 45%, #090f1b 100%);
}

.theme-dark .panel {
  background: #0f172a;
  border-color: #1f2937;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.theme-dark .panel.nested {
  background: #111827;
}

.theme-dark .action-card {
  border-color: #1f2937;
}

.theme-dark .join-card,
.theme-dark .start-card {
  background: #111827;
}

.theme-dark label,
.theme-dark .tagline,
.theme-dark .turn-progress,
.theme-dark #selection {
  color: #cbd5e1;
}

.theme-dark input {
  background: #0b1220;
  color: #e2e8f0;
  border-color: #1f2937;
}

.theme-dark button.ghost {
  background: #111827;
  color: #e2e8f0;
}

.theme-dark .pile {
  background: #111827;
  border-color: #1f2937;
}

.theme-dark .pile.on-fire {
  background: #2b1216;
  border-color: #b91c1c;
  box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.4), 0 12px 22px rgba(248, 113, 113, 0.18);
}

.theme-dark .pile .top.on-fire-top,
.theme-dark .pile .top.on-fire-top .top-old,
.theme-dark .pile .top.on-fire-top .top-new {
  color: #fecdd3;
}

.theme-dark .pile.selected {
  background: #1f2937;
}

.theme-dark .deck .card.ghost {
  background: #1f2937;
  color: #cbd5e1;
}

.theme-dark .card {
  background: #0c2038;
  color: #e5e7eb;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.theme-dark .card.selected {
  background: #312e81;
}

.theme-dark .card.on-fire-card {
  background: linear-gradient(135deg, #7f1d1d, #dc2626);
  color: #fff1f2;
  box-shadow: 0 12px 22px rgba(248, 113, 113, 0.35);
}

.theme-dark .card.on-fire-card.disabled {
  background: #7f1d1d;
  color: #fecdd3;
}

.theme-dark .card.drawn {
  background: #1e3a8a;
  color: #e5e7eb;
}

.theme-dark .pill {
  background: #0c2038;
  color: #e5e7eb;
  box-shadow: 0 0 0 2px #1a3b6a;
}

.theme-dark .pill.good-play {
  background: #22c55e;
  color: #0f172a;
  box-shadow: 0 0 0 2px #166534;
}

.theme-dark .pill.on-fire-pill {
  background: #dc2626;
  color: #fee2e2;
  box-shadow: 0 10px 18px rgba(248, 113, 113, 0.35);
}

.theme-dark .pile.pile-change {
  animation: pileHighlightDark 2s ease;
}

.theme-dark .fire-tag {
  background: linear-gradient(135deg, #7f1d1d, #dc2626);
  color: #fee2e2;
  box-shadow: 0 6px 14px rgba(248, 113, 113, 0.35);
}

.theme-dark .pile.pile-backwards::after {
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
}

.theme-dark .pile .top-old {
  color: #94a3b8;
}

.theme-dark .pile .top-new {
  color: #e5e7eb;
}

.theme-dark .remaining-player {
  color: #e2e8f0;
}

.theme-dark .remaining-none {
  color: #9ca3af;
}

.theme-dark .remaining-label {
  color: #e2e8f0;
}

@keyframes pileHighlightDark {
  0% {
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.5);
  }
  70% {
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.theme-dark .alert {
  background: #2f1f28;
  border-color: #7f1d1d;
  color: #fecdd3;
  box-shadow: 0 10px 24px rgba(124, 45, 18, 0.32);
}

.theme-dark .game-meta {
  background: #111827;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.theme-dark .subturn-log li {
  border-color: #1f2937;
}
