:root {
  --bg-color: #f1f8e9; /* Pastel light green */
  --font-color: #37474f;
  --ally-bg: #e1f5fe; /* Pastel blue */
  --enemy-bg: #ffebee; /* Pastel pink/red */
  --cell-border: rgba(176, 190, 197, 0.4);
  --speed-multiplier: 1;
}

body {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--font-color);
  margin: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 {
  font-size: 26px;
  color: #455a64;
  margin-bottom: 20px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.05);
}

.controls {
  margin-bottom: 25px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: bold;
  color: #455a64;
  background-color: white;
  padding: 10px 15px;
  border-radius: 25px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.speed-control select {
  border: none;
  background-color: transparent;
  font-weight: bold;
  color: #0277bd;
  font-size: 15px;
  cursor: pointer;
  outline: none;
}

button {
  background-color: #81d4fa;
  color: #01579b;
  border: none;
  padding: 12px 25px;
  font-size: 16px;
  font-weight: bold;
  border-radius: 25px;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: all 0.2s ease;
}

button:hover {
  background-color: #4fc3f7;
  transform: translateY(-2px);
}

button:disabled {
  background-color: #cfd8dc;
  color: #90a4ae;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.vs-text {
  font-size: 20px;
  font-weight: bold;
  color: #90a4ae;
  align-self: center;
  margin: 0 10px;
}

.game-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 30px;
}

.board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.team-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 8px;
}
.team-ally .team-title { color: #0277bd; }
.team-enemy .team-title { color: #c62828; }

.board-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 110px);
  grid-template-rows: repeat(3, 140px);
  gap: 8px;
  padding: 15px;
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.team-ally .board { background-color: var(--ally-bg); border: 2px solid #b3e5fc; }
.team-enemy .board { background-color: var(--enemy-bg); border: 2px solid #ffcdd2; }

.row-labels {
  display: grid;
  grid-template-columns: repeat(3, 110px);
  gap: 8px;
  padding: 5px 15px;
  font-size: 14px;
  font-weight: bold;
  color: #607d8b;
  text-align: center;
}

.cell {
  border-radius: 8px;
  border: 2px dashed var(--cell-border);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(255,255,255,0.4);
}

.card {
  width: 100px;
  height: 130px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 5px;
  box-sizing: border-box;
  font-size: 12px;
  position: absolute;
  transition: transform calc(0.2s / var(--speed-multiplier));
  animation: popIn calc(0.3s / var(--speed-multiplier)) cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.card.dead {
  opacity: 0.4;
  filter: grayscale(100%);
  transform: scale(0.95);
}

.card.rarity-sr {
  background-color: #fff9c4; /* Light yellow / gold */
  border: 2px solid #fbc02d;
  box-shadow: 0 4px 12px rgba(251, 192, 45, 0.3);
}

.team-ally .card.acting {
  transform: translate(var(--leap-distance, 30px), var(--leap-distance-y, -5px)) scale(1.05);
  box-shadow: 0 0 0 4px #ffeb3b, 0 0 15px rgba(255, 235, 59, 1);
  z-index: 100; /* Higher z-index when leaping */
}
.team-enemy .card.acting {
  transform: translate(calc(var(--leap-distance, 30px) * -1), var(--leap-distance-y, -5px)) scale(1.05);
  box-shadow: 0 0 0 4px #ffeb3b, 0 0 15px rgba(255, 235, 59, 1);
  z-index: 100;
}

.team-ally .card.acting-ability {
  transform: translate(var(--leap-distance, 50px), var(--leap-distance-y, -5px)) scale(1.15);
  box-shadow: 0 0 0 4px #ff9800, 0 0 25px rgba(255, 152, 0, 1);
  z-index: 100;
}
.team-enemy .card.acting-ability {
  transform: translate(calc(var(--leap-distance, 50px) * -1), var(--leap-distance-y, -5px)) scale(1.15);
  box-shadow: 0 0 0 4px #ff9800, 0 0 25px rgba(255, 152, 0, 1);
  z-index: 100;
}

.team-ally .card.taking-damage {
  background-color: #ffcdd2;
  box-shadow: 0 0 0 3px #f44336, 0 0 15px rgba(244, 67, 54, 0.8);
  transform: translateX(-10px) scale(0.95);
}
.team-enemy .card.taking-damage {
  background-color: #ffcdd2;
  box-shadow: 0 0 0 3px #f44336, 0 0 15px rgba(244, 67, 54, 0.8);
  transform: translateX(10px) scale(0.95);
}

.target-area-glow {
  background-color: rgba(255, 87, 34, 0.4) !important;
  box-shadow: inset 0 0 30px rgba(255, 87, 34, 0.8), 0 0 15px rgba(255, 87, 34, 0.5);
  transition: all calc(0.15s / var(--speed-multiplier));
}
.target-area-heal {
  background-color: rgba(76, 175, 80, 0.4) !important;
  box-shadow: inset 0 0 30px rgba(76, 175, 80, 0.8), 0 0 15px rgba(76, 175, 80, 0.5);
  transition: all calc(0.15s / var(--speed-multiplier));
}

/* Pre-attack Range Highlights */
.range-highlight-pre {
  animation: rangeFlash calc(0.6s / var(--speed-multiplier)) ease-in-out infinite alternate;
  z-index: 5;
}
.range-highlight-heal-pre {
  animation: rangeHealFlash calc(0.6s / var(--speed-multiplier)) ease-in-out infinite alternate;
  z-index: 5;
}

@keyframes rangeFlash {
  0% { background-color: rgba(255, 152, 0, 0); box-shadow: inset 0 0 0px rgba(255, 152, 0, 0); }
  100% { background-color: rgba(255, 152, 0, 0.25); box-shadow: inset 0 0 25px rgba(255, 152, 0, 0.5); }
}
@keyframes rangeHealFlash {
  0% { background-color: rgba(76, 175, 80, 0); box-shadow: inset 0 0 0px rgba(76, 175, 80, 0); }
  100% { background-color: rgba(76, 175, 80, 0.25); box-shadow: inset 0 0 25px rgba(76, 175, 80, 0.5); }
}

.card.healing {
  background-color: #c8e6c9;
  box-shadow: 0 0 0 3px #4caf50, 0 0 15px rgba(76, 175, 80, 0.8);
  transform: scale(1.05);
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.card-emoji { font-size: 32px; line-height: 1.2; }
.card-name { font-weight: bold; margin-bottom: 6px; font-size: 13px; text-align: center; }

.card-stats {
  width: 100%;
  background-color: #f5f5f5;
  border-radius: 6px;
  padding: 4px;
  font-size: 11px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  box-sizing: border-box;
}

.hp-bar-container {
  grid-column: span 2;
  height: 5px;
  background-color: #e0e0e0;
  border-radius: 3px;
  margin-top: 2px;
  overflow: hidden;
}

.hp-bar {
  height: 100%;
  background-color: #66bb6a;
  transition: width calc(0.3s / var(--speed-multiplier));
}

.val { font-weight: bold; color: #263238; }

.damage-popup {
  position: absolute;
  top: 10%; left: 50%;
  transform: translateX(-50%);
  color: #ff4444; font-weight: bold; font-size: 24px;
  pointer-events: none;
  animation: floatUp calc(1.5s / var(--speed-multiplier)) ease-out forwards;
  z-index: 100;
  text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 0 3px 6px rgba(0,0,0,0.3);
}
.damage-popup.heal { color: #4caf50; }
.damage-popup.buff { color: #1e88e5; font-size: 20px; }

@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -50px); }
}

.log-panel {
  width: 800px;
  max-width: 90%;
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  height: 250px;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
}

.log-entry {
  margin-bottom: 8px;
  line-height: 1.5;
  font-size: 15px;
  border-bottom: 1px dashed #eceff1;
  padding-bottom: 8px;
  animation: fadeIn calc(0.3s / var(--speed-multiplier));
}
.log-entry:last-child { border-bottom: none; }

@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(5px); }
  100% { opacity: 1; transform: translateY(0); }
}

.t-ally { color: #1565c0; font-weight: bold; }
.t-enemy { color: #c62828; font-weight: bold; }
.t-row { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 12px; margin-right: 5px; background: #eceff1; color: #546e7a; }
.stat-up { color: #2196f3; font-weight: bold; }
.stat-down { color: #f44336; font-weight: bold; }

/* ===== 状態異常バッジ ===== */
.status-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  margin-top: 2px;
}
.status-badge {
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  color: white;
  line-height: 1.4;
}
.status-badge.stun       { background: #7b1fa2; }
.status-badge.skill_seal { background: #1565c0; }
.status-badge.action_down{ background: #e65100; }
.status-badge.buff_at    { background: #d32f2f; }
.status-badge.buff_ag    { background: #1976d2; }
.status-badge.shield     { background: #fbc02d; color: #333; }

.shield-container {
  display: flex;
  justify-content: center;
  gap: 1px;
  margin-top: 2px;
  font-size: 14px;
}

/* ===== 属性カラー ===== */
.attr-red    { color: #f44336; }
.attr-blue   { color: #2196f3; }
.attr-green  { color: #4caf50; }
.attr-purple { color: #9c27b0; }
.attr-white  { color: #9e9e9e; }

/* Sudden Death Global Flash */
#flash-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: white;
  opacity: 0;
  pointer-events: none;
  z-index: 2000;
}
.flash-anim {
  animation: flashEffect calc(0.3s / var(--speed-multiplier)) ease-out;
}
@keyframes flashEffect {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

/* Lightning Bolt */
.lightning-bolt {
  position: absolute;
  top: -150px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 150px;
  background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(135,206,250,0.8) 50%, rgba(224,255,255,1) 100%);
  border-radius: 10px;
  filter: drop-shadow(0 0 10px #00bfff) drop-shadow(0 0 20px #87cefa);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  animation: strike calc(0.5s / var(--speed-multiplier)) ease-in forwards;
}
@keyframes strike {
  0% { top: -200px; opacity: 1; height: 100px; }
  50% { top: 0px; opacity: 1; height: 150px; }
  100% { top: 20px; opacity: 0; height: 50px; }
}

/* Phase Animation */
.phase-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 48px;
  font-weight: bold;
  padding: 20px 60px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  letter-spacing: 5px;
  text-transform: uppercase;
}

.phase-popup.show {
  animation: phaseAnim calc(1.2s / var(--speed-multiplier)) cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes phaseAnim {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1); opacity: 1; filter: blur(0px); }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; filter: blur(5px); }
}

/* Simulation Results Popup Panel */
.sim-panel-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.sim-panel {
  background-color: #fff3e0;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  border: 3px solid #ffb74d;
  text-align: center;
  min-width: 400px;
}
.sim-panel h2 { margin-top: 0; color: #e65100; font-size: 24px; border-bottom: 2px solid #ffcc80; padding-bottom: 10px; margin-bottom: 20px;}
.sim-stats { display: flex; flex-direction: column; gap: 15px; font-size: 18px; font-weight: bold; color: #424242; text-align: left; margin-bottom: 20px;}
.sim-val { font-size: 20px; color: #d84315; float: right;}

.btn-close-sim {
  padding: 10px 30px;
  font-size: 18px;
  background: linear-gradient(to bottom, #78909c, #546e7a);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.btn-close-sim:hover { background: linear-gradient(to bottom, #90a4ae, #607d8b); }

/* Ability */
.ability-count {
  color: #ff9800;
  font-weight: bold;
  font-size: 11px;
  display: inline-block;
}

.team-ally .card.acting-ability {
  transform: translate(40px, -5px) scale(1.15);
  box-shadow: 0 0 0 4px #ff9800, 0 0 25px rgba(255, 152, 0, 1);
  z-index: 20;
}
.team-enemy .card.acting-ability {
  transform: translate(-40px, -5px) scale(1.15);
  box-shadow: 0 0 0 4px #ff9800, 0 0 25px rgba(255, 152, 0, 1);
  z-index: 20;
}

/* Ability Cut-in */
.ability-cutin {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1) skewX(-15deg);
  width: 120%;
  height: 120px;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 152, 0, 0.9) 20%, rgba(255, 152, 0, 0.9) 80%, transparent 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: bold;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  text-shadow: 2px 2px 5px rgba(0,0,0,0.8);
  box-shadow: 0 0 30px rgba(255, 152, 0, 0.5);
  animation: cutinAnim calc(1.5s / var(--speed-multiplier)) cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
.ability-cutin .inner-name {
  transform: skewX(15deg); /* Revert skew for text */
  display: flex;
  align-items: center;
  gap: 15px;
}
.ability-cutin .cutin-emoji {
  font-size: 60px;
}
@keyframes cutinAnim {
  0% { transform: translate(100%, -50%) scale(1) skewX(-15deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1) skewX(-15deg); opacity: 1; }
  85% { transform: translate(-60%, -50%) scale(1) skewX(-15deg); opacity: 1; }
  100% { transform: translate(-200%, -50%) scale(1) skewX(-15deg); opacity: 0; }
}

/* --- Debug Modal --- */
.debug-modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3000;
  backdrop-filter: blur(4px);
}
.debug-modal {
  background: #2c3e50;
  color: #ecf0f1;
  padding: 20px;
  border-radius: 12px;
  min-width: 300px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.debug-field {
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.debug-field label { font-weight: bold; }
.debug-field input {
  background: #34495e;
  border: 1px solid #7f8c8d;
  color: #fff;
  padding: 5px;
  border-radius: 4px;
  width: 80px;
}
.debug-actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.debug-actions button {
  flex: 1;
  min-width: 80px;
  padding: 8px;
  cursor: pointer;
  border: none;
  border-radius: 4px;
  background: #3498db;
  color: white;
  transition: opacity 0.2s;
}
.debug-actions button:hover { opacity: 0.8; }

/* --- Stats Panel --- */
.stats-grid {
  display: flex;
  justify-content: space-around;
  margin-top: 20px;
}
.team-stat {
  background: rgba(255,255,255,0.05);
  padding: 10px;
  border-radius: 8px;
  width: 45%;
}
.stat-row {
  margin: 5px 0;
  font-size: 0.9em;
}

/* Master Data / Card Factory */
.master-panel, .factory-panel {
  max-width: 500px !important;
  border-radius: 20px !important;
  background: white !important;
  box-shadow: 0 15px 35px rgba(0,0,0,0.2) !important;
  padding: 30px !important;
}

.room-list {
  background: #f5f5f5;
  border-radius: 12px;
  padding: 10px;
  margin: 15px 0;
  max-height: 200px;
  overflow-y: auto;
}

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

.room-list li {
  padding: 10px 15px;
  margin-bottom: 5px;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.room-list li:hover {
  background: #e1f5fe;
  border-color: #81d4fa;
}

.room-list li.active {
  background: #fff9c4;
  border-color: #fbc02d;
  font-weight: bold;
}

.btn-del {
  padding: 4px 8px;
  background: #ffcdd2;
  color: #c62828;
  font-size: 12px;
  border-radius: 4px;
  box-shadow: none;
}

.master-actions, .factory-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.master-actions input, .factory-panel input, .factory-panel select {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.btn-save {
    background-color: #4caf50 !important;
    color: white !important;
}

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 15px;
}

.trait-selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  background: #f9f9f9;
  padding: 10px;
  border-radius: 8px;
  margin: 10px 0;
  max-height: 120px;
  overflow-y: auto;
}

.trait-cb {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.skill-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

.skill-edit-row select {
  flex: 1;
  padding: 5px;
}

.skill-edit-row input {
  padding: 5px;
}
