/* =============================================
   UNO ONLINE - Complete Stylesheet
   ============================================= */

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

:root {
  --color-red: #e74c3c;
  --color-blue: #3498db;
  --color-green: #2ecc71;
  --color-yellow: #f1c40f;
  --color-wild-bg: #1a1a2e;
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --text-primary: #eee;
  --text-secondary: #aaa;
  --text-muted: #666;
  --border-color: #2a2a4a;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Background --- */
.bg-decoration {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(233,68,96,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(52,152,219,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(46,204,113,0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- View Management --- */
.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.view.active {
  display: flex;
  flex-direction: column;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #c0392b);
  color: #fff;
  box-shadow: 0 4px 15px rgba(233,68,96,0.3);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(233,68,96,0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.btn-warning {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  font-size: 18px;
  padding: 12px 28px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(243,156,18,0.4);
  animation: pulse-uno 1.5s ease-in-out infinite;
}
.btn-warning:hover:not(:disabled) {
  box-shadow: 0 6px 25px rgba(243,156,18,0.6);
}
.btn-warning.pressed {
  animation: none;
  opacity: 0.6;
}

.btn-large {
  padding: 14px 32px;
  font-size: 17px;
  border-radius: var(--radius);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-icon-only {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 16px;
}
.btn-icon-only:hover {
  border-color: var(--accent);
}

.btn-icon {
  font-size: 18px;
}

@keyframes pulse-uno {
  0%, 100% { box-shadow: 0 4px 15px rgba(243,156,18,0.4); }
  50% { box-shadow: 0 6px 28px rgba(243,156,18,0.7); }
}

/* --- Inputs --- */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233,68,96,0.15);
}
.form-group input::placeholder {
  color: var(--text-muted);
}

/* =============================================
   LOBBY VIEW
   ============================================= */
.lobby-container {
  max-width: 420px;
  margin: auto;
  padding: 30px 20px;
  text-align: center;
}

.logo {
  margin-bottom: 30px;
}
.logo-icon {
  font-size: 64px;
  margin-bottom: 8px;
  animation: bounce 2s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.logo h1 {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #e74c3c, #f39c12, #2ecc71, #3498db);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradient-shift 4s ease infinite;
}
@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.lobby-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.lobby-buttons {
  margin-bottom: 16px;
}
.lobby-buttons .btn {
  width: 100%;
}

.divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}
.divider span {
  padding: 0 16px;
}

.join-row {
  display: flex;
  gap: 8px;
}
.join-row input {
  flex: 1;
}
.join-row .btn {
  flex-shrink: 0;
}

.tip {
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* =============================================
   ROOM WAITING VIEW
   ============================================= */
.room-container {
  max-width: 500px;
  margin: auto;
  padding: 20px;
  width: 100%;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.room-code-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
}

.room-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.room-code {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent);
  font-family: 'Courier New', monospace;
}

.room-content {
  flex: 1;
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.player-item.host {
  border-color: var(--accent);
}

.player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.player-name {
  flex: 1;
  font-weight: 600;
  font-size: 16px;
}

.player-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.player-badge.host {
  background: rgba(233,68,96,0.2);
  color: var(--accent);
}

.player-count {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 12px 0;
}

.room-footer {
  text-align: center;
  padding-top: 20px;
}

.room-tip {
  color: var(--text-muted);
  font-size: 14px;
  padding: 10px 0;
}

/* =============================================
   GAME VIEW
   ============================================= */
.game-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.opponents-area {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 8px 0;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.opponent-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  min-width: 100px;
  transition: all var(--transition);
}
.opponent-display.current-turn {
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(233,68,96,0.3);
  animation: turn-glow 1.5s ease-in-out infinite;
}
@keyframes turn-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(233,68,96,0.2); }
  50% { box-shadow: 0 0 20px rgba(233,68,96,0.5); }
}

.opponent-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.opponent-hand {
  display: flex;
  gap: 2px;
  position: relative;
}

.opponent-card {
  width: 28px;
  height: 38px;
  background: linear-gradient(135deg, #2c3e50, #34495e);
  border: 1px solid #4a6278;
  border-radius: 3px;
}

.opponent-uno-badge {
  font-size: 11px;
  padding: 2px 8px;
  background: rgba(243,156,18,0.2);
  color: #f39c12;
  border-radius: 10px;
  font-weight: 700;
  animation: pulse-uno 0.8s ease-in-out infinite;
}

/* --- Game Center (discard + draw piles) --- */
.game-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
}

.direction-indicator {
  font-size: 28px;
  color: var(--text-muted);
  height: 36px;
  line-height: 1;
}

.pile-area {
  display: flex;
  align-items: center;
  gap: 40px;
}

.discard-pile, .draw-pile {
  position: relative;
}

.draw-pile {
  cursor: pointer;
  transition: transform var(--transition);
}
.draw-pile:hover {
  transform: scale(1.05);
}
.draw-pile:active {
  transform: scale(0.97);
}
.draw-pile.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.draw-pile.disabled:hover {
  transform: none;
}

.pile-count {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.game-status {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  min-height: 24px;
}

/* --- My Hand Area --- */
.my-hand-area {
  padding: 8px 0 12px;
  flex-shrink: 0;
}

.hand-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.hand-cards {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 20px;
  min-height: 140px;
  align-items: flex-end;
}

/* =============================================
   UNO CARD DESIGN (CSS only)
   ============================================= */
.card {
  width: 90px;
  height: 130px;
  border-radius: 10px;
  background: #fff;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  user-select: none;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border: 3px solid #ddd;
}

.card:hover {
  transform: translateY(-12px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  z-index: 10;
}

.card.selected {
  transform: translateY(-16px);
  box-shadow: 0 0 20px rgba(233,68,96,0.6);
  border-color: var(--accent);
}

.card.not-playable {
  opacity: 0.6;
  cursor: not-allowed;
}
.card.not-playable:hover {
  transform: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Card colors */
.card.red {
  background: linear-gradient(135deg, #fff 60%, #e74c3c 60%);
  border-color: #c0392b;
  color: #c0392b;
}
.card.blue {
  background: linear-gradient(135deg, #fff 60%, #3498db 60%);
  border-color: #2980b9;
  color: #2980b9;
}
.card.green {
  background: linear-gradient(135deg, #fff 60%, #2ecc71 60%);
  border-color: #27ae60;
  color: #27ae60;
}
.card.yellow {
  background: linear-gradient(135deg, #fff 60%, #f1c40f 60%);
  border-color: #f39c12;
  color: #c8960c;
}
.card.wild {
  background: linear-gradient(135deg, #1a1a2e 50%, #e74c3c 25%, #3498db 50%, #2ecc71 75%, #f1c40f 100%);
  border-color: #333;
  color: #fff;
}

/* Card content */
.card-value {
  font-size: 32px;
  line-height: 1;
  position: absolute;
  top: 40%;
  transform: translateY(-50%);
}

.card-type-icon {
  font-size: 28px;
  position: absolute;
  top: 40%;
  transform: translateY(-50%);
}

.card-corner-top, .card-corner-bottom {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.card-corner-top {
  top: 6px;
  left: 8px;
}
.card-corner-bottom {
  bottom: 6px;
  right: 8px;
  transform: rotate(180deg);
}

/* Card back */
.card-back {
  background: linear-gradient(135deg, #1a1a2e, #16213e) !important;
  border-color: #333 !important;
  cursor: default;
}
.card-back:hover {
  transform: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.card-back-inner {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 2px;
}

/* Discard pile card (larger) */
.discard-pile .card {
  width: 100px;
  height: 140px;
}
.discard-pile .card-value {
  font-size: 36px;
}
.discard-pile .card-type-icon {
  font-size: 32px;
}

/* =============================================
   COLOR PICKER MODAL
   ============================================= */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal.active {
  display: flex;
}

.color-picker-content {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.color-picker-content h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

.color-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-btn {
  width: 70px;
  height: 70px;
  border: 3px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  transition: all var(--transition);
}
.color-btn:hover {
  transform: scale(1.1);
  border-color: #fff;
  box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

/* =============================================
   GAME OVER VIEW
   ============================================= */
.gameover-container {
  max-width: 460px;
  margin: auto;
  padding: 30px 20px;
  text-align: center;
}

.gameover-header {
  margin-bottom: 24px;
}
.trophy {
  font-size: 64px;
  margin-bottom: 8px;
  animation: bounce 1.5s ease-in-out infinite;
}
.gameover-header h2 {
  font-size: 28px;
  color: #f1c40f;
  margin-bottom: 4px;
}
.gameover-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.score-table {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.score-row {
  display: flex;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  gap: 12px;
}
.score-row:last-child {
  border-bottom: none;
}
.score-row.winner {
  background: rgba(241,196,15,0.1);
}
.score-rank {
  font-weight: 800;
  font-size: 18px;
  color: var(--text-muted);
  width: 30px;
}
.score-row.winner .score-rank {
  color: #f1c40f;
}
.score-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
}
.score-points {
  font-weight: 800;
  font-size: 18px;
  color: var(--accent);
}

.gameover-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.score-history {
  text-align: left;
}
.score-history h3 {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}
.history-item {
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.history-item .history-winner {
  color: #f1c40f;
  font-weight: 600;
}

/* =============================================
   CHAT / TOAST
   ============================================= */
#chat-container {
  position: fixed;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 90%;
  max-width: 500px;
}

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 80px;
  overflow: hidden;
}

.chat-msg {
  padding: 4px 14px;
  background: rgba(26,26,46,0.9);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  animation: chat-in 0.3s ease, chat-out 0.3s ease 3.7s;
  white-space: nowrap;
}
@keyframes chat-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes chat-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(233,68,96,0.4);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
}
.toast.success {
  background: #27ae60;
  box-shadow: 0 4px 15px rgba(39,174,96,0.4);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-20px); }
}

/* Shared link toast */
.share-link-toast {
  cursor: pointer;
  background: #2980b9;
  box-shadow: 0 4px 15px rgba(41,128,185,0.4);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 600px) {
  .card {
    width: 64px;
    height: 96px;
    border-radius: 7px;
    border-width: 2px;
  }
  .card-value {
    font-size: 22px;
  }
  .card-type-icon {
    font-size: 20px;
  }
  .card-corner-top, .card-corner-bottom {
    font-size: 9px;
  }
  .card-corner-top {
    top: 4px;
    left: 5px;
  }
  .card-corner-bottom {
    bottom: 4px;
    right: 5px;
  }

  .discard-pile .card {
    width: 78px;
    height: 110px;
  }

  .opponent-card {
    width: 20px;
    height: 28px;
  }

  .hand-cards {
    gap: 3px;
    padding: 0 8px;
    min-height: 100px;
  }

  .pile-area {
    gap: 24px;
  }

  .btn-large {
    padding: 12px 24px;
    font-size: 15px;
  }
  .btn-warning {
    font-size: 15px;
    padding: 10px 22px;
  }

  .logo h1 {
    font-size: 28px;
  }
}

@media (max-width: 400px) {
  .card {
    width: 52px;
    height: 78px;
    border-radius: 5px;
  }
  .card-value {
    font-size: 18px;
  }
  .card-type-icon {
    font-size: 16px;
  }
  .card-corner-top, .card-corner-bottom {
    font-size: 7px;
  }

  .discard-pile .card {
    width: 64px;
    height: 90px;
  }
  .card-back-inner {
    font-size: 16px;
  }

  .hand-cards {
    gap: 2px;
    padding: 0 4px;
  }
}
