*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at top, #0f172a, #020617 55%);
  color: #e5e7eb;
}

.app-header {
  padding: 1.5rem 1.5rem 0.5rem;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: #9ca3af;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.panel {
  background: rgba(15, 23, 42, 0.95);
  border-radius: 0.75rem;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.hidden {
  display: none;
}

.setup-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.setup-column {
  flex: 1 1 260px;
}

label {
  display: block;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.5rem 0.6rem;
  margin-top: 0.25rem;
  border-radius: 0.5rem;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: transform 0.08s ease, box-shadow 0.08s ease,
    background 0.2s ease;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.45);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(34, 197, 94, 0.55);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.error-message {
  color: #f97373;
  min-height: 1.1rem;
  margin-top: 0.5rem;
}

.room-code {
  font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.player-list li {
  padding: 0.25rem 0;
}

.game-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.game-table {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 1rem;
}

@media (max-width: 800px) {
  .game-table {
    grid-template-columns: 1fr;
  }
}

.pile-area {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.pile {
  text-align: center;
}

#draw-pile {
  cursor: pointer;
}

#draw-pile:hover .card.back {
  transform: translateY(-1px);
}

#discard-pile.pile--drop-target .card,
#discard-pile.pile--drop-target #discard-top {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
}

.pile span {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.card {
  width: 60px;
  height: 86px;
  border-radius: 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: radial-gradient(circle at top, #111827, #020617);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.4rem;
  color: #f9fafb;
  position: relative;
}

.card.small {
  width: 48px;
  height: 68px;
  font-size: 1.1rem;
}

.card-text {
  line-height: 1;
}

.card-value {
  position: absolute;
  right: 5px;
  bottom: 4px;
  font-size: 0.62rem;
  color: #cbd5e1;
  font-weight: 700;
  line-height: 1;
}

.card.back {
  background: linear-gradient(145deg, #1d4ed8, #0ea5e9);
  border-color: rgba(191, 219, 254, 0.8);
}

.card.placeholder {
  opacity: 0.4;
}

.card.selected {
  outline: 2px solid #22c55e;
  outline-offset: 2px;
}

.status-area {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: #e5e7eb;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.hand-area,
.words-area,
.controls-area {
  margin-bottom: 0.75rem;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.card-row.drag-over {
  background-color: rgba(34, 197, 94, 0.1);
  border-radius: 0.5rem;
  padding: 0.2rem;
}

.card {
  cursor: grab;
  user-select: none;
  transition: transform 0.1s, opacity 0.2s;
}

.card:active {
  cursor: grabbing;
}

.card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.card.drag-over {
  border-color: #22c55e;
  transform: scale(1.1);
}

.word-slot {
  border-radius: 0.75rem;
  border: 1px dashed rgba(148, 163, 184, 0.7);
  padding: 0.4rem;
  margin-bottom: 0.4rem;
  min-height: 60px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.word-slot.drag-over {
  background-color: rgba(34, 197, 94, 0.1);
  border-color: #22c55e;
  border-style: solid;
}

.word-slot.invalid {
  border-style: solid;
  border-color: #f97373;
}

.word-slot.valid {
  border-style: solid;
  border-color: #22c55e;
}

.word-slot-title {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-bottom: 0.25rem;
  flex-basis: 100%;
  width: 100%;
}

.controls-area button {
  margin-right: 0.3rem;
}

.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.scoreboard th,
.scoreboard td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(55, 65, 81, 0.8);
}

.scoreboard th {
  text-align: left;
  color: #9ca3af;
  font-weight: 500;
}

.scoreboard tbody tr:nth-child(odd) {
  background: rgba(15, 23, 42, 0.8);
}

.challenge-panel {
  margin-top: 1rem;
  border: 2px solid transparent;
  border-radius: 0.5rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.challenge-help {
  font-size: 0.85rem;
  color: #9ca3af;
  margin-bottom: 0.5rem;
}

.challenge-word-list {
  font-size: 0.9rem;
}

.challenge-word-item {
  margin-bottom: 0.3rem;
}

.challenge-word-item button {
  margin-left: 0.4rem;
}

.challenge-already {
  margin-left: 0.4rem;
  color: #6b7280;
  font-size: 0.85rem;
}

.challenge-result {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #e5e7eb;
}

#skip-challenge-btn {
  margin-top: 0.65rem;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4);
}

.app-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 1.5rem;
  display: flex;
  justify-content: flex-end;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
}

.modal-content {
  background: #020617;
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  position: relative;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #111827;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

.modal-close:hover {
  transform: none;
}

/* Ensure hidden wins over the modal's flex layout */
.modal.hidden {
  display: none;
}

.go-out-banner {
  margin-bottom: 0.75rem;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  background: rgba(34, 197, 94, 0.2);
  border: 1px solid rgba(34, 197, 94, 0.5);
  color: #86efac;
  font-weight: 600;
}
.go-out-banner.go-out-banner--challenge {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.5);
  color: #fcd34d;
}
.go-out-banner.hidden {
  display: none;
}

.challenge-countdown {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fcd34d;
  font-weight: 600;
}
.challenge-countdown.hidden {
  display: none;
}
.challenge-countdown-number {
  color: #fde047;
  font-variant-numeric: tabular-nums;
}

.challenge-panel.challenge-panel--focus {
  border-color: rgba(251, 191, 36, 0.7);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.25);
}

.summary-word {
  display: inline-block;
  margin: 0.1rem 0;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.82rem;
  border: 1px solid transparent;
}

.summary-word--clickable {
  margin-top: 0;
  box-shadow: none;
  cursor: pointer;
}

.summary-word--clickable:hover {
  transform: none;
  box-shadow: none;
}

.summary-word--valid {
  color: #86efac;
  background: rgba(34, 197, 94, 0.2);
  border-color: rgba(34, 197, 94, 0.5);
}

.summary-word--invalid-unchallenged {
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(251, 191, 36, 0.45);
}

.summary-word--invalid-challenged {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.5);
}

.summary-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.5rem 0 0.85rem;
}

.penalty-details {
  margin-top: 0.35rem;
  color: #fca5a5;
  font-size: 0.78rem;
  line-height: 1.25;
}

.penalty-details--summary {
  margin-top: 0.25rem;
}

