<section class="character-main character-main-{{ifThen isPlayMode 'play' 'edit'}}">
  <fieldset>
    <legend>{{localize "OATHHAMMER.Label.Character"}}</legend>
    <div class="character-pc character-pc-{{ifThen isPlayMode 'play' 'edit'}}">

      {{!-- Portrait column --}}
      <div class="character-portrait">
        <img class="actor-img" src="{{actor.img}}" data-edit="img" data-action="editImage" data-tooltip="{{actor.name}}" />
      </div>

      {{!-- Right column: name + identity + stats band --}}
      <div class="character-right">

        {{!-- Row 1: Name + toggle --}}
        <div class="character-name">
          {{formInput fields.name value=source.name rootId=partId disabled=isPlayMode}}
          <a class="control" data-action="toggleSheet" data-tooltip="OATHHAMMER.ToggleSheet" data-tooltip-direction="UP">
            <i class="fa-solid fa-user-{{ifThen isPlayMode 'lock' 'pen'}}"></i>
          </a>
        </div>

        {{!-- Row 2: Identity bar (lineage + class + level/xp) --}}
        <div class="character-identity-bar">
          <div class="identity-slot lineage-slot">
            <i class="fa-solid fa-person slot-icon"></i>
            {{formInput systemFields.lineage.fields.name value=system.lineage.name name="system.lineage.name" placeholder=(localize "OATHHAMMER.Label.Lineage") disabled=isPlayMode}}
          </div>
          <div class="identity-slot class-slot {{#unless characterClass}}empty{{/unless}}" data-drop-type="class">
            {{#if characterClass}}
            <img src="{{characterClass.img}}" class="identity-img" data-item-id="{{characterClass.id}}" data-item-uuid="{{characterClass.uuid}}" />
            <a class="identity-name class-open-link" data-action="edit" data-item-id="{{characterClass.id}}" data-item-uuid="{{characterClass.uuid}}" data-tooltip="{{localize 'OATHHAMMER.Label.OpenClass'}}">{{characterClass.name}}</a>
            {{#unless isPlayMode}}
            <a data-action="delete" data-item-id="{{characterClass.id}}" data-item-uuid="{{characterClass.uuid}}"><i class="fa-solid fa-trash"></i></a>
            {{/unless}}
            {{else}}
            <i class="fa-solid fa-shield-halved slot-icon"></i>
            <span class="slot-placeholder">{{localize "OATHHAMMER.Label.DropClass"}}</span>
            {{/if}}
          </div>
          <div class="identity-xp">
            <span class="xp-label">{{localize "OATHHAMMER.Label.XP"}}</span>
            {{formInput systemFields.experience.fields.current value=system.experience.current name="system.experience.current" disabled=isPlayMode}}
            <span class="xp-sep">/</span>
            {{formInput systemFields.experience.fields.total value=system.experience.total name="system.experience.total" disabled=isPlayMode}}
          </div>
        </div>

        {{!-- Row 3: Unified stats band: resources | attributes --}}
        <div class="character-stats-band">
          <fieldset class="character-resources">
            <div class="character-resource">
              <span class="resource-label">{{localize "OATHHAMMER.Label.Grit"}}</span>
              <div class="grit-stepper">
                <a data-action="adjustGrit" data-delta="-1" class="grit-btn">−</a>
                {{formInput systemFields.grit.fields.value value=system.grit.value name="system.grit.value"}}
                <a data-action="adjustGrit" data-delta="1" class="grit-btn">+</a>
              </div>
              <span class="res-sep">/</span>
              <span class="grit-max-group">
                {{formInput systemFields.grit.fields.max value=system.grit.max name="system.grit.max" disabled=true}}
                {{#unless isPlayMode}}
                  <span class="res-bonus-label">+</span>
                  {{formInput systemFields.grit.fields.bonus value=system.grit.bonus name="system.grit.bonus" class="res-bonus-input"}}
                {{/unless}}
              </span>
            </div>
            <div class="character-resource character-resource--luck">
              <span class="resource-label">{{localize "OATHHAMMER.Label.Luck"}}</span>
              <div class="luck-stepper">
                <a data-action="adjustLuck" data-delta="-1" class="luck-btn">−</a>
                {{formInput systemFields.luck.fields.value value=system.luck.value name="system.luck.value"}}
                <a data-action="adjustLuck" data-delta="1" class="luck-btn">+</a>
              </div>
              <span class="res-sep">/</span>
              {{formInput systemFields.luck.fields.max value=system.luck.max name="system.luck.max" disabled=isPlayMode}}
            </div>
            <div class="character-resource">
              <span class="resource-label">{{localize "OATHHAMMER.Label.Movement"}}</span>
              {{formInput systemFields.movement.fields.base value=system.movement.base name="system.movement.base" disabled=isPlayMode}}
            </div>
          </fieldset>

          <fieldset class="character-attributes character-attributes-{{ifThen isPlayMode 'play' 'edit'}}">
            <legend>{{localize "OATHHAMMER.Label.Attributes"}}</legend>
            <div class="attributes-grid">
              {{#each system.attributes as |attr key|}}
              <div class="attribute-box">
                <label>{{localize (concat "OATHHAMMER.Attribute." (capitalize key))}}</label>
                <input type="number" name="system.attributes.{{key}}.rank" value="{{attr.rank}}" min="1" max="4" {{#if ../isPlayMode}}disabled{{/if}}>
              </div>
              {{/each}}
            </div>
          </fieldset>
        </div>

      </div>
    </div>
  </fieldset>
</section>
