body {
  margin: 0;
  padding: 1em;
  min-width: 400px;
}

h1 {
  margin: 0.2em 0 0.4em;
}

@media screen and (max-width: 480px) {
  body {
    padding: 1em 0.5em;
  }

  h1 {
    text-align: center;
  }

  #main {
    column-gap: 0;
  }

  table {
    font-size: 1em;
  }
}

p,
ul,
li {
  margin: 0.25em 0;
}

.inline-note {
  font-size: 75%;
  position: relative;
  bottom: -0.1em;
}

#main {
  display: grid;
  grid-auto-flow: dense;
  --color-t: #eff;
  --color-f-star: #fcecfc;
  --color-t-star: #eef;
  --color-f: #fde9e9;
}

#main.grad-bkgd {
  --color-t: hsl(180deg 100% 95%);
  --color-f: hsl(0deg 100% 95%);
}

#main > div > :first-child,
#main > div > :first-child > :first-child,
#main > div > :first-child > :first-child > :first-child {
  margin-top: 0;
}

#main > div > :last-child,
#main > div > :last-child > :last-child,
#main > div > :last-child > :last-child > :last-child,
.chi2 > :last-child {
  margin-bottom: 0;
}

.flex-container {
  display: flex;
  flex-wrap: wrap;
}

#main,
.flex-container {
  gap: 1em 2em;
}

#main + *,
.flex-container + * {
  margin-top: 1em;
}

#input {
  height: fit-content;
}

#input > * {
  margin-bottom: 0.4em;
}

#input > *:nth-last-child(n+3) {
  line-height: 0;
}

#input > *:nth-last-child(n+3) p {
  line-height: initial;
}

textarea,
button {
  font-size: 1em;
}

textarea {
  width: calc(100% - 12px);
  font-family: auto;
  padding: 2px 5px;
  border-width: 1px;
  resize: vertical;
  height: 4.5em;
}

.rime-count-only textarea#material {
  height: 13.5em;
}

.rime-count-only textarea:not(#material) {
  height: 0em;
}

#buttons button:not(:first-of-type) {
  margin-left: 0.5em;
}

:disabled + label {
  color: silver;
}

#options div:not(:last-child) {
  margin-bottom: 0.2em;
}

#copy-buttons {
  margin-bottom: 1.5em;
  white-space: nowrap;
}

#copy-buttons.absolute {
  position: absolute;
  margin-top: -3em;
}

#copy-buttons > :not(:last-child) {
  margin-right: 0.5em;
}

table,
th,
td {
  border: 0 solid;
}

table {
  margin-top: 0.33333em;
  border-spacing: 0;
  border-width: 1px 0;
  line-height: 1;
  font-size: 1.125em;
}

.narrow1 table {
  font-size: 1em;
}

table caption {
  font-size: 1.33333em;
  margin-bottom: 0.375em;
}

th,
td {
  text-align: left;
  font-weight: normal;
  width: 2.5em;
  padding: 9px;
  padding-right: 7px;
}

.narrow2 th,
.narrow2 td {
  width: 2.2em;
}

.narrow2 th > :first-child,
.narrow2 td > :first-child {
  margin-left: -0.15em;
}

.narrow2 th:nth-of-type(2),
.narrow2 td:nth-of-type(2) {
  padding-left: 0px;
  padding-right: 7px;
}

th {
  padding-right: 0;
}

th:first-of-type,
td:first-of-type {
  width: auto;
}

th:nth-of-type(2),
td:nth-of-type(2) {
  padding-left: 2px;
  padding-right: 9px;
  width: auto;
}

th:nth-of-type(3),
td:nth-of-type(3) {
  padding-left: 10px;
}

th .rime-name {
  display: inline-block;
  margin-right: -5px;
}

td .value {
  margin-right: 0.05em;
}

td sup,
td sub {
  display: inline-block;
  width: 2em;
  margin-right: -2em;
  font-size: 0.667em;
  vertical-align: baseline;
  position: relative;
  bottom: 0.667em;
}

td sub {
  bottom: -0.333em;
}

th:nth-of-type(3),
td:nth-of-type(3),
td.cell-diag + td,
th.dummy.add-border + th,
td.dummy.add-border + td {
  border-left-width: 1px;
  padding-left: 8px;
}

th.dummy.double-border + th,
td.dummy.double-border + td {
  border-left-width: 3px;
  border-left-style: double;
}

tr:nth-of-type(2) td,
:not(.dummy) + td.cell-diag,
tr.dummy.add-border + tr td {
  border-top-width: 1px;
  padding-top: 8px;
}

tr.dummy.double-border + tr td {
  border-top-width: 3px;
  border-top-style: double;
}

th.dummy.gray-border + th,
td:not(.cell-diag) + td.dummy.gray-border + td {
  border-left-color: #ccc;
}

tr.dummy.gray-border + tr td:not(.cell-diag) {
  border-top-color: #ccc;
}

.cell-t,
#main:not(.hide-bkgd) .cell-diag {
  background: var(--color-t);
}

.cell-f,
.cell-nan {
  background: var(--color-f);
}

.cell-f-star {
  background: var(--color-f-star);
}

.cell-t-star {
  background: var(--color-t-star);
}

#main.hide-bkgd td {
  background: none;
}

h4 {
  margin: 0 0 0.75em;
}

.legend:not(.bkgd) .title,
.legend .icon {
  display: inline-block;
  white-space: nowrap;
}

.legend .icon ~ * {
  line-height: 1;
}

.legend.value .title {
  width: 6.25em;
}

.legend.chi2 .title {
  width: 4.25em;
}

.legends .legend .title {
  font-weight: bold;
}

.legend.bkgd .icon {
  width: 1em;
  height: 1em;
  line-height: 1;
  vertical-align: bottom;
  padding: 0.1em;
  margin-left: 2em;
  margin-right: 0.5em;
  text-align: center;
}

.legend.bkgd .icon span {
  font-size: 0.75em;
  position: relative;
  top: -0.125em;
}

.legend.chi2 {
  padding: 0.5em;
  border: solid 1px #ddd;
}

#instruction p {
  margin-top: 0.5em;
}

#instruction .indent {
  margin-left: 3em;
  text-indent: -2em;
}

#main.phono-desc .hide-if-phono-desc,
#main:not(.phono-desc) .show-if-phono-desc,
#main.pinyin .hide-if-pinyin,
#main:not(.pinyin) .show-if-pinyin,
#main.rime-name-only .hide-if-rime-name-only,
#main:not(.rime-name-only) .show-if-rime-name-only,
#main.rime-count-only .hide-if-rime-count-only,
#main:not(.rime-count-only) .show-if-rime-count-only,
#main.rhyme-group .hide-if-rhyme-group,
#main:not(.rhyme-group) .show-if-rhyme-group,
#main.show-tf .hide-if-tf,
#main:not(.show-tf) .show-if-tf,
#main.grad-bkgd .hide-if-grad-bkgd,
#main:not(.grad-bkgd) .show-if-grad-bkgd,
#main.skip-test .hide-if-skip-test,
#main:not(.skip-test) .show-if-skip-test,
#main:not(.hide-zero) .show-if-hide-zero,
#main:not(.hide-zero-idx) .show-if-hide-zero-idx,
#main.hide-bkgd .hide-if-hide-bkgd,
#main:not(.has-unannotated) .show-if-has-unannotated,
#main:not(.table-valid) .show-if-table-valid,
#main.input-invalid .hide-if-input-invalid {
  display: none;
}

#main.rime-name-only .empty-if-rime-name-only,
#main.rime-count-only .empty-if-rime-count-only {
  visibility: hidden;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input#rhyme-check:checked ~ .count-total-line,
input#rhyme-group-check:checked ~ .show-tf-check-line,
.dummy {
  display: none;
}

code,
#deriver-code {
  font-size: 1em;
  font-family: Courier New, monospace;
}

code {
  background: #eee;
  padding: 0.15em;
  line-height: 1;
}