{# Stats paradigm: chrome.
   Ported element-by-element from tier2/genomes/chrome/horizon/github-profile-stats-card-v6.svg.
   495x260, material stack (envelope + well + rail), 4 centered metric columns,
   gradient activity bars with glow, horizon shelf. #}

{# MATERIAL STACK — every color below is genome-driven via CSS vars or
   template params plumbed through compose/resolver._profile_visual_context.
   Fallbacks preserve chrome's appearance when a genome omits a
   field, so the specimen card still renders identically. #}
<g clip-path="url(#{{ uid }}-clip)">
  <rect width="{{ stats_layout.width }}" height="{{ stats_layout.height }}" fill="url(#{{ uid }}-env)" filter="url(#{{ uid }}-bevel)"/>
  <rect x="{{ stats_layout.chrome_outer_rect.x }}" y="{{ stats_layout.chrome_outer_rect.y }}"
        width="{{ stats_layout.chrome_outer_rect.w }}" height="{{ stats_layout.chrome_outer_rect.h }}"
        rx="{{ stats_layout.chrome_outer_rect.rx }}" fill="none"
        stroke="var(--dna-surface-deep)" stroke-width="0.8"/>
  <rect x="{{ stats_layout.chrome_well_rect.x }}" y="{{ stats_layout.chrome_well_rect.y }}"
        width="{{ stats_layout.chrome_well_rect.w }}" height="{{ stats_layout.chrome_well_rect.h }}"
        rx="{{ stats_layout.chrome_well_rect.rx }}" fill="url(#{{ uid }}-well)"/>
  <rect x="{{ stats_layout.chrome_rail_rect.x }}" y="{{ stats_layout.chrome_rail_rect.y }}"
        width="{{ stats_layout.chrome_rail_rect.w }}" height="{{ stats_layout.chrome_rail_rect.h }}"
        fill="url(#{{ uid }}-env)" opacity="0.78"/>
  <rect x="{{ stats_layout.chrome_top_highlight_rect.x }}" y="{{ stats_layout.chrome_top_highlight_rect.y }}"
        width="{{ stats_layout.chrome_top_highlight_rect.w }}" height="{{ stats_layout.chrome_top_highlight_rect.h }}"
        rx="{{ stats_layout.chrome_top_highlight_rect.rx }}"
        fill="var(--dna-border-tint, rgba(91,163,212,0.14))" opacity="0.9"/>
  <rect x="{{ stats_layout.chrome_outer_rect.x }}" y="{{ stats_layout.chrome_outer_rect.y }}"
        width="{{ stats_layout.chrome_outer_rect.w }}" height="{{ stats_layout.chrome_outer_rect.h }}"
        rx="{{ stats_layout.chrome_outer_rect.rx }}" fill="none"
        stroke="url(#{{ uid }}-rim)" stroke-width="1.0"/>
</g>

{# ZONE 1: HERO #}
{# v0.3.9 Bug #2/#3: glyph fill consumes the variant's ``glyph_inner``
   chromatic (matches chrome badge + chrome chart, all three artifacts
   now share the same per-variant glyph color). Fallback to
   ``--dna-signal`` for genomes that don't declare per-variant glyph_inner. #}
{% if glyph_path %}
<g data-hw-zone="glyph" transform="translate({{ stats_layout.rects.chrome_glyph.x }},{{ stats_layout.rects.chrome_glyph.y }})">
  <svg viewBox="{{ glyph_viewbox }}" width="{{ stats_layout.rects.chrome_glyph.w }}" height="{{ stats_layout.rects.chrome_glyph.h }}">
    <path d="{{ glyph_path }}"{% if glyph_fill_rule %} fill-rule="{{ glyph_fill_rule }}"{% endif %} fill="var(--dna-glyph-inner, var(--dna-signal))"/>
  </svg>
</g>
{% endif %}
<text data-hw-zone="identity" class="{{ uid }}-identity" x="{{ stats_layout.texts.chrome_identity.x }}" y="{{ stats_layout.texts.chrome_identity.y }}"
  {%- if identity_text_length %} textLength="{{ identity_text_length }}" lengthAdjust="spacingAndGlyphs"{%- endif %}>{{ stats_username | xml_escape }}</text>

<text data-hw-zone="hero-value" class="{{ uid }}-hero" x="{{ stats_layout.texts.chrome_hero_value.x }}" y="{{ stats_layout.texts.chrome_hero_value.y }}">{{ stars_display | xml_escape }}</text>
<text data-hw-zone="hero-label" class="{{ uid }}-hero-label" x="{{ stats_layout.texts.chrome_hero_label.x }}" y="{{ stats_layout.texts.chrome_hero_label.y }}">{{ hero_caption | default('TOTAL STARS · LIFETIME') }}</text>

<line x1="{{ stats_layout.chrome_hero_rule.x1 }}" y1="{{ stats_layout.chrome_hero_rule.y1 }}"
      x2="{{ stats_layout.chrome_hero_rule.x2 }}" y2="{{ stats_layout.chrome_hero_rule.y2 }}"
      stroke="url(#{{ uid }}-sep)" stroke-width="0.8"/>

{# ZONE 2: METRICS — 4 centered columns, adaptive textLength per value.
   Column centers at 62/186/309/433, budget 112px (124px - 12px gutter).
   commits/prs/issues/streak_text_length is 0 when the value fits naturally,
   or the budget value when it would overflow — resolver computes this
   from a measure_text() call so the template just reads the decision. #}
  <g data-hw-zone="metrics">
  {% for slot in metric_layouts %}
  <g data-hw-zone="metric-{{ loop.index0 }}">
    <text class="{{ uid }}-mlabel" x="{{ slot.label_x }}" y="{{ slot.label_y }}" text-anchor="{{ slot.text_anchor }}">{{ slot.label_text | xml_escape }}</text>
    <text class="{{ uid }}-mval" x="{{ slot.value_x }}" y="{{ slot.value_y }}" text-anchor="{{ slot.text_anchor }}"
      {%- if slot.value_text_length %} textLength="{{ slot.value_text_length }}" lengthAdjust="spacingAndGlyphs"{%- endif %}>{{ slot.value_display | xml_escape }}</text>
  </g>
  {% endfor %}
  {% for divider_x in stats_layout.metric_divider_xs %}
  <line x1="{{ divider_x }}" y1="{{ stats_layout.lines.chrome_metric_divider_span.y1 }}"
        x2="{{ divider_x }}" y2="{{ stats_layout.lines.chrome_metric_divider_span.y2 }}"
        stroke="var(--dna-border-tint)" stroke-width="0.4"/>
  {% endfor %}
</g>

{# Horizon glow — genome highlight or signal. #}
<rect class="{{ uid }}-horizon" x="{{ stats_layout.rects.chrome_horizon.x }}" y="{{ stats_layout.rects.chrome_horizon.y }}"
      width="{{ stats_layout.rects.chrome_horizon.w }}" height="{{ stats_layout.rects.chrome_horizon.h }}"
      fill="{{ specular_light }}"
      filter="url(#{{ uid }}-horizon-glow)"/>

{# ZONE 3: ACTIVITY — dispatched by normalized activity type. #}
{% if activity %}
  <g data-hw-zone="activity">
  <text class="{{ uid }}-act-label" x="{{ stats_layout.texts.chrome_activity_label.x }}" y="{{ stats_layout.texts.chrome_activity_label.y }}">ACTIVITY · {% if activity.type == "sparkline_30d" %}30D{% else %}52W{% endif %}</text>
  <text class="{{ uid }}-act-label" x="{{ stats_layout.texts.chrome_activity_peak.x }}" y="{{ stats_layout.texts.chrome_activity_peak.y }}" text-anchor="{{ stats_layout.texts.chrome_activity_peak.anchor }}">{% if activity.type == "sparkline_30d" %}PEAK · {{ activity_peak_label | default('—') }}{% elif activity_peak > 0 %}{{ activity_peak }} CONTRIB/WK PEAK{% endif %}</text>

  <line x1="{{ stats_layout.chrome_activity_baseline.x1 }}" y1="{{ stats_layout.chrome_activity_baseline.y1 }}"
        x2="{{ stats_layout.chrome_activity_baseline.x2 }}" y2="{{ stats_layout.chrome_activity_baseline.y2 }}"
        stroke="var(--dna-border-tint)" stroke-width="0.4"/>

  {% if activity.type == "sparkline_30d" %}
    {% include "frames/stats/zones/activity-sparkline.j2" %}
  {% else %}
    {% set activity_group_opacity = "0.72" %}
    {% include "frames/stats/zones/activity-bars.j2" %}
  {% endif %}

  {% if activity_bars %}
  <g data-hw-zone="activity-present" transform="translate({{ stats_layout.activity_present_x }},{{ stats_layout.activity_present_y }})">
    <rect class="{{ uid }}-present" x="{{ stats_layout.rects.chrome_present.x }}" y="{{ stats_layout.rects.chrome_present.y }}"
          width="{{ stats_layout.rects.chrome_present.w }}" height="{{ stats_layout.rects.chrome_present.h }}"
          rx="{{ stats_layout.rects.chrome_present.rx }}" fill="{{ specular_light }}"/>
  </g>
  {% endif %}
</g>
{% endif %}

{# ZONE 4: FOOTER #}
<line x1="{{ stats_layout.chrome_footer_rule.x1 }}" y1="{{ stats_layout.chrome_footer_rule.y1 }}"
      x2="{{ stats_layout.chrome_footer_rule.x2 }}" y2="{{ stats_layout.chrome_footer_rule.y2 }}"
      stroke="url(#{{ uid }}-sep)" stroke-width="0.4" opacity="0.55"/>

<g data-hw-zone="status" transform="translate({{ stats_layout.rects.chrome_status_anchor.x }},{{ stats_layout.rects.chrome_status_anchor.y }})">
  <rect class="{{ uid }}-dia" x="{{ stats_layout.rects.chrome_status_diamond.x }}" y="{{ stats_layout.rects.chrome_status_diamond.y }}"
        width="{{ stats_layout.rects.chrome_status_diamond.w }}" height="{{ stats_layout.rects.chrome_status_diamond.h }}"
        rx="{{ stats_layout.rects.chrome_status_diamond.rx }}"
        transform="rotate(45)" fill="var(--hw-core, var(--dna-signal))"/>
</g>

<text data-hw-zone="subject-url" class="{{ uid }}-foot" x="{{ stats_layout.texts.chrome_footer_url.x }}" y="{{ stats_layout.texts.chrome_footer_url.y }}">{{ subject_url | default(stats_username | lower) | xml_escape }}</text>
<text data-hw-zone="brand" class="{{ uid }}-brand" x="{{ stats_layout.texts.chrome_footer_brand.x }}" y="{{ stats_layout.texts.chrome_footer_brand.y }}" text-anchor="{{ stats_layout.texts.chrome_footer_brand.anchor }}">HYPERWEAVE</text>
