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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
}

header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 2rem;
  font-weight: 600;
  margin: 0;
  word-wrap: break-word;
}

.back-link {
  color: white;
  text-decoration: none;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  display: inline-block;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.8;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
  box-sizing: border-box;
}

/* Search Container */
.search-container {
  position: relative;
  margin-bottom: 2rem;
  width: 100%;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.search-input {
  width: 100%;
  padding: 0.75rem 3rem 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.search-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.search-input::placeholder {
  color: #999;
}

.clear-search {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.clear-search:hover {
  color: #333;
}

.clear-search:focus {
  outline: none;
  color: #667eea;
}

.no-results-message {
  text-align: center;
  padding: 3rem 2rem;
  color: #666;
}

.no-results-message p {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.no-results-hint {
  font-size: 0.9rem;
  color: #999;
  font-style: italic;
}

/* Loading and Error States */
.loading, .error {
  text-align: center;
  padding: 3rem;
  font-size: 1.2rem;
}

.error {
  color: #d32f2f;
  background-color: #ffebee;
  border: 1px solid #ef5350;
  border-radius: 4px;
}

/* Content Container */
.content {
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

/* AgentRank Sections */
.agent-rank-section {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.rank-heading {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  color: #667eea;
  border-bottom: 2px solid #667eea;
  padding-bottom: 0.5rem;
}

.card-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
  width: 100%;
}

.empty-message {
  color: #999;
  font-style: italic;
  padding: 2rem;
  text-align: center;
}

/* Digimon Cards */
.digimon-card {
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.digimon-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-color: #667eea;
}

.card-icon {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

.card-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.card-number {
  font-size: 0.9rem;
  color: #666;
  margin: 0;
}

.card-generation {
  font-size: 0.85rem;
  margin: 0.5rem 0 0 0;
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  display: inline-block;
  font-weight: 600;
  text-align: center;
}

/* Apply generation styles to card generations too */
.card-generation.generation-in-training {
  background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
  color: #616161;
  border: 1px solid #9e9e9e;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.card-generation.generation-rookie {
  background: linear-gradient(135deg, #c8e6c9 0%, #a5d6a7 100%);
  color: #2e7d32;
  border: 1px solid #81c784;
  box-shadow: 0 2px 4px rgba(46,125,50,0.2);
}

.card-generation.generation-champion {
  background: linear-gradient(135deg, #90caf9 0%, #64b5f6 100%);
  color: #1565c0;
  border: 1px solid #42a5f5;
  box-shadow: 0 2px 6px rgba(21,101,192,0.3);
}

.card-generation.generation-ultimate {
  background: linear-gradient(135deg, #ce93d8 0%, #ba68c8 100%);
  color: #6a1b9a;
  border: 1px solid #ab47bc;
  box-shadow: 0 3px 8px rgba(106,27,154,0.4);
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

.card-generation.generation-mega {
  background: linear-gradient(135deg, #ffb74d 0%, #ffa726 100%);
  color: #e65100;
  border: 2px solid #ff9800;
  box-shadow: 0 4px 12px rgba(255,152,0,0.5), 0 0 8px rgba(255,152,0,0.3);
  text-shadow: 0 1px 3px rgba(255,255,255,0.5);
  font-weight: 700;
  animation: mega-glow 2s ease-in-out infinite alternate;
}

.card-generation.generation-unknown {
  background: #f5f5f5;
  color: #757575;
  border: 1px solid #bdbdbd;
}

/* Digimon Detail Page */
.digimon-content {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.digimon-basic-info {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.digimon-info-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.digimon-info-top {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.digimon-info-left {
  flex: 1;
  min-width: 0;
}

.digimon-info-right {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.digimon-info-right h3,
.digimon-description-container h3 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  color: #667eea;
}

.digimon-info-bottom {
  width: 100%;
}

.digimon-info-bottom h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: #667eea;
}

.digimon-description-container {
  margin-top: 1.5rem;
}

.digimon-description-container h3 {
  margin-bottom: 0.75rem;
}

.digimon-header {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.digimon-icon-large {
  width: 150px;
  height: 150px;
  object-fit: contain;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.5rem;
  background: #fafafa;
}

.digimon-header-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.digimon-number {
  font-size: 1.2rem;
  font-weight: 600;
  color: #667eea;
}

.digimon-agent-rank {
  font-size: 1.1rem;
  font-weight: 600;
  color: #764ba2;
  margin: 0.5rem 0;
  text-align: center;
}

.digimon-generation {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  display: inline-block;
  margin-top: 0.25rem;
  text-align: center;
}

/* Generation styling based on power level */
.generation-in-training {
  background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
  color: #616161;
  border: 1px solid #9e9e9e;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.generation-rookie {
  background: linear-gradient(135deg, #c8e6c9 0%, #a5d6a7 100%);
  color: #2e7d32;
  border: 1px solid #81c784;
  box-shadow: 0 2px 4px rgba(46,125,50,0.2);
}

.generation-champion {
  background: linear-gradient(135deg, #90caf9 0%, #64b5f6 100%);
  color: #1565c0;
  border: 1px solid #42a5f5;
  box-shadow: 0 2px 6px rgba(21,101,192,0.3);
}

.generation-ultimate {
  background: linear-gradient(135deg, #ce93d8 0%, #ba68c8 100%);
  color: #6a1b9a;
  border: 1px solid #ab47bc;
  box-shadow: 0 3px 8px rgba(106,27,154,0.4);
  text-shadow: 0 1px 2px rgba(255,255,255,0.3);
}

.generation-mega {
  background: linear-gradient(135deg, #ffb74d 0%, #ffa726 100%);
  color: #e65100;
  border: 2px solid #ff9800;
  box-shadow: 0 4px 12px rgba(255,152,0,0.5), 0 0 8px rgba(255,152,0,0.3);
  text-shadow: 0 1px 3px rgba(255,255,255,0.5);
  font-weight: 700;
  animation: mega-glow 2s ease-in-out infinite alternate;
}

@keyframes mega-glow {
  from {
    box-shadow: 0 4px 12px rgba(255,152,0,0.5), 0 0 8px rgba(255,152,0,0.3);
  }
  to {
    box-shadow: 0 4px 16px rgba(255,152,0,0.7), 0 0 12px rgba(255,152,0,0.5);
  }
}

.generation-unknown {
  background: #f5f5f5;
  color: #757575;
  border: 1px solid #bdbdbd;
}

.digimon-attribute {
  font-size: 1rem;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.digimon-attribute-with-icon {
  justify-content: center;
}

.digimon-personality {
  font-size: 1rem;
  color: #666;
  text-align: center;
}

.inline-icon {
  width: 32px;
  height: 32px;
  vertical-align: middle;
  margin-right: 0.5rem;
  background-color: #9fa8da;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid #7986cb;
}

.digimon-description {
  font-size: 1rem;
  line-height: 1.7;
  color: #555;
  text-align: justify;
  margin: 0;
  padding: 0;
}

.evolution-graph-container {
  width: 100%;
  height: 600px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: #fafafa;
}


/* Skills Table */
.skills-table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.skills-table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0;
  table-layout: fixed;
  box-sizing: border-box;
}

/* Skills Cards for Mobile */
.skills-cards {
  display: none;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.skill-card {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.skill-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.skill-card-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.skill-card-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.skill-card-description {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.5;
  margin: 0 0 0.75rem 0;
}

.skill-card-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e0e0e0;
}

.skill-card-stat {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}

.stat-label {
  font-weight: 600;
  color: #667eea;
  margin-bottom: 0.25rem;
}

.stat-value {
  color: #333;
}

.no-skills-message {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 2rem;
}

.skills-table thead {
  background: #667eea;
  color: white;
}

.skills-table th,
.skills-table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border: 1px solid #e0e0e0;
  vertical-align: top;
}

.skills-table th {
  font-weight: 600;
  white-space: nowrap;
}

.skills-table td {
  font-size: 0.85rem;
}

.skills-table tbody tr:nth-child(even) {
  background: #f9f9f9;
}

.skills-table tbody tr:hover {
  background: #f0f0f0;
}

.skill-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* Description column styling */
.skills-table td:nth-child(3) {
  max-width: 300px;
  word-wrap: break-word;
  line-height: 1.4;
}

/* Node Tooltip */
.node-tooltip {
  display: none;
  position: fixed;
  z-index: 10000;
  background-color: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  min-width: 250px;
  max-width: 350px;
  border: 2px solid #667eea;
  pointer-events: auto;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tooltip-close {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  color: #aaa;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tooltip-close:hover,
.tooltip-close:focus {
  color: #000;
}

.node-tooltip h3 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  margin-right: 1.5rem;
  color: #667eea;
  padding-top: 0.5rem;
}

.conditions-list {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}

.conditions-list li {
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 0.9rem;
}

.conditions-list li strong {
  color: #667eea;
}

.tooltip-button {
  background: #667eea;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 1rem;
  width: 100%;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px; /* Touch target size */
}

.tooltip-button:hover {
  background: #5568d3;
}

/* Responsive Design */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }
  
  header h1 {
    font-size: 1.5rem;
  }
  
  main {
    padding: 1rem;
  }
  
  .search-container {
    margin-bottom: 1.5rem;
  }
  
  .search-input {
    padding: 0.65rem 2.5rem 0.65rem 0.75rem;
    font-size: 0.95rem;
  }
  
  .clear-search {
    right: 0.5rem;
    font-size: 1.3rem;
    padding: 0.2rem 0.4rem;
  }
  
  .no-results-message {
    padding: 2rem 1rem;
  }
  
  .no-results-message p {
    font-size: 1rem;
  }
  
  .no-results-hint {
    font-size: 0.85rem;
  }
  
  .agent-rank-section {
    padding: 1.5rem;
  }
  
  .rank-heading {
    font-size: 1.5rem;
  }
  
  .card-container {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
  }
  
  .digimon-card {
    padding: 0.75rem;
  }
  
  .card-icon {
    width: 60px;
    height: 60px;
  }
  
  .card-name {
    font-size: 1rem;
  }
  
  .digimon-basic-info {
    padding: 1.5rem;
  }
  
  .digimon-info-container {
    gap: 1.5rem;
  }
  
  .digimon-info-top {
    flex-direction: column;
    gap: 1.5rem;
  }
  
  .digimon-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }
  
  .digimon-header-text {
    align-items: center;
    text-align: center;
  }
  
  .digimon-icon-large {
    width: 120px;
    height: 120px;
  }
  
  .digimon-description-container {
    margin-top: 1rem;
  }
  
  .digimon-description-container h3,
  .digimon-info-right h3 {
    font-size: 1.2rem;
  }
  
  .skills-table-wrapper,
  .skills-table-wrapper table {
    display: none !important;
    visibility: hidden !important;
  }
  
  .skills-cards {
    display: flex !important;
    visibility: visible !important;
  }
  
  .evolution-graph-container {
    height: 400px;
  }
  
  .digimon-info-bottom h2 {
    font-size: 1.3rem;
  }
  
  .node-tooltip {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 100vw !important;
    padding: 1rem;
    left: 0 !important;
    right: 0 !important;
    top: 20px !important;
    transform: none !important;
    border-radius: 8px 8px 0 0;
    box-sizing: border-box;
  }
  
  .tooltip-close {
    font-size: 28px;
    right: 0.5rem;
    top: 0.5rem;
  }
}

@media (max-width: 480px) {
  header {
    padding: 0.75rem 1rem;
  }
  
  header h1 {
    font-size: 1.25rem;
  }
  
  .back-link {
    font-size: 0.9rem;
  }
  
  main {
    padding: 0.75rem;
  }
  
  .agent-rank-section {
    padding: 1rem;
  }
  
  .rank-heading {
    font-size: 1.3rem;
    padding-bottom: 0.5rem;
  }
  
  .card-container {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
  }
  
  .digimon-card {
    padding: 0.5rem;
  }
  
  .card-icon {
    width: 50px;
    height: 50px;
  }
  
  .card-name {
    font-size: 0.9rem;
  }
  
  .card-number {
    font-size: 0.8rem;
  }
  
  .card-generation {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
  }
  
  .digimon-basic-info {
    padding: 1rem;
  }
  
  .digimon-info-container {
    gap: 1rem;
  }
  
  .digimon-info-top {
    gap: 1rem;
  }
  
  .digimon-icon-large {
    width: 100px;
    height: 100px;
  }
  
  .digimon-number {
    font-size: 1rem;
  }
  
  .digimon-generation {
    font-size: 0.9rem;
    padding: 0.2rem 0.6rem;
  }
  
  .digimon-description-container h3,
  .digimon-info-right h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }
  
  .digimon-description {
    font-size: 0.9rem;
    line-height: 1.6;
  }
  
  .skill-card {
    padding: 0.75rem;
  }
  
  .skill-card-icon {
    width: 35px;
    height: 35px;
  }
  
  .skill-card-name {
    font-size: 1rem;
  }
  
  .skill-card-description {
    font-size: 0.85rem;
  }
  
  .skill-card-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  
  .skill-card-stat {
    font-size: 0.8rem;
  }
  
  .evolution-graph-container {
    height: 300px;
  }
  
  .digimon-info-bottom h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }
  
  .node-tooltip {
    min-width: 180px;
    max-width: 85%;
    padding: 0.75rem;
    font-size: 0.9rem;
  }
  
  .node-tooltip h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }
  
  .tooltip-button {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }
  
  .conditions-list li {
    font-size: 0.85rem;
    padding: 0.4rem;
  }
}

