:root {
  --hm-compare-navy: #12344d;
  --hm-compare-teal: #0f6b6e;
  --hm-compare-green: #2f9678;
  --hm-compare-mint: #dff1eb;
  --hm-compare-line: #cbdce1;
  --hm-compare-copy: #536a77;
}

.hm-compare-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid rgba(15, 107, 110, 0.36);
  border-radius: 999px;
  padding: 7px 13px;
  background: #fff;
  color: var(--hm-compare-teal);
  font: 800 12px/1 Montserrat, Inter, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 5px 13px rgba(18, 52, 77, 0.08);
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.hm-compare-toggle > span {
  font-size: 16px;
  line-height: 0.8;
}

.hm-compare-toggle:hover {
  border-color: var(--hm-compare-teal);
  background: #f5fbf9;
  transform: translateY(-1px);
}

.hm-compare-toggle.is-selected {
  border-color: rgba(47, 150, 120, 0.56);
  background: var(--hm-compare-mint);
  color: #176a55;
  box-shadow: none;
}

.hm-compare-toggle:focus-visible,
.hm-compare-tray button:focus-visible {
  outline: 3px solid rgba(40, 171, 160, 0.38);
  outline-offset: 3px;
}

.hm-profile-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  flex: 0 0 auto;
}

.hm-compare-toggle--profile {
  min-width: 104px;
}

.hm-compare-toggle--compact {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 10px;
  box-shadow: none;
}

.hm-compare-toggle--compact > span {
  font-size: 13px;
}

.hm-compare-toggle--app-central {
  position: absolute;
  z-index: 3;
  top: 50px;
  right: 6px;
  width: 88px;
  min-height: 38px;
  padding: 0 8px;
  border-color: rgba(118, 217, 197, 0.72);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: #d8eee8;
  font-family: "Source Sans 3", "Source Sans Pro", Helvetica, Arial, sans-serif;
  font-size: 12px;
  box-shadow: 0 4px 10px rgba(5, 21, 29, 0.18);
}

.hm-compare-toggle--app-central:hover {
  border-color: #76d9c5;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.hm-compare-toggle--app-central.is-selected {
  border-color: rgba(87, 240, 163, 0.78);
  background: rgba(34, 197, 94, 0.12);
  color: #baf4d2;
}

.hm-tooltip-compare-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(138, 231, 194, 0.34);
}

.hm-tooltip-action-row {
  display: flex;
  align-items: stretch;
  gap: 7px;
}

.hm-tooltip-action-row .hm-tooltip-compare,
.hm-tooltip-action-row .hm-tooltip-report {
  flex: 0 0 calc((100% - 7px) / 2);
  box-sizing: border-box;
  width: calc((100% - 7px) / 2);
  min-width: 0;
}

.hm-tooltip-action-row .hm-tooltip-report:only-child {
  flex-basis: 100%;
  width: 100%;
}

.hm-tooltip-compare {
  min-height: 31px;
  border-color: rgba(149, 231, 205, 0.62);
  background: rgba(255, 255, 255, 0.09);
  color: #b8f0db;
  font-family: "Source Sans 3", "Source Sans Pro", Helvetica, Arial, sans-serif;
  font-size: 10px;
  box-shadow: none;
  pointer-events: auto;
}

.hm-tooltip-compare:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.hm-tooltip-report {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 31px;
  border: 0;
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(255, 255, 255, 0.04);
  color: #d8eee8;
  font: 800 10px/1 "Source Sans 3", "Source Sans Pro", Helvetica, Arial, sans-serif;
  letter-spacing: 0.01em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: none;
  pointer-events: auto;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.hm-tooltip-report::before {
  position: absolute;
  inset: 0;
  padding: 1.5px;
  border-radius: inherit;
  background: linear-gradient(120deg, #76d9c5 0%, #d6b38b 52%, #8fc4dc 100%);
  content: "";
  pointer-events: none;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.hm-tooltip-report:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
  transform: translateY(-1px);
}

.hm-tooltip-report:focus-visible {
  outline: 3px solid rgba(103, 232, 212, 0.72);
  outline-offset: 3px;
}

#deck-tooltip:has(.hm-tooltip-compare),
#deck-tooltip:has(.hm-tooltip-report),
.deck-tooltip:has(.hm-tooltip-compare),
.deck-tooltip:has(.hm-tooltip-report) {
  pointer-events: auto !important;
}

.hm-directory-compare-actions {
  position: absolute;
  left: 29px;
  bottom: 13px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 6px;
}

.hm-compare-toggle--directory {
  position: relative;
  min-height: 31px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.93);
  font-size: 9px;
  box-shadow: 0 3px 9px rgba(18, 52, 77, 0.08);
}

.hm-compare-toggle--directory::after {
  position: absolute;
  z-index: 12;
  bottom: calc(100% + 8px);
  left: 0;
  width: max-content;
  max-width: min(245px, calc(100vw - 40px));
  padding: 7px 9px;
  border-radius: 6px;
  background: rgba(24, 37, 42, 0.96);
  color: #fff;
  content: attr(data-compare-tooltip);
  font: 700 10px/1.4 Inter, Arial, sans-serif;
  text-align: left;
  white-space: normal;
  box-shadow: 0 8px 20px rgba(18, 52, 77, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.hm-compare-toggle--directory:hover::after,
.hm-compare-toggle--directory:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.hm-compare-tray {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 10050;
  width: min(390px, calc(100vw - 44px));
  overflow: hidden;
  border: 1px solid rgba(196, 218, 222, 0.92);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  color: var(--hm-compare-navy);
  box-shadow: 0 20px 48px rgba(18, 52, 77, 0.22);
  backdrop-filter: blur(12px);
  font-family: Inter, Arial, sans-serif;
}

.hm-compare-tray[hidden] {
  display: none !important;
}

.hm-compare-tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 10px 12px 10px 16px;
  background: linear-gradient(115deg, #edf8f5 0%, #f5f8fa 58%, #f8f2e9 100%);
}

.hm-compare-tray-head > div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.hm-compare-tray-head strong {
  font: 800 16px/1.2 Montserrat, Inter, sans-serif;
}

.hm-compare-count {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: rgba(15, 107, 110, 0.1);
  color: var(--hm-compare-teal);
  font-size: 12px;
  font-weight: 800;
}

.hm-compare-collapse,
.hm-compare-remove {
  appearance: none;
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--hm-compare-teal);
  cursor: pointer;
}

.hm-compare-collapse {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(15, 107, 110, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.74);
  font-size: 20px;
  font-weight: 700;
}

.hm-compare-tray-body {
  max-height: min(55vh, 420px);
  overflow: auto;
  padding: 11px 14px 14px;
}

.hm-compare-tray.is-collapsed .hm-compare-tray-body {
  display: none;
}

.hm-compare-items {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hm-compare-items li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border: 1px solid #dce8eb;
  border-radius: 11px;
  padding: 7px 7px 7px 12px;
  background: #f8fbfb;
  color: #314d5d;
  font-size: 12px;
  font-weight: 750;
}

.hm-compare-items li > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hm-compare-remove {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 21px;
}

.hm-compare-remove:hover {
  background: #e8f2f1;
}

.hm-compare-tray-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  margin-top: 12px;
}

.hm-compare-clear,
.hm-compare-open {
  appearance: none;
  min-height: 42px;
  border-radius: 10px;
  padding: 9px 13px;
  font: 800 12px/1 Montserrat, Inter, sans-serif;
}

.hm-compare-clear {
  border: 1px solid #d7e3e6;
  background: #fff;
  color: var(--hm-compare-copy);
  cursor: pointer;
}

.hm-compare-open {
  border: 1px solid rgba(15, 107, 110, 0.22);
  background: #dce8e8;
  color: #789095;
  cursor: not-allowed;
}

.hm-compare-open:not(:disabled) {
  border-color: transparent;
  background: linear-gradient(120deg, #0f6b6e 0%, #2f9678 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(15, 107, 110, 0.18);
}

.hm-compare-open:not(:disabled):hover {
  filter: brightness(1.04);
}

.hm-compare-next-stage {
  display: block;
  margin-top: 8px;
  color: #728791;
  font-size: 10px;
  font-weight: 650;
  line-height: 1.35;
  text-align: right;
}

.hm-compare-status {
  position: absolute;
  right: 13px;
  bottom: 13px;
  max-width: calc(100% - 26px);
  border-radius: 9px;
  padding: 8px 11px;
  background: #173d45;
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(5px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.hm-compare-status.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .hm-profile-heading-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 680px) {
  .hm-compare-toggle--app-central {
    top: 46px;
    width: 78px;
    min-height: 34px;
    padding: 0 6px;
    border-radius: 9px;
    font-size: 10.5px;
  }

  .rank-table-row .rank-metric {
    display: flex;
    grid-column: 2;
    align-items: center;
    justify-self: stretch;
    justify-content: flex-start;
    gap: 4px;
    margin-right: 0;
  }

  .rank-table-row .rank-score {
    grid-column: auto;
  }

  .rank-table-row .hm-compare-toggle--compact {
    min-height: 36px;
    padding: 7px;
    font-size: 9px;
  }

  .rank-table-row .hm-compare-toggle--compact > span {
    display: none;
  }

  .hm-compare-tray {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: calc(100vw - 20px);
    border-radius: 15px;
  }

  .hm-compare-tray-body {
    max-height: min(52vh, 390px);
  }
}

@media (max-width: 460px) {
  .hm-profile-heading-actions {
    align-items: flex-start;
    flex-direction: column-reverse;
    gap: 12px;
  }

  .hm-compare-toggle--profile {
    min-width: 112px;
    min-height: 42px;
  }

  .hm-compare-items li {
    min-height: 44px;
  }
}

/* Rankings mobile rows: keep place + score together and reserve row two for actions. */
@media (max-width: 680px) {
  body.rankings-page .rank-table-row {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 8px;
    row-gap: 6px;
    min-height: 88px;
    padding: 10px 0;
  }

  body.rankings-page .rank-number {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
  }

  body.rankings-page .rank-place {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
  }

  body.rankings-page .rank-place b {
    column-gap: 6px;
    max-width: none;
  }

  body.rankings-page .rank-place small {
    margin-top: 3px;
  }

  body.rankings-page .rank-table-row .rank-metric {
    display: contents;
  }

  body.rankings-page .rank-table-row .rank-score {
    grid-column: 3;
    grid-row: 1;
    align-self: start;
    justify-self: end;
    padding: 4px 8px;
  }

  body.rankings-page .rank-table-row .hm-compare-toggle--compact {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    min-height: 36px;
    padding: 7px 10px;
  }

  body.rankings-page .rank-table-row .rank-map-cue {
    position: static;
    grid-column: 3;
    grid-row: 2;
    align-self: center;
    justify-self: end;
    width: 40px;
    height: 40px;
    margin: 0;
    transform: none;
  }

  body.rankings-page .rank-table-row .rank-map-arrow {
    width: 21px;
    height: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hm-compare-toggle,
  .hm-compare-status {
    transition: none;
  }
}
