/* HeroesT3 — Material Design 3 layer (light, parchment palette).
   Tokens first; the vendored @material/web components (md3.js) read the --md-sys-* ones.
   Data tables are skinned by the selector list at the bottom: add a new table to it (or give it class="md-table"). */
:root {
  --md-sys-color-primary: #3f7d14;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #dcefc5;
  --md-sys-color-on-primary-container: #12310a;
  --md-sys-color-secondary: #6b5b2e;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #efe7cb;
  --md-sys-color-on-secondary-container: #3a2f12;
  --md-sys-color-surface: #fffef9;
  --md-sys-color-surface-container: #f6f0dc;
  --md-sys-color-surface-container-high: #efe7cb;
  --md-sys-color-on-surface: #2c2614;
  --md-sys-color-on-surface-variant: #5b5236;
  --md-sys-color-outline: #b9ad82;
  --md-sys-color-outline-variant: #d9cfae;
  --md-sys-color-error: #b3261e;
  --md-sys-shape-corner-small: 4px;
  --md-sys-shape-corner-medium: 12px;
  --md-elev-1: 0 1px 2px rgba(60, 48, 16, .18), 0 1px 3px 1px rgba(60, 48, 16, .10);
  --md-elev-2: 0 1px 2px rgba(60, 48, 16, .20), 0 2px 6px 2px rgba(60, 48, 16, .12);
  --md-sys-typescale-body: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif;
  --md-ref-typeface-brand: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif;
  --md-ref-typeface-plain: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif;
}

/* ---------- data tables (child combinators only, so tables nested inside them are left alone) ---------- */
table.md-table,
table.build_details,
table.under_progress,
table.troop_details,
table#troop_details,
table#troop_info,
table#distribution,
table.row_table_data,
table.troops,
table.attacker,
table.defender,
table.results,
table.raidList,
table#raidList,
table.researchFuture,
table#overview,
table.tbg {
  border-collapse: separate;
  border-spacing: 0;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-elev-1);
  overflow: hidden;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body);
}
table.md-table > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.md-table > tr > :is(th, td),
table.build_details > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.build_details > tr > :is(th, td),
table.under_progress > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.under_progress > tr > :is(th, td),
table.troop_details > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.troop_details > tr > :is(th, td),
table#troop_details > :is(thead, tbody, tfoot) > tr > :is(th, td),
table#troop_details > tr > :is(th, td),
table#troop_info > :is(thead, tbody, tfoot) > tr > :is(th, td),
table#troop_info > tr > :is(th, td),
table#distribution > :is(thead, tbody, tfoot) > tr > :is(th, td),
table#distribution > tr > :is(th, td),
table.row_table_data > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.row_table_data > tr > :is(th, td),
table.troops > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.troops > tr > :is(th, td),
table.attacker > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.attacker > tr > :is(th, td),
table.defender > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.defender > tr > :is(th, td),
table.results > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.results > tr > :is(th, td),
table.raidList > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.raidList > tr > :is(th, td),
table#raidList > :is(thead, tbody, tfoot) > tr > :is(th, td),
table#raidList > tr > :is(th, td),
table.researchFuture > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.researchFuture > tr > :is(th, td),
table#overview > :is(thead, tbody, tfoot) > tr > :is(th, td),
table#overview > tr > :is(th, td),
table.tbg > :is(thead, tbody, tfoot) > tr > :is(th, td),
table.tbg > tr > :is(th, td) {
  padding: 7px 10px;
  border: 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background: transparent;
  color: inherit;
}
table.md-table > thead > tr > :is(th, td),
table.build_details > thead > tr > :is(th, td),
table.under_progress > thead > tr > :is(th, td),
table.troop_details > thead > tr > :is(th, td),
table#troop_details > thead > tr > :is(th, td),
table#troop_info > thead > tr > :is(th, td),
table#distribution > thead > tr > :is(th, td),
table.row_table_data > thead > tr > :is(th, td),
table.troops > thead > tr > :is(th, td),
table.attacker > thead > tr > :is(th, td),
table.defender > thead > tr > :is(th, td),
table.results > thead > tr > :is(th, td),
table.raidList > thead > tr > :is(th, td),
table#raidList > thead > tr > :is(th, td),
table.researchFuture > thead > tr > :is(th, td),
table#overview > thead > tr > :is(th, td),
table.tbg > thead > tr > :is(th, td) {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 700;
  letter-spacing: .02em;
}
table.md-table > tbody > tr:last-child > :is(th, td),
table.build_details > tbody > tr:last-child > :is(th, td),
table.under_progress > tbody > tr:last-child > :is(th, td),
table.troop_details > tbody > tr:last-child > :is(th, td),
table#troop_details > tbody > tr:last-child > :is(th, td),
table#troop_info > tbody > tr:last-child > :is(th, td),
table#distribution > tbody > tr:last-child > :is(th, td),
table.row_table_data > tbody > tr:last-child > :is(th, td),
table.troops > tbody > tr:last-child > :is(th, td),
table.attacker > tbody > tr:last-child > :is(th, td),
table.defender > tbody > tr:last-child > :is(th, td),
table.results > tbody > tr:last-child > :is(th, td),
table.raidList > tbody > tr:last-child > :is(th, td),
table#raidList > tbody > tr:last-child > :is(th, td),
table.researchFuture > tbody > tr:last-child > :is(th, td),
table#overview > tbody > tr:last-child > :is(th, td),
table.tbg > tbody > tr:last-child > :is(th, td) {
  border-bottom: 0;
}
table.md-table > tbody > tr:hover > td,
table.build_details > tbody > tr:hover > td,
table.under_progress > tbody > tr:hover > td,
table.row_table_data > tbody > tr:hover > td,
table.troops > tbody > tr:hover > td,
table.raidList > tbody > tr:hover > td,
table#raidList > tbody > tr:hover > td,
table#distribution > tbody > tr:hover > td,
table.researchFuture > tbody > tr:hover > td {
  background: var(--md-sys-color-primary-container);
}

/* ---------- controls (@material/web): compact, parchment-friendly sizes ---------- */
md-filled-button, md-outlined-button, md-text-button, md-filled-tonal-button {
  --md-filled-button-container-height: 32px;
  --md-outlined-button-container-height: 32px;
  --md-text-button-container-height: 32px;
  --md-filled-tonal-button-container-height: 32px;
  --md-filled-button-label-text-size: 13px;
  --md-outlined-button-label-text-size: 13px;
  --md-text-button-label-text-size: 13px;
  --md-filled-tonal-button-label-text-size: 13px;
  --md-filled-button-container-shape: 16px;
  --md-outlined-button-container-shape: 16px;
  --md-text-button-container-shape: 16px;
  --md-filled-tonal-button-container-shape: 16px;
  --md-filled-button-leading-space: 14px; --md-filled-button-trailing-space: 14px;
  --md-outlined-button-leading-space: 14px; --md-outlined-button-trailing-space: 14px;
  --md-filled-tonal-button-leading-space: 12px; --md-filled-tonal-button-trailing-space: 12px;
  --md-outlined-button-outline-color: var(--md-sys-color-outline);
  vertical-align: middle;
}

/* ---------- native controls restyled to match (no markup change): buttons, text fields, selects ---------- */
.trav_buttons, button.trav_buttons, input[type="submit"].trav_buttons,
div#content input[type="submit"], div#content input[type="button"] {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 16px;
  border: 0; border-radius: 16px;
  background: var(--md-sys-color-primary) !important;
  background-image: none !important;
  color: var(--md-sys-color-on-primary) !important;
  font: 700 13px/1 var(--md-ref-typeface-plain);
  letter-spacing: .02em; text-shadow: none; text-decoration: none;
  box-shadow: var(--md-elev-1);
  cursor: pointer;
  transition: box-shadow .15s ease, filter .15s ease;
}
.trav_buttons:hover, div#content input[type="submit"]:hover, div#content input[type="button"]:hover {
  filter: brightness(1.08); box-shadow: var(--md-elev-2);
}
.trav_buttons:active { filter: brightness(.95); box-shadow: none; }
.trav_buttons:disabled, .trav_buttons[disabled] {
  background: var(--md-sys-color-surface-container-high) !important;
  color: var(--md-sys-color-on-surface-variant) !important;
  box-shadow: none; cursor: default; filter: none;
}
.trav_buttons::after { display: none !important; }

div#content :is(input.text, input[type="text"], input[type="password"], input[type="number"], input[type="email"], textarea, select) {
  box-sizing: content-box; /* the widths set by the old stylesheets keep meaning the text area */
  min-height: 16px; padding: 3px 6px;
  border: 1px solid var(--md-sys-color-outline); border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body);
  transition: border-color .15s ease, box-shadow .15s ease;
}
div#content :is(input.text, input[type="text"], input[type="password"], input[type="number"], input[type="email"], textarea, select):focus {
  outline: 0; border-color: var(--md-sys-color-primary); box-shadow: 0 0 0 2px rgba(63, 125, 20, .25);
}

/* the hero that goes with the army (send form) */
.ht3-goes { display: inline-block; margin-left: 6px; padding: 1px 10px; border-radius: 12px; background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); font-size: 12px; white-space: nowrap; }

/* troop counts in the send form: room for 6 digits (armies can exceed 1000) */
div.a2b table#troops input.text, div#build table#raidTroops input.text { width: 46px; text-align: right; font-size: 13px; }

/* hero star in the send form: the name of the hero that goes opens as a bubble on click */
.ht3-hwrap { position: relative; display: inline; } /* inline, so the star sits on the line like the other unit icons */
.ht3-hwrap .ht3-goes { position: absolute; left: 0; bottom: 100%; margin: 0 0 6px; z-index: 20; box-shadow: var(--md-elev-2); }
.ht3-hwrap .ht3-goes::after { content: ""; position: absolute; left: 10px; top: 100%; border: 5px solid transparent; border-top-color: var(--md-sys-color-primary-container); }

/* send form: target selection laid out on one grid, one size for labels and fields */
div.a2b table#coords { margin: 10px 0 8px 0; border-collapse: separate; border-spacing: 0 2px; background: transparent; border: 0; box-shadow: none; }
div.a2b table#coords td { padding: 2px 6px; vertical-align: middle; height: 26px; background: transparent !important; border: 0; }
div.a2b table#coords td.sel { white-space: nowrap; }
div.a2b table#coords td.sel label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
div.a2b table#coords td.sel input.radio { margin: 0; width: 14px; height: 14px; accent-color: var(--md-sys-color-primary); position: static; }
div.a2b table#coords td.vil, div.a2b table#coords td.target { white-space: nowrap; font-size: 13px; }
div.a2b table#coords td.vil *, div.a2b table#coords td.target * { font-size: 13px; vertical-align: middle; }
div.a2b table#coords td.vil span, div.a2b table#coords td.target span { display: inline-block; min-width: 14px; font-weight: 700; color: var(--md-sys-color-on-surface-variant); }
div.a2b table#coords td.vil input.text { width: 140px; }
div.a2b table#coords td.target input.text { width: 40px; margin-right: 10px; text-align: center; }
div.a2b table#coords td.or { font-size: 12px; font-style: italic; color: var(--md-sys-color-on-surface-variant); }
div.a2b table#coords input.text { min-height: 16px; padding: 2px 6px; }
div.a2b table#coords { border-spacing: 0; line-height: 18px; }
div.a2b table#coords tr { height: 28px; }
div.a2b table#coords td { height: 28px; padding: 0 6px; }
div.a2b table#coords td.vil *, div.a2b table#coords td.target * { float: none; margin-right: 0; }
div.a2b table#coords td.target input.text { margin-right: 8px; }

/* send form: the unit-input table looks like the confirmation table (same surface, border, row lines, no zebra) */
div.a2b table#troops {
  border-collapse: separate; border-spacing: 0;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-elev-1);
  overflow: hidden;
  width: 100%;
}
div.a2b table#troops > tbody > tr > td, div.a2b table#troops > tr > td {
  background: transparent !important;
  border: 0; border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 6px 10px; vertical-align: middle;
}
div.a2b table#troops > tbody > tr:last-child > td { border-bottom: 0; }

/* send / confirm: every block on these pages is the same card (surface, 1px border, 12px corners, soft shadow) */
div.a2b table#coords, div.a2b table#short_info {
  border-collapse: separate; border-spacing: 0;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-elev-1);
  overflow: hidden;
  width: 100%;
  margin: 10px 0;
}
div.a2b table#coords td { border-bottom: 1px solid var(--md-sys-color-outline-variant); padding: 0 10px; }
div.a2b table#coords tr:last-child > td { border-bottom: 0; }
div.a2b table#short_info td, div.a2b table#short_info th { background: transparent !important; padding: 6px 10px; border: 0; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
div.a2b table#short_info tr:last-child > td, div.a2b table#short_info tr:last-child > th { border-bottom: 0; }
div.a2b table#short_info th { background: var(--md-sys-color-surface-container) !important; width: 110px; }
/* the stripe on the 'Arrived' row is not wanted: no zebra on the confirmation table */
div.a2b table.troop_details > tbody > tr > td { background: transparent !important; }
div.a2b table#troops, div.a2b table#coords, div.a2b table.troop_details { margin-top: 10px; margin-bottom: 10px; }
/* send form: the caption row of the unit table, like the header of the confirmation table */
div.a2b table#troops > thead > tr > th {
  background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-secondary-container);
  font-weight: 700; text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

/* reports: the attacker and every defender / reinforcement table are the same card with the same compact rows */
div.reports td.report_content :is(table#attacker, table.defender, table#reinforcement, table.reinforcement, table.prisoners) {
  border-collapse: separate; border-spacing: 0;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-elev-1);
  overflow: hidden;
  font: 14px/1.3 var(--md-ref-typeface-plain);
}
div.reports td.report_content :is(table#attacker, table.defender, table#reinforcement, table.reinforcement, table.prisoners) > :is(thead, tbody, tfoot) > tr > :is(th, td) {
  padding: 5px 10px; height: auto; line-height: 1.3; font-size: 14px;
  border: 0; border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
div.reports td.report_content :is(table#attacker, table.defender, table#reinforcement, table.reinforcement, table.prisoners) > :is(thead, tbody, tfoot) > tr:last-child > :is(th, td) { border-bottom: 0; }
div.reports td.report_content :is(table#attacker, table.defender) > thead > tr > :is(th, td) { background: var(--md-sys-color-surface-container-high); font-weight: 700; }
div.reports td.report_content :is(table#attacker, table.defender) > tbody > tr > th { background: var(--md-sys-color-surface-container); font-weight: 700; width: 110px; }
div.reports td.report_content :is(table#attacker, table.defender) { margin-bottom: 12px; }

/* one text face for the whole game: Spectral for text, tables and controls; Cinzel stays for headings */
div#content :is(table, th, td, p, label, span, a, li, input, select, textarea, button) { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif; }
div#content :is(h1, h2, h3, h4) { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif; }
md-filled-button, md-outlined-button, md-text-button, md-filled-tonal-button, .trav_buttons { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "DejaVu Sans", sans-serif; font-weight: 700; }

/* headings: same face, a little heavier */
div#content :is(h1, h2, h3, h4), .ht3-title { font-weight: 700; letter-spacing: .01em; }

/* send form: the option cells (Normal attack / Raid / Reinforcement) are coloured like the 'Troops' caption row */
div.a2b table#coords td.sel {
  background: var(--md-sys-color-surface-container-high) !important;
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 700;
  width: 38%;
}
div.a2b table#coords td.sel label { font-weight: 700; }
/* same colours as the table captions of the theme (--tint / --heading) */
div.a2b table#coords td.sel { background: var(--tint) !important; color: var(--heading) !important; }
div.a2b table#coords td.sel label { color: var(--heading) !important; }

/* marketplace: the same card as the send-troops form for every block */
div#build.gid17 :is(table#send_select, table#target_select, table#target_validate, table.traders, table#sell, table#buy, table#range, table#offers, table.send_res, table.res_target) {
  border-collapse: separate; border-spacing: 0;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-elev-1);
  overflow: hidden;
  width: 100%;
  margin: 10px 0;
}
div#build.gid17 :is(table#send_select, table#target_select, table#target_validate, table.traders, table#sell, table#buy, table#range, table#offers, table.send_res, table.res_target) > :is(thead, tbody, tfoot) > tr > :is(th, td),
div#build.gid17 :is(table#send_select, table#target_select, table#target_validate, table.traders, table#sell, table#buy, table#range, table#offers, table.send_res, table.res_target) > tr > :is(th, td) {
  padding: 6px 10px; vertical-align: middle; height: auto;
  border: 0; border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
div#build.gid17 :is(table#send_select, table#target_select, table#target_validate, table.traders, table#sell, table#buy, table#range, table#offers, table.send_res, table.res_target) > :is(thead, tbody, tfoot) > tr:last-child > :is(th, td) { border-bottom: 0; }
/* label cells and caption rows: the theme's caption colours */
div#build.gid17 :is(table#target_validate, table.traders, table#sell, table#buy, table#range, table#offers) th,
div#build.gid17 table.traders > thead > tr > td { background: var(--tint) !important; color: var(--heading) !important; font-weight: 700; }

/* marketplace offers (Buy tab): even rows, names on one line, the action is a button, unavailable offers are muted */
div#build.gid17 table#range td { height: 44px; padding: 4px 10px; font-size: 14px; white-space: nowrap; }
div#build.gid17 table#range td.pla { white-space: nowrap; font-weight: 700; }
div#build.gid17 table#range td.act { text-align: center; }
div#build.gid17 table#range td.act a {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 28px; padding: 0 14px; border-radius: 16px;
  background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary) !important;
  font-size: 13px; font-weight: 700; text-decoration: none; box-shadow: var(--md-elev-1);
}
div#build.gid17 table#range td.act a:hover { filter: brightness(1.08); text-decoration: none; }
div#build.gid17 table#range td.act.none { font-size: 12px; font-weight: 400; color: var(--md-sys-color-on-surface-variant); }
div#build.gid17 table#range tbody tr:nth-child(even) > td { background: transparent !important; }

/* ---------- hero inventory as a character sheet ---------- */
.ht3-sheet { display: flex; gap: 14px; flex-wrap: wrap; align-items: stretch; margin: 10px 0; }
.ht3-paper {
  flex: 1 1 340px; display: grid; gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas: ". helmet portrait" "right body left" "horse shoes .";
  padding: 12px; background: var(--md-sys-color-surface); border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium); box-shadow: var(--md-elev-1);
}
.ht3-slot-helmet { grid-area: helmet; } .ht3-slot-body { grid-area: body; } .ht3-slot-right { grid-area: right; }
.ht3-slot-left { grid-area: left; } .ht3-slot-shoes { grid-area: shoes; } .ht3-slot-horse { grid-area: horse; }
.ht3-portrait { grid-area: portrait; }
.ht3-slot {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  min-height: 112px; padding: 8px 6px; border: 1px dashed var(--md-sys-color-outline); border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container); font-size: 12px;
}
.ht3-slot.has { border-style: solid; background: var(--md-sys-color-primary-container); border-color: #9bc47a; }
.ht3-slot-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--heading); }
.ht3-slot-name { font-weight: 700; line-height: 1.2; }
.ht3-slot-empty { margin-top: 18px; font-size: 22px; color: var(--md-sys-color-outline); }
.ht3-portrait { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px; border-radius: var(--md-sys-shape-corner-medium); background: var(--tint); color: var(--heading); text-align: center; }
.ht3-portrait span { font-size: 12px; }
.ht3-sheet-side { flex: 1 1 200px; padding: 12px; background: var(--md-sys-color-surface); border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-sys-shape-corner-medium); box-shadow: var(--md-elev-1); }
.ht3-sheet-title { font-weight: 700; color: var(--heading); margin-bottom: 6px; }
.ht3-bag-title { margin: 14px 0 6px; }
.ht3-bonus { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--md-sys-color-outline-variant); font-size: 13px; }
.ht3-bonus:last-child { border-bottom: 0; } .ht3-bonus span { color: var(--md-sys-color-on-surface-variant); font-size: 12px; }
.ht3-tier { display: inline-block; padding: 0 6px; border-radius: 8px; font-size: 11px; font-weight: 700; background: #e6dcbc; color: #4a3f22; }
.ht3-tier.t2 { background: #cfe3f5; color: #1d4a73; } .ht3-tier.t3 { background: #f3d9a8; color: #7a4b00; }
.ht3-qty { display: inline-block; padding: 0 6px; border-radius: 8px; font-size: 11px; font-weight: 700; background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.ht3-bag { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.ht3-card { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 10px; background: var(--md-sys-color-surface); border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--md-sys-shape-corner-medium); box-shadow: var(--md-elev-1); }
.ht3-card-head { display: flex; align-items: center; gap: 8px; }
.ht3-card-name { font-weight: 700; line-height: 1.2; } .ht3-card-meta { font-size: 12px; color: var(--md-sys-color-on-surface-variant); display: flex; gap: 6px; align-items: center; }
.ht3-card-act { margin: 0; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.ht3-card-act input[type="text"] { width: 30px; }
.ht3-bag-empty { grid-column: 1 / -1; padding: 12px; color: var(--md-sys-color-on-surface-variant); }
/* character sheet, second pass: symmetric layout, tighter slots, a proper portrait */
.ht3-paper { grid-template-areas: "portrait helmet horse" "right body left" ". shoes ."; }
.ht3-slot { min-height: 96px; padding: 6px; }
.ht3-slot-empty { margin-top: 10px; font-size: 18px; }
.ht3-portrait { border: 1px solid var(--md-sys-color-outline-variant); gap: 6px; }
.ht3-portrait img.unit { transform: scale(1.7); margin: 8px 0 6px; }
.ht3-portrait b { font-size: 15px; }

/* character sheet, third pass: condensed tiles, 'take off' is an X in the corner of the tile */
.ht3-paper { gap: 6px; padding: 8px; }
.ht3-slot { position: relative; min-height: 70px; padding: 4px 4px 6px; gap: 2px; }
.ht3-slot-label { font-size: 10px; }
.ht3-slot-item { line-height: 0; }
.ht3-slot-name { font-size: 12px; line-height: 1.15; }
.ht3-slot-empty { margin-top: 6px; font-size: 16px; }
.ht3-portrait { padding: 4px; gap: 2px; }
.ht3-portrait img.unit { transform: scale(1.3); margin: 4px 0 2px; }
.ht3-portrait b { font-size: 14px; }
.ht3-x-form { position: absolute; top: 3px; right: 3px; margin: 0; }
.ht3-x { appearance: none; display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 1px solid var(--md-sys-color-outline); border-radius: 50%; background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface-variant); font: 700 14px/1 var(--md-ref-typeface-plain); cursor: pointer; }
.ht3-x:hover { background: var(--md-sys-color-error); border-color: var(--md-sys-color-error); color: #fff; }
.ht3-sheet-side { padding: 8px 12px; }
.ht3-bonus { padding: 4px 0; }
.ht3-price { margin-right: auto; font-weight: 700; color: var(--heading); font-size: 13px; }
.ht3-tier.t4 { background: #e3d0f3; color: #5a2a85; } .ht3-tier.t5 { background: #f6c9c4; color: #8a1c10; }
.ht3-tier.t6 { background: linear-gradient(135deg, #f7d774, #e08a1e); color: #4a2a00; }
/* glow frames by tier: grey, green, blue, purple, red, gold */
.heroT4Item.tier1 { border-radius: 6px; box-shadow: 0 0 0 1px #a8a8a8, 0 0 4px #c8c8c8; }
.heroT4Item.tier2 { border-radius: 6px; box-shadow: 0 0 0 2px #4f9a3c, 0 0 6px #8fd079; }
.heroT4Item.tier3 { border-radius: 6px; box-shadow: 0 0 0 2px #2f78c4, 0 0 7px #7db7ee; }
.heroT4Item.tier4 { border-radius: 6px; box-shadow: 0 0 0 2px #8e5cc0, 0 0 8px #c4a0e8; }
.heroT4Item.tier5 { border-radius: 6px; box-shadow: 0 0 0 2px #c0392b, 0 0 9px #ee9a8e; }
.heroT4Item.tier6 { border-radius: 6px; box-shadow: 0 0 0 2px #e0a21a, 0 0 12px 2px #f7d774; }
/* marketplace filters: the active filter is clearly marked, a click on it again clears it */
p.ht3-filter-reset { margin: 6px 0; font-size: 13px; }
/* marketplace buy: filter bar (icon chips) and offers table */
.ht3-filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 12px 0 10px; padding: 10px 14px 12px; background: #fbf4e4; border-radius: 14px; border: 1px solid #e6d6b0; box-shadow: 0 1px 2px rgba(90,58,18,.12); }
.ht3-fgroup { display: flex; flex-direction: column; }
.ht3-flabel { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; font-weight: 700; color: #8a6a35; margin: 0 0 5px 4px; }
.ht3-fchips { display: flex; gap: 6px; }
a.ht3-fchip { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 36px; padding: 0 8px; border-radius: 18px; border: 1px solid #d7c196; background: #fffdf8; color: #3b2a12; text-decoration: none; font-size: 13px; font-weight: 700; line-height: 1; box-sizing: border-box; transition: background .12s, box-shadow .12s; }
a.ht3-fchip:hover { background: #f4e6c6; }
a.ht3-fchip.on { background: #e7c883; border-color: #a86a0a; box-shadow: 0 0 0 2px rgba(168,106,10,.35); }
a.ht3-fchip img { flex: none; }
.ht3-fmid { margin: 0 2px; }
p.ht3-filter-reset { margin: 4px 0 8px; font-size: 13px; }
p.ht3-filter-reset a { color: #8a1c10; text-decoration: none; font-weight: 700; }
div#build.gid17 table#range { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid #e6d6b0; border-radius: 12px; overflow: hidden; background: #fffdf8; }
div#build.gid17 table#range thead th { background: #f0e2c0; color: #5a3a12; padding: 8px; font-size: 15px; }
div#build.gid17 table#range thead td { background: #f7edd5; color: #8a6a35; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; }
div#build.gid17 table#range tbody td { padding: 7px 8px; border-top: 1px solid #f0e6cf; }
div#build.gid17 table#range tbody tr:nth-child(even) td { background: #fbf6ea; }
div#build.gid17 table#range tbody tr:hover td { background: #f6ebd0; }
div#build.gid17 table#range td.act a { display: inline-block; padding: 4px 12px; border-radius: 14px; background: #5f9b2e; color: #fff !important; text-decoration: none; font-weight: 700; font-size: 12px; }
div#build.gid17 table#range td.act.none { color: #a08a62; font-size: 12px; }

/* ===== Hero's Mansion on a phone: everything fits the width ===== */
@media (max-width: 700px) {
    div#build.gid37 { width: auto !important; max-width: 100%; min-width: 0; box-sizing: border-box; overflow-x: hidden; }
    div#build.gid37 table { width: 100% !important; max-width: 100%; }
    div#build.gid37 .ht3-hsec { flex-wrap: wrap; }
    /* hero tab */
    .t4h-wrap { max-width: 100%; }
    .t4h-panel { padding: 10px 10px 6px; }
    .t4h-head { flex-wrap: wrap; }
    .t4h-title { flex-wrap: wrap; white-space: normal; }
    .t4h-name { width: auto; min-width: 64px; white-space: normal; }
    .t4h-val, .t4h-num, .t4h-up { width: auto; }
    .t4h-barcell { width: auto; min-width: 44px; }
    .t4h-tbl td { padding: 5px 3px; }
    /* adventures tab: every offer is a small card */
    div#build.gid37 table#distribution thead td { display: none; }
    div#build.gid37 table#distribution tbody, div#build.gid37 table#distribution tbody tr { display: block; width: 100%; }
    div#build.gid37 table#distribution tbody tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 6px; border-bottom: 1px solid #e6dcbc; box-sizing: border-box; }
    div#build.gid37 table#distribution tbody td { display: block; width: auto !important; padding: 0 !important; border: 0 !important; background: none !important; }
    div#build.gid37 table#distribution tbody tr td:first-child { flex: 1 1 100%; }
    div#build.gid37 table#distribution tbody td[colspan] { flex: 1 1 100%; }
    /* inventory / shop cards */
    .ht3-bag { grid-template-columns: 1fr !important; }
    .ht3-sheet { flex-wrap: wrap; }
    .ht3-paper { max-width: 100%; }
}
a.ht3-inc-own { font-weight: 700; text-decoration: underline dotted; }

/* ===== top bar + resource strip in ONE sticky container (#header); thinner after scrolling (class set by Templates/res.tpl) ===== */
div#header { flex-wrap: wrap; row-gap: 0; }
div#header > div#res { flex: 1 1 100%; order: 10; position: static !important; background: none; box-shadow: none; padding: 0 0 2px !important; margin: 0; }
@media (min-width: 701px) {
    body.ht3-scrolled div#header { zoom: .72; padding-left: max(16px, calc((100% - 1542px) / 2)); padding-right: max(16px, calc((100% - 1542px) / 2)); }
    body.ht3-scrolled div#header > div#res { padding-top: 0 !important; padding-bottom: 3px !important; margin-top: 0; }
    body.ht3-scrolled div#res td.ht3-res-val::after { display: none; }
    body.ht3-scrolled div#res td.ht3-res-val::before { align-self: center; margin-top: 0; }
    body.ht3-scrolled div#res td.ht3-res-val { padding-top: 0 !important; padding-bottom: 0 !important; line-height: 1; }
}

/* building pages: much less padding around #build (was 43px 25px inside a card that already pads 26px) */
div#content { padding: 16px 14px 18px !important; }
div#build { padding: 8px 6px 0 !important; width: auto !important; }
div#content { padding-top: 12px !important; }
div#build > h1 { margin-top: 0; padding-top: 0; }
/* the content card fills its 606px grid column (its fixed 552px width left a gap towards the village list once the padding got smaller) */
@media (min-width: 1101px) { div#mid > div#content { width: auto !important; } }
/* the level badges are links to their building: the strip is above the map layers and only the badges take clicks */
div.village2 div#village_map div#levels { z-index: 100 !important; pointer-events: none; }
div.village2 div#village_map div#levels div[data-bid] { pointer-events: auto; cursor: pointer; }
div.village1 div#village_map span.ht3-lvl { z-index: 120; cursor: pointer; pointer-events: auto; }
/* marketplace offers: a slim accept button that does not stretch the rows */
div#build.gid17 table#range tbody td { height: auto !important; padding: 3px 8px !important; }
div#build.gid17 table#range td.act a { display: inline-block !important; min-height: 0 !important; padding: 2px 12px !important; line-height: 1.3 !important; font-size: 12px !important; border-radius: 12px; box-shadow: none; }
