/* Flex row for expanded card action buttons */
.history-expanded-buttons-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  margin-bottom: 8px;
}

.history-expanded-buttons-row .wikipedia-btn,
.history-expanded-buttons-row .set-time-btn {
  margin-top: 0;
  margin-left: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1em;
  line-height: 1.2;
}

.history-expanded-buttons-row svg {
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
}

/* Apply button row styling to history panel view as well */
.history-expanded-view .history-expanded-buttons-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  margin-bottom: 8px;
}

.history-expanded-view .history-expanded-buttons-row .wikipedia-btn,
.history-expanded-view .history-expanded-buttons-row .set-time-btn {
  margin-top: 0;
  margin-left: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1em;
  line-height: 1.2;
}

.history-expanded-view .history-expanded-buttons-row svg {
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
}
/* History expanded card styling */
/* Extends the base expanded card styles with history-specific theming */

.expanded-card.expanded.history-expanded {
  background: linear-gradient(145deg, #3d2f1f 0%, #2a1810 50%, #1f1207 100%);
  border: clamp(2px, 0.2vw, 4px) solid #8b6914;
  box-shadow: 
    0 clamp(0.7rem, 1.5vw, 2rem) clamp(1.8rem, 3vw, 4rem) rgba(0, 0, 0, 0.8),
    0 0 clamp(1rem, 2vw, 3rem) rgba(139, 105, 20, 0.3);
}

/* Add paper texture to expanded history cards */
.expanded-card.expanded.history-expanded::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.01) 1px, transparent 1px),
    radial-gradient(circle at 40% 40%, rgba(139, 105, 20, 0.03) 2px, transparent 2px);
  pointer-events: none;
  z-index: 1;
}

/* Add aged paper effect to expanded cards */
.expanded-card.expanded.history-expanded::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    rgba(139, 105, 20, 0.03) 0%,
    transparent 25%,
    transparent 75%,
    rgba(139, 105, 20, 0.03) 100%
  );
  pointer-events: none;
  border-radius: var(--border-radius);
  z-index: 1;
}

.expanded-card.expanded.history-expanded .left-section {
  background: rgba(0, 0, 0, 0.2);
  border-right: clamp(1px, 0.1vw, 2px) solid rgba(139, 105, 20, 0.4);
  position: relative;
  z-index: 2;
}

.expanded-card.expanded.history-expanded .right-section {
  position: relative;
  z-index: 2;
}

.expanded-card.expanded.history-expanded .meta-container span {
  border-bottom: clamp(1px, 0.05vw, 2px) solid rgba(139, 105, 20, 0.3);
  color: #d4c4a1;
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.expanded-card.expanded.history-expanded .meta-container span strong {
  color: #8b6914;
  font-weight: 600;
}

.expanded-card.expanded.history-expanded h3 {
  color: #f4e4c1;
  text-shadow: 0 0 clamp(0.3rem, 1vw, 0.8rem) rgba(139, 105, 20, 0.4);
  font-weight: 600;
}

.expanded-card.expanded.history-expanded .description {
  color: #d4c4a1;
  line-height: 1.6;
}

/* Wikipedia button styling for history cards */
.expanded-card.expanded.history-expanded .wikipedia-btn {
  background: linear-gradient(145deg, #8b6914, #6b5010);
  border: 2px solid #a67c19;
  color: #f4e4c1;
  padding: clamp(0.4rem, 1vw, 0.6rem) clamp(0.8rem, 2vw, 1.2rem);
  border-radius: clamp(0.2rem, 0.4vw, 0.6rem);
  font-size: clamp(0.8rem, 1.4vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
  margin-top: 12px;
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  position: relative;
  z-index: 10;
}

.expanded-card.expanded.history-expanded .wikipedia-btn:hover {
  background: linear-gradient(145deg, #a67c19, #8b6914);
  border-color: #c89a1f;
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.expanded-card.expanded.history-expanded .wikipedia-btn:active {
  transform: translateY(0);
  box-shadow: 
    0 2px 6px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Set Time button styling for history cards */

.expanded-card.expanded.history-expanded .set-time-btn {
  background: linear-gradient(145deg, #3a4e6b, #22304a);
  border: 2px solid #4a6b8b;
  color: #f4e4c1;
  padding: clamp(0.45rem, 1vw, 0.7rem) clamp(1rem, 2vw, 1.4rem);
  border-radius: clamp(0.25rem, 0.5vw, 0.7rem);
  font-size: clamp(0.9rem, 1.4vw, 1.05rem);
  font-family: inherit;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  margin-top: 12px;
  margin-left: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.28), 0 1px 0 rgba(255,255,255,0.08) inset;
  position: relative;
  z-index: 10;
  outline: none;
}

.expanded-card.expanded.history-expanded .set-time-btn:hover {
  background: linear-gradient(145deg, #4a6b8b, #2d3e57);
  border-color: #6b8ba6;
  color: #fffbe8;
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 6px 18px rgba(0,0,0,0.32), 0 1px 0 rgba(255,255,255,0.13) inset;
}

.expanded-card.expanded.history-expanded .set-time-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 6px rgba(0,0,0,0.22), 0 1px 0 rgba(255,255,255,0.08) inset;
}

/* Time Set (success) state for Set Time button */
.expanded-card.expanded.history-expanded .set-time-btn.time-set,
.expanded-card.expanded.history-expanded .set-time-btn[aria-pressed="true"] {
  background: linear-gradient(145deg, #3a8b3a, #1e5f2d);
  border: 2px solid #4ac86b;
  color: #f4ffe4;
  box-shadow: 0 2px 12px rgba(34, 139, 34, 0.25), 0 1px 0 rgba(255,255,255,0.10) inset;
}

.expanded-card.expanded.history-expanded .set-time-btn.time-set:hover,
.expanded-card.expanded.history-expanded .set-time-btn[aria-pressed="true"]:hover {
  background: linear-gradient(145deg, #4ac86b, #3a8b3a);
  border-color: #6bff8b;
  color: #fff;
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 6px 18px rgba(34, 139, 34, 0.32), 0 1px 0 rgba(255,255,255,0.13) inset;
}

.expanded-card.expanded.history-expanded .set-time-btn.time-set:active,
.expanded-card.expanded.history-expanded .set-time-btn[aria-pressed="true"]:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 6px rgba(34,139,34,0.22), 0 1px 0 rgba(255,255,255,0.08) inset;
}

/* Container styling for button containers */
.expanded-card.expanded.history-expanded .set-time-container {
  display: inline-block;
}

/* Image container styling for history expanded cards */
.expanded-card.expanded.history-expanded .image-container.history-image-container {
  border: var(--image-border-width) solid #8b6914;
  box-shadow: 
    0 0 clamp(0.4rem, 0.8vw, 1rem) rgba(139, 105, 20, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  background: linear-gradient(135deg, #2a1810, #1f1207);
}

.expanded-card.expanded.history-expanded .history-image {
  filter: sepia(0.1) contrast(1.1) brightness(0.95);
}

/* Locations section styling for history cards */
.expanded-card.expanded.history-expanded .locations-heading h4 {
  color: #f4e4c1;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.expanded-card.expanded.history-expanded .location-item {
  color: #d4c4a1;
  border-bottom: 1px solid rgba(139, 105, 20, 0.2);
  cursor: pointer;
  transition: color 0.2s ease;
}

.expanded-card.expanded.history-expanded .location-item:hover {
  color: #f4e4c1;
  background: rgba(139, 105, 20, 0.1);
}

.expanded-card.expanded.history-expanded .highlight-locations-btn {
  background: linear-gradient(145deg, #8b6914, #6b5010);
  border: 1px solid #a67c19;
  color: #f4e4c1;
  font-weight: 500;
}

.expanded-card.expanded.history-expanded .highlight-locations-btn:hover {
  background: linear-gradient(145deg, #a67c19, #8b6914);
  border-color: #c89a1f;
  color: #ffffff;
}

/* Close button styling for history cards */
.expanded-card.expanded.history-expanded .close-btn {
  color: #f4e4c1;
  background: rgba(139, 105, 20, 0.2);
  border: 1px solid rgba(139, 105, 20, 0.4);
}

.expanded-card.expanded.history-expanded .close-btn:hover {
  background: rgba(139, 105, 20, 0.4);
  color: #ffffff;
}

/* History Panel Expanded Item View Styles */
.history-expanded-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #3d2f1f 0%, #2a1810 50%, #1f1207 100%);
  border-radius: 8px;
  overflow: hidden;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s cubic-bezier(0.2, 1, 0.3, 1);
  z-index: 1000;
}

.history-expanded-view.active {
  opacity: 1;
  transform: translateX(0);
}

.history-expanded-view.closing {
  opacity: 0;
  transform: translateX(100%);
}

/* Add paper texture to expanded history view */
.history-expanded-view::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.01) 1px, transparent 1px),
    radial-gradient(circle at 40% 40%, rgba(139, 105, 20, 0.03) 2px, transparent 2px);
  pointer-events: none;
  z-index: 1;
}

/* Add aged paper effect */
.history-expanded-view::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    rgba(139, 105, 20, 0.03) 0%,
    transparent 25%,
    transparent 75%,
    rgba(139, 105, 20, 0.03) 100%
  );
  pointer-events: none;
  border-radius: 8px;
  z-index: 1;
}

.history-expanded-close {
  position: absolute;
  top: clamp(10px, 2vw, 20px);
  left: clamp(10px, 2vw, 20px);
  width: clamp(34px, 4vw, 44px);
  height: clamp(34px, 4vw, 44px);
  background: rgba(139, 105, 20, 0.815);
  color: #f4e4c1;
  border: 1px solid rgba(139, 105, 20, 0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: clamp(20px, 2.5vw, 26px);
  z-index: 1001;
  transition: all 0.2s ease;
}

.history-expanded-close.left {
  left: clamp(10px, 2vw, 20px);
  right: auto;
}

.history-expanded-close:hover {
  background: rgba(139, 105, 20, 0.956);
  color: #ffffff;
  transform: scale(1.1);
}

.history-expanded-content {
  display: flex;
  height: 100%;
  position: relative;
  z-index: 2;
}

.history-expanded-left {
  width: clamp(100px, 32%, 340px);
  min-width: clamp(100px, 32%, 340px);
  padding: clamp(10px, 1.5vw, 15px);
  background: rgba(0, 0, 0, 0.2);
  border-right: clamp(1px, 0.1vw, 2px) solid rgba(139, 105, 20, 0.4);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.2vw, 15px);
}


.history-expanded-image-container {
  width: 100%;
  aspect-ratio: 4/5;
  min-height: 310px;
  max-height: 500px;
  border: clamp(3px, 0.5vw, 5px) solid #8b6914;
  border-radius: clamp(4px, 0.5vw, 8px);
  overflow: hidden;
  background: linear-gradient(135deg, #2a1810, #1f1207);
  box-shadow: 
    0 0 clamp(0.4rem, 0.8vw, 1rem) rgba(139, 105, 20, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  
}

.history-expanded-image {
  width: 100%;
  height: 100%;
  object-fit: cover; 
  filter: sepia(0.1) contrast(1.1) brightness(0.95);
  display: block;
}

.history-expanded-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vw, 12px);
  font-size: clamp(0.85rem, 1.2vw, 0.95rem);
  overflow-y: auto;
  padding-right: clamp(5px, 1vw, 10px);
}

.history-expanded-meta span {
  display: block;
  color: #d4c4a1;
  padding-bottom: clamp(4px, 0.8vw, 6px);
  margin-bottom: clamp(6px, 1vw, 8px);
  border-bottom: clamp(1px, 0.05vw, 2px) solid rgba(139, 105, 20, 0.3);
  line-height: 1.4;
}

.history-expanded-meta span strong {
  color: #8b6914;
  font-weight: 600;
  display: block;
  margin-bottom: clamp(2px, 0.5vw, 4px);
  font-size: clamp(0.8rem, 1vw, 0.9rem);
}

.history-expanded-right {
  flex: 1;
  padding: clamp(10px, 1.5vw, 15px);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 105, 20, 0.3) rgba(0, 0, 0, 0.2);
}

.history-expanded-right h3 {
  margin: 0 0 clamp(8px, 1vw, 12px) 0;
  color: #f4e4c1;
  font-size: clamp(1.4rem, 2.5vw, 1.8rem);
  font-weight: 600;
  text-shadow: 0 0 clamp(0.3rem, 1vw, 0.8rem) rgba(139, 105, 20, 0.4);
  line-height: 1.3;
}

.history-expanded-description {
  flex: 2;
  color: #d4c4a1;
  font-size: clamp(0.9rem, 1.3vw, 1rem);
  line-height: 1.6;
  margin-bottom: clamp(15px, 2vw, 20px);
  padding: clamp(10px, 1.5vw, 15px);
  background: rgba(139, 105, 20, 0.08);
  border: 1px solid rgba(139, 105, 20, 0.2);
  border-radius: clamp(6px, 1vw, 8px);
  overflow-y: auto;
  min-height: clamp(180px, 25vh, 300px);
  max-height: none;
  position: relative;
  z-index: 10;
}

.history-expanded-view .wikipedia-container {
  margin-top: auto;
  padding-top: clamp(8px, 1vw, 12px);
}

.history-expanded-view .wikipedia-btn {
  background: linear-gradient(145deg, #8b6914, #6b5010);
  border: 2px solid #a67c19;
  color: #f4e4c1;
  padding: clamp(8px, 1.5vw, 12px) clamp(16px, 2.5vw, 20px);
  border-radius: clamp(4px, 0.8vw, 8px);
  font-size: clamp(0.85rem, 1.3vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.history-expanded-view .wikipedia-btn:hover {
  background: linear-gradient(145deg, #a67c19, #8b6914);
  border-color: #c89a1f;
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.history-expanded-view .wikipedia-btn:active {
  transform: translateY(0);
  box-shadow: 
    0 2px 6px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Set Time button styling for mobile history view */
.history-expanded-view .set-time-btn {
  background: linear-gradient(145deg, #3a4e6b, #22304a);
  border: 2px solid #4a6b8b;
  color: #f4e4c1;
  padding: clamp(8px, 1.5vw, 12px) clamp(16px, 2.5vw, 20px);
  border-radius: clamp(4px, 0.8vw, 8px);
  font-size: clamp(0.85rem, 1.3vw, 1rem);
  font-family: inherit;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 1, 0.3, 1);
  display: inline-flex;
  align-items: center;
  margin-left: clamp(8px, 1.5vw, 12px);
  box-shadow: 0 2px 10px rgba(0,0,0,0.28), 0 1px 0 rgba(255,255,255,0.08) inset;
  outline: none;
}

.history-expanded-view .set-time-btn:hover {
  background: linear-gradient(145deg, #4a6b8b, #2d3e57);
  border-color: #6b8ba6;
  color: #fffbe8;
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 6px 18px rgba(0,0,0,0.32), 0 1px 0 rgba(255,255,255,0.13) inset;
}

.history-expanded-view .set-time-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 6px rgba(0,0,0,0.22), 0 1px 0 rgba(255,255,255,0.08) inset;
}

/* Time Set (success) state for Set Time button in history panel */
.history-expanded-view .set-time-btn.time-set,
.history-expanded-view .set-time-btn[aria-pressed="true"] {
  background: linear-gradient(145deg, #3a8b3a, #1e5f2d);
  border: 2px solid #4ac86b;
  color: #f4ffe4;
  box-shadow: 0 2px 12px rgba(34, 139, 34, 0.25), 0 1px 0 rgba(255,255,255,0.10) inset;
}

.history-expanded-view .set-time-btn.time-set:hover,
.history-expanded-view .set-time-btn[aria-pressed="true"]:hover {
  background: linear-gradient(145deg, #4ac86b, #3a8b3a);
  border-color: #6bff8b;
  color: #fff;
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 6px 18px rgba(34, 139, 34, 0.32), 0 1px 0 rgba(255,255,255,0.13) inset;
}

.history-expanded-view .set-time-btn.time-set:active,
.history-expanded-view .set-time-btn[aria-pressed="true"]:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 6px rgba(34,139,34,0.22), 0 1px 0 rgba(255,255,255,0.08) inset;
}





/* Custom scrollbar for the expanded view right section */
.history-expanded-right::-webkit-scrollbar {
  width: 8px;
}

.history-expanded-right::-webkit-scrollbar-track {
  background: rgba(139, 105, 20, 0.1);
  border-radius: 4px;
}

.history-expanded-right::-webkit-scrollbar-thumb {
  background: rgba(139, 105, 20, 0.3);
  border-radius: 4px;
}

.history-expanded-right::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 105, 20, 0.5);
}


/* Responsive design for history expanded view */
@media (max-width: 1024px) {
  .history-expanded-left {
    width: 43%;
    min-width: 43%;
    padding: clamp(8px, 1.2vw, 12px);
  }
  
  .history-expanded-right {
    padding: clamp(8px, 1.2vw, 12px);
  }
  
  .history-expanded-meta {
    font-size: 0.8rem;
    gap: clamp(6px, 1vw, 8px);
  }
  
  .history-expanded-right h3 {
    font-size: 1.3rem;
    margin-bottom: clamp(6px, 0.8vw, 10px);
  }
  
  .history-expanded-description {
    font-size: 0.85rem;
    padding: clamp(8px, 1.2vw, 10px);
    min-height: clamp(120px, 18vh, 200px);
    margin-bottom: clamp(10px, 1.5vw, 15px);
  }
}

@media (max-width: 768px) {
  .history-expanded-content {
    flex-direction: column;
  }
  
  .history-expanded-left {
    width: 100%;
    min-width: 100%;
    max-height: 40%;
    border-right: none;
    border-bottom: clamp(1px, 0.1vw, 2px) solid rgba(139, 105, 20, 0.4);
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    padding: clamp(8px, 1.5vw, 12px);
  }
  
  .history-expanded-image-container {
    width: 140px !important;
    min-width: 140px !important;
    aspect-ratio: 4/5 !important;
    min-height: 140px !important;
    max-height: 280px !important;
  }
  
  .history-expanded-meta {
    flex: 1;
    max-height: none;
    font-size: 0.75rem;
    gap: clamp(4px, 0.8vw, 6px);
  }
  
  .history-expanded-right {
    flex: 1;
    padding: clamp(8px, 1.5vw, 12px);
  }
  
  .history-expanded-right h3 {
    font-size: 1.2rem;
    margin-bottom: clamp(6px, 0.8vw, 8px);
  }
  
  .history-expanded-description {
    font-size: 0.98rem !important;
    line-height: 1.5 !important;
    padding: 10px !important;
    min-height: 140px !important;
  }
}

/* Strong mobile override for history-expanded view when rendered inside the
   expanded-card's history panel (fixes very small images/text on narrow phones) */
@media (max-width: 428px) {
  .expanded-card.expanded .history-panel .history-expanded-left {
    padding: 8px !important;
    gap: 10px !important;
  }

  .expanded-card.expanded .history-panel .history-expanded-image-container {
    width: 140px !important;
    min-width: 140px !important;
    aspect-ratio: 4/5 !important;
    min-height: 140px !important;
    max-height: 280px !important;
  }

  .expanded-card.expanded .history-panel .history-expanded-meta {
    font-size: 0.9rem !important;
    gap: 8px !important;
  }

  .expanded-card.expanded .history-panel .history-expanded-right h3 {
    font-size: 1.25rem !important;
    line-height: 1.25 !important;
    margin-bottom: 8px !important;
  }

  .expanded-card.expanded .history-panel .history-expanded-description {
    font-size: 0.98rem !important;
    line-height: 1.5 !important;
    padding: 10px !important;
    min-height: 140px !important;
  }

  /* Slightly larger close button for touch */
  .expanded-card.expanded .history-panel .history-expanded-close {
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }
}
