/* Compact GitHub-style contribution heatmap — uses ametrine theme tokens */

.blog-heatmap {
  --heatmap-cell: 11px;
  --heatmap-gap: 3px;
  --heatmap-radius: 3px;
  --heatmap-month-height: 15px;
  --heatmap-hover-ring: var(--green-fg, #30a14e);
  position: relative;
  font-size: 12px;
  line-height: 1;
}

.heatmap-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: var(--accent-color) transparent;
  scrollbar-width: thin;
  padding-bottom: 2px;
}

.heatmap-scroll::-webkit-scrollbar {
  height: 6px;
}

.heatmap-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--accent-color);
}

.heatmap-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.heatmap-inner {
  width: max-content;
  min-width: min(100%, max-content);
}

.heatmap-months {
  display: grid;
  grid-template-columns: repeat(var(--heatmap-weeks), var(--heatmap-cell));
  gap: var(--heatmap-gap);
  min-height: var(--heatmap-month-height);
  margin-left: 0;
  margin-bottom: 4px;
  color: var(--fg-muted-1);
}

.heatmap-month-label {
  grid-row: 1;
  white-space: nowrap;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(var(--heatmap-weeks), var(--heatmap-cell));
  gap: var(--heatmap-gap);
}

.heatmap-week {
  display: grid;
  grid-template-rows: repeat(7, var(--heatmap-cell));
  gap: var(--heatmap-gap);
}

.heatmap-day {
  width: var(--heatmap-cell);
  height: var(--heatmap-cell);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--heatmap-radius);
  background: var(--heatmap-empty);
  cursor: default;
  transition: box-shadow 0.12s ease;
}

.heatmap-day:not(:disabled) {
  cursor: pointer;
}

.heatmap-day:not(:disabled):hover,
.heatmap-day:not(:disabled):focus-visible,
.heatmap-day:not(:disabled):active {
  outline: none;
  position: relative;
  z-index: 2;
  box-shadow:
    0 0 0 1px var(--fg-muted-1),
    0 0 0 3px var(--heatmap-hover-ring);
}

.heatmap-day[data-level="0"] {
  background: var(--heatmap-empty);
  border-color: var(--heatmap-empty-border);
}

.heatmap-day[data-level="1"] {
  background: var(--heatmap-l1);
  border-color: var(--heatmap-l1-border, var(--heatmap-l1));
}

.heatmap-day[data-level="2"] {
  background: var(--heatmap-l2);
  border-color: var(--heatmap-l2-border, var(--heatmap-l2));
}

.heatmap-day[data-level="3"] {
  background: var(--heatmap-l3);
  border-color: var(--heatmap-l3-border, var(--heatmap-l3));
}

.heatmap-day[data-level="4"] {
  background: var(--heatmap-l4);
  border-color: var(--heatmap-l4-border, var(--heatmap-l4));
}

.heatmap-day:disabled {
  opacity: 1;
}

.heatmap-tooltip {
  position: fixed;
  z-index: 10000;
  transform: translate(-50%, calc(-100% - 10px));
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-color);
  color: var(--fg-color);
  border: 1px solid var(--bg-muted-2);
  box-shadow: var(--shadow-glow);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.heatmap-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: var(--bg-color);
  border-right: 1px solid var(--bg-muted-2);
  border-bottom: 1px solid var(--bg-muted-2);
}

/* Archive: GitHub profile style */
.archive-heatmap-section {
  margin: 0.75rem 0 1rem;
  padding: 12px 14px;
  border: 1px solid var(--bg-muted-2);
  border-radius: 8px;
  background: var(--bg-muted-1);
  max-width: 100%;
  overflow: hidden;
}

.archive-heatmap-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 10px;
}

.archive-heatmap-stat {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-color);
}

.archive-year-picker {
  position: relative;
  flex-shrink: 0;
}

.archive-year-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--bg-muted-2);
  border-radius: 6px;
  background: var(--bg-color);
  color: var(--fg-color);
  font-size: 13px;
  cursor: pointer;
}

.archive-year-btn:hover {
  background: var(--bg-muted-2);
}

.archive-year-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 20;
  min-width: 120px;
  max-height: 220px;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  border: 1px solid var(--bg-muted-2);
  border-radius: 6px;
  background: var(--bg-color);
  box-shadow: var(--shadow-glow);
  overflow-y: auto;
}

.archive-year-option {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--fg-color);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.archive-year-option:hover {
  background: var(--bg-muted-1);
}

.blog-heatmap--archive {
  --heatmap-empty: var(--bg-muted-2);
  --heatmap-empty-border: var(--bg-muted-2);
  --heatmap-l1: var(--green-bg-1);
  --heatmap-l2: var(--green-bg-2);
  --heatmap-l3: color-mix(in srgb, var(--green-fg) 72%, var(--bg-color));
  --heatmap-l4: var(--green-fg);
  --heatmap-hover-ring: var(--green-fg);
  width: 100%;
  max-width: 100%;
}

/* Article: fixed widget */
.article-heatmap-fixed {
  position: fixed;
  top: 4.5rem;
  right: 1.25rem;
  z-index: 9997;
  pointer-events: none;
}

.article-heatmap-fixed .blog-heatmap {
  pointer-events: auto;
}

.blog-heatmap--article {
  --heatmap-cell: 10px;
  --heatmap-gap: 2px;
  --heatmap-empty: var(--bg-muted-2);
  --heatmap-empty-border: var(--bg-muted-2);
  --heatmap-l1: var(--purple-bg-1);
  --heatmap-l2: var(--purple-bg-2);
  --heatmap-l3: color-mix(in srgb, var(--purple-fg) 70%, var(--bg-color));
  --heatmap-l4: var(--purple-fg);
  --heatmap-hover-ring: var(--purple-fg);
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-muted-1);
  border: 1px solid var(--bg-muted-2);
  box-shadow: var(--shadow-glow);
  width: fit-content;
  max-width: min(220px, calc(100vw - 2.5rem));
}

@media (max-width: 960px) {
  .article-heatmap-fixed {
    top: auto;
    bottom: 5.5rem;
    right: 1rem;
  }

  .blog-heatmap--article {
    --heatmap-cell: 9px;
    padding: 10px;
  }
}

@media (max-width: 640px) {
  .archive-heatmap-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
