{# Brutalist BADGE — DARK substrate.
   v0.3.3 calibrated against tier2/genomes/brutalist/brutalist-v03/
   hw-elegant-mono-badge-matrix-v16.html. Two flat panels (elevated over canvas)
   with a single state-colored separator at the seam; no inset perimeter
   stroke. Spatial values flow from compose/layout.py (left_panel_width, right_panel_x,
   indicator_x, inner_bit_w). The prototype's 158x20 geometry is reproduced
   when label="BUILD" + value="passing" — other labels/values reshape via
   measure_text but the chromatic and geometric contracts stay constant.

   Element contract (audited element-by-element against v16 prototype):

     Left panel  : brand_panel_fill (elevated panel tone).
                   Reads from brand_panel_fill JSON field — a badge/strip-
                   semantic field, NOT the genome-wide canvas (surface_0).
                   Decoupling preserves strip/stats canvas integrity.
     Right panel : surface_0 (canvas/ground tone). Same
                   value the strip/stats/chart use for their substrate.
     Seam gap    : --dna-seam-gap (fallback --dna-surface) fills the
                   geometric gap when resolver computes seam_w > 0; without
                   the rect the gap renders transparent and shows page
                   background through (white in light MD, dark in dark MD).
     Accent bar  : --dna-signal (chassis tone), 4px at x=0
     Separator   : --hw-state-sep (per-state) → passing=accent, warn=amber,
                   fail=red. 2px overlay at x=left_panel_width.
     Glyph       : currentColor (set via accent_w-anchored translate)
     Label       : --dna-ink-primary (cream/ink-bright per variant, celadon
                   genome ink role), weight 700, ls 0.06em. Distinct from --dna-
                   label-text (which carries the strip's muted accent — same
                   semantic role, different per-frame tonal needs).
     Value       : --hw-state-value (per-state) → passing=ink_secondary,
                   warn/fail state roles. Weight 700, ls 0.04em.
     Indicator   : --hw-state-ring stroke (1.5px) + --dna-status-color bit
                   (10x10 outer, 6x6 inner at offset 2).

   No perimeter stroke under the dark prototype's flat-plate aesthetic.
   The light variant keeps the perimeter (paper substrate needs the rule).
#}

<g clip-path="url(#{{ uid }}-clip)">
  <rect width="{{ left_panel_width }}" height="{{ h }}" fill="var(--dna-brand-panel-fill)"/>
  <rect x="{{ right_panel_draw_x }}" width="{{ right_panel_draw_w }}" height="{{ h }}" fill="var(--dna-surface)"/>
</g>
<rect x="{{ badge_origin_x }}" y="{{ badge_origin_y }}" width="{{ accent_w }}" height="{{ h }}" fill="var(--dna-signal)" data-hw-zone="accent-bar"/>
<rect x="{{ left_panel_width }}" y="{{ badge_origin_y }}" width="{{ sep_width }}" height="{{ h }}" fill="var(--hw-state-sep, var(--dna-signal))"/>
{% if seam_width > 0 %}
<rect x="{{ seam_gap_x }}" y="{{ badge_origin_y }}" width="{{ seam_width }}" height="{{ h }}" fill="var(--dna-seam-gap, var(--dna-surface))"/>
{% endif %}

{# Glyph #}
{% if has_glyph and glyph_svg %}
<g data-hw-zone="glyph" transform="translate({{ glyph_x }},{{ glyph_y }})">
  {{ glyph_svg | safe }}
</g>
{% endif %}

{# Label — weight 700 + 0.06em tracking, cream ink (--dna-ink-primary, not
   --dna-label-text) so badge gets the bright tone the prototype shows while
   the strip preserves its muted-accent label tone via --dna-label-text. #}
<text data-hw-zone="label"
      x="{{ label_x }}" y="{{ text_y }}"
      text-anchor="middle"
      font-family="var(--dna-font-mono, 'SF Mono', monospace)"
      font-size="11" font-weight="700"
      fill="var(--dna-ink-primary)"
      letter-spacing="0.06em"{% if label_text_length and label_text_length > 0 %} textLength="{{ label_text_length }}" lengthAdjust="spacingAndGlyphs"{% endif %}>{{ label_display | default(label | upper) }}</text>

{# Value — weight 700 + 0.04em tracking (lighter than label by design;
   prototype reserves the heavier 0.06em for the uppercase identifier and
   gives the lowercase state word a tighter, more readable track). #}
<text data-hw-zone="value"
      x="{{ value_x }}" y="{{ text_y }}"
      text-anchor="middle"
      font-family="var(--dna-font-mono, 'SF Mono', monospace)"
      font-size="11" font-weight="700"
      fill="var(--hw-state-value, var(--dna-brand-text))"
      letter-spacing="0.04em"{% if value_text_length and value_text_length > 0 %} textLength="{{ value_text_length }}" lengthAdjust="spacingAndGlyphs"{% endif %}>{{ value }}</text>

{# Status indicator — gated on resolver-supplied show_indicator (mode-driven).
   Brutalist anchors the indicator at the badge frame's vertical center
   (geometric, not text-baseline-pinned like cellular/chrome).
   stroke-width and inner-bit dimensions are paradigm-supplied:
   brutalist v0.3.3 ships 1.5 / 6 (0.6 ratio), matching the v16
   prototype's translate(138,5) → 10x10 ring + 6x6 bit at offset 2. #}
{% if show_indicator %}
{% set indicator_ring_class = "" %}
{% set indicator_ring_stroke = "var(--hw-state-ring, var(--dna-signal))" %}
{% set indicator_stroke_width_value = indicator_stroke_width %}
{% set indicator_bit_class = "hw-logic-bit" %}
{% set indicator_bit_fill = "var(--dna-status-color, var(--dna-signal))" %}
{% include "frames/badge/indicators/" ~ indicator_shape ~ "-indicator.j2" %}
{% endif %}

{# No state tint overlay: brutalist paradigm keeps the value zone flat --dna-surface-deep
   across all states. State color flows via text fill, separator bar, and status cube only —
   "truth to materials" — no decorative background wash. #}
