.hidden { display: none !important; }

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --text: #eee;
  --text-muted: #aaa;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --card-width: 70px;
  --card-height: 100px;
  --green-felt: #2d7a3a;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Landing Page */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 2rem;
  text-align: center;
}

.landing h1 {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--accent), #f39c12);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

.create-form, .join-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 300px;
}

input[type="text"] {
  padding: 0.75rem 1rem;
  border: 2px solid #333;
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--accent);
}

input[type="submit"], .btn-start, .btn-copy {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

input[type="submit"], .btn-start {
  background: var(--accent);
  color: white;
}

input[type="submit"]:hover, .btn-start:hover {
  transform: scale(1.02);
}

input[type="submit"]:disabled, .btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-copy {
  background: transparent;
  border: 2px solid #444;
  color: var(--text);
}

.btn-copy:hover {
  border-color: var(--text);
}

.alert {
  background: #c0392b33;
  color: #e74c3c;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.join-section {
  margin-top: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  width: 100%;
  max-width: 300px;
}

.divider {
  text-align: center;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Lobby */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  height: 100dvh;
}

.lobby h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.room-code {
  color: var(--accent);
  font-family: monospace;
  font-size: 2rem;
  letter-spacing: 0.2em;
}

.players-list {
  width: 100%;
  max-width: 400px;
  margin-bottom: 1.5rem;
}

.players-list h2 {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.player-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--player-color);
}

.player-name {
  font-weight: 500;
}

.host-badge {
  font-size: 0.65rem;
  background: var(--accent);
  color: white;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 300px;
}

/* Game Board */
.game-board {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
}

.players-bar {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.player-avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  opacity: 0.6;
  transition: opacity 0.3s, transform 0.3s;
}

.player-avatar.active {
  opacity: 1;
  transform: scale(1.1);
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--player-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  border: 2px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.player-avatar.active .avatar-circle {
  border-color: white;
  box-shadow: 0 0 12px var(--accent-glow);
}

.avatar-name {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.player-avatar.active .avatar-name {
  color: var(--text);
}

/* Board Area */
.board-area {
  flex: 1;
  display: flex;
  position: relative;
  padding: 0.5rem;
  min-height: 0;
}

.card-pile {
  flex: 1;
  position: relative;
  background:
    url("data:image/svg+xml,%3Csvg width='6' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='6' height='6' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at center, rgba(255,255,255,0.06) 0%, transparent 70%),
    var(--green-felt);
  border-radius: 16px;
  overflow: hidden;
  touch-action: none;
  box-shadow: inset 0 2px 12px rgba(0,0,0,0.3);
}

.card-pile::before {
  content: "Name That Card\2122";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 2.2rem;
  font-style: italic;
  font-weight: 700;
  color: rgba(255,255,255,0.18);
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.sidebar {
  width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  flex-shrink: 0;
  overflow: hidden;
  min-height: 0;
}

/* Chat */
.chat-box {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 0.5rem;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.25rem;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  min-height: 60px;
}

.chat-msg {
  font-size: 0.65rem;
  line-height: 1.3;
  color: var(--text-muted);
  word-break: break-word;
}

.chat-msg strong {
  color: var(--text);
  font-weight: 600;
}

.chat-msg--system {
  color: var(--accent);
  font-style: italic;
  font-size: 0.6rem;
}

.chat-input-wrap {
  margin-top: 0.25rem;
  width: 100%;
}

.chat-input {
  width: 100%;
  padding: 0.3rem 0.4rem;
  border: 1px solid #444;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.7rem;
  outline: none;
  box-sizing: border-box;
}

input.chat-input:focus {
  border-color: #555;
}

.remaining-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  margin: 0.25rem 0;
}

.discard-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.discard-card {
  width: 60px;
  height: 86px;
  background: white;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  font-family: "Georgia", "Times New Roman", serif;
  flex-shrink: 0;
}

/* Cards */
.card {
  position: absolute;
  width: var(--card-width);
  height: var(--card-height);
  cursor: grab;
  transform: translate(-50%, -50%) rotate(var(--rotation, 0deg));
  transition: left 0.15s ease-out, top 0.15s ease-out;
  perspective: 600px;
}

.card.grabbing {
  cursor: grabbing;
  transition: none;
  z-index: 9999 !important;
}

.card.flipped {
  pointer-events: none;
}

.card.discarded {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transition: opacity 0.4s, transform 0.4s;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease-in-out;
  border-radius: 6px;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-back, .card-front {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Bicycle-style card backs */
.card-back {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid white;
  overflow: hidden;
}

.card-back--red {
  background: #c41e2a;
}

.card-back--blue {
  background: #1a3a6b;
}

.card-back::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 2px;
}

.card-back::after {
  content: "";
  width: 60%;
  height: 70%;
  border: 1.5px solid rgba(255,255,255,0.4);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at center, transparent 30%, rgba(255,255,255,0.08) 31%, rgba(255,255,255,0.08) 32%, transparent 33%),
    radial-gradient(ellipse at center, transparent 55%, rgba(255,255,255,0.08) 56%, rgba(255,255,255,0.08) 57%, transparent 58%),
    repeating-conic-gradient(
      from 0deg,
      rgba(255,255,255,0.06) 0deg 10deg,
      transparent 10deg 20deg
    );
  position: relative;
  z-index: 1;
}

/* Ornamental corner flourishes */
.card-back--red::before { border-color: rgba(255,255,255,0.4); }
.card-back--blue::before { border-color: rgba(255,255,255,0.35); }

.card-front {
  background: white;
  transform: rotateY(180deg);
  border: 1px solid #ccc;
  overflow: hidden;
}

/* Casino card layout */
.casino-card {
  width: 100%;
  height: 100%;
  position: relative;
  font-family: "Georgia", "Times New Roman", serif;
}

.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.card-corner--top {
  top: 3px;
  left: 4px;
}

.card-corner--bottom {
  bottom: 3px;
  right: 4px;
  transform: rotate(180deg);
}

.corner-rank {
  font-size: 0.75rem;
  font-weight: 700;
}

.corner-suit {
  font-size: 0.6rem;
  margin-top: -1px;
}

.card-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ace-symbol {
  font-size: 2.2rem;
  line-height: 1;
}

/* Pip grid for number cards */
.pip-grid {
  position: absolute;
  inset: 0;
}

.pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  line-height: 1;
}

.pip--flip {
  transform: translate(-50%, -50%) rotate(180deg);
}

/* Face cards */
.face-card-center {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.face-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 5px;
  pointer-events: none;
}

/* Discard card inherits casino-card styles */
.discard-card .casino-card {
  width: 100%;
  height: 100%;
}

/* Rules Button & Modal */
.rules-btn {
  position: absolute;
  top: 0.5rem;
  left: 0.75rem;
  z-index: 100;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.rules-btn:hover {
  background: rgba(255,255,255,0.2);
  color: var(--text);
}

.rules-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fade-in 0.2s;
}

.rules-overlay.hidden {
  display: none;
}

.rules-content {
  background: var(--bg-card);
  border: 1px solid #333;
  border-radius: 16px;
  padding: 2rem;
  max-width: 380px;
  width: 90%;
  position: relative;
}

.rules-content h2 {
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.rules-content > p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.rules-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.rules-close:hover {
  color: var(--text);
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
}

.rule-item--big {
  background: rgba(233, 69, 96, 0.12);
  border: 1px solid rgba(233, 69, 96, 0.25);
}

.rule-drinks {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
  min-width: 90px;
  flex-shrink: 0;
}

.rule-item--big .rule-drinks {
  color: #f39c12;
}

.rule-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rules-note {
  font-style: italic;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0 !important;
}

/* Turn Indicator */
.turn-indicator {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.your-turn {
  color: var(--accent);
  font-weight: 600;
  animation: pulse-text 1.5s ease-in-out infinite;
}

.waiting {
  color: var(--text-muted);
}

.your-turn-active {
  background: rgba(233, 69, 96, 0.1);
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Game Over */
.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fade-in 0.5s;
}

.game-over-overlay.hidden {
  display: none;
}

.game-over-content {
  text-align: center;
  padding: 2rem;
}

.game-over-content h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--accent), #f39c12);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-over-content p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --card-width: 50px;
    --card-height: 72px;
  }

  .landing h1 {
    font-size: 2rem;
  }

  .avatar-circle {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .avatar-name {
    font-size: 0.6rem;
  }

  .players-bar {
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
  }

  .sidebar {
    width: 90px;
  }

  .corner-rank {
    font-size: 0.5rem;
  }

  .corner-suit {
    font-size: 0.4rem;
  }

  .ace-symbol {
    font-size: 1.4rem;
  }

  .pip {
    font-size: 0.6rem;
  }

  .face-rank-big {
    font-size: 1.2rem;
  }

  .face-suit-big {
    font-size: 0.8rem;
  }
}
