.character-sheet textarea {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.character-sheet :is(
  input[data-field]:read-only,
  textarea[data-field]:read-only,
  #trope-answer-one:read-only,
  #trope-answer-two:read-only,
  [data-loyal-count]:read-only
) {
  color: var(--locked-text);
  background-color: var(--read-only-surface);
  cursor: text;
}

.character-sheet :is(select:disabled, input[type="checkbox"]:disabled) {
  color: var(--locked-text);
  background-color: var(--disabled-surface);
  opacity: 1;
  cursor: not-allowed;
  -webkit-text-fill-color: currentcolor;
}

.sheet {
  width: var(--page-width);
  min-height: var(--page-height);
  padding: 24px;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 5px 20px var(--sheet-shadow);
}

.sheet-one {
  display: grid;
  grid-template-rows: auto auto minmax(342px, 1fr);
}

.sheet-two {
  display: grid;
  grid-template-columns: 277px 442px;
  grid-template-rows: 141px auto;
  gap: 23px;
}

.sheet-two .mechanics-heading,
.sheet-two .mechanics-grid {
  display: contents;
}

.sheet-two .sheet-logo {
  grid-column: 1;
  grid-row: 1;
  justify-self: center;
}

.sheet-two .mechanics-title {
  display: none;
}

.sheet-two .mechanics-column {
  grid-column: 2;
  grid-row: 1 / -1;
}

.sheet-two .mechanics-stats-column {
  grid-column: 1;
  grid-row: 2;
}

.sheet-heading {
  display: grid;
  grid-template-columns: 184px 1fr;
  gap: 22px;
  min-height: 141px;
}

.sheet-logo,
.tree-logo {
  display: block;
  width: 184px;
  height: 141px;
  object-fit: contain;
}

.identity-card,
.bordered-card {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 2px solid var(--border);
}

.identity-card {
  display: grid;
  grid-template-columns: 1fr 1.03fr;
  grid-auto-rows: minmax(29px, 1fr);
  gap: 0 10px;
  min-height: 141px;
  padding: 13px 10px;
}

.line-field {
  display: flex;
  align-items: end;
  min-width: 0;
  gap: 0.3125rem;
  font-family: var(--display-font);
  font-size: 1.25rem;
  font-weight: 800;
  white-space: nowrap;

  :where(input, select) {
    width: 100%;
    min-width: 0;
    height: 1.75rem;
    padding: 0.0625rem 0.1875rem 0;
    border: 0;
    border-bottom: 2px solid var(--ink);
    border-radius: 0;
    background: transparent;
    font-family: var(--body-font);
    font-size: 1.125rem;
    font-weight: 400;
  }
}

.identity-trope,
.physical-other {
  grid-column: 1 / -1;
}

.page-one-grid,
.mechanics-grid {
  display: grid;
  grid-template-columns: 442px 277px;
  gap: 23px;
  margin-top: 23px;
}

.mechanics-heading {
  display: grid;
  grid-template-columns: 184px 1fr;
  gap: 22px;
  min-height: 141px;
}

.mechanics-title {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 141px;
  padding: 8px;
  margin: 0;
  color: var(--inverse-text);
  background: var(--ink);
  font-family: var(--section-font);
  font-size: 3.25rem;
  font-weight: 400;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.mechanics-column {
  .resource-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.875rem;
    margin-top: 0;
  }

  .resource-card .section-title {
    font-size: 1.4375rem;
  }

  .token-counter {
    gap: 0.375rem;

    button {
      width: 3.4375rem;
    }

    output {
      min-width: 3.125rem;
    }
  }
}

.mechanics-traits {
  padding-top: 20px;
}

.character-column,
.utility-column,
.mechanics-column,
.mechanics-stats-column {
  min-width: 0;
}

.traits-card {
  padding: 0 9px 9px;
}

.traits-card > .section-title,
.trope-questions-card > .section-title,
.strength-actions-card > .section-title {
  width: calc(100% + 18px);
  margin-inline: -9px;
}

.structured-traits {
  display: grid;
  gap: 0.625rem;
  padding: 0.75rem 0 0.5rem;

  :where(select, input) {
    height: 2.125rem;
    padding: 0.1875rem 0.25rem;
  }

  textarea {
    min-height: 4rem;
    padding: 0.25rem;
    line-height: 1.6875rem;
  }

  textarea[data-description-autosize] {
    height: auto;
    min-height: 0;
    box-sizing: border-box;
    overflow-y: auto;
  }
}

.structured-traits select,
.structured-traits input,
.structured-traits textarea,
.question-fields textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  font-family: var(--body-font);
  font-size: 0.9375rem;
}

.trait-choice-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(155px, 2fr);
  align-items: end;
  gap: 0.5rem;
  min-width: 0;

  &:has(.custom-trait-name:not([hidden])) {
    grid-template-columns: minmax(115px, 0.75fr) minmax(105px, 0.7fr) minmax(145px, 1fr);
  }
}

.cape-power-row {
  grid-template-columns: 1fr 1fr;
}

.trait-choice-row label,
.structured-line {
  min-width: 0;
}

.custom-trait-name,
.trait-description {
  display: grid;
  gap: 0.125rem;
  font-family: var(--display-font);
  font-size: 0.6875rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cape-power-row label,
.structured-line {
  display: grid;
  gap: 0.125rem;
  font-family: var(--display-font);
  font-size: 0.8125rem;
  font-weight: 800;
  text-transform: uppercase;
}

.trait-choices {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.5rem;
  margin: 0;
  border: 2px solid var(--border);

  legend {
    padding: 0 0.3125rem;
    font-family: var(--display-font);
    font-size: 1.125rem;
    font-weight: 900;
    text-transform: uppercase;
  }
}

.age-benefits {
  padding: 0.5625rem;
  border: 2px solid var(--ink);
  background: var(--subtle-surface);

  :where(h3, p) {
    margin: 0;
  }

  h3 {
    font-family: var(--display-font);
    font-size: 1rem;
    text-transform: uppercase;
  }
}

.age-benefits p,
.choice-help,
.effect-detail {
  font-size: 0.8125rem;
  line-height: 1.35;
}

.choice-help {
  min-height: 1.2em;
  margin: 0;
}

.lined-entry {
  position: relative;
  display: block;
  height: 67px;
  font-family: var(--display-font);
  font-size: 1.25rem;
  font-weight: 800;

  > span {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    padding: 1px 5px 0 0;
    background: var(--paper);
    line-height: 31px;
  }

  textarea {
    display: block;
    width: 100%;
    height: 65px;
    padding: 1px 3px 0;
    overflow-y: auto;
    border: 0;
    background-color: transparent;
    background-image: repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 29px,
      var(--ink) 29px,
      var(--ink) 31px,
      transparent 31px,
      transparent 33px
    );
    font-family: var(--body-font);
    font-size: 1.125rem;
    font-weight: 400;
    line-height: 33px;
    text-indent: var(--label-indent);
  }
}

.lined-entry-motivation {
  --label-indent: 7.9rem;
}

.lined-entry-obligations {
  --label-indent: 8.3rem;
}

.lined-entry-weak-points {
  --label-indent: 8.1rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 49px;
  padding: 3px 8px 0;
  margin: 0;
  border: 0;
  color: var(--inverse-text);
  background: var(--section-bar);
  font-family: var(--section-font);
  font-size: 1.9375rem;
  font-weight: 400;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.trope-questions-card,
.strength-actions-card {
  padding: 0 9px 12px;
  margin-top: 20px;
}

.question-fields {
  display: grid;
  gap: 0.75rem;
  padding-top: 0.75rem;

  label {
    display: grid;
    gap: 0.3125rem;
    font-size: 0.875rem;
    font-weight: 800;
    line-height: 1.25;
  }

  textarea {
    min-height: 3.875rem;
    padding: 0.25rem;
    resize: vertical;
  }
}

.sheet-action,
.strength-action {
  min-height: 2.125rem;
  padding: 0.3125rem 0.5625rem;
  border: 2px solid var(--ink);
  color: var(--inverse-text);
  background: var(--ink);
  font-family: var(--display-font);
  font-weight: 900;
  cursor: pointer;

  &:hover:not(:disabled) {
    color: var(--ink);
    background: var(--paper);
  }

  &:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
}

.sheet-action {
  margin-top: 0.75rem;
}

.resource-cards {
  display: grid;
  gap: 0.875rem;
  margin-top: 21px;
}

.resource-card {
  min-height: 100px;
}

.resource-card .section-title {
  float: none;
}

.strength-actions-content {
  display: grid;
  gap: 0.625rem;
  padding-top: 12px;
}

.strength-rule {
  display: grid;
  gap: 0.375rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--border);

  &:last-child {
    padding-bottom: 0;
    border-bottom: 0;
  }

  :where(h3, p) {
    margin: 0;
  }

  h3 {
    font-family: var(--display-font);
    font-size: 1.0625rem;
  }
}

.strength-rule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4375rem;
}

.token-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: 3.0625rem;

  button {
    width: 4.375rem;
    height: 2.125rem;
    padding: 0.0625rem 0.5rem 0;
    border: 2px solid var(--ink);
    background: var(--paper);
    font-family: var(--display-font);
    font-size: 1.25rem;
    font-weight: 900;
    cursor: pointer;

    &:hover:not(:disabled) {
      color: var(--inverse-text);
      background: var(--ink);
    }

    &:disabled {
      opacity: 0.35;
      cursor: not-allowed;
    }
  }

  output {
    min-width: 4.125rem;
    font-family: var(--display-font);
    font-size: 1.8125rem;
    font-weight: 900;
    text-align: center;
  }
}

.writing-card {
  overflow: hidden;

  > label {
    display: block;
    height: calc(100% - 49px);
    padding: 0 0.5rem;
  }
}

.ruled-textarea,
.utility-belt-field {
  display: block;
  width: 100%;
  overflow-y: auto;
  border: 0;
  background-color: transparent;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 37px,
    var(--ink) 37px,
    var(--ink) 39px,
    transparent 39px,
    transparent 40px
  );
  font-family: var(--body-font);
  font-size: 1.125rem;
  line-height: 40px;
}

.ruled-textarea {
  height: 100%;
  padding: 3px 2px 0;
}

.description-card {
  min-height: 342px;
  margin-top: 20px;
}

.stats-card {
  height: 556px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 96px);
  height: 288px;
}

.stat-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  border-top: 2px solid var(--border);
  border-right: 2px solid var(--border);
  font-size: 1.1875rem;
  text-transform: uppercase;

  &:nth-child(even) {
    border-right: 0;
  }

  button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 2.3125rem;
    padding: 0 0.25rem 0.3125rem;
    border: 0;
    background: transparent;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;

    &:hover {
      color: var(--inverse-text);
      background: var(--ink);
    }
  }
}

.stat-value-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  grid-template-rows: 35px 20px;
  gap: 1px 4px;
  width: 100%;
  height: 58px;
  padding: 2px 6px 0;

  select {
    width: 100%;
    min-width: 0;
    height: 2.1875rem;
    padding: 0.125rem;
    border: 0;
    border-bottom: 1px solid var(--ink);
    border-radius: 0;
    background: transparent;
    font-size: 1.0625rem;
    font-weight: 700;
    text-align: center;
  }
}

.stat-adjustment {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 2.1875rem;
  border-bottom: 1px solid var(--ink);
  font-size: 1.0625rem;
  font-weight: 700;

  input {
    width: 100%;
    min-width: 0;
    height: 2.0625rem;
    padding: 0.125rem;
    border: 0;
    background: transparent;
    font-size: 1.0625rem;
    font-weight: 700;
    text-align: center;
  }
}

.age-stat-bonus,
.stress-stat-indicator {
  color: var(--danger);
  font-weight: 900;
}

.age-stat-bonus {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  line-height: 20px;
  text-align: center;
  text-transform: uppercase;
}

.stress-stat-indicator {
  margin-left: 0.2em;
  font-family: var(--display-font);
}

.die-roller-button {
  width: 100%;
  min-height: 2.875rem;
  padding: 0.4375rem 0.75rem;
  border: 0;
  border-top: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  background: var(--paper);
  font-family: var(--display-font);
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;

  &:hover {
    color: var(--inverse-text);
    background: var(--ink);
  }
}

.stat-modifiers {
  display: grid;
  grid-template-rows: repeat(2, 84px);
  border-top: 2px solid var(--border);
}

.stacked-line-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.1875rem 1.9375rem 0;
  font-family: var(--display-font);
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;

  :where(input, select) {
    width: 100%;
    height: 2.1875rem;
    padding: 0.125rem 0.1875rem 0;
    border: 0;
    border-bottom: 2px solid var(--ink);
    border-radius: 0;
    background: transparent;
    font-family: var(--body-font);
    font-size: 1.125rem;
    font-weight: 400;
    text-align: center;
  }
}

.utility-card {
  height: 535px;
  margin-top: 24px;
  overflow: hidden;
}

.utility-column .utility-card {
  margin-top: 0;
}

.utility-belt-field {
  height: calc(100% - 49px);
  padding: 3px 11px 0;
}


/* Page three */

.physical-card {
  grid-template-columns: 1fr 1fr;
  padding-top: 19px;
}

.details-sections {
  display: grid;
  gap: 23px;
  margin-top: 23px;
}

.detail-card {
  height: 189px;
}

.relationship-card,
.notes-card {
  height: 225px;
}

@media (max-width: 830px) {
  .sheet {
    justify-self: center;
    width: calc(100% - 24px);
    box-shadow: 0 5px 20px -20px var(--sheet-shadow);
  }

  .sheet-one,
  .sheet-two,
  .sheet-three,
  .sheet-four {
    min-height: 0;
  }

  .page-one-grid,
  .mechanics-grid {
    grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr);
  }
}

@media (max-width: 760px) {
  .sheet {
    width: calc(100% - 16px);
    padding: 1rem;
  }

  .sheet-two {
    display: block;
  }

  .sheet-two .mechanics-heading {
    display: flex;
  }

  .sheet-two .mechanics-grid {
    display: grid;
    margin-top: 1.25rem;
  }

  .sheet-two .mechanics-column,
  .sheet-two .mechanics-stats-column {
    grid-column: auto;
    grid-row: auto;
  }

  .sheet-two .mechanics-stats-column {
    order: -1;
  }

  .sheet-heading,
  .mechanics-heading {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: auto;
  }

  .mechanics-title {
    width: 100%;
    min-height: 96px;
    font-size: clamp(2.5rem, 12vw, 3.25rem);
  }

  .sheet:not(.sheet-one) .sheet-logo,
  .sheet:not(.sheet-one) .tree-logo {
    display: none;
  }

  .sheet-logo {
    width: 170px;
    height: 130px;
  }

  .identity-card {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    gap: 0.5rem;
    width: 100%;
    height: auto;
    padding: 0.875rem;
  }

  .identity-trope,
  .physical-other {
    grid-column: auto;
  }

  .page-one-grid,
  .mechanics-grid {
    grid-template-columns: 1fr;
  }

  .traits-card,
  .stats-card,
  .description-card,
  .utility-card,
  .detail-card,
  .relationship-card,
  .notes-card {
    height: auto;
  }

  .traits-card {
    padding-bottom: 9px;
  }

  .trait-choice-row,
  .cape-power-row {
    grid-template-columns: 1fr;
  }

  .trait-choice-row:has(.custom-trait-name:not([hidden])) {
    grid-template-columns: 1fr;
  }

  .description-card > label,
  .detail-card > label {
    height: auto;
  }

  .description-card .ruled-textarea {
    height: 300px;
  }

  .utility-column,
  .mechanics-column,
  .mechanics-stats-column {
    display: grid;
    gap: 1.25rem;
  }

  .utility-card {
    margin-top: 0;
  }

  .utility-belt-field {
    min-block-size: 12rem;
  }

  .details-sections {
    gap: 1.25rem;
  }

  .detail-card .ruled-textarea {
    height: 140px;
  }

  .relationship-card .ruled-textarea,
  .notes-card .ruled-textarea {
    height: 180px;
  }

  .section-title {
    font-size: clamp(1.4375rem, 7vw, 1.9375rem);
  }
  .mechanics-column .strength-actions-card {
    margin-top: 0;
  }
}

@media (max-width: 430px) {
  .mechanics-column .resource-cards {
    grid-template-columns: minmax(0, 1fr);
  }
  .lined-entry {
    font-size: 1.0625rem;
  }

  .lined-entry textarea {
    font-size: 1rem;
  }

  .line-field {
    font-size: 1.125rem;
  }

  .stacked-line-field {
    padding-inline: 1.125rem;
    font-size: 1.125rem;
  }
}
