html.mid { --w-tech: 10rem; --w-count: 6.4rem; --w-res: 11rem; --w-rm: 2rem; }
html.mid fieldset.res { font-size: .84rem; padding: .5rem .55rem .55rem; }
html.mid .bl-long { display: none; }
html.mid .bl-short { display: inline; }
@media (min-width: 600px) {
  html.narrow.show-bld { --w-wood: 4.4rem; --w-food: 4.4rem; --w-gold: 4.4rem; --w-stone: 4.4rem; }
}
html.narrow .postimp-cell { display: none; }
html.narrow .postimp-alt { display: inline-flex; margin-bottom: .2rem; }
html.narrow .clear-techs-alt, html.narrow .clear-techs-alt[hidden] {
    display: inline-block;
    align-self: flex-start;
    margin-bottom: .2rem;
  }
html.narrow .sheet thead th { white-space: normal; overflow: visible; line-height: 1.15; vertical-align: bottom; }
html.narrow {
    --w-tech: 9.5rem;
    --w-count: 6.4rem;
    --w-wood: 5rem;
    --w-food: 5rem;
    --w-gold: 5rem;
    --w-stone: 5rem;
    --w-rm: 2rem;
  }
html.narrow .lanes {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas: "add add add add" "wood food gold stone";
  }
html.narrow .adder { grid-area: add; grid-column: 1 / -1; padding: .55rem .6rem .45rem; }
html.narrow fieldset.res.wood { grid-area: wood; border-left: 0; }
html.narrow fieldset.res.food { grid-area: food; }
html.narrow fieldset.res.gold { grid-area: gold; }
html.narrow fieldset.res.stone { grid-area: stone; }
html.narrow .food-grid { grid-template-columns: auto auto; column-gap: 1.6rem; }
html.narrow .others { display: grid; grid-template-columns: auto auto; column-gap: .9rem; align-content: start; }
html.narrow .meta-row { display: none; }
@media (max-width: 820px), (max-height: 520px) {
  html.narrow { --w-tech: 0px; }
  html.narrow .lane-bg > .tech-lane { display: none; }
  html.narrow .sheet-wrap { display: flex; flex-direction: column; }
  html.narrow .techs {
    position: static; width: auto; border-left: 0; border-bottom: 1px solid var(--rule);
    flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: .15rem 1rem;
    padding: .35rem .6rem; background: var(--surface); flex: none;
    position: relative; z-index: 1; order: -1;
  }
  html.narrow table.sheet { order: 0; }
  html.narrow #ut-list { flex-direction: row; flex-wrap: wrap; gap: .15rem 1rem; }
  html.narrow .techs .opt input { margin-top: 0; }
  html.narrow .grand-box {
    flex-direction: row;
    align-items: baseline;
    gap: .35rem;
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
  }
  html.narrow #grand { font-size: 1.15rem; }
  html.narrow .postimp-alt { margin: 0; font-size: .85rem; }
  html.narrow .clear-techs-alt, html.narrow .clear-techs-alt[hidden] {
    margin: 0;
    padding: .1rem .5rem;
    font-size: .75rem;
  }
  html.narrow .techs .opt { align-items: center; }
  html.narrow .te { display: none; }
}
@media (max-width: 599px) {
  html.narrow {
    --w-count: 3.9rem;
    --w-wood: 2.6rem;
    --w-food: 2.6rem;
    --w-gold: 2.6rem;
    --w-stone: 2.6rem;
    --w-rm: 1.6rem;
  }
  html.narrow .stepper { --sh: 1.45em; }
  html.narrow .stepper input { width: 1.8em; }
  html.narrow .sheet td.count, html.narrow .sheet td.bld-cell { padding: .2em .15em; }
  html.narrow .app {
    padding-left: max(.5rem, env(safe-area-inset-left, 0px));
    padding-right: max(.5rem, env(safe-area-inset-right, 0px));
    padding-top: .5rem;
    gap: .4rem;
  }
  html.narrow .top h1 { font-size: 1.2rem; flex: 1 1 auto; }
  html.narrow #reset, html.narrow #clear-civs { padding: .15rem .45rem; font-size: .75rem; }
  html.narrow .top { column-gap: .5rem; }
  html.narrow .top h1 { font-size: 1.1rem; flex: 0 1 auto; }
  html.narrow .clear-slot { flex: 1 1 auto; gap: .35rem; flex-wrap: wrap; row-gap: .25rem; justify-content: flex-end; }
  html.narrow .civpick label { font-size: .75rem; }
  html.narrow .tab { font-size: .8rem; padding: .25rem .4rem; }
  html.narrow .civbar { flex-wrap: wrap; font-size: .82rem; margin-top: 0; }
  html.narrow #civ-fx { flex-basis: 100%; }
  html.narrow .age { flex: 1 1 100%; flex-wrap: wrap; gap: .15rem .7rem; }
  html.narrow .age label { gap: .25rem; white-space: nowrap; }
  html.narrow fieldset.res { font-size: .8rem; padding: .4rem .3rem .45rem; }
  html.narrow fieldset.res .lg { flex-direction: column; align-items: flex-start; gap: 0; }
  html.narrow .lg strong { font-size: .95rem; line-height: 1.15; }
  html.narrow .src-sel { margin: 0 0 .15rem; padding: .04rem .15rem; font-size: .84em; }
  html.narrow .rate { font-size: .74rem; }
  html.narrow fieldset.res .opt {
    gap: .25rem;
    align-items: flex-start;
    white-space: normal;
    -webkit-hyphens: auto;
    hyphens: auto;
  }
  html.narrow fieldset.res .opt input { width: .85rem; height: .85rem; margin-top: .1rem; }
  html.narrow .food-grid { column-gap: .8rem; }
  html.narrow #relics, html.narrow #soldiers, html.narrow #garrison { row-gap: 0; }
  html.narrow #relics .stepper, html.narrow #soldiers .stepper, html.narrow #garrison .stepper { --sh: .95rem; }
  html.narrow #relics .stepper input { width: 1.3em; }
  html.narrow #soldiers .stepper input { width: 1.9em; }
  html.narrow #relics .relic-out, html.narrow #soldiers .relic-out, html.narrow #garrison .relic-out {
    font-size: .7rem;
    line-height: 1.1;
  }
  html.narrow .others { grid-template-columns: auto; }
  html.narrow .sheet th, html.narrow .sheet td { padding-left: .4em; padding-right: .4em; }
  html.narrow .long { display: none; }
  html.narrow .short { display: inline; }
  html.narrow .techs { font-size: .8rem; gap: .1rem .8rem; padding: .3rem .45rem; }
  html.narrow .adder-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  html.narrow .clear-techs-alt[hidden] { display: none; }
  html.narrow .gl-long { display: none; }
  html.narrow .gl-short { display: inline; }
  html.narrow .age { gap: .1rem .5rem; font-size: .76rem; }
  html.narrow .civpick .combo input { padding-top: .28rem; padding-bottom: .28rem; }
}
@media (max-width: 599px) {
  html.narrow.show-bld {
    --w-count: 3.5rem;
    --w-wood: 2.3rem;
    --w-food: 2.3rem;
    --w-gold: 2.3rem;
    --w-stone: 2.3rem;
    --w-rm: 1.4rem;
  }
  html.narrow.show-bld .stepper { --sh: 1.3em; }
  html.narrow.show-bld .stepper input { width: 1.55em; }
}
@media (max-height: 520px) {
  html.narrow .app { padding-top: .45rem; padding-bottom: .5rem; gap: .35rem; }
  html.narrow .top h1 { font-size: 1.1rem; }
  html.narrow #reset, html.narrow #clear-civs { padding: .15rem .45rem; font-size: .75rem; }
  html.narrow .tab { font-size: .8rem; padding: .25rem .5rem; }
  html.narrow .civpick label { font-size: .75rem; }
  html.narrow .civpick .combo input { padding-top: .28rem; padding-bottom: .28rem; }
  html.narrow .civbar { font-size: .82rem; margin-top: 0; }
  html.narrow #civ-fx { -webkit-line-clamp: 1; line-clamp: 1; }
  html.narrow fieldset.res { font-size: .8rem; padding: .35rem .45rem .4rem; }
  html.narrow .src-sel { margin: 0 0 .15rem; padding-top: .04rem; padding-bottom: .04rem; }
  html.narrow #relics .stepper, html.narrow #soldiers .stepper, html.narrow #garrison .stepper { --sh: .95rem; }
  html.narrow #relics .stepper input { width: 1.3em; }
  html.narrow #soldiers .stepper input { width: 1.9em; }
  html.narrow #relics .relic-out, html.narrow #soldiers .relic-out, html.narrow #garrison .relic-out {
    font-size: .7rem;
  }
}
:root.no-stone .sheet .stone { color: transparent; pointer-events: none; user-select: none; }
:root.no-stone .sheet tfoot td.stone { background: none; }
:root.no-stone fieldset.res.stone { visibility: hidden; }
:root.no-stone .lane-bg > .stone { background: none; }
#te-row, .te-box { display: none; }
html.tab-te #te-row { display: table-row; }
html.tab-te .te-box { display: flex; }
html.tab-te #rows, html.tab-te #tot-row, html.tab-te .grand-box, html.tab-te #consc-opt, html.tab-te #crane-opt,
html.tab-te #shipwright-opt,
html.tab-te .postimp-alt { display: none; }
html.tab-te .adder, html.tab-te .age, html.tab-te .postimp-cell .postimp-opt,
html.tab-te .sheet thead th:nth-child(-n+4) { visibility: hidden; }
html.tab-te .lane-bg > div:nth-child(-n+4) { border-left: 0; }
.sheet tfoot #te-row > * { border-top: 1px solid var(--rule); font-weight: 400; font-size: 1em; vertical-align: top; }
.sheet td.te-ages { padding: .45em .75em; }
.te-age { display: flex; align-items: center; gap: .45em; line-height: 1.6; white-space: nowrap; cursor: pointer; }
.te-age input { margin: 0; accent-color: var(--focus); cursor: pointer; }
.te-age input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.te-age .mod { text-decoration: underline dotted; text-underline-offset: 2px; }
.te-after-wrap { display: inline-grid; }
.te-after-wrap > * { grid-area: 1 / 1; }
.te-after-size {
  visibility: hidden;
  white-space: pre;
  height: 0;
  min-width: 2.15em;
  box-sizing: border-box;
  padding: 0 .15em;
  border: solid transparent;
  border-width: 0 1px;
}
.te-after-in {
  width: 0;
  min-width: 100%;
  height: 1.2em;
  font: inherit;
  line-height: 1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule); border-radius: 3px; padding: 0 .15em; text-align: right;
  -moz-appearance: textfield; appearance: textfield;
}
.te-after-in::-webkit-inner-spin-button, .te-after-in::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.te-after-in:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.te-after-line { display: flex; flex-wrap: wrap; align-items: center; column-gap: .8em; }
.te-after-slide {
  flex: 1 1 7em;
  min-width: 0;
  max-width: 14em;
  margin: 0;
  accent-color: var(--focus);
  cursor: pointer;
}
.te-after-slide[hidden] { display: block; visibility: hidden; }
.te-after-slide:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sheet td.te-in { padding: .45em .4em; }
.te-clear, .te-clear[hidden] { display: none; }
html.tab-te:not(.narrow) .te-clear:not(.te-clear-alt), html.tab-te.narrow .te-clear-alt {
  display: inline-block;
  position: absolute;
}
html.tab-te .te-clear:not([hidden]) { visibility: visible; }
.te-clear:not(.te-clear-alt) { bottom: .5rem; right: .8rem; font-size: .8rem; padding: .25rem .65rem; }
#unit-head { position: relative; }
.te-clear-alt { bottom: .25em; right: .4em; font-size: 1em; line-height: 1.15; padding: .1em .45em; }
.te-box { flex-direction: column; margin-top: .5rem; padding-top: .55rem; border-top: 1px solid var(--rule); }
.te-amts {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  column-gap: .8rem;
  row-gap: .05rem;
  margin-top: .25rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.te-amt-wrap { display: inline-grid; justify-self: end; }
.te-amt-wrap > * { grid-area: 1 / 1; }
.te-amt-size { visibility: hidden; white-space: pre; padding: 0 .2em; border: solid transparent; border-width: 0 1px; }
.te-amt {
  align-self: center; width: 0; min-width: 100%; height: 1.3em;    font: inherit; line-height: 1; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 3px; padding: 0 .2em; text-align: right;
}
.te-amt:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.te-amts .t-wood { color: var(--wood); }
.te-amts .t-food { color: var(--food); }
.te-amts .t-gold { color: var(--gold); }
.te-amts .t-stone { color: var(--stone); }
.te-vils {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .6rem;
  margin-top: .45rem;
  padding-top: .4rem;
  border-top: 1px solid var(--rule);
}
#te-vils { font-size: 1.05rem; color: var(--ink); }
.tv-short { display: none; }
html.tab-te.narrow, html.tab-te.narrow.show-bld {
  --w-rm: 0px;
  --w-count: 0px;
  --w-bld: 0px;
  --w-wood: 6.4rem;
  --w-food: 6.4rem;
  --w-gold: 6.4rem;
  --w-stone: 6.4rem;
}
html.tab-te.narrow .sheet thead th:nth-child(-n+4):not(:nth-child(2)) { padding: 0; border: 0; overflow: hidden; }
html.tab-te.narrow .adder, html.tab-te.narrow .age { display: none; }
html.tab-te.narrow .lanes { grid-template-areas: "wood food gold stone"; }
@media (max-width: 820px), (max-height: 520px) {
  html.tab-te.narrow .te-box {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .1rem .6rem;
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
  }
  html.tab-te.narrow .te-amts { display: flex; flex-wrap: wrap; gap: .1rem .3rem; margin: 0; font-size: .9rem; }
  html.tab-te.narrow .te-amt-wrap { margin-right: .45rem; }
  html.tab-te.narrow .te-amt-size { padding: 0; border: 0; }
  html.tab-te.narrow .te-amt { padding: 0; border-width: 0 0 1px; border-radius: 0; background: none; }
  html.tab-te.narrow .te-vils { gap: .35rem; margin: 0; padding: 0; border: 0; }
  html.tab-te.narrow #te-vils { font-size: .9rem; }
  html.tab-te.narrow .tv-long { display: none; }
  html.tab-te.narrow .tv-short { display: inline; }
}
@media (max-height: 520px) {
  html.tab-te.narrow .te-ages > div { display: flex; flex-wrap: wrap; gap: 0 1.1rem; }
  html.tab-te.narrow .te-age .long { display: none; }
  html.tab-te.narrow .te-after-slide { flex-basis: 3em; }
  html.tab-te.narrow .sheet td.te-ages { padding-top: .35em; padding-bottom: .35em; }
}
@media (max-width: 599px) {
  html.tab-te.narrow, html.tab-te.narrow.show-bld {
    --w-wood: 3.9rem;
    --w-food: 3.9rem;
    --w-gold: 3.9rem;
    --w-stone: 3.9rem;
  }
  .sheet td.te-ages { padding: .35em .4em; }
  .te-age { white-space: normal; line-height: 1.3; margin-bottom: .2em; align-items: flex-start; }
  .te-age input { margin-top: .15em; }
}
