:root {
  --surface: #131318;
  --surface-dim: #131318;
  --surface-bright: #39383e;
  --surface-container-lowest: #0e0e13;
  --surface-container-low: #1b1b20;
  --surface-container: #1f1f24;
  --surface-container-high: #2a292f;
  --surface-container-highest: #35343a;
  --on-surface: #e4e1e9;
  --on-surface-variant: #b9cacb;
  --inverse-surface: #e4e1e9;
  --inverse-on-surface: #303035;
  --outline: #849495;
  --outline-variant: #3a494b;
  --surface-tint: #00dbe7;
  --primary: #e1fdff;
  --on-primary: #00363a;
  --primary-container: #00f2ff;
  --on-primary-container: #006a71;
  --inverse-primary: #00696f;
  --secondary: #e9c349;
  --on-secondary: #3c2f00;
  --secondary-container: #af8d11;
  --on-secondary-container: #342800;
  --tertiary: #fcf5ff;
  --on-tertiary: #3f008e;
  --tertiary-container: #e4d4ff;
  --on-tertiary-container: #7530e6;
  --error: #ffb4ab;
  --on-error: #690005;
  --error-container: #93000a;
  --on-error-container: #ffdad6;
  --primary-fixed: #74f5ff;
  --primary-fixed-dim: #00dbe7;
  --on-primary-fixed: #002022;
  --on-primary-fixed-variant: #004f54;
  --secondary-fixed: #ffe088;
  --secondary-fixed-dim: #e9c349;
  --on-secondary-fixed: #241a00;
  --on-secondary-fixed-variant: #574500;
  --tertiary-fixed: #eaddff;
  --tertiary-fixed-dim: #d2bbff;
  --on-tertiary-fixed: #25005a;
  --on-tertiary-fixed-variant: #5a00c6;
  --background: #131318;
  --on-background: #e4e1e9;
}

.clip-edges {
    clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
}
.bg-nebula {
    background-image: radial-gradient(circle at 50% 50%, rgba(0, 242, 255, 0.1) 0%, transparent 50%),
                      radial-gradient(circle at 80% 20%, rgba(117, 48, 230, 0.05) 0%, transparent 40%);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; background: var(--background); overflow: hidden; font-family: 'Space Grotesk', 'Courier New', monospace; color: var(--on-background); }

.monolith-card {
    background-color: rgba(19, 19, 24, 0.9);
    border: 1px solid rgba(0, 242, 255, 0.1);
}
.projection-layer {
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 6px -1px rgba(0, 242, 255, 0.1), 0 2px 4px -1px rgba(0, 242, 255, 0.06);
}
.runic-pulse {
    box-shadow: 0 0 24px rgba(225, 253, 255, 0.5);
}
.holographic-hud {
    background: linear-gradient(180deg, rgba(0, 242, 255, 0.05) 0%, rgba(0, 242, 255, 0) 100%);
    border: 1px solid rgba(0, 242, 255, 0.2);
    position: relative;
}
.holographic-hud::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 242, 255, 0.03) 2px,
        rgba(0, 242, 255, 0.03) 4px
    );
    pointer-events: none;
}
.btn-pharaoh {
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    transition: all 0.3s ease;
    border: 1px solid var(--primary-container);
    background: transparent;
}
.btn-pharaoh:hover {
    background: rgba(0, 242, 255, 0.15);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
}
.bg-stardust {
    background-color: #050508;
    background-image: radial-gradient(circle at 50% 50%, rgba(0, 242, 255, 0.05) 0%, transparent 60%);
}

#canvas-container { position: fixed; inset: 0; }
canvas { display: block; width: 100% !important; height: 100% !important; }

/* ── HUD ─────────────────────────────────── */
#hud { position: fixed; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }

/* LP bars */
#lp-row { display: flex; justify-content: space-between; padding: 10px 16px; pointer-events: none; }
.lp-box { background: rgba(0,0,0,.78); border: 1px solid #2a5a8a; border-radius: 8px; padding: 6px 18px; min-width: 150px; }
.lp-box.player { border-color: #c8a200; }
.lp-label { font-size: 9px; letter-spacing: 2px; text-transform: uppercase; color: #5aaad0; }
.lp-box.player .lp-label { color: #c8a200; }
.lp-value { font-size: 22px; font-weight: bold; }

/* Phase badge */
#phase-badge { position: fixed; top: 68px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.8); border: 1px solid #2a5a8a; border-radius: 20px;
  padding: 3px 20px; font-size: 10px; letter-spacing: 3px; color: #5aaad0; pointer-events: none; }

/* Log */
#log { position: fixed; bottom: 10px; right: 10px; width: 250px;
  background: rgba(0,0,0,.82); border: 1px solid #1a3a5a; border-radius: 8px;
  padding: 8px; max-height: 180px; overflow-y: auto; pointer-events: none; }
#log::-webkit-scrollbar { width: 3px; }
#log::-webkit-scrollbar-thumb { background: #2a5a8a; }
.log-line { font-size: 10px; line-height: 1.45; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.log-line.ev-important { color: #ffd700; }
.log-line.ev-damage    { color: #ff5555; }
.log-line.ev-summon    { color: #55d4ff; }
.log-line.ev-fusion    { color: #cc88ff; }

/* Hand */
#hand-area { display: flex; justify-content: center; align-items: flex-end; gap: 7px;
  padding: 10px 10px 8px; pointer-events: auto;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); min-height: 110px; }
.hand-card { width: 130px; height: 187px; border-radius: 8px; border: 1.5px solid rgba(255,255,255,.22);
  cursor: grab; position: relative; overflow: hidden; flex-shrink: 0;
  /* transform-origin abaixo do card cria o arco côncavo de leque (pontas caem, centro fica alto) */
  transform-origin: 50% calc(100% + 110px);
  transform: translateY(var(--card-y, 0)) rotate(var(--card-rot, 0deg));
  /* translate é propriedade separada — compõe com transform sem sobrescrevê-lo */
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              translate 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.18s ease; }

/* Animação de entrada da mão */
@keyframes hand-card-enter {
  from { translate: 0 30px; opacity: 0; }
  to   { translate: 0 0;    opacity: 1; }
}
.hand-card-enter { animation: hand-card-enter 0.3s ease-out backwards; }
.hand-card:active { cursor: grabbing; }
/* hover e selected usam `translate` para levantar sem sobrescrever o transform do arco */
.hand-card:hover:not(.selected)  { translate: 0 -18px; box-shadow: 0 0 20px rgba(80,200,255,.7); border-color: #55c8ff; z-index: 10; }
.hand-card.selected               { translate: 0 -28px; box-shadow: 0 0 28px rgba(255,215,0,.9);  border-color: #ffd700; z-index: 11; }
.hand-card.selected::after { content: attr(data-order); position: absolute; top: 0; right: 0; background: #ffd700; color: #000; font-weight: bold; font-size: 10px; padding: 2px 5px; border-bottom-left-radius: 4px; }
.hand-card.disabled { filter: brightness(0.5) grayscale(0.7); cursor: default; }
.hand-card.disabled:hover { translate: none; box-shadow: none; }

/* ── Modo de Descarte (vermelho) ── */
body.discard-mode .hand-card:hover:not(.selected) { box-shadow: 0 0 20px rgba(255,80,80,.6); border-color: #ff6666; }
body.discard-mode .hand-card.selected             { translate: 0 -28px; box-shadow: 0 0 28px rgba(255,60,60,.9); border-color: #ff3333; z-index: 11; }
body.discard-mode .hand-card.selected::after      { background: #cc2222; color: #fff; content: '✕'; }
.btn.red { border-color: #cc2222; color: #ff4444; }
.btn.red:hover:not(:disabled) { background: rgba(200,30,30,.2); border-color: #ff4444; color: #fff; }
.btn.red:not(:disabled) { animation: pulse-red 1.5s ease-in-out infinite; }
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 6px rgba(255,50,50,.3); } 50% { box-shadow: 0 0 16px rgba(255,50,50,.7); } }


.card-bg { position: absolute; inset: 0; overflow: hidden; }
.card-art { width: 100%; height: 100%; object-fit: cover; filter: brightness(0.9); }
.card-icon { position: absolute; bottom: 33px; left: 6px; font-size: 16px; line-height: 1; }
.card-atk-label { position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: bold;
  color: #ff3333; background: rgba(0,0,0,.85); padding: 3px 6px; border-radius: 4px; text-shadow: 1px 1px 0 #000; }
.card-def-label { position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: bold;
  color: #33aaff; background: rgba(0,0,0,.85); padding: 3px 6px; border-radius: 4px; text-shadow: 1px 1px 0 #000; }
.card-name-label { position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.82); font-size: 11px; text-align: center; padding: 6px 2px; line-height: 1.2; }
.card-stars-label { position: absolute; bottom: 35px; right: 6px; font-size: 11px; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 4px; }

/* Action bar */
#action-bar { display: flex; justify-content: center; gap: 8px; padding: 6px 10px 10px; pointer-events: auto; }
#btn-summon { display: none; } /* Hidden, now we use drag and drop */
.btn { background: rgba(0,0,0,.82); border: 1px solid #2a5a6a; color: #5aaad0; font-family: inherit;
  font-size: 11px; letter-spacing: 1px; padding: 6px 14px; border-radius: 5px; cursor: pointer; transition: all .15s; }
.btn:hover:not(:disabled) { background: rgba(40,100,140,.3); border-color: #55c8ff; color: #fff; }
.btn:disabled { opacity: .3; cursor: not-allowed; }
.btn.gold { border-color: #c8a200; color: #ffd700; }
.btn.gold:hover:not(:disabled) { background: rgba(200,162,0,.15); }

/* Fusion hint */
#fusion-hint { position: fixed; left: 12px; bottom: 130px;
  background: rgba(0,0,0,.85); border: 1px solid #8855cc; border-radius: 7px;
  padding: 7px 12px; font-size: 10px; color: #cc88ff; max-width: 200px;
  pointer-events: none; display: none; line-height: 1.4; }

/* Deck counter */
#deck-info { position: fixed; left: 12px; top: 68px;
  background: rgba(0,0,0,.75); border: 1px solid #1a3a5a; border-radius: 6px;
  padding: 5px 10px; font-size: 9px; color: rgba(255,255,255,.45); pointer-events: none; line-height: 1.6; }

/* Win screen */
#win-screen { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.88);
  align-items: center; justify-content: center; z-index: 300; pointer-events: auto; flex-direction: column; gap: 20px; }
#win-screen.open { display: flex; }
#win-msg { font-size: 36px; font-weight: bold; letter-spacing: 4px; }
#win-msg.victory { color: #ffd700; text-shadow: 0 0 40px rgba(255,215,0,.6); }
#win-msg.defeat  { color: #ff4444; text-shadow: 0 0 40px rgba(255,40,40,.6); }
#btn-restart { font-size: 14px; padding: 10px 30px; }

/* Modal API */
#modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85);
  align-items: center; justify-content: center; z-index: 400; pointer-events: auto; }
#modal-overlay.open { display: flex; }
.modal-box { background: rgba(10, 15, 25, 0.98); border: 2px solid #5aaad0; border-radius: 12px;
  padding: 30px; width: 90%; max-width: 500px; text-align: center; box-shadow: 0 0 50px rgba(90, 170, 208, 0.6); position: relative; }
.modal-close { position: absolute; top: 12px; right: 15px; font-size: 28px; color: rgba(255,255,255,0.4);
  cursor: pointer; transition: color 0.15s; line-height: 1; }
.modal-close:hover { color: #ff4444; }
.modal-title { font-size: 18px; color: #ffd700; margin-bottom: 12px; letter-spacing: 1px; }
.modal-message { font-size: 14px; color: #fff; margin-bottom: 24px; line-height: 1.6; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; }
.modal-buttons .btn { border-color: #5aaad0; }

/* ── Combat Display ──────────────────────────────────────── */
@keyframes cd-in  { from { opacity:0; transform:translate(-50%,-50%) scale(0.82); } to { opacity:1; transform:translate(-50%,-50%) scale(1); } }
@keyframes cd-out { from { opacity:1; transform:translate(-50%,-50%) scale(1);    } to { opacity:0; transform:translate(-50%,-50%) scale(0.88); } }

#combat-display {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  z-index: 500;
  background: rgba(4, 8, 22, 0.97);
  border: 2px solid #5aaad0;
  border-radius: 16px;
  padding: 24px 28px 18px;
  min-width: 520px;
  box-shadow: 0 0 70px rgba(90,170,208,.45), 0 0 150px rgba(90,170,208,.12);
  animation: cd-in 0.3s ease-out forwards;
  cursor: pointer;
  pointer-events: auto;
}
.cd-title { text-align:center; font-size:11px; letter-spacing:3px; color:#5aaad0; margin-bottom:18px; text-transform:uppercase; }
.cd-arena { display:flex; align-items:flex-start; gap:16px; }
.cd-side  { flex:1; }
.cd-role  { font-size:9px; letter-spacing:2px; color:#666; margin-bottom:5px; text-transform:uppercase; }
.cd-cname { font-size:14px; font-weight:bold; color:#fff; margin-bottom:3px; }
.cd-elem  { font-size:10px; letter-spacing:1px; margin-bottom:11px; }
.cd-table { width:100%; border-collapse:collapse; font-size:12px; }
.cd-table td { padding:4px 0; color:#bbb; }
.cd-table td:last-child { text-align:right; font-family:'Courier New',monospace; }
.cd-field td  { color:#999; font-size:11px; }
.cd-mult  td  { color:#ffd700; font-size:11px; }
.cd-sep   td  { border-top:1px solid rgba(255,255,255,.1); padding:3px 0; }
.cd-final-row td { color:#fff; font-weight:bold; padding-top:4px; }
.cd-n     { color:#5aaad0; }
.cd-big   { font-size:20px !important; color:#ffd700 !important; }
.cd-gold  { color:#ffd700 !important; }
.cd-pos   { color:#44ff88 !important; }
.cd-neg   { color:#ff4444 !important; }
.cd-vs    { display:flex; align-items:center; justify-content:center; padding-top:36px;
            font-size:20px; font-weight:bold; color:#ff4444;
            text-shadow:0 0 18px rgba(255,68,68,.8); }
.cd-skip  { text-align:center; font-size:9px; color:rgba(255,255,255,.25);
            margin-top:14px; letter-spacing:2px; }

/* Resultado do combate */
.cd-winner-side .cd-cname { color:#ffd700; text-shadow:0 0 14px rgba(255,215,0,.8); }
.cd-winner-side .cd-role  { color:#ffd700; }
.cd-loser-side  .cd-cname { color:#ff4444; text-shadow:0 0 10px rgba(255,68,68,.6); }
.cd-loser-side  .cd-role  { color:#ff4444; }
.cd-loser-side  .cd-final-row td { color:#ff4444; }
.cd-draw-side   .cd-cname { color:#ff8800; }
.cd-draw-side   .cd-role  { color:#ff8800; }

.cd-result {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  flex:0 0 auto; padding: 0 10px;
  opacity:0; transform:scale(0.4);
  transition: opacity 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275),
              transform 0.4s  cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.cd-result.cd-result-visible { opacity:1; transform:scale(1); }

.cd-result-text {
  font-size:15px; font-weight:900; letter-spacing:2px;
  text-align:center; text-transform:uppercase; line-height:1.2;
}
.cd-result-attacker { color:#ffd700; text-shadow:0 0 22px rgba(255,215,0,.9); }
.cd-result-defender { color:#ff4444; text-shadow:0 0 22px rgba(255,68,68,.9);  }
.cd-result-draw     { color:#ff8800; text-shadow:0 0 22px rgba(255,136,0,.9);  }

.cd-result-sub {
  font-size:10px; color:rgba(255,255,255,.55);
  letter-spacing:1px; margin-top:6px; text-align:center;
}

/* Custom content for card preview in Modal */
.preview-card-img { width: 100%; max-width: 260px; border-radius: 10px; border: 2px solid #33aaff; margin: 0 auto 15px; display: block; box-shadow: 0 0 15px rgba(51, 170, 255, 0.3); }
.preview-stats { display: flex; justify-content: center; gap: 25px; margin: 15px 0; font-size: 18px; }
.preview-atk { color: #ff4444; font-weight: bold; text-shadow: 1px 1px 0 #000; }
.preview-def { color: #44aaff; font-weight: bold; text-shadow: 1px 1px 0 #000; }
.preview-desc { font-style: italic; color: #ccc; font-size: 14px; line-height: 1.5; margin: 15px 0; background: rgba(255,255,255,0.05); padding: 12px; border-radius: 6px; border-left: 3px solid #ffd700; }
.preview-meta { font-size: 13px; color: #888; margin-top: 10px; }
