* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at center, #1f6b3a 0%, #0d3a1f 100%);
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.hidden { display: none !important; }

/* ============ LOBBY ============ */
.lobby-box, .room-box {
  background: rgba(0,0,0,0.55);
  padding: 28px;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
h1 { font-size: 38px; margin-bottom: 6px; }
h1 .tag { display: inline-block; background: #d32f2f; color: #fff; padding: 2px 10px; font-size: 16px; border-radius: 6px; vertical-align: middle; }
.hint { color: #cbd5d0; margin-bottom: 18px; font-size: 14px; }
label { display: block; text-align: left; font-size: 12px; color: #cbd5d0; margin-bottom: 6px; }
input {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: #fff;
  margin-bottom: 14px;
}
input:focus { outline: none; border-color: #f9a825; }
.btn-row { display: flex; flex-direction: column; gap: 10px; }
.create-row { display: flex; gap: 10px; align-items: center; }
.create-row .btn-primary { flex: 1; }
.check-private {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #cbd5d0;
  text-align: left !important;
  margin: 0 !important;
  cursor: pointer;
}
.check-private input { width: auto; margin: 0; }
.join-group { display: flex; gap: 8px; }
.join-group input { margin: 0; text-transform: uppercase; flex: 1; }
button {
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 16px;
  transition: transform 0.1s, box-shadow 0.1s;
}
button:active { transform: scale(0.97); }
.btn-primary { background: #d32f2f; color: #fff; }
.btn-primary:hover { background: #b71c1c; }
.btn-secondary { background: #f9a825; color: #000; }
.btn-text { background: transparent; color: #cbd5d0; margin-top: 12px; }
.btn-text:hover { color: #fff; }
.error { color: #ff8a80; margin-top: 10px; font-size: 14px; min-height: 18px; }

.rooms-section {
  margin-top: 22px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 18px;
  text-align: left;
}
.rooms-title { font-size: 13px; color: #cbd5d0; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.rooms-count {
  background: #f9a825;
  color: #000;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 4px;
}
.rooms-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.08);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.room-item:hover, .room-item:active { background: rgba(249,168,37,0.2); }
.room-item.started { border-left: 3px solid #f9a825; }
.room-item .ri-code { font-family: monospace; font-size: 16px; color: #f9a825; letter-spacing: 2px; }
.room-item .ri-info { font-size: 12px; color: #cbd5d0; text-align: right; }
.room-item .ri-host { font-weight: 600; color: #fff; }
.ri-badge {
  background: #d32f2f;
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
}
.rooms-empty { color: #888; font-size: 13px; text-align: center; padding: 14px; font-style: italic; }

/* ============ ROOM ============ */
#room-code { font-family: monospace; font-size: 36px; color: #f9a825; letter-spacing: 4px; }
#room-players { list-style: none; margin: 20px 0 14px; }
.room-chat {
  margin-bottom: 16px;
  text-align: left;
}
.room-chat-list {
  max-height: 180px;
  overflow-y: auto;
  background: rgba(0,0,0,0.35);
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.08);
}
.room-chat-list div {
  padding: 3px 0;
  word-break: break-word;
}
.room-chat-list .msg-nick { font-weight: 700; color: #f9a825; margin-right: 6px; }
.room-chat-empty { color: #777; font-style: italic; text-align: center; padding: 14px 0 !important; }
.room-chat .chat-input-wrap input {
  flex: 1;
  margin: 0;
  padding: 8px 12px;
  font-size: 14px;
}
#room-players li {
  padding: 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}
.host-badge { background: #f9a825; color: #000; padding: 2px 8px; border-radius: 4px; font-size: 11px; }

/* ============ GAME ============ */
.table {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: 10px;
  gap: 10px;
}

.btn-cover {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 30;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 22px;
  padding: 0;
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.btn-abandon {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  background: rgba(150,30,30,0.9);
  color: #fff;
  font-size: 13px;
  padding: 11px 16px;
  border-radius: 30px;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Banner de turno enorme */
.turn-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  padding: 14px 60px 14px 78px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #2e7d32 0%, #1f6b3a 50%, #2e7d32 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  transition: background 0.3s;
}
.turn-banner.my-turn {
  background: linear-gradient(90deg, #f9a825 0%, #ff6f00 50%, #f9a825 100%);
  color: #000;
  font-size: 22px;
  animation: bannerPulse 0.9s ease-in-out infinite;
}
@keyframes bannerPulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(249,168,37,0.4); }
  50% { box-shadow: 0 4px 30px rgba(249,168,37,0.95); }
}

.flash-layer {
  position: fixed;
  inset: 0;
  background: #f9a825;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.5s ease-out;
}
.flash-layer.fire { opacity: 0.5; transition: opacity 0.05s; }

.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: #d32f2f;
  color: #fff;
  padding: 10px 20px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 6px 18px rgba(0,0,0,0.55);
  animation: toastIn 0.2s ease-out;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}
.toast.ok { background: #2e7d32; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.announce {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.announce-text {
  font-size: 84px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 24px rgba(0,0,0,0.8), 0 6px 12px rgba(0,0,0,0.6);
  animation: announcePop 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
  letter-spacing: 2px;
}
.announce-text.uno { color: #ffeb3b; }
.announce-text.draw2 { color: #ff5252; }
.announce-sub {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  margin-top: 6px;
  animation: announcePop 0.5s ease-out;
}
@keyframes announcePop {
  0% { opacity: 0; transform: scale(0.3); }
  60% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}
@media (max-width: 600px) {
  .announce-text { font-size: 56px; }
  .announce-sub { font-size: 18px; }
}

.opponents {
  margin-top: 56px;
  display: flex;
  gap: 14px;
  row-gap: 36px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 60px 0 4px;
}
.opponent {
  background: rgba(0,0,0,0.45);
  padding: 8px 12px;
  border-radius: 10px;
  text-align: center;
  min-width: 96px;
  border: 2px solid transparent;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.opponent.current {
  border-color: #f9a825;
  box-shadow: 0 0 20px #f9a825;
  background: rgba(249,168,37,0.15);
  animation: oppBreath 1.4s ease-in-out infinite;
}
@keyframes oppBreath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.opponent.eliminated { opacity: 0.4; text-decoration: line-through; }
.opponent.offline { opacity: 0.5; }
.opponent .nick { font-weight: 700; font-size: 14px; }
.opponent .count { font-size: 11px; color: #cbd5d0; }
.uno-badge { background: #d32f2f; color: #fff; padding: 1px 6px; border-radius: 4px; font-size: 10px; margin-left: 4px; }
.order-badge {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 24px;
  height: 24px;
  background: #1565c0;
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  z-index: 3;
}
.order-badge.next { background: #f9a825; color: #000; }
.offline-tag {
  display: block;
  font-size: 9px;
  color: #ff8a80;
  font-weight: 700;
}
#my-order {
  background: #1565c0;
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  margin-left: 6px;
}

.chat-bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #111;
  padding: 6px 10px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 14px rgba(0,0,0,0.55);
  z-index: 40;
  animation: bubbleIn 0.2s ease-out;
  pointer-events: none;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-bubble::after {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: #fff;
  border-top: 0;
}
@media (min-width: 701px) {
  .chat-bubble {
    top: auto;
    bottom: calc(100% + 8px);
    animation: bubbleInUp 0.2s ease-out;
  }
  .chat-bubble::after {
    top: auto;
    bottom: -6px;
    border-bottom-color: transparent;
    border-top-color: #fff;
    border-bottom: 0;
    border-top: 6px solid #fff;
  }
  .opponents { row-gap: 14px; }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes bubbleInUp {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}
.pile { width: 90px; height: 130px; position: relative; }
.card-back, .card {
  width: 90px; height: 130px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  transition: transform 0.15s;
  position: relative;
  user-select: none;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}
.card-back {
  background: #0d3a1f;
  border: 4px solid #fff;
  font-style: italic;
  font-size: 22px;
  cursor: pointer;
}
.pile-count {
  position: absolute;
  bottom: -8px;
  right: -8px;
  background: #f9a825;
  color: #000;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.card.red { background: #d32f2f; }
.card.yellow { background: #f9a825; color: #000; }
.card.green { background: #2e7d32; }
.card.blue { background: #1565c0; }
.card.wild { background: linear-gradient(135deg, #d32f2f 0%, #f9a825 33%, #2e7d32 66%, #1565c0 100%); }

.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-10px); }
.card.locked { opacity: 0.7; cursor: not-allowed; }
.card .val { font-size: 22px; padding: 0 4px; text-align: center; line-height: 1.1; }
.card.text-label .val { font-size: 14px; font-weight: 800; letter-spacing: 0.5px; }
.card .corner { position: absolute; font-size: 11px; }
.card .corner.tl { top: 4px; left: 6px; }
.card .corner.br { bottom: 4px; right: 6px; }

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 8px 12px;
  border-radius: 8px;
}
.color-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  vertical-align: middle;
  border: 2px solid #fff;
}
.color-dot.red { background: #d32f2f; }
.color-dot.yellow { background: #f9a825; }
.color-dot.green { background: #2e7d32; }
.color-dot.blue { background: #1565c0; }
.color-dot.wild { background: linear-gradient(135deg, #d32f2f, #f9a825, #2e7d32, #1565c0); }
.pending { background: #d32f2f; padding: 4px 8px; border-radius: 4px; font-weight: 700; }

.my-area {
  background: rgba(0,0,0,0.4);
  border-radius: 14px;
  padding: 10px;
  transition: box-shadow 0.3s, border 0.3s;
  border: 2px solid transparent;
}
.my-area.my-turn {
  box-shadow: 0 0 24px rgba(249,168,37,0.7);
  border-color: #f9a825;
}
.my-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; padding: 0 4px; gap: 8px; }
.my-actions { display: flex; gap: 8px; align-items: center; }
#my-nick { font-weight: 700; font-size: 14px; }
.btn-sort {
  background: rgba(255,255,255,0.15);
  color: #fff;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}
.btn-sort.active {
  background: #f9a825;
  border-color: #fff;
  box-shadow: 0 0 12px rgba(249,168,37,0.5);
}
.btn-pass {
  background: #455a64;
  color: #fff;
  padding: 10px 18px;
  font-size: 14px;
  border-radius: 30px;
  font-weight: 700;
  border: 2px solid #f9a825;
  animation: passPulse 1.1s ease-in-out infinite;
}
@keyframes passPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249,168,37,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(249,168,37,0); }
}
.btn-uno {
  background: #d32f2f;
  color: #fff;
  padding: 10px 20px;
  font-size: 14px;
  border-radius: 30px;
  font-weight: 700;
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.2s;
}
.btn-uno.urgent {
  opacity: 1;
  animation: unoPulse 0.7s ease-in-out infinite;
  box-shadow: 0 0 18px rgba(211,47,47,0.8);
}
@keyframes unoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* Mano en filas múltiples */
.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 4px;
  justify-content: center;
  align-content: flex-start;
  max-height: 38vh;
  overflow-y: auto;
}
.hand .card { flex-shrink: 0; }

/* Barra inferior con chat + log */
.bottom-bar { display: flex; flex-direction: column; gap: 8px; }

.chat-zone {
  background: rgba(0,0,0,0.4);
  border-radius: 10px;
  padding: 8px;
}
.chat-input-wrap { display: flex; gap: 6px; }
.chat-input-wrap input {
  flex: 1;
  margin: 0;
  padding: 8px 12px;
  font-size: 14px;
}
.btn-chat-send {
  background: #f9a825;
  color: #000;
  padding: 8px 14px;
  font-size: 16px;
  border-radius: 8px;
}

.log { display: none; }

/* ============ MODALS ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: #1f6b3a;
  padding: 26px;
  border-radius: 14px;
  text-align: center;
  width: 100%;
  max-width: 320px;
}
.modal-box .btn-primary { width: 100%; margin-top: 4px; }
.color-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 4px; }
#btn-cancel-color { width: 100%; margin-top: 10px; }
.cc { width: 100%; height: 80px; border-radius: 12px; border: 3px solid #fff; }
.cc.red { background: #d32f2f; }
.cc.yellow { background: #f9a825; }
.cc.green { background: #2e7d32; }
.cc.blue { background: #1565c0; }

/* ============ COVER ============ */
.cover {
  position: fixed;
  inset: 0;
  background: #ffffff;
  color: #1a1a1a;
  z-index: 100;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: coverIn 0.25s ease-out;
}
@keyframes coverIn { from { opacity: 0; } to { opacity: 1; } }
.cover-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 22px 60px;
  font-family: Georgia, "Times New Roman", serif;
}
.cover-back {
  display: inline-block;
  margin-top: 8px;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #9aa0a6;
  cursor: pointer;
}
.cover-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #666;
  margin-bottom: 14px;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cover-source { color: #2962ff; font-weight: 600; }
.cover-title {
  font-size: 30px;
  line-height: 1.2;
  margin-bottom: 10px;
  color: #111;
}
.cover-byline {
  color: #777;
  font-size: 14px;
  margin-bottom: 20px;
  font-family: -apple-system, sans-serif;
  font-style: italic;
}
.cover-img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  margin-bottom: 22px;
  display: block;
}
.cover-content p {
  font-size: 18px;
  line-height: 1.65;
  margin-bottom: 18px;
  color: #2a2a2a;
}
.cover-content h2 {
  font-size: 22px;
  margin: 24px 0 12px;
  color: #111;
}
.cover-turn-alert {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #d32f2f;
  color: #fff;
  padding: 10px 22px;
  border-radius: 30px;
  font-family: -apple-system, sans-serif;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 6px 20px rgba(211,47,47,0.5);
  animation: pulse 1s infinite;
  z-index: 110;
}
@keyframes pulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.05); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 700px) {
  .table { padding: 8px; gap: 8px; }
  .opponents { padding: 0 56px 0 4px; gap: 12px; row-gap: 34px; margin-top: 54px; }
  .opponent { min-width: 84px; padding: 7px 10px; }
  .opponent .nick { font-size: 12px; }
  .center { gap: 10px; }
  .card-back, .card, .pile { width: 70px; height: 100px; }
  .card .val { font-size: 18px; }
  .card.text-label .val { font-size: 12px; }
  .card-back { font-size: 18px; }
  .info-panel { font-size: 11px; padding: 6px 10px; }
  h1 { font-size: 30px; }
  .lobby-box, .room-box { padding: 22px; }
  .cover-title { font-size: 24px; }
  .cover-content p { font-size: 16px; }
  .turn-banner { font-size: 16px; padding: 12px 56px 12px 70px; }
  .turn-banner.my-turn { font-size: 19px; }
  .hand { max-height: 36vh; }
}

@media (max-width: 420px) {
  .card-back, .card, .pile { width: 60px; height: 86px; }
  .card .val { font-size: 15px; }
  .card.text-label .val { font-size: 10px; }
  .card .corner { font-size: 9px; }
  .opponents { gap: 10px; row-gap: 32px; padding: 0 52px 0 4px; }
  .opponent { min-width: 76px; padding: 6px 8px; }
  .opponent .nick { font-size: 11px; }
  .opponent .count { font-size: 10px; }
  .chat-bubble { font-size: 12px; padding: 5px 9px; max-width: 130px; }
  .btn-cover { width: 42px; height: 42px; font-size: 19px; top: 8px; right: 8px; }
  .info-panel { font-size: 10px; padding: 5px 8px; }
  .cover-title { font-size: 22px; }
  .turn-banner { font-size: 15px; padding: 10px 52px 10px 64px; }
  .turn-banner.my-turn { font-size: 18px; }
  .btn-abandon { font-size: 12px; padding: 9px 12px; }
  .chat-preset { padding: 5px 10px; font-size: 12px; }
  .hand { max-height: 42vh; gap: 4px; padding: 8px 2px; }
  .pile { width: 60px; height: 86px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .table { grid-template-rows: auto 1fr auto auto; }
  .opponents { margin-top: 50px; }
  .card-back, .card, .pile { width: 60px; height: 86px; }
  .hand { max-height: 28vh; }
  .log-toggle { display: none; }
}
