<style>
  .pagebreak {
    page-break-after: always;
    margin: 0;
    padding: 0;
    width: 8.5in;
    height: 11in;
    font-size: 10px;
    position: relative;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* Ensure consistent column widths */
  }

  th, td {
    border: 1px solid black;
    text-align: center;
    vertical-align: middle; /* Center-align text vertically */
    font-size: 8px; /* Reduce font size */
    padding: 1px;   /* Minimize padding */
    line-height: 1; /* Compact line spacing */
  }

  tbody {
    height: calc(100% - 50px); /* Adjust based on heading and footer content */
    display: table-row-group;
  }

  tr {
    height: 50px; /* Default row height */
  }

  tr.small-row {
    height: 15px; /* Smaller height for choice rows */
  }

  .fixed-width {
    width: 80px; /* Fixed width for specific columns */
    max-width: 80px;
    word-wrap: break-word; /* Wrap long content within the fixed width */
    overflow: hidden; /* Hide overflow if content is too long */
  }

  h4, p {
    margin: 0;
    padding: 2px; /* Minimized padding for text */
  }

  .narrow {
    height: 0.9in; /* Adjust for periods or content */
  }
</style>

<% @matches.each do |match| %>
<% w1 = @wrestlers_by_id[match.w1] %>
<% w2 = @wrestlers_by_id[match.w2] %>
<% w1_name = w1&.name || match.loser1_name %>
<% w2_name = w2&.name || match.loser2_name %>

<div class="pagebreak">
  <p><strong>Bout Number:</strong> <%= match.bout_number %> <strong>Weight Class:</strong> <%= match.weight.max %> <strong>Round:</strong> <%= match.round %> <strong>Bracket Position:</strong> <%= match.bracket_position %></p>
  <p><strong>Key: </strong>Takedown: T3, Escape: E1, Reversal: R2, Nearfall: N2 or N3 or N4, Stalling: S, Caution: C, Penalty Point: P1</p>

  <table>
    <thead>
      <tr class="small-row">
        <th class="fixed-width">Circle Winner</th>
        <th>
          <p><%= w1_name %>-<%= w1&.school&.name %></p>
        </th>
        <th>
          <p><%= w2_name %>-<%= w2&.school&.name %></p>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr class="small-row">
        <td class="fixed-width"></td>
        <td>red / green (circle one)</td>
        <td>red / green (circle one)</td>
      </tr>
      <% ['Period 1'].each do |period| %>
        <tr>
          <td class="fixed-width"><%= period %></td>
          <td class="narrow"></td>
          <td class="narrow"></td>
        </tr>
      <% end %>
      <% ['Period 2', 'Period 3'].each do |period| %>
        <tr class="small-row">
          <td class="fixed-width">Choice (if applicable)</td>
          <td>top / bottom / neutral / defer (circle one)</td>
          <td>top / bottom / neutral / defer (circle one)</td>
        </tr>
        <tr>
          <td class="fixed-width"><%= period %></td>
          <td class="narrow"></td>
          <td class="narrow"></td>
        </tr>
      <% end %>
      <% ['Overtime 1', 'Overtime 2', 'Overtime 3'].each do |period| %>
        <tr class="small-row">
          <td class="fixed-width">Choice (if applicable)</td>
          <td>top / bottom / neutral / defer (circle one)</td>
          <td>top / bottom / neutral / defer (circle one)</td>
        </tr>
        <tr class="small-row">
          <td class="fixed-width"><%= period %></td>
          <td class="narrow"></td>
          <td class="narrow"></td>
        </tr>
      <% end %>
      <tr class="small-row">
        <td class="fixed-width"><strong>Final Score</strong> (or pin time, default, disqualified, etc)</td>
        <td class="narrow"></td>
        <td class="narrow"></td>
      </tr>
    </tbody>
  </table>
</div>
<% end %>
