/* Arcomage — Dark Fantasy Theme */
/* Visual overhaul: towers, walls, animations, cards, mobile */

@import url('https://fonts.googleapis.com/css2?family=Philosopher:wght@400;700&family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  /* Core palette */
  --bg-deep: #0d0816;
  --bg-dark: #130e1e;
  --bg-panel: #1a1228;
  --bg-card: #1e1630;
  --bg-hover: #251d3a;
  --border: #2e2345;
  --border-light: #3d3156;

  /* Text */
  --text: #e8e0f0;
  --text-dim: #8a7fa0;
  --text-muted: #5a5070;

  /* Accent */
  --gold: #d4a843;
  --gold-bright: #f0c850;
  --gold-glow: rgba(212, 168, 67, 0.3);

  /* Resources */
  --brick: #d4734a;
  --brick-dim: #a85535;
  --brick-bg: #2a150d;
  --brick-border: #5a2e18;
  --gem: #7c6ae8;
  --gem-dim: #5f4fc4;
  --gem-bg: #1a1535;
  --gem-border: #3a2d6a;
  --recruit: #4ac48a;
  --recruit-dim: #2e9a60;
  --recruit-bg: #0d2218;
  --recruit-border: #1a4a30;

  /* Buildings */
  --tower: #5a9ae8;
  --tower-top: #8ec0ff;
  --wall: #8a8a9a;
  --wall-top: #b0b0c0;

  /* Status */
  --red: #e04050;
  --green: #40c878;

  /* Fonts */
  --font-title: 'Philosopher', 'Georgia', serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 80%, rgba(90, 60, 180, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(60, 40, 120, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(30, 20, 60, 0.8) 0%, transparent 100%);
}

/* ==================== START SCREEN ==================== */

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(100, 70, 200, 0.12) 0%, transparent 60%),
    var(--bg-deep);
  animation: startFadeIn 0.6s ease;
}

.start-screen.hidden {
  display: none;
}

@keyframes startFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.start-title {
  font-family: var(--font-title);
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--gold-bright);
  text-shadow: 0 0 40px rgba(212, 168, 67, 0.35), 0 2px 8px rgba(0,0,0,0.5);
  letter-spacing: 4px;
  text-transform: uppercase;
}

.start-subtitle {
  font-size: 1rem;
  color: var(--text-dim);
  max-width: 500px;
  text-align: center;
  line-height: 1.6;
  margin-top: -8px;
}

.start-rules {
  max-width: 480px;
  background: rgba(255,255,255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.7;
}

.start-rules h3 {
  font-family: var(--font-title);
  color: var(--gold);
  font-size: 1rem;
  margin-bottom: 10px;
}

.start-rules ul {
  list-style: none;
  padding: 0;
}

.start-rules li {
  padding: 3px 0;
}

.start-rules li::before {
  content: '\2014  ';
  color: var(--gold);
}

.start-btn {
  background: linear-gradient(135deg, var(--gold), #b88a30);
  color: #1a1025;
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 2px;
  border: none;
  padding: 14px 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  box-shadow: 0 4px 20px var(--gold-glow);
  margin-top: 8px;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(212, 168, 67, 0.5);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
}

.start-btn:active {
  transform: translateY(0);
}

.start-credit {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 16px;
}

.start-credit a {
  color: var(--text-dim);
  text-decoration: none;
}

.start-credit a:hover {
  color: var(--gold);
}

/* ==================== HEADER ==================== */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  background: rgba(20, 14, 30, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  height: 42px;
  z-index: 10;
  position: relative;
}

.header h1 {
  font-family: var(--font-title);
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 2px;
}

.header h1 span {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 400;
  margin-left: 8px;
  letter-spacing: 0;
}

.header-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

#new-game-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-body);
  transition: all 0.2s;
}

#new-game-btn:hover {
  color: var(--gold);
  border-color: var(--gold);
  background: rgba(212, 168, 67, 0.08);
}

.turn-indicator {
  padding: 4px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.3s;
}

.turn-indicator.your-turn {
  background: linear-gradient(135deg, rgba(64, 200, 120, 0.2), rgba(64, 200, 120, 0.1));
  color: var(--green);
  border: 1px solid rgba(64, 200, 120, 0.3);
  animation: turnPulse 1.5s ease infinite;
}

.turn-indicator.enemy-turn {
  background: linear-gradient(135deg, rgba(224, 64, 80, 0.2), rgba(224, 64, 80, 0.1));
  color: var(--red);
  border: 1px solid rgba(224, 64, 80, 0.3);
}

.turn-indicator.win {
  background: linear-gradient(135deg, var(--gold-glow), rgba(212, 168, 67, 0.1));
  color: var(--gold-bright);
  border: 1px solid var(--gold);
}

.turn-indicator.lose {
  background: linear-gradient(135deg, rgba(224, 64, 80, 0.25), rgba(224, 64, 80, 0.1));
  color: var(--red);
  border: 1px solid rgba(224, 64, 80, 0.4);
}

@keyframes turnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(64, 200, 120, 0); }
  50% { box-shadow: 0 0 8px 2px rgba(64, 200, 120, 0.2); }
}

/* ==================== GAME BOARD LAYOUT ==================== */

.game-board {
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  grid-template-rows: 1fr auto;
  height: calc(100vh - 42px);
  height: calc(100dvh - 42px);
  overflow-x: hidden;
  max-width: 100vw;
}

/* ==================== RESOURCE PANELS ==================== */

.resource-panel {
  background: var(--bg-panel);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  position: relative;
}

.resource-panel.enemy {
  border-right: none;
  border-left: 1px solid var(--border);
}

.resource-panel h3 {
  font-family: var(--font-title);
  font-size: 0.85rem;
  margin-bottom: 4px;
  text-align: center;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.resource-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  transition: background 0.2s;
  position: relative;
}

.resource-row.structure {
  background: rgba(255,255,255, 0.03);
  border: 1px solid rgba(255,255,255, 0.04);
}

.resource-row.bricks {
  background: linear-gradient(90deg, var(--brick-bg), rgba(42, 21, 13, 0.3));
  border: 1px solid var(--brick-border);
}

.resource-row.gems {
  background: linear-gradient(90deg, var(--gem-bg), rgba(26, 21, 53, 0.3));
  border: 1px solid var(--gem-border);
}

.resource-row.recruits {
  background: linear-gradient(90deg, var(--recruit-bg), rgba(13, 34, 24, 0.3));
  border: 1px solid var(--recruit-border);
}

.resource-icon {
  font-size: 0.95rem;
  width: 20px;
  text-align: center;
}

.resource-label {
  flex: 1;
  margin-left: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.resource-gen {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.78rem;
  margin-right: 6px;
  min-width: 14px;
  text-align: center;
}

.resource-val {
  font-weight: 700;
  min-width: 24px;
  text-align: right;
  font-size: 0.9rem;
  display: inline-block;
  position: relative;
}

.resource-row.bricks .resource-val { color: var(--brick); }
.resource-row.gems .resource-val { color: var(--gem); }
.resource-row.recruits .resource-val { color: var(--recruit); }
.resource-row.structure .resource-val { color: var(--text); }

.resource-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 4px 0;
}

/* Value change animation — bounce + glow */
.resource-val.changed-up {
  animation: resChangeUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.resource-val.changed-down {
  animation: resChangeDown 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes resChangeUp {
  0% { transform: scale(1); }
  30% { transform: scale(1.5); color: var(--green); text-shadow: 0 0 8px rgba(64, 200, 120, 0.6); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); text-shadow: none; }
}
@keyframes resChangeDown {
  0% { transform: scale(1); }
  30% { transform: scale(1.5); color: var(--red); text-shadow: 0 0 8px rgba(224, 64, 80, 0.6); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); text-shadow: none; }
}

/* ==================== FLOATING NUMBERS ==================== */

.float-number {
  position: absolute;
  right: 8px;
  top: -4px;
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 20;
  animation: floatUp 0.9s ease-out forwards;
}

.float-number.positive {
  color: var(--green);
  text-shadow: 0 0 6px rgba(64, 200, 120, 0.5);
}

.float-number.negative {
  color: var(--red);
  text-shadow: 0 0 6px rgba(224, 64, 80, 0.5);
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  70% { opacity: 0.8; }
  100% { opacity: 0; transform: translateY(-28px); }
}

/* ==================== BATTLEFIELD ==================== */

.battlefield {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 30px;
  padding: 16px 30px 20px;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(90, 60, 180, 0.06) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-deep) 0%, rgba(20, 14, 30, 0.6) 100%);
  overflow: hidden;
}

/* Ground line */
.battlefield::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 5%;
  right: 5%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(212, 168, 67, 0.2), rgba(90, 60, 180, 0.15), rgba(212, 168, 67, 0.2), transparent);
}

/* Ground glow */
.battlefield::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  right: 10%;
  height: 40px;
  background: linear-gradient(180deg, transparent, rgba(90, 60, 180, 0.03));
  pointer-events: none;
}

/* Win conditions strip */
.win-conditions {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  z-index: 5;
}

.win-cond {
  font-size: 0.68rem;
  color: var(--text-muted);
  background: rgba(255,255,255, 0.03);
  border: 1px solid rgba(255,255,255, 0.05);
  padding: 3px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ==================== TOWER & WALL STRUCTURES ==================== */

.structure-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.structure-group .label {
  font-family: var(--font-title);
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.tower-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 220px;
  position: relative;
}

.tower-wrapper, .wall-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

/* Tower container — narrower (башня — узкая высокая) */
.tower-container {
  width: 36px;
  height: 180px;
  background: rgba(255,255,255, 0.02);
  border: 1px solid rgba(255,255,255, 0.06);
  border-radius: 4px 4px 0 0;
  position: relative;
  overflow: visible;
}

/* Wall container — wider (стена — широкая, защищает башню) */
.wall-container {
  width: 48px;
  height: 140px;
  background: rgba(255,255,255, 0.02);
  border: 1px solid rgba(255,255,255, 0.06);
  border-radius: 3px 3px 0 0;
  position: relative;
  overflow: visible;
}

/* ---- TOWER BAR ---- */
.tower-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    #1a3a6a 0%,
    #2a5aaa 15%,
    #3a6abb 40%,
    #5a9ae8 70%,
    #7ab4f0 90%,
    #8ec0ff 100%
  );
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0;
  transform-origin: bottom center;
  overflow: visible;
}

/* Tower brick pattern + window shapes */
.tower-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    /* Horizontal mortar lines */
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 10px,
      rgba(0,0,0,0.12) 10px,
      rgba(0,0,0,0.12) 11px
    ),
    /* Offset vertical lines (brick pattern) */
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 11px,
      rgba(0,0,0,0.07) 11px,
      rgba(0,0,0,0.07) 12px
    ),
    /* Window-like dark patches */
    radial-gradient(ellipse 4px 6px at 26px 20%, rgba(0,0,0,0.25) 0%, transparent 100%),
    radial-gradient(ellipse 4px 6px at 26px 50%, rgba(0,0,0,0.2) 0%, transparent 100%),
    radial-gradient(ellipse 4px 6px at 26px 80%, rgba(0,0,0,0.15) 0%, transparent 100%);
  pointer-events: none;
}

/* Tower battlements / crenellations at top */
.tower-bar::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -3px;
  right: -3px;
  height: 12px;
  background: linear-gradient(to bottom, #8ec0ff, #5a9ae8);
  clip-path: polygon(
    0% 100%,
    0% 40%,
    10% 40%,
    10% 0%,
    25% 0%,
    25% 40%,
    38% 40%,
    38% 0%,
    52% 0%,
    52% 40%,
    65% 40%,
    65% 0%,
    78% 0%,
    78% 40%,
    90% 40%,
    90% 0%,
    100% 0%,
    100% 100%
  );
  z-index: 2;
}

/* Inner glow for tower depth */
.tower-container::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 2px 0 8px rgba(0,0,0,0.3), inset -2px 0 8px rgba(0,0,0,0.3);
  pointer-events: none;
  z-index: 3;
}

/* ---- WALL BAR ---- */
.wall-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    #3a3a48 0%,
    #505060 20%,
    #6a6a7a 45%,
    #8a8a9a 70%,
    #9a9aaa 85%,
    #b0b0c0 100%
  );
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0;
  transform-origin: bottom center;
  overflow: visible;
}

/* Wall brick/stone texture — offset brick pattern */
.wall-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    /* Horizontal mortar */
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 7px,
      rgba(0,0,0,0.18) 7px,
      rgba(0,0,0,0.18) 8px
    ),
    /* Vertical mortar — even rows */
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 14px,
      rgba(0,0,0,0.12) 14px,
      rgba(0,0,0,0.12) 15px
    );
  /* Offset every other row is simulated by the two patterns overlapping */
  pointer-events: none;
}

/* Wall top — flat battlements (simpler than tower) */
.wall-bar::before {
  content: '';
  position: absolute;
  top: -6px;
  left: -2px;
  right: -2px;
  height: 8px;
  background: linear-gradient(to bottom, #b0b0c0, #8a8a9a);
  clip-path: polygon(
    0% 100%,
    0% 50%,
    15% 50%,
    15% 0%,
    35% 0%,
    35% 50%,
    65% 50%,
    65% 0%,
    85% 0%,
    85% 50%,
    100% 50%,
    100% 100%
  );
  z-index: 2;
}

/* Inner shadow for wall depth */
.wall-container::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 1px 0 6px rgba(0,0,0,0.35), inset -1px 0 6px rgba(0,0,0,0.35);
  pointer-events: none;
  z-index: 3;
}

/* ---- STRUCTURE ANIMATIONS ---- */

/* Shake on damage */
.tower-container.shake,
.wall-container.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-4px); }
  30% { transform: translateX(4px); }
  45% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(1px); }
}

/* Red flash overlay on damage */
.tower-container.damage-flash-active::before,
.wall-container.damage-flash-active::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(224, 64, 80, 0.25);
  z-index: 5;
  animation: flashDmg 0.35s ease-out forwards;
  pointer-events: none;
}

/* Tower grow animation */
.tower-bar.tower-grow {
  animation: towerGrow 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes towerGrow {
  0% { transform: scaleY(0.85); }
  50% { transform: scaleY(1.04); }
  100% { transform: scaleY(1); }
}

.wall-bar.wall-grow {
  animation: towerGrow 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.structure-val {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
}

/* ==================== VS DIVIDER ==================== */

.vs-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-self: center;
}

.vs-text {
  font-family: var(--font-title);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold-glow);
  letter-spacing: 2px;
}

/* ==================== AI CHAT BUBBLE ==================== */

.ai-chat {
  position: absolute;
  top: 40px;
  right: 16px;
  max-width: 240px;
  opacity: 0;
  transform: translateY(-8px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 10;
}

.ai-chat.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.ai-bubble {
  background: linear-gradient(135deg, rgba(90, 60, 180, 0.15), rgba(60, 40, 120, 0.1));
  border: 1px solid rgba(124, 106, 232, 0.3);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: rgba(200, 180, 240, 0.9);
  font-style: italic;
  line-height: 1.4;
  backdrop-filter: blur(4px);
  position: relative;
}

.ai-bubble::before {
  content: '\1F3AD';
  position: absolute;
  top: -10px;
  left: -6px;
  font-size: 1.1rem;
}

/* ==================== HAND AREA ==================== */

.hand-area {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, var(--bg-panel), rgba(20, 14, 30, 0.98));
  border-top: 1px solid var(--border);
  padding: 8px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hand-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
  height: 14px;
}

.hand-hint.visible {
  opacity: 1;
}

.hand {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

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

/* ==================== CARDS ==================== */

.card {
  width: 132px;
  min-width: 132px;
  height: 176px;
  border-radius: 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  cursor: default;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.25s ease;
  position: relative;
  border: 2px solid transparent;
  user-select: none;
  overflow: hidden;
  /* Disabled/can't afford state by default */
  filter: grayscale(0.7) brightness(0.6);
  opacity: 0.55;
}

/* Card parchment texture overlay */
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 3px,
      rgba(255,255,255,0.015) 3px,
      rgba(255,255,255,0.015) 4px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 5px,
      rgba(255,255,255,0.01) 5px,
      rgba(255,255,255,0.01) 6px
    );
  pointer-events: none;
  z-index: 1;
  border-radius: 10px;
}

/* Card inner structure */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 9px 5px;
  position: relative;
  z-index: 2;
}

.card-cost {
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 3px;
}

.card-cost-icon {
  font-size: 0.75rem;
}

.card-type-icon {
  font-size: 0.85rem;
  opacity: 0.6;
}

.card-name {
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-title);
  color: #fff;
  line-height: 1.2;
  position: relative;
  z-index: 2;
}

.card-body {
  flex: 1;
  padding: 5px 9px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.card-desc {
  font-size: 0.67rem;
  color: rgba(255,255,255, 0.6);
  line-height: 1.35;
}

.card-footer {
  padding: 4px 9px 7px;
  text-align: center;
  position: relative;
  z-index: 2;
}

.card-again {
  font-size: 0.68rem;
  color: var(--gold);
  font-weight: 700;
}

/* Card type themes — multi-layer: dark base + colored tint */
.card.bricks {
  background: linear-gradient(160deg, #2d1a0f 0%, #3d2215 40%, #2a180e 100%);
  border-color: var(--brick-border);
  box-shadow: inset 0 0 20px rgba(212, 115, 74, 0.08);
}
.card.bricks .card-cost { color: var(--brick); }
.card.bricks .card-header { border-bottom: 1px solid rgba(212, 115, 74, 0.15); }

.card.gems {
  background: linear-gradient(160deg, #1a1538 0%, #22194a 40%, #18132e 100%);
  border-color: var(--gem-border);
  box-shadow: inset 0 0 20px rgba(124, 106, 232, 0.08);
}
.card.gems .card-cost { color: var(--gem); }
.card.gems .card-header { border-bottom: 1px solid rgba(124, 106, 232, 0.15); }

.card.recruits {
  background: linear-gradient(160deg, #0f221a 0%, #15301f 40%, #0d1e16 100%);
  border-color: var(--recruit-border);
  box-shadow: inset 0 0 20px rgba(74, 196, 138, 0.08);
}
.card.recruits .card-cost { color: var(--recruit); }
.card.recruits .card-header { border-bottom: 1px solid rgba(74, 196, 138, 0.15); }

/* Playable cards — remove grayscale, full opacity */
.card.playable {
  opacity: 1;
  filter: none;
  cursor: pointer;
}

.card.playable:hover {
  transform: translateY(-8px) scale(1.02);
}

.card.playable.bricks:hover {
  border-color: var(--brick);
  box-shadow:
    0 8px 24px rgba(212, 115, 74, 0.3),
    0 0 0 1px rgba(212, 115, 74, 0.15),
    inset 0 0 24px rgba(212, 115, 74, 0.12);
}

.card.playable.gems:hover {
  border-color: var(--gem);
  box-shadow:
    0 8px 24px rgba(124, 106, 232, 0.3),
    0 0 0 1px rgba(124, 106, 232, 0.15),
    inset 0 0 24px rgba(124, 106, 232, 0.12);
}

.card.playable.recruits:hover {
  border-color: var(--recruit);
  box-shadow:
    0 8px 24px rgba(74, 196, 138, 0.3),
    0 0 0 1px rgba(74, 196, 138, 0.15),
    inset 0 0 24px rgba(74, 196, 138, 0.12);
}

/* Discard mode */
.card.discard-mode {
  opacity: 1;
  filter: none;
  cursor: pointer;
}

.card.discard-mode:hover {
  border-color: var(--red) !important;
  box-shadow: 0 8px 24px rgba(224, 64, 80, 0.3) !important;
  transform: translateY(-8px);
}

/* ---- CARD ANIMATIONS ---- */

/* Card play: translate up + rotate + fade */
.card.card-played {
  animation: cardPlay 0.35s ease forwards;
}

@keyframes cardPlay {
  0% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
  50% { transform: translateY(-50px) rotate(-3deg) scale(1.04); opacity: 0.7; }
  100% { transform: translateY(-90px) rotate(-5deg) scale(0.85); opacity: 0; }
}

/* Card discard: fade + slight rotation */
.card.card-discarded {
  animation: cardDiscard 0.3s ease forwards;
}

@keyframes cardDiscard {
  0% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
  100% { transform: translateY(20px) rotate(4deg) scale(0.9); opacity: 0; }
}

/* Card draw: slide in from offset */
.card.card-drawn {
  animation: cardDraw 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes cardDraw {
  0% { transform: translateX(40px) translateY(10px) scale(0.9); opacity: 0; }
  100% { transform: translateX(0) translateY(0) scale(1); opacity: 1; }
}

/* ==================== GAME LOG ==================== */

.game-log-area {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 260px;
  max-height: 110px;
  overflow-y: auto;
  background: rgba(13, 8, 22, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  z-index: 5;
  backdrop-filter: blur(4px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.game-log-area::-webkit-scrollbar {
  width: 3px;
}

.game-log-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Mobile log toggle */
.game-log-area.collapsed {
  max-height: 28px;
  overflow: hidden;
  cursor: pointer;
}

.log-toggle-btn {
  display: none;
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 6;
  background: rgba(13, 8, 22, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  color: var(--text-dim);
  font-size: 0.7rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.log-line {
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255, 0.02);
  line-height: 1.4;
}

.log-line:last-child {
  color: var(--text-dim);
  border-bottom: none;
}

/* ==================== MESSAGE TOAST ==================== */

.message {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.message.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.message.error {
  background: rgba(224, 64, 80, 0.9);
  color: white;
  border: 1px solid rgba(224, 64, 80, 0.5);
}

.message.info {
  background: rgba(90, 60, 180, 0.9);
  color: white;
  border: 1px solid rgba(124, 106, 232, 0.3);
}

/* ==================== GAME OVER OVERLAY ==================== */

.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 16, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  backdrop-filter: blur(8px);
}

.game-over-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#game-over-title {
  font-family: var(--font-title);
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
}

.game-over-overlay.win #game-over-title {
  color: var(--gold-bright);
  text-shadow: 0 0 40px var(--gold-glow), 0 0 80px rgba(212, 168, 67, 0.2);
  animation: winPulseTitle 2s ease infinite;
}

.game-over-overlay.lose #game-over-title {
  color: var(--red);
  text-shadow: 0 0 40px rgba(224, 64, 80, 0.4);
}

@keyframes winPulseTitle {
  0%, 100% { text-shadow: 0 0 40px var(--gold-glow), 0 0 80px rgba(212, 168, 67, 0.2); }
  50% { text-shadow: 0 0 60px var(--gold-glow), 0 0 120px rgba(212, 168, 67, 0.3); }
}

#game-over-subtitle {
  font-size: 1rem;
  color: var(--text-dim);
  max-width: 400px;
  text-align: center;
  line-height: 1.5;
}

#restart-btn {
  background: linear-gradient(135deg, var(--gold), #b88a30);
  color: #1a1025;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 1px;
  border: none;
  padding: 12px 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 8px;
  box-shadow: 0 4px 20px var(--gold-glow);
}

#restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(212, 168, 67, 0.5);
}

/* ---- CONFETTI (CSS only) ---- */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 201;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ==================== DAMAGE FLASH ==================== */

.damage-flash {
  position: absolute;
  inset: 0;
  background: rgba(224, 64, 80, 0.15);
  border-radius: 4px;
  animation: flashDmg 0.4s ease forwards;
  pointer-events: none;
}

@keyframes flashDmg {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* ==================== REDUCED MOTION ==================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .card.playable:hover {
    transform: none;
  }

  .tower-bar, .wall-bar {
    transition: height 0.01ms !important;
  }
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 900px) {
  .game-board {
    grid-template-columns: 140px 1fr 140px;
  }

  .card {
    width: 115px;
    min-width: 115px;
    height: 158px;
  }

  .card-name { font-size: 0.72rem; }
  .card-desc { font-size: 0.62rem; }
  .card-cost { font-size: 0.76rem; }

  .tower-area { height: 180px; }
  .tower-container { height: 150px; }
  .wall-container { height: 150px; }

  .battlefield { gap: 20px; padding: 12px 20px 16px; }
}

@media (max-width: 650px) {
  .game-board {
    grid-template-columns: 95px 1fr 95px;
  }

  .resource-label { display: none; }
  .resource-panel { padding: 8px 6px; gap: 4px; }
  .resource-row { padding: 4px 6px; font-size: 0.78rem; }
  .resource-gen { font-size: 0.72rem; margin-right: 4px; }

  .header h1 span { display: none; }
  .header h1 { font-size: 1rem; }

  .card {
    width: 100px;
    min-width: 100px;
    height: 145px;
  }

  .card-header { padding: 5px 7px 4px; }
  .card-name { padding: 0 7px; font-size: 0.68rem; }
  .card-body { padding: 4px 7px; }
  .card-desc { font-size: 0.58rem; }
  .card-footer { padding: 3px 7px 5px; }
  .card-again { font-size: 0.62rem; }

  /* Show log toggle, hide full log by default */
  .game-log-area { display: none; }
  .log-toggle-btn { display: block; }

  .battlefield { gap: 14px; padding: 8px 10px 14px; }

  .win-conditions { gap: 6px; }
  .win-cond { font-size: 0.6rem; padding: 2px 6px; }

  .tower-area { height: 160px; gap: 4px; }
  .tower-container { height: 130px; width: 44px; }
  .wall-container { height: 130px; width: 26px; }

  .start-title { font-size: 2.2rem; }
  .start-rules { padding: 14px 16px; font-size: 0.78rem; }
  .start-btn { font-size: 1.1rem; padding: 12px 36px; }

  .hand-area { padding: 6px 10px 8px; }
  .hand { gap: 6px; }
}

/* Full mobile vertical layout (<600px) */
@media (max-width: 599px) {
  * {
    max-width: 100vw;
  }

  .game-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    height: calc(100dvh - 42px);
    overflow-x: hidden;
    width: 100vw;
  }

  /* Enemy resources — top compact row */
  .resource-panel.enemy {
    order: 1;
    border-left: none;
    border-bottom: 1px solid var(--border);
    border-right: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
    padding: 6px 8px;
    justify-content: center;
  }

  .resource-panel.enemy h3 {
    width: 100%;
    font-size: 0.68rem;
    margin-bottom: 0;
  }

  .resource-panel.enemy .resource-row {
    padding: 2px 6px;
    font-size: 0.72rem;
    flex: 0 0 auto;
    min-width: 0;
    border-radius: 4px;
  }

  .resource-panel.enemy .resource-divider {
    display: none;
  }

  /* Battlefield — middle */
  .battlefield {
    order: 2;
    min-height: 0;
    padding: 8px 16px 12px;
  }

  /* Player resources — below battlefield */
  .resource-panel.player {
    order: 3;
    border-right: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
    padding: 6px 8px;
    justify-content: center;
  }

  .resource-panel.player h3 {
    width: 100%;
    font-size: 0.68rem;
    margin-bottom: 0;
  }

  .resource-panel.player .resource-row {
    padding: 2px 6px;
    font-size: 0.72rem;
    flex: 0 0 auto;
    min-width: 0;
    border-radius: 4px;
  }

  .resource-panel.player .resource-divider {
    display: none;
  }

  /* Hand — bottom */
  .hand-area {
    order: 4;
    padding: 6px 8px env(safe-area-inset-bottom, 8px);
  }

  .hand {
    justify-content: flex-start;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding-bottom: 2px;
  }

  .hand .card {
    scroll-snap-align: center;
    min-width: 100px;
    min-height: 130px;
  }

  /* Ensure 44px tap target */
  .hand .card {
    min-width: max(100px, 44px);
    min-height: max(130px, 44px);
  }

  .resource-label { display: none; }
  .resource-gen { display: none; }

  .tower-area { height: 140px; gap: 4px; }
  .tower-container { height: 110px; width: 40px; }
  .wall-container { height: 110px; width: 22px; }
}

@media (max-width: 420px) {
  /* Only override if not already in vertical mobile layout */
  .resource-icon { font-size: 0.8rem; width: 16px; }
  .resource-val { font-size: 0.8rem; min-width: 20px; }
  .resource-panel h3 { font-size: 0.72rem; }

  .card {
    width: 88px;
    min-width: 88px;
    height: 130px;
  }

  .card-name { font-size: 0.62rem; }
  .card-desc { font-size: 0.54rem; }
  .card-cost { font-size: 0.7rem; }
  .card-again { font-size: 0.58rem; }
}
