:root {
  --bg-night: #07090f;
  --bg-deep: #0f1425;
  --panel: rgba(13, 20, 33, 0.88);
  --panel-edge: rgba(180, 156, 102, 0.36);
  --text-main: #f4edd3;
  --text-soft: #c8bda0;
  --gold: #d1ac60;
  --gold-strong: #e6c47d;
  --danger: #a33636;
  --emerald: #6dbf92;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Marcellus", serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 14% 18%, rgba(109, 191, 146, 0.18), transparent 30%),
    radial-gradient(circle at 82% 6%, rgba(209, 172, 96, 0.2), transparent 38%),
    radial-gradient(circle at 60% 78%, rgba(81, 114, 191, 0.17), transparent 34%),
    linear-gradient(170deg, rgba(7, 9, 15, 0.5), rgba(9, 13, 24, 0.64) 52%, rgba(16, 12, 28, 0.72)),
    url("arcane-duel.png"),
    linear-gradient(160deg, var(--bg-night), var(--bg-deep) 52%, #161026);
  background-size: auto, auto, auto, auto, cover, auto;
  background-position: center, center, center, center, center, center;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat;
  background-attachment: scroll, scroll, scroll, scroll, fixed, scroll;
  overflow-x: hidden;
}

.sky-glow {
  position: fixed;
  inset: 0;
  background: repeating-radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03) 1px, transparent 3px, transparent 18px);
  opacity: 0.22;
  pointer-events: none;
}

.grain {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(120deg, rgba(255, 255, 255, 0.02) 0%, transparent 45%, rgba(255, 255, 255, 0.02) 100%);
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(1.2rem + 25px) 1.5rem;
  border-bottom: 1px solid var(--panel-edge);
  backdrop-filter: blur(6px);
}

h1,
h2,
h3,
h4 {
  font-family: "Cinzel", serif;
  margin: 0;
  letter-spacing: 0.04em;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  color: var(--gold-strong);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-soft);
}

.topbar-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.mode-label {
  font-size: 0.82rem;
  color: var(--text-soft);
  border: 1px solid rgba(209, 172, 96, 0.32);
  border-radius: 999px;
  padding: 0.34rem 0.6rem;
  background: rgba(0, 0, 0, 0.2);
}

.layout {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.main-column,
.side-column {
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1rem;
  animation: rise 500ms ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.state-grid,
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.state-chip,
.stats div {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(209, 172, 96, 0.3);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.state-chip span,
.stats span {
  font-size: 0.78rem;
  color: var(--text-soft);
}

.state-chip strong,
.stats strong {
  font-size: 1.05rem;
}

#phase-label {
  display: flex;
  align-items: center;
  min-height: 2.4em;
  line-height: 1.2;
}

.players-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.player-panel {
  position: relative;
}

.player-panel.active {
  outline: 2px solid rgba(109, 191, 146, 0.65);
}

.player-panel.winner {
  outline: none;
  border-color: rgba(230, 196, 125, 0.9);
  box-shadow:
    0 0 0 2px rgba(230, 196, 125, 0.45),
    0 0 28px rgba(230, 196, 125, 0.38),
    0 16px 40px rgba(0, 0, 0, 0.58);
}

.player-panel.winner::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 20px;
  padding: 2px;
  background: linear-gradient(135deg, rgba(255, 240, 186, 0.95), rgba(230, 196, 125, 0.95), rgba(159, 116, 34, 0.95));
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  animation: winner-frame-glint 2.4s linear infinite;
}

@keyframes winner-frame-glint {
  0% { filter: drop-shadow(0 0 4px rgba(230, 196, 125, 0.45)); opacity: 0.9; }
  50% { filter: drop-shadow(0 0 11px rgba(255, 232, 170, 0.72)); opacity: 1; }
  100% { filter: drop-shadow(0 0 4px rgba(230, 196, 125, 0.45)); opacity: 0.9; }
}

.zone {
  margin-top: 0.7rem;
}

.zone h3 {
  margin-bottom: 0.55rem;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(230, 196, 125, 0.95);
  border-bottom: 1px solid rgba(230, 196, 125, 0.28);
  padding-bottom: 0.28rem;
}

.battle-grid > div > h4 {
  margin-bottom: 0.4rem;
  font-size: 1rem;
  font-weight: 700;
  color: rgba(220, 229, 246, 0.95);
}

.battle-grid {
  display: grid;
  gap: 0.7rem;
}

.cards {
  display: flex;
  gap: 0.48rem;
  flex-wrap: wrap;
  min-height: 48px;
}

/* ── Real playing-card look ── */
.card {
  position: relative;
  width: 78px;
  height: 114px;
  border-radius: 8px;
  border: 2px solid #ddd;
  background: #fefefe;
  box-shadow: 2px 4px 10px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(0,0,0,0.08);
  display: grid;
  grid-template-rows: auto 1fr auto;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
  flex-shrink: 0;
  user-select: none;
  padding: 0;
  overflow: hidden;
}

.card:hover:not(.disabled) {
  transform: translateY(-6px) scale(1.05);
  box-shadow: 4px 12px 24px rgba(0,0,0,0.65);
  z-index: 10;
}

.card.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(30%);
}

.card.selected {
  outline: 3px solid var(--emerald);
  outline-offset: 2px;
  transform: translateY(-8px);
  box-shadow: 0 0 18px rgba(109,191,146,0.7);
}

.card.attacked {
  transform: rotate(90deg);
  transform-origin: center;
  margin: 18px 0;
}

/* Corner labels: top-left and bottom-right */
.card-corner {
  padding: 3px 5px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card-corner.bottom-right {
  align-self: end;
  justify-self: end;
  transform: rotate(180deg);
}

.card-corner .c-rank {
  font-family: "Cinzel", serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: inherit;
  line-height: 1;
}

.card-corner .c-suit {
  font-size: 0.68rem;
  line-height: 1;
  margin-top: 1px;
}

/* Center pip area */
.card-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 4px;
}

.card-pip {
  font-size: 1.55rem;
  line-height: 1;
}

/* Game info ribbon at the bottom */
.card-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.72);
  padding: 2px 4px;
  font-size: 0.58rem;
  color: #e8e0c8;
  line-height: 1.25;
  text-align: center;
  pointer-events: none;
}

.card-info .ci-type {
  font-family: "Cinzel", serif;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-info .ci-stats {
  color: #b8f5c8;
}

/* Suit colours */
.suit-red  { color: #c0302a; }
.suit-black { color: #111; }

/* Glow rings for state */
.card.selected.suit-red  { box-shadow: 0 0 18px rgba(192,48,42,0.55), 0 0 0 3px var(--emerald); }
.card.selected.suit-black { box-shadow: 0 0 18px rgba(30,30,60,0.55), 0 0 0 3px var(--emerald); }

/* Face-down card back */
.card-back {
  position: relative;
  width: 78px;
  height: 114px;
  border-radius: 8px;
  border: 2px solid #3a2a5a;
  background:
    repeating-linear-gradient(
      45deg,
      rgba(80,50,120,0.55) 0px,
      rgba(80,50,120,0.55) 3px,
      rgba(40,20,70,0.7) 3px,
      rgba(40,20,70,0.7) 9px
    ),
    linear-gradient(160deg, #1a0f33, #2f1b55);
  box-shadow: 2px 4px 10px rgba(0,0,0,0.55);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: rgba(180,150,255,0.35);
  user-select: none;
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 4px;
  border: 1px solid rgba(180,150,255,0.2);
  pointer-events: none;
}

.action-row {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.hand-selection-inline {
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(230, 196, 125, 0.48);
  border-radius: 14px;
  background: linear-gradient(150deg, #151322, #222034);
  color: var(--text-soft);
  text-align: center;
  font-size: 0.9rem;
  font-family: "Marcellus", serif;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.creature-selection-inline {
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(109, 191, 146, 0.5);
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(13, 38, 31, 0.92), rgba(22, 46, 43, 0.86));
  color: #cdebd9;
  font-size: 0.9rem;
}

.creature-selection-actions {
  margin-top: 0.55rem;
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid rgba(209, 172, 96, 0.55);
  background: rgba(12, 18, 29, 0.86);
  color: var(--text-main);
  text-decoration: none;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font-family: "Cinzel", serif;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(23, 31, 49, 0.95);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-gold {
  border-color: rgba(230, 196, 125, 0.78);
  background: rgba(73, 52, 20, 0.65);
}

.btn-danger {
  border-color: rgba(179, 90, 90, 0.8);
  background: rgba(88, 20, 20, 0.56);
}

#ai-level-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-main) 50%),
    linear-gradient(135deg, var(--text-main) 50%, transparent 50%);
  background-position: calc(100% - 1.0rem) calc(50% - 1px), calc(100% - 0.7rem) calc(50% - 1px);
  background-size: 0.34rem 0.34rem, 0.34rem 0.34rem;
  background-repeat: no-repeat;
}

.combat-content {
  min-height: 60px;
  color: var(--text-soft);
}

#log {
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid rgba(209, 172, 96, 0.24);
  border-radius: 10px;
  padding: 0.55rem;
  background: rgba(0, 0, 0, 0.26);
  font-size: 0.9rem;
  line-height: 1.3;
  scrollbar-width: thin;
  scrollbar-color: rgba(230, 196, 125, 0.72) rgba(14, 20, 34, 0.9);
}

#log::-webkit-scrollbar {
  width: 10px;
}

#log::-webkit-scrollbar-track {
  background: linear-gradient(180deg, rgba(18, 24, 40, 0.95), rgba(10, 14, 24, 0.95));
  border-radius: 999px;
}

#log::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(230, 196, 125, 0.9), rgba(170, 126, 62, 0.9));
  border-radius: 999px;
  border: 2px solid rgba(14, 20, 34, 0.95);
}

#log::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(241, 212, 150, 0.95), rgba(186, 142, 78, 0.95));
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
    align-items: start;
  }

  .main-column {
    grid-column: 1;
  }

  .side-column {
    grid-column: 2;
    align-self: start;
  }

  .log-panel {
    position: sticky;
    top: 1rem;
    height: calc(100vh - 8.5rem);
    display: flex;
    flex-direction: column;
  }

  #log {
    max-height: none;
    height: 100%;
    min-height: 0;
  }
}

.log-entry {
  margin: 0.35rem 0;
  border-bottom: 1px dashed rgba(209, 172, 96, 0.2);
  padding-bottom: 0.25rem;
}

#damage-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0;
}

#damage-flash.active {
  animation: damage-flash 500ms ease-out forwards;
}

@keyframes damage-flash {
  0%   { background: rgba(180, 30, 30, 0.55); opacity: 1; }
  100% { background: rgba(180, 30, 30, 0); opacity: 0; }
}

.winner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 180;
  z-index: 200;
  animation: fadeIn 400ms ease;
}

.winner-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.winner-card {
  text-align: center;
  width: min(480px, 92vw);
  background: linear-gradient(150deg, #12101f, #1e1a30);
  border: 1px solid rgba(230, 196, 125, 0.6);
  border-radius: 20px;
  padding: 2.5rem 2rem 2rem;
  box-shadow: 0 0 60px rgba(209, 172, 96, 0.25), 0 20px 60px rgba(0,0,0,0.6);
  animation: riseUp 420ms cubic-bezier(0.22,1,0.36,1);
  position: relative;
}

.winner-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  background: transparent;
  border: none;
  color: rgba(230, 196, 125, 0.7);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  line-height: 1;
  transition: color 150ms ease;
}

.winner-close:hover {
  color: rgba(230, 196, 125, 1);
}

@keyframes riseUp {
  from { opacity: 0; transform: translateY(24px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.winner-sym {
  font-size: 4rem;
  animation: glowPulse 2.2s ease-in-out infinite;
  margin-bottom: 0.4rem;
}

@keyframes glowPulse {
  0%, 100% { text-shadow: 0 0 16px rgba(230,196,125,0.5); }
  50%       { text-shadow: 0 0 48px rgba(230,196,125,1), 0 0 12px rgba(230,196,125,0.7); }
}

.winner-title {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  color: #e6c47d;
  margin-bottom: 0.5rem;
  letter-spacing: 0.04em;
}

.winner-sub {
  color: #c8bda0;
  font-family: 'Marcellus', serif;
  font-size: 1.05rem;
  margin-bottom: 1.6rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 180;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(620px, 96vw);
  background: linear-gradient(150deg, #151322, #222034);
  border: 1px solid rgba(230, 196, 125, 0.48);
  border-radius: 14px;
  padding: 1rem;
  color: var(--text-main);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  position: relative;
}

.modal-card h3 {
  color: var(--gold-strong);
  font-family: 'Cinzel', serif;
  margin-bottom: 0.4rem;
}

.modal-card p {
  color: var(--text-soft);
  margin-bottom: 0.3rem;
}

.modal-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.combat-block-card {
  width: min(860px, 96vw);
}

.combat-block-attackers {
  margin-top: 0.7rem;
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.combat-block-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.combat-block-slot {
  width: 90px;
  min-height: 92px;
  border: 2px dashed rgba(230, 196, 125, 0.42);
  border-radius: 12px;
  background: rgba(7, 12, 20, 0.58);
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  cursor: pointer;
}

.combat-block-slot:hover {
  border-color: rgba(230, 196, 125, 0.72);
}

.combat-slot-label {
  font-size: 0.88rem;
  width: 100%;
  text-align: center;
  font-family: "Cinzel", serif;
  letter-spacing: 0.03em;
}

.combat-block-picker-wrap {
  margin-top: 0.8rem;
}

.combat-block-picker-wrap h4 {
  margin: 0 0 0.45rem;
  color: var(--gold-strong);
  font-family: "Cinzel", serif;
  font-size: 0.95rem;
}

.combat-block-picker {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-height: 114px;
}

.modal-empty-choice {
  width: 78px;
  height: 114px;
  border-radius: 8px;
  border: 2px dashed rgba(230, 196, 125, 0.6);
  background: rgba(13, 18, 31, 0.8);
  color: var(--text-soft);
  font-family: "Cinzel", serif;
  cursor: pointer;
}

.modal-empty-choice:hover {
  border-color: rgba(230, 196, 125, 0.95);
  color: var(--gold-strong);
}

.modal-option {
  border: 1px solid rgba(109, 191, 146, 0.5);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  background: rgba(15, 23, 38, 0.8);
  color: var(--text-main);
  font-family: 'Marcellus', serif;
  font-size: 0.9rem;
}

.modal-option:hover {
  background: rgba(18, 31, 50, 0.95);
}

@media (max-width: 760px) {
  .modal-card {
    width: min(620px, calc(100vw - 1rem));
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.7rem;
  }

  .card, .card-back {
    width: 66px;
    height: 96px;
  }

  .card-pip {
    font-size: 1.2rem;
  }

  .card-corner .c-rank {
    font-size: 0.72rem;
  }
}
