:root {
  --ink: #1f2933;
  --muted: #667085;
  --paper: #fffaf0;
  --line: #e0cfaa;
  --red: #d92d20;
  --gold: #d99a20;
  --teal: #0f766e;
  --blue: #2563eb;
  --purple: #6d28d9;
  --green: #15803d;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(217, 45, 32, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(15, 118, 110, 0.16), transparent 38%),
    #f6efe2;
  font-family: Arial, Helvetica, sans-serif;
}

.game {
  display: grid;
  gap: 12px;
  padding: 16px;
}

header,
.header-actions,
.table,
.hand-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

header {
  justify-content: space-between;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1;
}

h2 {
  font-size: 20px;
}

#contextLabel {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: white;
  background: var(--teal);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  background: #9aa4b2;
  cursor: not-allowed;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 6px;
}

.player,
.turn-panel,
.discard,
.special-panel,
.hand-panel {
  border: 1px solid rgba(99, 70, 28, 0.18);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.08);
}

.player {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
}

.player strong {
  font-size: 14px;
  line-height: 1.15;
}

.player.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.player.out {
  color: var(--muted);
  text-decoration: line-through;
}

.player strong,
.player span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
}

.table {
  flex-wrap: wrap;
  justify-content: center;
}

.deck {
  display: grid;
  place-items: center;
  width: min(34vw, 180px);
  min-width: 136px;
  aspect-ratio: 5 / 7;
  border: 4px solid #4d2c1a;
  color: #fff7ed;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 42%),
    var(--red);
  box-shadow: 0 18px 36px rgba(31, 41, 51, 0.22);
}

.deck span {
  font-size: 44px;
  font-weight: 900;
  line-height: 1;
}

.discard,
.turn-panel {
  min-width: min(100%, 260px);
  padding: 14px;
}

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

#status {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.special-panel,
.hand-panel {
  padding: 14px;
}

.special-panel.hidden,
.result-overlay.hidden {
  display: none;
}

.placement-actions,
.glimpse-row,
.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hand-heading {
  justify-content: space-between;
  margin-bottom: 12px;
}

.card {
  position: relative;
  display: grid;
  align-content: center;
  place-items: center;
  gap: 6px;
  width: 116px;
  min-height: 136px;
  border: 3px solid #3f2b1b;
  border-radius: 8px;
  padding: 10px;
  color: #1f2933;
  background: var(--paper);
  box-shadow: 0 10px 18px rgba(31, 41, 51, 0.16);
  text-align: center;
}

.card.playable {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.18), 0 10px 18px rgba(31, 41, 51, 0.16);
}

/* 방금 받은 카드는 손패에서 바로 알아볼 수 있게 표시한다. */
.card.just-received {
  border-color: #e0a928;
  box-shadow: 0 0 0 5px rgba(224, 169, 40, 0.32), 0 10px 18px rgba(31, 41, 51, 0.16);
}

.new-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 999px;
  color: #1f2933;
  background: #e0a928;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
}

.card.mini {
  width: 92px;
  min-height: 106px;
}

.card.empty {
  color: var(--muted);
  background: #f4ead8;
}

.card.hazard {
  color: white;
  background: var(--red);
}

.card.safety {
  background: #fef3c7;
}

.card.pileon {
  color: white;
  background: var(--purple);
}

.card.bypass {
  color: white;
  background: var(--blue);
}

.card.glimpse {
  color: white;
  background: var(--teal);
}

.card.scramble {
  color: white;
  background: var(--green);
}

.card.swipe {
  color: white;
  background: var(--gold);
}

.card.shield {
  color: white;
  background: #334155;
}

.card strong {
  max-width: 100%;
  min-width: 0;
  font-size: 18px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.card span {
  max-width: 100%;
  min-width: 0;
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  opacity: 0.82;
  overflow-wrap: anywhere;
}

.result-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 20;
  display: grid;
  min-width: min(78vw, 380px);
  padding: 28px 34px;
  border: 2px solid #facc15;
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.97);
  box-shadow: 0 24px 60px rgba(31, 41, 51, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#resultMessage {
  color: var(--teal);
  font-size: clamp(40px, 9vmin, 78px);
  font-weight: 900;
  line-height: 1;
}

@media (max-width: 640px) {
  .game {
    padding: 14px;
  }

  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .table {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
  }

  .deck {
    width: 112px;
    min-width: 104px;
    border-width: 3px;
  }

  .deck span {
    font-size: 38px;
  }

  .discard {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px;
  }

  .turn-panel {
    flex: 1 0 100%;
    min-width: 0;
    padding: 10px;
  }

  .discard .card.mini {
    width: 82px;
    min-height: 96px;
    padding: 8px;
  }

  .discard .card.mini strong {
    font-size: 15px;
  }

  .discard .card.mini span {
    font-size: 11px;
  }

  .card {
    width: 104px;
    min-height: 124px;
    gap: 5px;
    padding: 8px;
  }

  .card strong {
    font-size: 16px;
  }

  .card span {
    font-size: 11px;
  }
}
