/* Size the word to its card, including narrow desktop and landscape cards. */
body[data-route="card"] .card-3d-perspective {
  container-type: inline-size;
}

body[data-route="card"] #card-front {
  overflow: hidden;
}

body[data-route="card"] #card-front > div {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 2.5rem 1rem 1rem;
  padding: clamp(2.5rem, 12cqi, 3rem) clamp(.75rem, 4cqi, 1.5rem) clamp(.75rem, 4cqi, 1.5rem);
  gap: .75rem;
  gap: clamp(.5rem, 4cqi, 1.25rem);
  justify-content: flex-start;
  justify-content: safe center;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

body[data-route="card"] #card-front > div > * {
  flex-shrink: 0;
  max-width: 100%;
}

body[data-route="card"] #card-front [data-card-front-headword] {
  width: 100%;
  margin: 0;
  /* The app supplies Unicode character count; the small spare width covers
     glyph spacing and fonts that have not finished loading yet. */
  font-size: min(6rem, 28vw, calc((100vw - 6rem) / var(--hsk-headword-length, 4)));
  line-height: 1.1;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

@supports (font-size: 1cqi) {
  body[data-route="card"] #card-front [data-card-front-headword] {
    font-size: min(6rem, 28cqi, calc(88cqi / var(--hsk-headword-length, 4)));
  }
}

body[data-route="card"] #card-front > div > p {
  margin: 0;
  font-size: 1.25rem;
  font-size: clamp(1rem, 6cqi, 1.75rem);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

body[data-route="card"] #speak-front {
  width: 3rem;
  height: 3rem;
  width: clamp(2.5rem, 16cqi, 3.5rem);
  height: clamp(2.5rem, 16cqi, 3.5rem);
}

body[data-route="card"] #speak-front .material-symbols-outlined {
  font-size: 1.5rem !important;
}

body[data-route="card"] #card-front [data-hanzi-actions] {
  width: 100%;
}

body[data-route="card"] #card-front [data-hanzi-action] {
  min-height: 2rem;
  padding: .375rem .625rem;
  white-space: normal;
}

/* Older Safari has no container units. The landscape card is capped at
   23rem/48vh, so use that conservative width instead of the whole viewport. */
@supports not (font-size: 1cqi) {
  @media (min-width: 700px) {
    body[data-route="card"] #card-front [data-card-front-headword] {
      font-size: min(6rem, calc((min(36rem, calc(100vw - 8rem)) - 2rem) / var(--hsk-headword-length, 4)));
    }
  }

  @media (min-width: 700px) and (orientation: landscape) {
    body[data-route="card"] #card-front [data-card-front-headword] {
      font-size: min(6rem, 6.44rem, 13.44vh, calc((min(23rem, 48vh) - 2rem) / var(--hsk-headword-length, 4)));
    }
  }
}
