/**
 * TCG Masters Web Simulator - Core Stylesheet
 * Desktop-First Architecture with Mobile-Friendly Breakpoints
 * Modern Light Theme default
 */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-primary: #f0f4f8;
  --bg-surface: #ffffff;
  --bg-arena: #1b4d3e;
  --bg-mat-player: rgba(255, 255, 255, 0.08);
  --border-color: #cbd5e1;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #f8fafc;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --p1-color: #3b82f6;
  --p2-color: #ec4899;
  --card-ratio: 1.4;
  --card-w: 92px;
  --card-h: calc(var(--card-w) * var(--card-ratio));
  --hand-card-w: 104px;
  --hand-card-h: calc(var(--hand-card-w) * var(--card-ratio));
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.15), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* ================= HEADER & TOOLBAR ================= */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  z-index: 50;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 24px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: #dbeafe;
  color: #1e40af;
  text-transform: uppercase;
}

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

.theme-selector-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.theme-dropdown {
  padding: 4px 8px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
}

/* ================= MODERN BUTTONS ================= */
.app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.app-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.app-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

.app-btn.accent {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

.app-btn.danger {
  background: #fee2e2;
  border-color: #ef4444;
  color: #b91c1c;
}

.app-btn.small {
  padding: 3px 8px;
  font-size: 0.75rem;
}

/* ================= MOBILE VIEW NAVIGATION ================= */
.mobile-nav-bar {
  display: none;
  background: #0f172a;
  padding: 6px 12px;
  gap: 8px;
  justify-content: center;
  z-index: 40;
}

.mobile-nav-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  background: #1e293b;
  color: #94a3b8;
  cursor: pointer;
}

.mobile-nav-btn.active {
  background: var(--primary);
  color: #fff;
}

/* ================= MAIN ARENA LAYOUT ================= */
.main-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.arena-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0c2017;
  background-image: 
    radial-gradient(circle at 50% 50%, #154530 0%, #08160f 100%),
    linear-gradient(to right, rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 100% 100%, 30px 30px, 30px 30px;
  overflow-y: auto;
  position: relative;
  padding: 12px;
  gap: 10px;
}

/* ================= PLAYER MAT SECTIONS ================= */
.player-mat {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.player-mat.p1 {
  border-left: 4px solid var(--p1-color);
}

.player-mat.p2 {
  border-left: 4px solid var(--p2-color);
}

.player-mat.is-active-turn {
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.35);
  border-color: rgba(96, 165, 250, 0.6);
}

/* Player Meta Header */
.player-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-size: 0.85rem;
}

.player-identity {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.75rem;
}

.player-badge.p1 { background: var(--p1-color); }
.player-badge.p2 { background: var(--p2-color); }

.deck-title {
  font-weight: 600;
  color: #cbd5e1;
}

.player-quick-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Play Field (Prizes, Bench, Active, Deck/Discard) */
.play-field-grid {
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  gap: 12px;
  align-items: center;
}

/* Prizes Zone */
.prizes-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.zone-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.prizes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.prize-card-slot {
  width: 52px;
  height: 72px;
  border-radius: 5px;
  border: 1px dashed rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  overflow: hidden;
}

.prize-card-slot.has-card {
  border: 1px solid #1e3a8a;
  background: linear-gradient(135deg, #1e3a8a, #0f172a);
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.prize-card-slot.has-card:hover {
  transform: translateY(-3px) scale(1.05);
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(96, 165, 250, 0.5);
}

.card-back-art {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #cbd5e1;
  font-size: 0.65rem;
  font-weight: 700;
}

.prize-pokeball {
  font-size: 16px;
  margin-bottom: 2px;
}

.prize-label {
  font-size: 0.55rem;
  color: #93c5fd;
}

.taken-label {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.2);
}

/* Pokemon Center Mat (Bench & Active) */
.pokemon-zones-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.active-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.bench-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

/* Pokémon Slots */
.pokemon-slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius-sm);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s ease;
}

.pokemon-slot.active-spot {
  border-style: solid;
  border-color: rgba(245, 158, 11, 0.5);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

.pokemon-slot.has-pokemon {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.4);
  background: transparent;
}

.empty-slot-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.7rem;
  text-align: center;
  padding: 4px;
}

.empty-slot-placeholder .slot-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.empty-slot-placeholder small {
  font-size: 0.55rem;
  color: rgba(255, 255, 255, 0.3);
}

/* Deck & Discard Zone */
.deck-discard-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.deck-pile-box,
.discard-pile-box {
  width: 68px;
  height: 88px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.deck-pile-box {
  background: linear-gradient(135deg, #1e293b, #0f172a);
}

.discard-pile-box {
  background: linear-gradient(135deg, #334155, #1e293b);
}

.deck-pile-box:hover,
.discard-pile-box:hover {
  transform: translateY(-2px);
  border-color: #60a5fa;
}

.pile-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.pile-title {
  font-size: 0.65rem;
  font-weight: 700;
  color: #cbd5e1;
}

.pile-count-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid #fff;
}

.deck-actions-subbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

/* ================= CENTER ARENA DIVIDER ================= */
.arena-center-divider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  gap: 12px;
}

.stadium-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stadium-card-slot {
  width: 90px;
  height: 64px;
  border-radius: 6px;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.stadium-card-slot.has-card {
  border-style: solid;
  border-color: #38bdf8;
}

.stadium-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

.stadium-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.turn-status-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.turn-badge {
  background: #334155;
  color: #f8fafc;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.2);
}

.active-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  color: #fff;
}

.active-badge.p1 { background: var(--p1-color); }
.active-badge.p2 { background: var(--p2-color); }

.quick-action-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ================= HAND CARDS DOCK ================= */
.hand-dock-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hand-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #94a3b8;
  padding: 0 4px;
}

.hand-cards-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 4px 12px 4px;
  min-height: calc(var(--hand-card-h) + 20px);
  align-items: center;
}

.hand-card-item {
  flex: 0 0 var(--hand-card-w);
  height: var(--hand-card-h);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.15s ease;
  position: relative;
  box-shadow: var(--shadow-md);
}

.hand-card-item:hover {
  transform: translateY(-12px) scale(1.08);
  z-index: 30;
  box-shadow: 0 12px 24px rgba(0,0,0,0.4);
}

.hand-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
}

.concealed-card {
  background: linear-gradient(135deg, #1e3a8a, #0f172a);
  border: 1px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================= POKEMON CARD IN PLAY ================= */
.pokemon-card-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.card-visual-container {
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.card-visual-container .card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Pokemon In-Play Overlay Controls */
.pokemon-controls-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.75) 60%, transparent 100%);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 10;
}

.hp-gauge-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hp-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
}

.card-title-truncated {
  max-width: 50px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hp-badge {
  font-size: 0.6rem;
  background: rgba(0,0,0,0.6);
  padding: 1px 4px;
  border-radius: 3px;
}

.hp-badge.ko {
  background: var(--danger);
  color: #fff;
}

.hp-progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.hp-progress-fill {
  height: 100%;
  transition: width 0.2s ease, background 0.2s ease;
}

.damage-control-bar {
  display: flex;
  gap: 2px;
  justify-content: space-between;
}

.dmg-btn {
  flex: 1;
  padding: 1px 0;
  font-size: 0.55rem;
  font-weight: 700;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(30, 41, 59, 0.9);
  color: #fff;
  cursor: pointer;
}

.dmg-btn:hover {
  background: rgba(51, 65, 85, 1);
}

.dmg-btn.btn-ko {
  background: var(--danger);
  border-color: #b91c1c;
}

.badges-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.attached-pills-btn {
  background: rgba(245, 158, 11, 0.3);
  border: 1px solid #f59e0b;
  color: #fbbf24;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

.no-energy-pill {
  font-size: 0.5rem;
  color: rgba(255,255,255,0.4);
}

.promote-btn,
.inspect-btn {
  background: rgba(59, 130, 246, 0.3);
  border: 1px solid #60a5fa;
  color: #93c5fd;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

.status-conditions-row {
  display: flex;
  justify-content: space-around;
  gap: 1px;
}

.status-chip {
  font-size: 9px;
  opacity: 0.25;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.status-chip.active {
  opacity: 1;
  transform: scale(1.2);
  filter: drop-shadow(0 0 2px #fff);
}

/* ================= SYNTHETIC / PROGRAMMATIC CARD RENDERER ================= */
.card-rendered {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  padding: 4px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: var(--font-family);
  font-size: 0.65rem;
  line-height: 1.1;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3);
}

.card-rendered.is-ex {
  box-shadow: inset 0 0 0 2px #f59e0b, 0 0 8px rgba(245, 158, 11, 0.5);
}

.card-rendered-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

.card-name {
  font-size: 0.65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-hp {
  font-size: 0.65rem;
  white-space: nowrap;
}

.card-badge-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.55rem;
  opacity: 0.85;
}

.card-badge {
  background: rgba(0,0,0,0.3);
  padding: 1px 3px;
  border-radius: 2px;
}

.card-rendered-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0;
  font-size: 0.55rem;
}

.card-ability {
  background: rgba(239, 68, 68, 0.2);
  padding: 2px;
  border-radius: 2px;
}

.ability-tag {
  color: #f87171;
  font-weight: 700;
  font-size: 0.5rem;
}

.card-attack {
  background: rgba(0,0,0,0.15);
  padding: 2px;
  border-radius: 2px;
}

.atk-header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.atk-cost {
  font-size: 8px;
}

.card-trainer-text {
  font-size: 0.55rem;
  opacity: 0.9;
}

.card-rendered-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.5rem;
  opacity: 0.75;
}

/* ================= SIDEBAR & BATTLE LOG ================= */
.sidebar-panel {
  width: 290px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.sidebar-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: 700;
}

.game-log-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: monospace;
  font-size: 0.75rem;
  background: #f8fafc;
}

.log-entry {
  padding: 4px 6px;
  border-radius: 4px;
  background: #fff;
  border: 1px solid #e2e8f0;
  display: flex;
  gap: 6px;
  line-height: 1.3;
}

.log-time {
  color: var(--text-muted);
  font-size: 0.65rem;
  white-space: nowrap;
}

.log-danger { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.log-warning { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.log-prize { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.log-win { background: #dcfce7; border-color: #86efac; color: #166534; font-weight: bold; }
.log-coin-heads { background: #fef08a; color: #854d0e; }
.log-coin-tails { background: #e2e8f0; color: #334155; }
.log-dice { background: #ede9fe; color: #5b21b6; }

/* ================= POPUP ACTION MENU ================= */
.hand-action-dropdown {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 100;
  min-width: 200px;
  max-width: 260px;
  animation: popIn 0.15s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.menu-header {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 4px;
}

.menu-header b {
  display: block;
  font-size: 0.85rem;
  color: var(--text-main);
}

.menu-header small {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.menu-divider {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 4px 8px 2px 8px;
}

.menu-item-btn {
  text-align: left;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
  transition: background 0.1s ease;
  font-family: inherit;
}

.menu-item-btn:hover {
  background: #f1f5f9;
}

.menu-item-btn.small {
  font-size: 0.75rem;
  padding: 4px 10px;
}

.menu-item-btn.text-danger {
  color: var(--danger);
}

.menu-item-btn.text-danger:hover {
  background: #fee2e2;
}

/* ================= MODAL BASE ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-color);
  animation: modalEnter 0.2s ease-out;
}

@keyframes modalEnter {
  from { opacity: 0; transform: translateY(15px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Inspector Modal */
.inspector-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
}

.inspector-main-img {
  width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.inspector-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 14px 0;
}

.meta-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  font-weight: 600;
}

.inspector-ability-box,
.inspector-attack-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.ability-title {
  color: #dc2626;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.atk-title-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.atk-dmg {
  font-weight: 700;
  color: #ea580c;
}

.atk-cost-bar {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Search Deck Results */
.deck-search-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.deck-search-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.deck-search-select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.deck-search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
}

.search-result-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #fff;
}

.search-card-thumbnail {
  height: 130px;
  overflow: hidden;
  border-radius: 4px;
}

.search-card-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-card-info b {
  font-size: 0.75rem;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-card-info small {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.search-card-actions {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Discard List */
.discard-list-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 55vh;
  overflow-y: auto;
}

.discard-pile-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #fff;
}

.discard-thumb {
  width: 40px;
  height: 56px;
  border-radius: 4px;
  overflow: hidden;
}

.discard-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.discard-info {
  flex: 1;
}

.discard-info b {
  font-size: 0.85rem;
  display: block;
}

.discard-actions {
  display: flex;
  gap: 6px;
}

/* Coin & Dice Animators */
.tool-animator-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  gap: 16px;
}

.coin {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd700, #b8860b);
  border: 4px solid #fff;
  box-shadow: 0 8px 16px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  color: #7a5802;
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.coin.flipping {
  animation: flipCoinAnim 0.8s ease-in-out infinite;
}

@keyframes flipCoinAnim {
  0% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(720deg) scale(1.3); }
  100% { transform: rotateY(1440deg) scale(1); }
}

.dice {
  width: 70px;
  height: 70px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid #cbd5e1;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: #1e293b;
}

.dice.rolling {
  animation: rollDiceAnim 0.7s ease-in-out infinite;
}

@keyframes rollDiceAnim {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

.tool-result-text {
  font-size: 1.2rem;
  font-weight: 700;
}

.res-heads { color: #b45309; }
.res-tails { color: #475569; }

/* Deck Manager Code Area */
.deck-manager-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.deck-player-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.deck-textarea {
  width: 100%;
  height: 200px;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  resize: vertical;
}

/* ================= RESPONSIVE / MOBILE-FRIENDLY ================= */
@media (max-width: 1024px) {
  .sidebar-panel {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --card-w: 68px;
    --hand-card-w: 78px;
  }

  .mobile-nav-bar {
    display: flex;
  }

  .play-field-grid {
    grid-template-columns: 80px 1fr 70px;
    gap: 6px;
  }

  .prize-card-slot {
    width: 36px;
    height: 52px;
  }

  .deck-pile-box,
  .discard-pile-box {
    width: 54px;
    height: 72px;
  }

  .inspector-grid {
    grid-template-columns: 1fr;
  }

  .deck-manager-grid {
    grid-template-columns: 1fr;
  }

  /* Mobile Tabs View Switching */
  .arena-container.view-p1 #p2-board {
    display: none;
  }

  .arena-container.view-p2 #p1-board {
    display: none;
  }
}
