html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #0b0f14;
  color: #e5eef8;
  touch-action: manipulation;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

header {
  position: fixed;
  top: 0;
  z-index: 200;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 32px);
  background: linear-gradient(180deg, rgba(18, 28, 40, 0.95), rgba(12, 18, 26, 0.95));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  left: 0;
  right: 0;
}

header strong {
  font-size: 18px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  margin-right: auto;
}

main {
  flex: 1;
  padding: 50px 20px 0 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(16px, 3vw, 20px);
  align-content: start;
}

/* Hide sidebar by default; shown when deck builder is active */
#sidebar {
  display: none;
  padding-top: 32px;
}

/* Board layout inside #root */
#root .board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  grid-template-rows:
    auto
    auto;
  grid-template-areas:
    'ai-hero ai-field'
    'p-hero p-field';
  gap: clamp(16px, 3vw, 32px);
  align-items: start;
}

/* Assign grid areas */
.ai-hero { grid-area: ai-hero; }
.ai-hand { grid-area: ai-hand; }
.ai-field { grid-area: ai-field; }
.p-hero { grid-area: p-hero; }
.p-field { grid-area: p-field; }

.board .zone {
  background: none;
  padding: 16px;
  border: none;
  border-radius: 0;
}

.board .slot {
  border: none;
  background: none;
  padding: 0;
}

.board h3 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8fa2b5;
}

.slot.ai-hero,
.slot.p-hero {
  background: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.slot.ai-hero h3,
.slot.p-hero h3 {
  margin: 0;
}

.slot.ai-hero .card-tooltip,
.slot.p-hero .card-tooltip {
  margin: 0 auto;
}

.slot.ai-hero .hero-mana,
.slot.p-hero .hero-mana {
  font-size: 18px;
  font-weight: 600;
  color: #f5fafc;
  letter-spacing: 0.02em;
}

.slot.ai-hero .ai-hand-count {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: #cad6e4;
}

.ai-field,
.p-field {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.ai-field .cards,
.p-field .cards {
  gap: clamp(12px, 2vw, 20px);
  min-height: 140px;
}

.p-field .card-tooltip {
  transition: transform 0.3s ease, filter 0.3s ease, z-index 0.3s ease;
  will-change: transform;
  transform-origin: center center;
}

.ai-field .card-tooltip,
.slot.ai-hero .card-tooltip,
.slot.p-hero .card-tooltip {
  transition: transform 0.3s ease, filter 0.3s ease, z-index 0.3s ease;
  will-change: transform;
  transform-origin: center center;
}

.ai-field .card-tooltip[data-touch-preview='1'],
.p-field .card-tooltip[data-touch-preview='1'],
.slot.ai-hero .card-tooltip[data-touch-preview='1'],
.slot.p-hero .card-tooltip[data-touch-preview='1'] {
  transform: translate3d(var(--touch-translate-x, 0), var(--touch-translate-y, 0), 0) scale(1.5);
  z-index: 1500;
  filter: drop-shadow(0 30px 60px rgba(0, 0, 0, 0.75));
}

.ai-hand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}

.ai-hand .count {
  font-size: 14px;
  letter-spacing: 0.06em;
  color: #cad6e4;
}

.ai-hand[data-debug-view='1'] .cards {
  justify-content: center;
}

.log-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.log-pane ul {
  flex: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  max-height: calc(100% - 50px);
  min-height: 50px;
}

.ai-log {
  background: none;
}

.p-log {
  background: none;
}

.zone.p-hand {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 540px;
  padding-top: 440px;
  overflow: hidden;
  --hand-overlap: 100px;
  z-index: 450;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  pointer-events: none;
}

.p-hand h3 {
  margin: 0 0 18px;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 14px;
  color: #8fa2b5;
}

.p-hand .cards {
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  padding-bottom: 16px;
  min-height: clamp(200px, 32vh, 300px);
  overflow: visible;
  pointer-events: none;
}

.p-hand .card-tooltip {
  flex: 0 0 auto;
  margin-left: calc(-1 * var(--hand-overlap, 100px));
  transform-origin: bottom center;
  transform: translateY(calc(var(--fan-translate, 0) * 1%)) rotate(var(--fan-rotate, 0deg)) scale(0.88);
  transition: transform 0.25s ease, filter 0.25s ease, z-index 0.25s ease;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5));
  z-index: var(--fan-z, 1);
  pointer-events: all;
}

.p-hand .card-tooltip:first-child {
  margin-left: 0;
}

.p-hand .card-tooltip:hover,
.p-hand .card-tooltip:focus-within,
.p-hand .card-tooltip[data-touch-preview='1'] {
  transform: translateY(-60%) scale(1.05);
  z-index: 999;
  filter: drop-shadow(0 36px 60px rgba(0, 0, 0, 0.75));
}

.combat-log {
  --drawer-width: min(420px, 90vw);
  --toggle-width: 44px;
  position: fixed;
  top: clamp(64px, 12vh, 128px);
  right: 0;
  bottom: clamp(24px, 12vh, 112px);
  width: var(--drawer-width);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  transform: translateX(calc(100% - var(--toggle-width)));
  transition: transform 0.3s ease;
  z-index: 500;
  pointer-events: none;
}

.combat-log[data-open='1'] {
  transform: translateX(0);
}

.combat-log__toggle {
  flex: 0 0 var(--toggle-width);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(32, 48, 66, 0.96), rgba(20, 30, 42, 0.96));
  color: #e5eef8;
  border: 1px solid rgba(122, 152, 184, 0.35);
  border-right: none;
  border-radius: 8px 0 0 8px;
  font-size: 22px;
  cursor: pointer;
  pointer-events: auto;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.combat-log__toggle:hover,
.combat-log__toggle:focus-visible {
  background: linear-gradient(180deg, rgba(40, 60, 82, 0.96), rgba(26, 38, 52, 0.96));
  color: #ffffff;
  outline: none;
}

.combat-log__content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, rgba(18, 28, 40, 0.96), rgba(10, 16, 24, 0.96));
  border-left: 1px solid rgba(122, 152, 184, 0.35);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  overflow-y: auto;
}

.combat-log__content .log-pane {
  background: none;
  max-height: 44%;
}

@media (pointer: coarse) {
  .combat-log {
    top: clamp(16px, 10vh, 80px);
    bottom: clamp(16px, 14vh, 96px);
  }

  .combat-log {
    --toggle-width: 40px;
    width: min(360px, 92vw);
  }

  .combat-log__toggle {
    font-size: 18px;
  }

  body {
    overflow-x: hidden;
  }

  #app {
    width: calc(100% / 0.4);
    min-height: calc(100% / 0.4);
    transform: scale(0.4);
    transform-origin: top left;
  }

  #root .board {
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
    grid-template-areas:
      'ai-hero ai-field'
      'p-hero p-field';
  }

  .ai-log,
  .p-log {
    min-height: initial;
  }

  .combat-log {
    --toggle-width: 44px;
    width: var(--drawer-width);
    top: clamp(64px, 12vh, 128px);
    bottom: clamp(24px, 12vh, 112px);
  }

  .combat-log__toggle {
    font-size: 22px;
  }

  .p-hand .card-tooltip:hover,
  .p-hand .card-tooltip:focus-within,
  .p-hand .card-tooltip[data-touch-preview='1'] {
    transform: translateY(-30%) scale(1.5);
  }
}

/* Card containers */
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.cards .card-tooltip { cursor: pointer; }

footer {
  padding: 12px clamp(16px, 4vw, 32px);
  font-size: 12px;
  opacity: 0.7;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.zone {
  background: none;
  padding: 16px;
  border: none;
  border-radius: 0;
}

ul.zone-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

ul.zone-list li {
  padding: 4px 6px;
  margin: 2px 0;
  background: none;
  cursor: pointer;
  border-radius: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 4px;
}

.target-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000; /* ensure above card tooltips */
}

.target-prompt ul {
  background: #0b0f14;
  list-style: none;
  padding: 1em;
}

.target-prompt li {
  cursor: pointer;
  margin: 0.25em 0;
  padding: 4px 6px;
}

.target-prompt button {
  margin-top: 0.5em;
  padding: 4px 6px;
}

.option-prompt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000; /* ensure above card tooltips */
}

.option-prompt ul {
  background: #0b0f14;
  list-style: none;
  padding: 1em;
}

.option-prompt li {
  cursor: pointer;
  margin: 0.25em 0;
  padding: 4px 6px;
}

.game-over {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000; /* ensure above card tooltips */
}

.game-over > div {
  background: #0b0f14;
  border: 1px solid #203040;
  padding: 1em;
  text-align: center;
}

.game-over button {
  margin-top: 0.5em;
  padding: 4px 6px;
}

/* AI thinking overlay */
.ai-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
.ai-overlay .panel {
  background: #0b0f14;
  border: 1px solid #203040;
  padding: 1em 1.25em;
  min-width: 280px;
  max-width: 420px;
}
.ai-overlay .msg { margin: 0 0 8px; }
.ai-overlay .progress {
  position: relative;
  --progress-pos: 0;
  height: 10px;
  border: 1px solid #203040;
  background: linear-gradient(180deg, rgba(16, 30, 46, 0.94), rgba(32, 64, 92, 0.94));
  box-shadow:
    inset 0 0 4px rgba(8, 12, 18, 0.85),
    inset 0 0 14px rgba(56, 128, 188, 0.25);
  overflow: hidden;
}
.ai-overlay .progress::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--progress-pos, 0) * 100%);
  width: 70%;
  background: linear-gradient(180deg, rgba(55, 140, 220, 0) 0%, rgba(90, 180, 255, 0.55) 35%, rgba(150, 230, 255, 0.95) 50%, rgba(90, 180, 255, 0.55) 65%, rgba(55, 140, 220, 0) 100%);
  transform: translateX(-50%);
  transition: left 0.4s ease-out, opacity 0.3s ease-out, width 0.4s ease-out, background 0.3s ease-out;
  filter: drop-shadow(0 0 8px rgba(40, 120, 190, 0.35));
  opacity: calc(0.4 + var(--progress-pos, 0) * 0.45);
  pointer-events: none;
}
.ai-overlay .progress::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 0%, rgba(173, 216, 230, 0.55) 50%, transparent 100%);
  background-size: 200% 100%;
  background-position: -150% 0;
  animation: aiProgressSheen 1.4s linear infinite;
  opacity: 0.32;
  mix-blend-mode: screen;
  transition: opacity 0.3s ease-out;
}
.ai-overlay .progress[data-complete='1']::before {
  left: 50%;
  width: 115%;
  background: linear-gradient(180deg, rgba(120, 210, 255, 0.85) 0%, rgba(150, 230, 255, 0.95) 100%);
  opacity: 1;
}
.ai-overlay .progress[data-complete='1']::after {
  opacity: 0;
}

@keyframes aiProgressSheen {
  0% { background-position: -150% 0; }
  100% { background-position: 150% 0; }
}

/* Card tooltip styling */

.card-tooltip {
  position: relative;
  color: #e5eef8;
  text-shadow: 3px 3px 3px #000;
  font-size: 12px;
  width: 220px;
  aspect-ratio: 1024 / 1536;
  text-align: left;
  touch-action: manipulation;
  border-radius: 25px;
  overflow: hidden;
}

.card-tooltip img.card-frame,
.card-tooltip img.card-art {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.card-tooltip img.card-art {
  left: 14.1%;
  top: 5.6%;
  width: 72%;
  height: 42.9%;
  object-fit: cover;
}

.card-tooltip .stat {
  position: absolute;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  z-index: 3;
  font-size: 28px;
}

.card-tooltip .stat.cost,
.card-tooltip .stat.armor {
  top: 8.5%;
  right: 7%;
  background: #1e90ff;
}

.card-tooltip .stat.attack {
  bottom: 4%;
  left: 7%;
  background: #f0b429;
}

.card-tooltip .stat.health {
  bottom: 4%;
  right: 7%;
  background: #e74c3c;
}

/* Secret indicator: top-center '?' badges, fanned horizontally */
.card-tooltip .stat.secret {
  top: 3%;
  left: 50%;
  transform: translateX(-50%);
  background: #f0b429; /* same yellow as attack */
}

/* Status indicators */
.card-tooltip .status-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 92%;
  height: 90%;
  border-radius: 50% / 55%; /* ellipse */
  pointer-events: none;
  z-index: 1; /* above art/frame, below text/stats */
}

.card-tooltip.status-stealthed {
  opacity: 0.6; /* stealth dim */
}

.card-tooltip .status-overlay.status-divine-shield {
  background: rgba(250, 128, 114, 0.35); /* salmon pink */
}

.card-tooltip .status-overlay.status-frozen {
  background: rgba(0, 255, 255, 0.30); /* cyan */
}

.card-tooltip .status-overlay.status-windfury {
  background: rgba(255, 255, 255, 0.25); /* white */
}

.card-info {
  position: absolute;
  left: 10.4%;
  top: 52.1%;
  width: 78.8%;
  height: 41.5%;
  display: flex;
  flex-direction: column;
  z-index: 2;
}

.card-type {
  margin: 4px 8px 0;
  font-size: 10px;
  text-transform: capitalize;
}

.card-info h4 {
  margin: 4px 8px;
}

.card-text {
  flex: 1;
  margin: 0 8px;
}

.card-keywords {
  margin: 0 30px 8px;
  font-style: italic;
  font-size: 10px;
}

/* Shake animation for hit feedback */
@keyframes shake-hit {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); }
  20% { transform: translate3d(-2px, 0, 0) rotate(-1deg); }
  40% { transform: translate3d(2px, 0, 0) rotate(1deg); }
  60% { transform: translate3d(-2px, 0, 0) rotate(-1deg); }
  80% { transform: translate3d(2px, 0, 0) rotate(1deg); }
  100% { transform: translate3d(0, 0, 0) rotate(0deg); }
}

.card-tooltip.shake-hit {
  animation: shake-hit 0.35s ease;
  box-shadow: 0 0 0 2px rgba(255, 64, 64, 0.6);
}

/* Fade-out when a battlefield ally is removed */
.card-tooltip.fade-out {
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* Attack animation overlay */
.attack-animation-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
}

.attack-flyer {
  pointer-events: none;
  z-index: 901;
  filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.45));
}

.attack-flyer img,
.attack-flyer .card-info {
  pointer-events: none;
}

@keyframes attack-bump {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  45% { transform: translate3d(3px, -4px, 0) scale(1.05); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

.card-tooltip.attack-bump {
  animation: attack-bump 0.28s ease;
}
