:root {
  --bg-dark: #1e1f22;
  --bg-card: #2b2d31;
  --bg-board: #313338;
  --primary: #5865f2;
  --primary-hover: #4752c4;
  --success: #23a55a;
  --danger: #f23f43;
  --warning: #f0b232;
  --text-main: #f2f3f5;
  --text-muted: #b5bac1;
  --card-border: #4e5058;
  --card-unit-bg: linear-gradient(135deg, #2b2d31 0%, #1a1c23 100%);
  --card-spell-bg: linear-gradient(135deg, #2d233e 0%, #171226 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'gg sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* LOBBY SCREEN */
#lobby-screen, #waiting-screen {
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #2b2d31 0%, #1e1f22 100%);
}

.lobby-card {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  width: 90%;
  max-width: 440px;
  border: 1px solid var(--card-border);
}

.lobby-card h1 {
  font-size: 2.2rem;
  color: var(--primary);
  text-align: center;
  margin-bottom: 0.2rem;
}

.lobby-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"], select {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  background: #1e1f22;
  color: var(--text-main);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.btn {
  padding: 0.8rem 1.2rem;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #4e5058;
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background: #6d6f78;
}

.btn-warning {
  background: var(--warning);
  color: #1e1f22;
}

.btn-warning:hover:not(:disabled) {
  background: #d99b24;
}

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  position: relative;
}

.join-box {
  display: flex;
  gap: 0.5rem;
}

.room-code-display {
  font-size: 2.5rem;
  font-weight: bold;
  letter-spacing: 4px;
  color: var(--warning);
  margin: 1.5rem 0;
  padding: 1rem;
  background: #1e1f22;
  border-radius: 8px;
  border: 2px dashed var(--warning);
}

.status-message {
  margin-top: 1rem;
  text-align: center;
  color: var(--danger);
  font-size: 0.9rem;
}

/* SCHERMATA COLLEZIONE */
#collection-screen {
  background: var(--bg-dark);
  padding: 1.5rem;
}

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--card-border);
}

.collection-header h2 {
  font-size: 1.8rem;
  color: var(--text-main);
}

.card-count-badge {
  background: var(--primary);
  color: white;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-weight: bold;
}

.collection-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
  background: var(--bg-card);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
}

.collection-controls input[type="text"] {
  flex: 2;
  min-width: 200px;
}

.collection-controls select {
  flex: 1;
  min-width: 160px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.95rem;
}

.collection-grid-container {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 1.5rem;
  padding: 1rem 0;
}

.collection-grid .tcg-card {
  width: 145px;
  height: 200px;
}

.collection-grid .card-art-box {
  height: 115px;
}

/* ZOOM STYLES PER GRIGLIA COLLEZIONE */
.collection-grid.zoom-large {
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 1.8rem;
}

.collection-grid.zoom-large .tcg-card {
  width: 185px;
  height: 255px;
}

.collection-grid.zoom-large .card-member {
  font-size: 0.95rem;
  max-width: 125px;
}

.collection-grid.zoom-large .card-subtitle {
  font-size: 0.75rem;
  max-width: 125px;
}

.collection-grid.zoom-large .card-mana {
  width: 28px;
  height: 28px;
  font-size: 0.98rem;
}

.collection-grid.zoom-large .badge {
  width: 30px;
  height: 30px;
  font-size: 0.88rem;
}

.collection-grid.zoom-large .card-effect-box {
  font-size: 0.7rem;
  line-height: 1.2;
  max-height: 58px;
  padding: 0.25rem 0.35rem;
}

.collection-grid.zoom-large .spell-tag-badge {
  font-size: 0.75rem;
}

.collection-grid.zoom-xlarge {
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 2rem;
}

.collection-grid.zoom-xlarge .tcg-card {
  width: 225px;
  height: 310px;
}

.collection-grid.zoom-xlarge .card-member {
  font-size: 1.1rem;
  max-width: 155px;
}

.collection-grid.zoom-xlarge .card-subtitle {
  font-size: 0.85rem;
  max-width: 155px;
}

.collection-grid.zoom-xlarge .card-mana {
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
}

.collection-grid.zoom-xlarge .badge {
  width: 34px;
  height: 34px;
  font-size: 1rem;
}

.collection-grid.zoom-xlarge .card-effect-box {
  font-size: 0.8rem;
  line-height: 1.25;
  max-height: 70px;
  padding: 0.3rem 0.4rem;
}

.collection-grid.zoom-xlarge .spell-tag-badge {
  font-size: 0.85rem;
}

#game-screen {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.game-header {
  background: #111214;
  padding: 0.5rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
  z-index: 50;
}

.room-info {
  font-weight: bold;
  color: var(--text-muted);
}

.turn-banner {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--primary);
  background: rgba(88, 101, 242, 0.15);
  padding: 0.3rem 1rem;
  border-radius: 20px;
}

/* OVERLAY HUD FLUTTUANTE (4 ANGOLI + BORDO DESTRO) */
.hud-corner {
  position: absolute;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: rgba(17, 18, 20, 0.85);
  padding: 0.4rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.65);
  pointer-events: auto;
}

.hud-corner.top-left {
  top: 55px;
  left: 16px;
}

.hud-corner.top-right {
  top: 55px;
  right: 16px;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.hud-corner.bottom-left {
  bottom: 16px;
  left: 16px;
}

.hud-corner.bottom-right {
  bottom: 16px;
  right: 16px;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.hud-edge.right-center {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  z-index: 100;
}

.btn-end-turn-3d {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  font-weight: 900;
  font-size: 0.88rem;
  letter-spacing: 0.5px;
  padding: 0.65rem 1.1rem;
  border-radius: 25px;
  border: 2px solid #fcd34d;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.5), inset 0 2px 2px rgba(255, 255, 255, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-end-turn-3d:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.85), inset 0 2px 2px rgba(255, 255, 255, 0.6);
}

.btn-end-turn-3d:disabled {
  background: #27272a;
  border-color: #52525b;
  color: #71717a;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.7;
}

.battleground {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.5rem;
  gap: 0.4rem;
  background: var(--bg-board);
  width: 100%;
}

.player-zone {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
}

.player-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 1rem;
  background: rgba(24, 25, 28, 0.9);
  border-radius: 12px;
  border: 1px solid var(--card-border);
  backdrop-filter: blur(6px);
  width: 100%;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  position: relative;
}

.mana-crystals-container {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.player-name {
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 80px;
  color: #f4f4f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mana-crystals {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mana-crystal {
  width: 16px;
  height: 22px;
  clip-path: polygon(50% 0%, 100% 35%, 100% 70%, 50% 100%, 0% 70%, 0% 35%);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  flex-shrink: 0;
}

.mana-crystal.active {
  background: linear-gradient(135deg, #c084fc 0%, #818cf8 50%, #4f46e5 100%);
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.9);
  filter: drop-shadow(0 0 4px #a855f7);
  transform: scale(1.05);
}

.mana-crystal.spent {
  background: rgba(30, 27, 75, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.25);
  filter: grayscale(80%) opacity(0.35);
}

.mana-text {
  font-weight: 800;
  color: #c084fc;
  font-size: 0.9rem;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

/* SFERA DI VITA (HEALTH ORB) IN BASSO A DESTRA */
.health-orb-container {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  border: 3px solid #f87171;
  background: #111827;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.7), inset 0 0 14px rgba(0,0,0,0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.health-orb-container:hover {
  transform: scale(1.06);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.95), inset 0 0 14px rgba(0,0,0,0.95);
}

.health-orb-liquid {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(180deg, #fca5a5 0%, #ef4444 40%, #991b1b 100%);
  transition: height 0.4s ease-in-out;
  box-shadow: inset 0 3px 6px rgba(255, 255, 255, 0.5);
}

.health-orb-value {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.95), 0 0 10px rgba(0, 0, 0, 0.95);
  pointer-events: none;
  font-weight: 900;
  line-height: 1;
}

.health-orb-value .hp-num {
  font-size: 1.35rem;
}

.health-orb-value .hp-max {
  font-size: 0.62rem;
  color: #fca5a5;
  margin-top: 1px;
}

.mana-container {
  font-weight: bold;
  color: #5865f2;
  font-size: 0.9rem;
  white-space: nowrap;
}

.board-container {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 0.3rem;
  border: 1px dashed #4e5058;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.board-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
  text-align: center;
}

.board {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  min-height: 0;
  width: 100%;
}

/* MANO GIOCATORE (SCROLLABILE ED ADATTIVA SENZA TAGLIARE CARTE) */
.hand {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding: 0.4rem 0.2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) #1e1f22;
}

.hand::-webkit-scrollbar {
  height: 6px;
}

.hand::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 3px;
}

/* CARTE IN MANO DEL GIOCATORE (PIÙ GRANDI E FACILI DA LEGGERE) */
.my-hand {
  padding: 0.6rem 0.4rem;
  gap: 0.8rem;
  align-items: flex-end;
  min-height: 225px;
  max-width: calc(100vw - 260px);
  margin: 0 auto;
  z-index: 25;
}

.my-hand .tcg-card {
  width: 155px;
  height: 215px;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.7), inset 0 0 12px rgba(255,255,255,0.05);
}

.my-hand .tcg-card:hover {
  transform: translateY(-14px) scale(1.1);
  box-shadow: 0 16px 32px rgba(88, 101, 242, 0.5), 0 0 15px rgba(88, 101, 242, 0.3);
  z-index: 50;
}

.my-hand .tcg-card .card-header {
  padding: 0.35rem 0.5rem;
}

.my-hand .tcg-card .card-member {
  font-size: 0.88rem;
  max-width: 105px;
}

.my-hand .tcg-card .card-subtitle {
  font-size: 0.68rem;
  max-width: 105px;
}

.my-hand .tcg-card .card-mana {
  width: 25px;
  height: 25px;
  font-size: 0.9rem;
}

.my-hand .tcg-card .badge {
  width: 27px;
  height: 27px;
  font-size: 0.8rem;
}

.my-hand .tcg-card .card-effect-box {
  font-size: 0.62rem;
  line-height: 1.15;
  max-height: 48px;
  padding: 0.2rem 0.3rem;
}

.my-hand .tcg-card .spell-tag-badge {
  font-size: 0.68rem;
  padding: 0.18rem 0.5rem;
}

.my-hand .tcg-card .card-tag-badge {
  font-size: 0.58rem;
  padding: 0.1rem 0.4rem;
}

.battlefield-divider {
  text-align: center;
  padding: 0.1rem;
}

.combat-log {
  background: #18191c;
  display: inline-block;
  padding: 0.25rem 0.8rem;
  border-radius: 15px;
  font-size: 0.8rem;
  color: var(--warning);
  border: 1px solid #35363c;
}

/* CARTA TCG STYLING ELEGANTE & HUD RIVISITATO */
.tcg-card {
  width: 125px;
  height: 175px;
  flex-shrink: 0;
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s, border-color 0.2s;
  border: 2px solid #3f3f46;
  box-shadow: 0 6px 14px rgba(0,0,0,0.6), inset 0 0 12px rgba(255,255,255,0.03);
  background: linear-gradient(145deg, #27272a 0%, #18181b 100%);
}

.tcg-card.unit {
  border-color: #4f46e5;
}

.tcg-card.spell {
  border-color: #9333ea;
}

.tcg-card:hover {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 0 12px 25px rgba(88, 101, 242, 0.4), 0 0 10px rgba(88, 101, 242, 0.2);
  z-index: 20;
}

.tcg-card.selected {
  border-color: #f59e0b !important;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.9), 0 0 5px #fbbf24 !important;
  transform: translateY(-10px) scale(1.08) !important;
  z-index: 30;
}

.tcg-card.can-attack {
  border-color: #10b981 !important;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.85) !important;
}

.tcg-card.card-back {
  background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  border-color: var(--primary);
  display: flex;
  justify-content: center;
  align-items: center;
}

.tcg-card.card-back::after {
  content: 'TSR';
  font-weight: 900;
  color: var(--primary);
  font-size: 1.4rem;
  letter-spacing: 2px;
  text-shadow: 0 0 10px var(--primary);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.3rem 0.4rem;
  background: rgba(17, 18, 20, 0.88);
  backdrop-filter: blur(4px);
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.12);
  z-index: 10;
  margin-bottom: 0;
}

.card-name-box {
  display: flex;
  flex-direction: column;
}

.card-member {
  font-size: 0.78rem;
  font-weight: 800;
  color: #f4f4f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85px;
  letter-spacing: 0.2px;
}

.card-tag-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: linear-gradient(90deg, #7c3aed, #a855f7);
  color: #ffffff;
  font-size: 0.52rem;
  font-weight: 800;
  padding: 0.08rem 0.35rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid #c084fc;
  box-shadow: 0 2px 5px rgba(0,0,0,0.8);
  z-index: 5;
}

.card-subtitle {
  font-size: 0.62rem;
  color: #fbbf24;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85px;
  font-style: italic;
}

/* MANA GEM GEMMA 3D */
.card-mana {
  background: radial-gradient(circle at 35% 35%, #818cf8 0%, #4f46e5 60%, #312e81 100%);
  color: white;
  font-size: 0.8rem;
  font-weight: 900;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1.5px solid #c7d2fe;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.8), 0 2px 4px rgba(0,0,0,0.6);
  flex-shrink: 0;
}

/* ARTWORK FULL-ART (DA SOTTOTITOLO A BORDO INFERIORE) */
.card-art-box {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 0;
  background-size: cover;
  background-position: center;
  border: none;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.8);
  background-color: #09090b;
}

/* CARD FOOTER & BOX TESTO EFFETTO SULLA CARTA CON SFONDO OPACO TRA ATK E HP */
.card-footer {
  position: absolute;
  bottom: 3px;
  left: 3px;
  right: 3px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.2rem;
  z-index: 10;
  pointer-events: none;
  margin-top: 0;
}

.card-footer.spell-footer {
  justify-content: center;
}

.card-effect-box {
  flex: 1;
  position: relative;
  background: rgba(18, 19, 23, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  padding: 0.15rem 0.25rem;
  font-size: 0.55rem;
  line-height: 1.1;
  color: #f4f4f5;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  max-height: 42px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  z-index: 5;
  pointer-events: auto;
}

.card-footer-spacer {
  flex: 1;
}

/* BADGES ATK / HP DESIGN 3D METALLICO */
.badge {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  font-size: 0.72rem;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.6), inset 0 1px 1px rgba(255,255,255,0.4);
  flex-shrink: 0;
  pointer-events: auto;
}

.badge-atk {
  background: linear-gradient(140deg, #ef4444 0%, #b91c1c 100%);
  border: 1px solid #fca5a5;
}

.badge-hp {
  background: linear-gradient(140deg, #10b981 0%, #047857 100%);
  border: 1px solid #6ee7b7;
}

/* MEDIA QUERIES RESPONSIVE PER SCHERMI PIÙ PICCOLI E PORTATILI */
@media (max-height: 800px) {
  .tcg-card {
    width: 105px;
    height: 148px;
    padding: 0.25rem;
  }

  .card-art-box {
    min-height: 65px;
  }

  .card-member {
    font-size: 0.7rem;
    max-width: 70px;
  }

  .card-subtitle {
    font-size: 0.55rem;
    max-width: 70px;
  }

  .card-mana {
    width: 18px;
    height: 18px;
    font-size: 0.68rem;
  }

  .badge {
    width: 19px;
    height: 19px;
    font-size: 0.65rem;
  }

  .card-effect-box {
    bottom: 22px;
    font-size: 0.5rem;
    padding: 0.12rem 0.25rem;
    max-height: 36px;
    -webkit-line-clamp: 2;
  }

  .hand {
    padding: 0.2rem;
    gap: 0.4rem;
  }

  .my-hand {
    min-height: 185px;
    padding: 0.3rem 0.2rem;
  }

  .my-hand .tcg-card {
    width: 132px;
    height: 182px;
  }

  .my-hand .tcg-card .card-member {
    font-size: 0.76rem;
    max-width: 85px;
  }

  .my-hand .tcg-card .card-subtitle {
    font-size: 0.6rem;
    max-width: 85px;
  }

  .game-header {
    padding: 0.3rem 1rem;
  }

  .turn-banner {
    font-size: 0.95rem;
    padding: 0.2rem 0.8rem;
  }
}

@media (max-height: 650px) {
  .tcg-card {
    width: 90px;
    height: 128px;
  }

  .card-art-box {
    min-height: 50px;
  }
}

@media (max-width: 768px) {
  .hand {
    justify-content: flex-start;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .collection-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .player-stats {
    gap: 0.5rem;
  }

  .player-name {
    min-width: 70px;
  }
}

/* MODAL & CARD INSPECT MODAL (INGRANDIMENTO CARTA) */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.85);
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: 12px;
  text-align: center;
  border: 2px solid var(--primary);
  max-width: 400px;
  box-shadow: 0 0 30px rgba(88, 101, 242, 0.4);
}

.modal-content h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--warning);
}

.modal-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

/* CARTA INGRANDITA IN MODAL */
.card-inspect-container {
  position: relative;
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: 14px;
  border: 2px solid var(--primary);
  width: 320px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 0 35px rgba(0,0,0,0.9);
}

.btn-close-modal {
  position: absolute;
  top: 10px;
  right: 12px;
  background: #da373c;
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: bold;
  cursor: pointer;
  font-size: 1rem;
}

.card-inspect-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.card-inspect-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-inspect-title {
  display: flex;
  flex-direction: column;
}

.card-inspect-member {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--text-main);
}

.card-inspect-subtitle {
  font-size: 0.95rem;
  color: var(--warning);
}

.card-inspect-mana {
  background: var(--primary);
  color: white;
  font-size: 1.1rem;
  font-weight: bold;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.card-inspect-art {
  position: relative;
  width: 100%;
  height: 210px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  border: 2px solid var(--card-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.inspect-tag-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  background: linear-gradient(90deg, #7c3aed, #a855f7);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid #c084fc;
  box-shadow: 0 2px 8px rgba(0,0,0,0.9);
  z-index: 5;
}

.card-inspect-effect {
  background: rgba(168, 85, 247, 0.15);
  padding: 0.8rem;
  border-radius: 6px;
  border-left: 3px solid #a855f7;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #f2f3f5;
  font-weight: 500;
}

.card-inspect-flavor {
  background: #1e1f22;
  padding: 0.8rem;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
  font-size: 0.9rem;
  line-height: 1.4;
  color: #dbdee1;
  font-style: italic;
}

.card-inspect-stats {
  display: flex;
  justify-content: space-around;
  padding-top: 0.4rem;
}

.inspect-stat-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1rem;
  font-weight: bold;
  background: #18191c;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

/* SANDBOX TOOLBAR & SPAWN MODAL */
.sandbox-toolbar {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  z-index: 100;
  background: rgba(30, 27, 75, 0.92);
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  border: 1px solid #7c3aed;
  border-radius: 12px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  pointer-events: auto;
}

.sandbox-badge {
  font-size: 0.8rem;
  font-weight: 800;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #f59e0b;
  letter-spacing: 0.5px;
  text-align: center;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.spawn-modal-container {
  width: 420px;
  max-width: 95vw;
}

.spawn-cards-list {
  max-height: 350px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.3rem;
}

.spawn-card-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #18191c;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.spawn-card-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.spawn-card-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--text-main);
}

.spawn-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* TAUNT / PROVOCAZIONE HUD STYLING */
.tcg-card.has-taunt {
  border: 2px solid #f0b232 !important;
  box-shadow: 0 0 16px rgba(240, 178, 50, 0.8), inset 0 0 10px rgba(240, 178, 50, 0.3) !important;
}

.taunt-badge-overlay {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(15, 16, 20, 0.9);
  border: 1px dashed #f0b232;
  border-radius: 12px;
  padding: 2px 7px;
  z-index: 10;
  box-shadow: 0 0 10px rgba(240, 178, 50, 0.9);
  animation: tauntPulse 2s infinite ease-in-out;
}

@keyframes tauntPulse {
  0% { box-shadow: 0 0 6px rgba(240, 178, 50, 0.6); }
  50% { box-shadow: 0 0 14px rgba(240, 178, 50, 1); }
  100% { box-shadow: 0 0 6px rgba(240, 178, 50, 0.6); }
}

.taunt-shield-img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #f0b232;
}

.taunt-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: #f0b232;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ACCOUNT SYSTEM & DECK BUILDER STYLING */
.account-bar {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  z-index: 100;
}

.auth-bar-content {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--bg-card);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--card-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

.user-info-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  transition: background 0.2s;
}

.user-info-badge:hover {
  background: rgba(255, 255, 255, 0.05);
}

.user-avatar-mini {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--text-main);
  line-height: 1.1;
}

.user-stats-mini {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* AUTH MODAL */
.auth-modal-content {
  max-width: 380px;
  width: 90%;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
}

.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--card-border);
  margin-bottom: 1.2rem;
}

.auth-tab {
  flex: 1;
  padding: 0.8rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  margin-bottom: -2px;
}

/* PROFILE MODAL */
.profile-modal-content {
  max-width: 520px;
  width: 92%;
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  max-height: 85vh;
  overflow-y: auto;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--card-border);
}

.avatar-picker-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.profile-avatar-large {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary);
}

.profile-title h2 {
  font-size: 1.5rem;
  color: var(--text-main);
}

.avatar-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 0.6rem;
  margin: 1rem 0;
  padding: 0.8rem;
  background: #18191c;
  border-radius: 8px;
  max-height: 160px;
  overflow-y: auto;
}

.avatar-picker-item {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.avatar-picker-item:hover {
  transform: scale(1.1);
  border-color: var(--primary);
}

.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-top: 1rem;
}

.stat-box {
  background: #18191c;
  padding: 0.8rem;
  border-radius: 8px;
  text-align: center;
  border: 1px solid var(--card-border);
}

.stat-val {
  display: block;
  font-size: 1.4rem;
  font-weight: bold;
}

.stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.match-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.match-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #18191c;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  border-left: 4px solid var(--card-border);
}

.match-history-item.win {
  border-left-color: var(--success);
}

.match-history-item.loss {
  border-left-color: var(--danger);
}

.match-result-badge {
  font-weight: bold;
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.match-result-badge.win {
  background: rgba(35, 165, 90, 0.2);
  color: var(--success);
}

.match-result-badge.loss {
  background: rgba(242, 63, 67, 0.2);
  color: var(--danger);
}

/* DECK BUILDER MODAL */
.deck-builder-container {
  width: 95%;
  max-width: 920px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1.2rem;
}

.deck-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--card-border);
  gap: 1rem;
}

.deck-builder-meta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.deck-builder-meta input {
  width: 220px;
  padding: 0.4rem 0.8rem;
}

.deck-count-badge {
  background: var(--primary);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.85rem;
}

.deck-builder-body {
  display: flex;
  gap: 1rem;
  flex: 1;
  overflow: hidden;
  margin-top: 1rem;
}

.deck-catalog-side {
  flex: 1.4;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow: hidden;
}

.catalog-filters {
  display: flex;
  gap: 0.6rem;
}

.deck-catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
  overflow-y: auto;
  padding-right: 0.3rem;
  flex: 1;
}

.deck-catalog-card {
  background: #18191c;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  position: relative;
}

.deck-catalog-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.deck-catalog-card img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
}

.deck-catalog-card-title {
  font-size: 0.75rem;
  font-weight: bold;
  text-align: center;
  margin-top: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.deck-list-side {
  flex: 1;
  background: #18191c;
  border-radius: 8px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--card-border);
}

.deck-list-side h3 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.deck-items-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.deck-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.deck-item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.deck-item-qty {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
}

.profile-decks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 0.8rem;
}

.profile-deck-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #18191c;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}

.profile-deck-name {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--text-main);
}

/* RANKED LEADERBOARD STYLING */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 380px;
  overflow-y: auto;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #18191c;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
}

.leaderboard-row.rank-1 {
  border-color: #f0b232;
  background: linear-gradient(135deg, rgba(240, 178, 50, 0.15) 0%, #18191c 100%);
}

.leaderboard-row.rank-2 {
  border-color: #94a3b8;
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.15) 0%, #18191c 100%);
}

.leaderboard-row.rank-3 {
  border-color: #b45309;
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.15) 0%, #18191c 100%);
}

.lb-rank-badge {
  font-size: 1.1rem;
  font-weight: bold;
  width: 32px;
  text-align: center;
}

.lb-player-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex: 1;
  margin-left: 0.4rem;
}

.lb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--primary);
}

.lb-player-name {
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--text-main);
}

.lb-tier-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.lb-elo-box {
  text-align: right;
}

.lb-elo-num {
  font-size: 1.1rem;
  font-weight: bold;
  color: #10b981;
}

.lb-record {
  font-size: 0.72rem;
  color: var(--text-muted);
}



