/* Periodic Table Specific Styling for Himiq School */

/* Element Styling */
.element .atomic-number {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: bold;
    line-height: 1;
    z-index: 1; /* Ensure it appears above other elements */
}

.element .symbol {
    font-family: var(--font-primary);
    font-size: 1.4rem; /* Further reduced for better fit */
    font-weight: 700;
    margin: 12px 0 6px; /* Adjusted margins for better vertical centering */
    color: var(--text-primary);
    letter-spacing: -0.5px;
    max-width: 90%; /* Prevent overflow */
    text-align: center;
}

.element.science .symbol {
    color: var(--science);
}

.element.humanities .symbol {
    color: var(--humanities);
}

.element.sports .symbol {
    color: var(--sports);
}

.element.technology .symbol {
    color: var(--technology);
}

.element.values .symbol {
    color: var(--values);
}

.element.events .symbol {
    color: var(--events);
}

.element.admin .symbol {
    color: var(--admin);
}

.element .name {
    font-size: 0.7rem;
    color: var(--text-primary); /* Changed to primary for better contrast */
    max-width: 95%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: auto;
    padding: 0 3px; /* Increased side padding */
    line-height: 1.2; /* Improve text spacing */
    text-align: center;
    display: block; /* Ensure proper element sizing */
    width: 100%; /* Use full width */
    box-sizing: border-box; /* Include padding in width calculation */
}

/* Group and Period Labels */
.group-label, .period-label {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-primary);
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.series-label {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}

/* Element hover effects */
.element:hover {
    /* No transform to prevent layout shifts */
    z-index: 10;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
    border-width: 2px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); /* More fluid animation */
    /* Ensure hover effect doesn't cause overflow */
    overflow: visible;
}

.element.science:hover {
    box-shadow: 0 0 8px var(--science);
    border-color: var(--science);
}

.element.humanities:hover {
    box-shadow: 0 0 8px var(--humanities);
    border-color: var(--humanities);
}

.element.sports:hover {
    box-shadow: 0 0 8px var(--sports);
    border-color: var(--sports);
}

.element.technology:hover {
    box-shadow: 0 0 8px var(--technology);
    border-color: var(--technology);
}

.element.values:hover {
    box-shadow: 0 0 8px var(--values);
    border-color: var(--values);
}

.element.events:hover {
    box-shadow: 0 0 8px var(--events);
    border-color: var(--events);
}

.element.admin:hover {
    box-shadow: 0 0 8px var(--admin);
    border-color: var(--admin);
}

/* Category Labels */
.category-label {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    font-weight: bold;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.category-label:hover {
    opacity: 1;
}

.category-label.science {
    background-color: var(--science);
}

.category-label.humanities {
    background-color: var(--humanities);
}

.category-label.sports {
    background-color: var(--sports);
}

.category-label.technology {
    background-color: var(--technology);
}

.category-label.values {
    background-color: var(--values);
}

.category-label.events {
    background-color: var(--events);
}

.category-label.admin {
    background-color: var(--admin);
}

/* Element content container to prevent overflow */
.element-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
    overflow: visible; /* Allow content to be visible when needed */
    padding: 2px; /* Small padding to prevent edge clipping */
    box-sizing: border-box;
}

/* Enhanced Element Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 1000;  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  overflow-y: auto;
}

.modal-content {
  position: relative;
  background-color: var(--card-bg);
  margin: 5vh auto;
  padding: 0;
  width: 90%;
  max-width: 700px;
  border-radius: 12px;
  box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.close {
  position: absolute;
  top: 15px;
  right: 15px;
  color: white;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10;
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

.close:hover {
  background-color: rgba(255, 0, 0, 0.5);
  transform: rotate(90deg);
}

.element-header {
  padding: 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 20px;
}

.element-header.science {
  background: linear-gradient(135deg, var(--science), var(--science-dark, #d63031));
}

.element-header.humanities {
  background: linear-gradient(135deg, var(--humanities), var(--humanities-dark, #1e3799));
}

.element-header.sports {
  background: linear-gradient(135deg, var(--sports), var(--sports-dark, #009432));
}

.element-header.technology {
  background: linear-gradient(135deg, var(--technology), var(--technology-dark, #0099cc));
}

.element-header.values {
  background: linear-gradient(135deg, var(--values), var(--values-dark, #e58e26));
}

.element-header.events {
  background: linear-gradient(135deg, var(--events), var(--events-dark, #8854d0));
}

.element-header.admin {
  background: linear-gradient(135deg, var(--admin), var(--admin-dark, #576574));
}

.element-symbol {
  font-family: var(--font-primary);
  font-size: 48px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.2);
  width: 80px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.element-info {
  flex: 1;
}

.element-info h2 {
  font-family: var(--font-primary);
  font-size: 24px;
  margin: 0 0 5px 0;
}

.element-number {
  font-size: 16px;
  opacity: 0.8;
}

.element-details {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.info-box {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 15px;
  position: relative;
}

.info-box h3 {
  font-size: 18px;
  margin-bottom: 10px;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.facts-box ul {
  padding-left: 20px;
  list-style-type: none;
}

.facts-box ul li {
  position: relative;
  padding: 4px 0;
}

.facts-box ul li:before {
  content: '✓';
  color: var(--accent-primary);
  position: absolute;
  left: -20px;
}

.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.schedule-day {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  padding: 8px;
  font-size: 14px;
}

.schedule-day strong {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-primary);
}

.modal-actions {
  padding: 20px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent-primary);
  border: none;
  border-radius: 20px;
  color: white;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.share-btn:hover {
  background: var(--accent-secondary);
  transform: translateY(-2px);
}

/* Mobile-First Responsive Design for 9-Row Periodic Table */

/* Base styles for periodic table grid */
.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, minmax(60px, 1fr));
    grid-template-rows: repeat(9, auto);
    gap: 4px;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    justify-content: center;
    align-content: start;
}

/* Enhanced Mobile Breakpoints */

/* Large tablets and small desktops (1200px and below) */
@media (max-width: 1200px) {
    .periodic-table {
        grid-template-columns: repeat(18, minmax(55px, 1fr));
        gap: 3px;
        padding: 1rem;
    }
    
    .element {
        width: 55px;
        height: 55px;
        padding: 4px 3px;
    }
    
    .element .symbol {
        font-size: 1.3rem;
        margin: 10px 0 4px;
    }
    
    .element .name {
        font-size: 0.65rem;
    }
    
    .element .atomic-number {
        font-size: 0.65rem;
        top: 3px;
        left: 4px;
    }
}

/* Medium tablets (1024px and below) */
@media (max-width: 1024px) {
    .periodic-table {
        grid-template-columns: repeat(16, minmax(50px, 1fr));
        gap: 3px;
        padding: 1rem;
    }
    
    .element {
        width: 50px;
        height: 50px;
        padding: 3px 2px;
    }
    
    .element .symbol {
        font-size: 1.2rem;
        margin: 8px 0 4px;
    }
    
    .element .name {
        font-size: 0.6rem;
    }
}

/* Small tablets and large phones (768px and below) */
@media (max-width: 768px) {
    .periodic-table {
        grid-template-columns: repeat(12, minmax(45px, 1fr));
        gap: 3px;
        padding: 0.8rem;
    }
    
    .element {
        width: 45px;
        height: 45px;
        padding: 3px 2px;
    }
    
    .element .symbol {
        font-size: 1.1rem;
        margin: 6px 0 3px;
    }
    
    .element .name {
        font-size: 0.55rem;
        line-height: 1.1;
    }
    
    .element .atomic-number {
        font-size: 0.6rem;
        top: 2px;
        left: 3px;
    }
}

/* Medium phones (600px and below) */
@media (max-width: 600px) {
    .periodic-table {
        grid-template-columns: repeat(10, minmax(40px, 1fr));
        gap: 2px;
        padding: 0.6rem;
    }
    
    .element {
        width: 40px;
        height: 40px;
        padding: 2px 1px;
    }
    
    .element .symbol {
        font-size: 1rem;
        margin: 5px 0 2px;
    }
    
    .element .name {
        font-size: 0.5rem;
        line-height: 1;
    }
    
    .element .atomic-number {
        font-size: 0.55rem;
        top: 2px;
        left: 2px;
    }
}

/* Small phones (480px and below) */
@media (max-width: 480px) {
    .periodic-table {
        grid-template-columns: repeat(8, minmax(38px, 1fr));
        gap: 2px;
        padding: 0.5rem;
    }
    
    .element {
        width: 38px;
        height: 38px;
        padding: 2px 1px;
    }
    
    .element .symbol {
        font-size: 0.95rem;
        margin: 4px 0 2px;
        font-weight: 600;
    }
    
    .element .name {
        font-size: 0.45rem;
        line-height: 1;
    }
    
    .element .atomic-number {
        font-size: 0.5rem;
        top: 1px;
        left: 2px;
    }
    
    /* Simplify hover effects on mobile */
    .element:hover {
        transform: scale(1.02);
    }
}

/* Extra small phones (375px and below) */
@media (max-width: 375px) {
    .periodic-table {
        grid-template-columns: repeat(6, minmax(35px, 1fr));
        gap: 1px;
        padding: 0.4rem;
    }
    
    .element {
        width: 35px;
        height: 35px;
        padding: 1px;
    }
    
    .element .symbol {
        font-size: 0.85rem;
        margin: 3px 0 1px;
        font-weight: 600;
    }
    
    .element .name {
        font-size: 0.4rem;
        line-height: 1;
    }
    
    .element .atomic-number {
        font-size: 0.45rem;
        top: 1px;
        left: 1px;
    }
}

/* Very small phones (320px and below) */
@media (max-width: 320px) {
    .periodic-table {
        grid-template-columns: repeat(5, minmax(32px, 1fr));
        gap: 1px;
        padding: 0.3rem;
    }
    
    .element {
        width: 32px;
        height: 32px;
        padding: 1px;
    }
    
    .element .symbol {
        font-size: 0.8rem;
        margin: 2px 0 1px;
        font-weight: 600;
    }
    
    .element .name {
        font-size: 0.35rem;
        line-height: 1;
    }
    
    .element .atomic-number {
        font-size: 0.4rem;
        top: 1px;
        left: 1px;
    }
    
    /* Disable hover effects on very small screens */
    .element:hover {
        transform: none;
    }
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    /* Improve touch targets */
    .element {
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    /* Better spacing for mobile headers */
    .main-title {
        font-size: 1.8rem;
        margin-bottom: 0.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Mobile-friendly controls */
    .controls {
        flex-direction: column;
        gap: 0.8rem;
        padding: 0.5rem;
    }
    
    /* Improve search on mobile */
    .search-container {
        width: 100%;
        max-width: none;
    }
    
    .search-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 10px 12px;
    }
}

/* Landscape orientation for mobile devices */
@media (max-width: 768px) and (orientation: landscape) {
    .periodic-table {
        grid-template-columns: repeat(14, minmax(40px, 1fr));
        gap: 2px;
        padding: 0.5rem;
    }
    
    .element {
        width: 40px;
        height: 40px;
    }
}
