/* ==========================================================================
   Achievements page. Rarity colours are design tokens; the tier a class names comes from
   Rarity in app/models, so these classes are built in Ruby.
   ========================================================================== */

.rarity-ultra { --rarity-color: var(--rarity-ultra); }
.rarity-very-rare { --rarity-color: var(--rarity-very-rare); }
.rarity-rare { --rarity-color: var(--rarity-rare); }
.rarity-uncommon { --rarity-color: var(--rarity-uncommon); }
.rarity-common { --rarity-color: var(--rarity-common); }
.rarity-unknown { --rarity-color: var(--rarity-unknown); }

/* A tier in words, never colour alone */
.rarity-chip {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: .3em;
  padding: .15rem .45rem;
  font-family: var(--font-data);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: .03em;
  white-space: nowrap;
  color: var(--rarity-color);
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
}

.rarity-chip.rarity-unknown {
  border-style: dashed;
}

.rarity-chip-glyph {
  font-size: .75em;
  letter-spacing: -.08em;
}

.rarity-chip-percent {
  font-variant-numeric: tabular-nums;
}

/* Overview: 2 by 2 at every width */
.achievements-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.achievements-stat-hint {
  display: block;
  margin-top: .25rem;
  font-size: var(--text-xs);
  line-height: 1.3;
  color: var(--text-secondary);
}

/* The page's one gold moment ties to rarity */
.achievements-stat-item .achievements-perfect-badge {
  color: var(--rarity-ultra);
  border-color: var(--rarity-ultra);
}

.achievements-stat-item:hover .achievements-perfect-badge {
  color: var(--surface-page);
  background: var(--rarity-ultra);
}

/* Rarity doughnut and its table, which is also its legend */
.achievements-chart-card {
  height: 100%;
}

.rarity-breakdown {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
}

.rarity-donut {
  position: relative;
  flex: 0 0 auto;
  width: min(100%, 14rem);
  aspect-ratio: 1;
}

.rarity-donut-canvas {
  position: absolute;
  inset: 0;
}

.rarity-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  text-align: center;
  pointer-events: none;
}

.rarity-donut-value {
  font-family: var(--font-data);
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--rarity-ultra);
}

.rarity-donut-label {
  max-width: 7rem;
  font-size: var(--text-xs);
  line-height: 1.3;
  color: var(--text-secondary);
}

.rarity-table {
  flex: 1 1 17rem;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.rarity-table th,
.rarity-table td {
  padding: .4rem .5rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.rarity-table thead th {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}

.rarity-table tbody th {
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-primary);
}

.rarity-table td {
  color: var(--text-secondary);
}

.rarity-table .rarity-table-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rarity-swatch {
  display: inline-block;
  width: .7rem;
  height: .7rem;
  margin-right: .5rem;
  vertical-align: -.05rem;
  background: var(--rarity-color);
  border-radius: 2px;
}

.rarity-unknown .rarity-swatch {
  background: transparent;
  border: 1px dashed var(--rarity-color);
}

@media (max-width: 640px) {
  .rarity-breakdown {
    flex-direction: column;
    align-items: stretch;
  }

  .rarity-donut {
    align-self: center;
  }

  .rarity-table {
    flex-basis: auto;
    font-size: var(--text-xs);
  }

  .rarity-table th,
  .rarity-table td {
    padding: .35rem .25rem;
  }
}

/* Rarest unlocks: five jewels in a quincunx, the rarest (first in reading order) in the centre.
   Sizes follow the grid's width, so a phone shrinks the jewels instead of overflowing. */
.crown-jewels-card {
  overflow: visible;
}

.quincunx-grid {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 22rem);
  margin: 0 auto;
  padding: 1.75rem 0;
  list-style: none;
}

.crown-jewel-item {
  --jewel-color: var(--rarity-color);
  --jewel-glow: color-mix(in srgb, var(--rarity-color) 40%, transparent);
  position: relative;
  aspect-ratio: 1;
}

.crown-jewel-item:nth-child(1) { grid-area: 2 / 2; z-index: var(--z-raised); }
.crown-jewel-item:nth-child(2) { grid-area: 1 / 1; }
.crown-jewel-item:nth-child(3) { grid-area: 1 / 3; }
.crown-jewel-item:nth-child(4) { grid-area: 3 / 1; }
.crown-jewel-item:nth-child(5) { grid-area: 3 / 3; }

.crown-jewel-badge-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.crown-jewel-badge-container:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.crown-jewel-diamond {
  position: absolute;
  width: 92%;
  aspect-ratio: 1;
  transform: rotate(45deg);
  border: 2px solid var(--jewel-color);
  box-shadow: 0 0 15px var(--jewel-glow), inset 0 0 10px var(--jewel-glow);
}

.crown-jewel-diamond .scanline {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.crown-jewel-diamond .scanline::after {
  content: "";
  position: absolute;
  top: -100%;
  left: -100%;
  width: 300%;
  height: 50%;
  background: linear-gradient(to bottom, transparent, var(--jewel-color), transparent);
  opacity: .3;
  transform: rotate(-45deg);
  animation: neonScanline 3.5s infinite linear;
}

.crown-jewel-icon {
  position: relative;
  z-index: 1;
  width: 48%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
}

.crown-jewel-percentage {
  position: absolute;
  bottom: 4%;
  z-index: 2;
  padding: .15rem .5rem;
  font-size: clamp(.6rem, 3.6cqi, .8rem);
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--jewel-color);
  background: var(--surface-sunken);
  border: 1px solid var(--jewel-color);
  border-radius: 12px;
  box-shadow: 0 0 8px var(--jewel-glow);
}

.crown-jewel-glyph {
  font-size: .8em;
  letter-spacing: -.08em;
}

/* Shown on hover and focus, hoverable, and hidden by Escape (dismissable-tooltip). Aligned to the
   jewel's column, so the outer ones never leave the card. */
.custom-tooltip {
  position: absolute;
  bottom: 88%;
  left: 50%;
  z-index: var(--z-raised); /* above the other jewels, within the card */
  display: flex;
  flex-direction: column;
  gap: .25rem;
  width: max-content;
  max-width: min(17rem, 80vw);
  padding: .75rem;
  text-align: center;
  background: var(--surface-overlay);
  border: 1px solid var(--jewel-color);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, .5rem);
  transition: opacity var(--dur-fast) ease, transform var(--dur-fast) ease, visibility var(--dur-fast);
}

.crown-jewel-item:is(:nth-child(2), :nth-child(4)) .custom-tooltip {
  left: 0;
  text-align: left;
  transform: translate(0, .5rem);
}

.crown-jewel-item:is(:nth-child(3), :nth-child(5)) .custom-tooltip {
  right: 0;
  left: auto;
  text-align: right;
  transform: translate(0, .5rem);
}

.crown-jewel-badge-container:is(:hover, :focus-visible):not([data-dismissed]) .custom-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

.crown-jewel-item:is(:nth-child(n+2)) .crown-jewel-badge-container:is(:hover, :focus-visible):not([data-dismissed]) .custom-tooltip {
  transform: none;
}

.tooltip-game {
  font-family: var(--font-display);
  font-size: .7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.tooltip-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.tooltip-meta {
  font-size: .75rem;
  font-weight: 600;
  color: var(--jewel-color);
}

.tooltip-desc {
  font-size: .75rem;
  line-height: 1.4;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

.crown-jewels-note {
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
  font-size: var(--text-sm);
  text-align: center;
  color: var(--text-secondary);
}

@keyframes neonScanline {
  0% { top: -100%; }
  100% { top: 200%; }
}

/* Neon: only the rarest jewel breathes */
@keyframes jewelPulse {
  50% { box-shadow: 0 0 30px var(--jewel-color), inset 0 0 16px var(--jewel-glow); }
}

:root:not([data-theme="beige"], [data-theme="hacker"]) .crown-jewel-item:first-child .crown-jewel-diamond {
  animation: jewelPulse 3s ease-in-out infinite;
}

/* Retro Desk: seals on file, a red "certified" stamp on the ultra rare */
:root[data-theme="beige"] .crown-jewel-diamond {
  width: 78%;
  transform: rotate(-3deg);
  background: var(--surface-raised);
  border: 4px double var(--jewel-color);
}

:root[data-theme="beige"] .crown-jewel-item:nth-child(even) .crown-jewel-diamond {
  transform: rotate(2deg);
}

:root[data-theme="beige"] .crown-jewel-diamond .scanline {
  display: none;
}

:root[data-theme="beige"] .rarity-ultra .crown-jewel-badge-container::after {
  content: "Certified rare";
  position: absolute;
  top: 6%;
  right: -4%;
  z-index: 3;
  padding: .1rem .3rem;
  font-family: var(--font-display);
  font-size: clamp(.5rem, 3cqi, .65rem);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--danger);
  background: var(--surface-raised);
  border: 2px solid currentColor;
  transform: rotate(-4deg);
}

/* Netrunner: bracketed terminal frames with a blinking cursor */
:root[data-theme="hacker"] .crown-jewel-diamond {
  width: 82%;
  transform: none;
  border: 0;
}

:root[data-theme="hacker"] .crown-jewel-diamond::before,
:root[data-theme="hacker"] .crown-jewel-diamond::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14%;
  border: 2px solid var(--jewel-color);
}

:root[data-theme="hacker"] .crown-jewel-diamond::before {
  left: 0;
  border-right: 0;
}

:root[data-theme="hacker"] .crown-jewel-diamond::after {
  right: 0;
  border-left: 0;
}

:root[data-theme="hacker"] .crown-jewel-diamond .scanline {
  inset: auto 18% 6% auto;
  width: .45em;
  height: .9em;
  background: var(--jewel-color);
  animation: terminalBlink 1.1s steps(1) infinite;
}

:root[data-theme="hacker"] .crown-jewel-diamond .scanline::after {
  display: none;
}

:root[data-theme="hacker"] .crown-jewel-percentage {
  border-radius: 0;
}

:root[data-theme="hacker"] .crown-jewel-percentage::before {
  content: "[ ";
}

:root[data-theme="hacker"] .crown-jewel-percentage::after {
  content: " ]";
}

@keyframes terminalBlink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .crown-jewel-diamond,
  .crown-jewel-diamond .scanline,
  .crown-jewel-diamond .scanline::after {
    animation: none !important;
  }
}

/* Recent unlocks */
.recent-activity-list {
  max-height: 26rem;
  padding: .25rem;
  overflow-y: auto;
  border-radius: var(--radius-md);
}

.recent-activity-list:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.recent-activity-items {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recent-activity-row {
  display: flex;
  align-items: center;
  gap: .75rem 1rem;
  padding: .75rem;
  background: var(--surface-chip);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--rarity-color, var(--border-subtle));
  border-radius: 8px;
  transition: border-color var(--dur-fast) ease;
}

.recent-activity-row:hover {
  border-color: var(--rarity-color, var(--border-strong));
}

.recent-activity-row-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
}

.recent-activity-row-info {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
}

.recent-activity-row-title {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: .95rem;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-primary);
  text-decoration: none;
}

.recent-activity-row-title:hover,
.recent-activity-row-title:focus-visible {
  text-decoration: underline;
}

.recent-activity-row-game {
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  font-size: .8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.recent-activity-row-desc {
  display: -webkit-box;
  overflow: hidden;
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--text-secondary);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.recent-activity-row-meta {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  align-items: flex-end;
  gap: .35rem;
}

.recent-activity-row-time {
  font-size: var(--text-xs);
  white-space: nowrap;
  color: var(--text-secondary);
}

.recent-activity-more {
  display: block;
  margin: var(--space-3) auto 0;
}

.recent-activity-empty {
  font-style: italic;
}

@media (max-width: 480px) {
  .recent-activity-row {
    flex-wrap: wrap;
  }

  .recent-activity-row-meta {
    flex-basis: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
  }
}

/* Closest to 100%, easiest missing, perfect games */
.achievement-goal-list,
.achievement-missing-list,
.perfect-game-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.achievement-goal-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.achievement-goal {
  padding: var(--space-3);
  background: var(--surface-chip);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.achievement-goal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.achievement-goal-game,
.perfect-game-name {
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-display);
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.achievement-goal-count {
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.achievement-goal-bar {
  display: block;
  width: 100%;
  height: .4rem;
  margin: var(--space-2) 0 var(--space-3);
  overflow: hidden;
  appearance: none;
  background: var(--surface-inset);
  border: 0;
  border-radius: 999px;
}

.achievement-goal-bar::-webkit-progress-bar {
  background: var(--surface-inset);
}

.achievement-goal-bar::-webkit-progress-value {
  background: var(--accent);
}

.achievement-goal-bar::-moz-progress-bar {
  background: var(--accent);
}

.achievement-missing-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.achievement-missing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.achievement-easiest-list .achievement-missing {
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.achievement-missing-text {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}

.achievement-missing-name {
  font-weight: 600;
  color: var(--text-primary);
}

.achievement-missing-desc,
.achievement-missing-game {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.achievement-missing-game {
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.perfect-game-scroll {
  max-height: 24rem;
  overflow-y: auto;
}

.perfect-game-scroll:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.perfect-game {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.perfect-game-meta {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--rarity-ultra);
}

.perfect-game.is-lapsed .perfect-game-meta {
  font-weight: 400;
  color: var(--text-secondary);
}

/* Unlock history: the same grid as the Playtime year heatmap */
.unlock-history-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}

.unlock-history-stat {
  padding: var(--space-2) var(--space-3);
  background: var(--surface-chip);
  border-radius: var(--radius-md);
}

.unlock-history-stat dt {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}

.unlock-history-stat dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.unlock-heatmap-scroll {
  padding-bottom: var(--space-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.unlock-heatmap-scroll:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.unlock-heatmap {
  display: flex;
  gap: var(--space-1);
  min-inline-size: 30rem;
}

.unlock-heatmap-weekdays,
.unlock-heatmap-grid {
  display: grid;
  grid-template-rows: 1rem repeat(7, auto);
  gap: 2px;
}

.unlock-heatmap-weekdays {
  font-size: var(--text-xs);
  line-height: 1;
  color: var(--text-faint);
}

.unlock-heatmap-weekdays span {
  display: flex;
  align-items: center;
}

.unlock-heatmap-grid {
  flex: 1;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
}

.unlock-heatmap-month {
  font-size: var(--text-xs);
  line-height: 1;
  white-space: nowrap;
  color: var(--text-secondary);
}

.unlock-heatmap-cell,
.unlock-heatmap-gap {
  display: block;
  aspect-ratio: 1;
  min-inline-size: .4rem;
}

.unlock-heatmap-cell {
  background: var(--heat-0);
  border-radius: var(--radius-xs);
  box-shadow: inset 0 0 0 1px var(--heat-outline);
}

.unlock-heat-1 { background: var(--heat-1); }
.unlock-heat-2 { background: var(--heat-2); }
.unlock-heat-3 { background: var(--heat-3); }
.unlock-heat-4 { background: var(--heat-4); }

.unlock-heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.unlock-heatmap-legend .unlock-heatmap-cell {
  inline-size: .75rem;
  min-inline-size: 0;
}

@media (max-width: 480px) {
  .unlock-history-stats {
    grid-template-columns: 1fr;
  }
}

/* The split layout, the stats card and its icons: only the Achievements page uses them. */
/* Stats Card Widget */
.stats-card::before {
  background: var(--gradient-primary);
}

/* Layout: one column on phones, in phone order. Desktop pairs the cards in two columns that end
   together: Closest to 100% spans Easiest missing and Perfect games (Perfect games takes up any
   difference), and Unlock history runs across the page. A card the grid stretches centres its content (charts, tiles) or keeps its list on top. */
.achievements-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--layout-gutter);
}

.achievements-grid > section,
.achievements-grid turbo-frame {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

.achievements-grid > section > *,
.achievements-grid turbo-frame > * {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

@media (min-width: 1200px) {
  .achievements-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas:
      "overview rarity"
      "closest easiest"
      "closest perfect"
      "rarest recent"
      "history history";
  }

  .ach-overview-area { grid-area: overview; }
  .ach-rarity-area { grid-area: rarity; }
  .ach-closest-area { grid-area: closest; }
  .ach-easiest-area { grid-area: easiest; }
  .ach-perfect-area { grid-area: perfect; }
  .ach-rarest-area { grid-area: rarest; }
  .ach-recent-area { grid-area: recent; }
  .ach-history-area { grid-area: history; }

  .achievements-stats {
    flex: 1;
  }

  .achievements-stats .achievements-stat-item {
    justify-content: center;
  }

  .ach-rarity-area .rarity-breakdown,
  .crown-jewels-card .quincunx-grid {
    margin-block: auto;
  }
}

/* Fade-in Animation */
.animate-fade-in {
  animation: fade-in 0.4s ease-out forwards;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

