/* 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);
}

/* Archive: GitHub / Codeberg contribution ramp (high empty ↔ L1 contrast) */
.blog-heatmap--archive {
  --heatmap-empty: #ebedf0;
  --heatmap-empty-border: #ebedf0;
  --heatmap-l1: #9be9a8;
  --heatmap-l2: #40c463;
  --heatmap-l3: #30a14e;
  --heatmap-l4: #216e39;
  --heatmap-hover-ring: #30a14e;
  width: 100%;
  max-width: 100%;
}

@media (prefers-color-scheme: dark) {
  .blog-heatmap--archive {
    --heatmap-empty: #161b22;
    --heatmap-empty-border: #161b22;
    --heatmap-l1: #0e4429;
    --heatmap-l2: #006d32;
    --heatmap-l3: #26a641;
    --heatmap-l4: #39d353;
    --heatmap-hover-ring: #39d353;
  }
}

/* Article: fixed widget stack (heatmap + music) */
.article-widgets-fixed {
  position: fixed;
  top: 4.5rem;
  right: 1.25rem;
  z-index: 9997;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.article-widgets-fixed > * {
  pointer-events: auto;
}

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

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

/* Article widget: same contrast steps, purple accent */
.blog-heatmap--article {
  --heatmap-cell: 10px;
  --heatmap-gap: 2px;
  --heatmap-empty: #ebedf0;
  --heatmap-empty-border: #ebedf0;
  --heatmap-l1: #e9d5ff;
  --heatmap-l2: #c084fc;
  --heatmap-l3: #9333ea;
  --heatmap-l4: #6b21a8;
  --heatmap-hover-ring: #9333ea;
  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 (prefers-color-scheme: dark) {
  .blog-heatmap--article {
    --heatmap-empty: #161b22;
    --heatmap-empty-border: #161b22;
    --heatmap-l1: #581c87;
    --heatmap-l2: #7e22ce;
    --heatmap-l3: #a855f7;
    --heatmap-l4: #d8b4fe;
    --heatmap-hover-ring: #a855f7;
  }
}

@media (max-width: 960px) {
  .article-widgets-fixed,
  .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;
  }
}

/* Kanban heatmap */
.blog-heatmap--kanban {
  --heatmap-cell: 14px;
  --heatmap-gap: 4px;
  --heatmap-radius: 3px;
  --heatmap-empty: var(--bg-muted-2);
  --heatmap-empty-border: var(--border-color);
  --heatmap-l1: var(--blue-bg-1, #dbeafe);
  --heatmap-l2: var(--blue-bg-2, #93c5fd);
  --heatmap-l3: color-mix(in srgb, var(--blue-fg, #2563eb) 65%, var(--bg-color));
  --heatmap-l4: var(--blue-fg, #2563eb);
  --heatmap-hover-ring: var(--blue-fg, #2563eb);
  width: 100%;
}

.heatmap-scroll--kanban-year,
.heatmap-scroll--kanban-month {
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

/* Year view: two rows 1–6 / 7–12, spaced months */
.kanban-heatmap-year {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.kanban-heatmap-semester {
  display: flex;
  flex-wrap: nowrap;
  gap: 1.25rem;
  align-items: flex-end;
  min-width: min-content;
}

.kanban-heatmap-month-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
  padding-inline-end: 0.25rem;
  border-inline-end: 1px dashed color-mix(in srgb, var(--border-color) 80%, transparent);
}

.kanban-heatmap-semester .kanban-heatmap-month-block:last-child {
  border-inline-end: none;
  padding-inline-end: 0;
}

.kanban-heatmap-month-block-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted-2);
  white-space: nowrap;
}

.kanban-heatmap-month-weeks {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--heatmap-gap);
}

/* Week cell — fill height = effective days / 7 */
.heatmap-week-cell {
  position: relative;
  width: var(--heatmap-cell);
  height: var(--heatmap-cell);
  padding: 0;
  border: 1px solid var(--heatmap-empty-border);
  border-radius: var(--heatmap-radius);
  background: var(--heatmap-empty);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}

.heatmap-week-cell:not(:disabled)::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--week-fill, 0) * 100%);
  border-radius: inherit;
  pointer-events: none;
}

.heatmap-week-cell[data-level="1"]:not(:disabled)::before {
  background: var(--heatmap-l1);
}

.heatmap-week-cell[data-level="2"]:not(:disabled)::before {
  background: var(--heatmap-l2);
}

.heatmap-week-cell[data-level="3"]:not(:disabled)::before {
  background: var(--heatmap-l3);
}

.heatmap-week-cell[data-level="4"]:not(:disabled)::before {
  background: var(--heatmap-l4);
}

.heatmap-week-cell.is-partial:not(:disabled) {
  border-color: color-mix(in srgb, var(--heatmap-l4) 35%, var(--heatmap-empty-border));
}

.heatmap-week-cell:not(:disabled):hover,
.heatmap-week-cell:not(:disabled):focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 4px var(--heatmap-hover-ring);
}

.heatmap-week-cell:disabled {
  opacity: 0.5;
  cursor: default;
}

.kanban-heatmap-week-slot,
.kanban-heatmap-day-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.kanban-heatmap-today-marker {
  display: none;
  position: relative;
  width: 10px;
  height: 6px;
  flex-shrink: 0;
}

.kanban-heatmap-week-slot.is-current .kanban-heatmap-today-marker,
.kanban-heatmap-day-slot.is-current .kanban-heatmap-today-marker {
  display: block;
}

.kanban-heatmap-today-marker::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 6px solid var(--blue-fg, var(--accent-color));
}

.kanban-heatmap-today-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 1px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-bottom: 4px solid var(--bg-muted-1);
}

/* Month view: daily grid */
.kanban-heatmap-daily {
  min-width: min-content;
}

.kanban-heatmap-daily-header {
  margin: 0 0 0.5rem;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted-2);
}

.kanban-heatmap-daily-labels {
  display: grid;
  grid-template-columns: repeat(var(--kanban-days, 30), var(--heatmap-cell));
  gap: var(--heatmap-gap);
  min-height: 14px;
  margin-bottom: 0.25rem;
}

.kanban-heatmap-daily-label {
  font-size: 9px;
  color: var(--fg-muted-2);
  text-align: center;
}

.kanban-heatmap-daily-grid {
  display: grid;
  grid-template-columns: repeat(var(--kanban-days, 30), var(--heatmap-cell));
  gap: var(--heatmap-gap);
}

.heatmap-day-cell {
  position: relative;
  width: var(--heatmap-cell);
  height: var(--heatmap-cell);
  padding: 0;
  border: 1px solid var(--heatmap-empty-border);
  border-radius: var(--heatmap-radius);
  background: var(--heatmap-empty);
  cursor: pointer;
  overflow: hidden;
}

.heatmap-day-cell:not(:disabled) {
  border-color: color-mix(in srgb, var(--heatmap-l4) 70%, var(--heatmap-empty-border));
}

.heatmap-day-cell[data-level="1"]:not(:disabled) {
  background: var(--heatmap-l1);
}

.heatmap-day-cell[data-level="2"]:not(:disabled) {
  background: var(--heatmap-l2);
}

.heatmap-day-cell[data-level="3"]:not(:disabled) {
  background: var(--heatmap-l3);
}

.heatmap-day-cell[data-level="4"]:not(:disabled) {
  background: var(--heatmap-l4);
}

.heatmap-day-cell:not(:disabled):hover,
.heatmap-day-cell:not(:disabled):focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 4px var(--heatmap-hover-ring);
}

.heatmap-day-cell:disabled {
  opacity: 0.45;
  cursor: default;
}

.kanban-heatmap-section .archive-heatmap-toolbar {
  position: relative;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1rem;
  margin-bottom: 0.75rem;
  min-height: 2.25rem;
}

.kanban-heatmap-section .archive-heatmap-stat {
  width: 100%;
  text-align: center;
  font-size: calc(var(--font-size-base, 1rem) + 0.5rem);
  font-weight: 700;
  line-height: 1.35;
}

.kanban-heatmap-section .kanban-picker-row {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 30;
}

.kanban-heatmap-section .archive-year-picker {
  position: relative;
  z-index: 31;
}

@media (max-width: 720px) {
  .kanban-heatmap-section .archive-heatmap-toolbar {
    min-height: 0;
    padding-top: 2.5rem;
  }
}

@media (max-width: 720px) {
  .kanban-heatmap-semester {
    flex-wrap: wrap;
    gap: 0.85rem 1rem;
  }

  .kanban-heatmap-month-block {
    border-inline-end: none;
    padding-inline-end: 0;
  }
}
