:root {
  --hm-l0: color-mix(in oklab, var(--text) 6%, var(--panel));
  --hm-l1: color-mix(in oklab, var(--accent) 32%, var(--panel));
  --hm-l2: color-mix(in oklab, var(--accent) 60%, var(--panel));
  --hm-l3: var(--accent);
  --hm-l4: color-mix(in oklab, var(--accent-shade) 35%, var(--accent));
  --hm-edge: rgba(32, 31, 29, 0.10);
  --hm-tip-bg: #201f1d;
  --hm-tip-ink: #f3f2f2;
}

html[data-theme="dark"] {
  --hm-l1: color-mix(in oklab, var(--accent) 25%, var(--panel));
  --hm-l2: color-mix(in oklab, var(--accent) 45%, var(--panel));
  --hm-l3: color-mix(in oklab, var(--accent) 70%, var(--panel));
  --hm-l4: var(--accent);
  --hm-edge: rgba(227, 232, 225, 0.08);
  --hm-tip-bg: #e3e8e1;
  --hm-tip-ink: #151c19;
}

.hm {
  --gap: 3px;
  --cell-r: 3px;
  --months-h: 18px;
  --days-col: 34px;
  display: grid;
  gap: 12px;
  min-width: 0;
}

.hm-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.hm-tile {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--bg);
  min-width: 0;
}

.hm-tile-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: var(--muted);
}

.hm-tile-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.hm-tile-sub {
  font-size: 12px;
  color: var(--muted);
}

.hm-area {
  position: relative;
  display: flex;
  gap: 6px;
  min-width: 0;
  container-type: inline-size;
}

.hm-days,
.hm-scroll {
  --cell: clamp(11px, calc((100cqi - var(--days-col) - 6px - 52 * var(--gap)) / 53), 14px);
}

.hm-days {
  flex: none;
  width: var(--days-col);
  display: grid;
  grid-template-rows: var(--months-h) repeat(7, var(--cell));
  row-gap: var(--gap);
  font-size: 11px;
  color: var(--muted);
}

.hm-days span {
  line-height: var(--cell);
}

.hm-scroll {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 4px;
}

.hm-scroll.fade-left {
  mask-image: linear-gradient(to right, transparent 0, #000 28px);
}

.hm-months {
  display: flex;
  gap: var(--gap);
  width: max-content;
  height: var(--months-h);
  font-size: 11px;
  color: var(--muted);
}

.hm-mw {
  flex: none;
  width: var(--cell);
  white-space: nowrap;
  line-height: 1;
}

.hm-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-columns: var(--cell);
  gap: var(--gap);
  width: max-content;
  margin-top: var(--gap);
}

.hm-cell {
  display: block;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  border-radius: var(--cell-r);
  background: var(--hm-l0);
  box-shadow: inset 0 0 0 1px var(--hm-edge);
  cursor: default;
  forced-color-adjust: none;
  transition: transform 120ms ease;
}

.hm-cell[data-level="1"] { background: var(--hm-l1); }
.hm-cell[data-level="2"] { background: var(--hm-l2); }
.hm-cell[data-level="3"] { background: var(--hm-l3); }
.hm-cell[data-level="4"] { background: var(--hm-l4); }

.hm-cell.has-detail {
  cursor: pointer;
}

.hm-cell.is-future {
  visibility: hidden;
}

.hm-cell:not(.is-future):hover {
  position: relative;
  z-index: 1;
  transform: scale(1.25);
}

.hm-cell:focus-visible,
.hm-cell.is-selected {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.hm-tip {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--hm-tip-bg);
  color: var(--hm-tip-ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 8px));
}

.hm-tip.below {
  transform: translate(-50%, 8px);
}

.hm-tip-sub {
  margin-left: 6px;
  opacity: 0.8;
}

.hm-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  min-height: 34px;
  font-size: 14px;
  color: var(--muted);
}

.hm-caption[hidden] {
  display: none;
}

.hm-caption strong {
  color: var(--text);
}

.hm-view {
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.hm-view:hover {
  background: var(--folder-hover);
}

.hm-view:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hm-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.hm-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: var(--cell-r);
  background: var(--hm-l0);
  box-shadow: inset 0 0 0 1px var(--hm-edge);
  forced-color-adjust: none;
}

.hm-swatch[data-level="1"] { background: var(--hm-l1); }
.hm-swatch[data-level="2"] { background: var(--hm-l2); }
.hm-swatch[data-level="3"] { background: var(--hm-l3); }
.hm-swatch[data-level="4"] { background: var(--hm-l4); }

.hm-unit {
  margin-left: 6px;
}

@media (max-width: 700px) {
  .hm-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .hm-cell {
    transition: none;
  }
  .hm-cell:not(.is-future):hover {
    transform: none;
  }
}
