:root {
  --cell: calc(min(58vw, 900px) / 11);
  --selected-cell: #3A3732;
  --translation-background: #262523;
  --translation-border: #45423D;
  --translation-foreground: #E8E5DE;
  --translation-shadow: 0 4px 20px rgb(0 0 0 / 14%), 0 1px 3px rgb(0 0 0 / 8%);
  --translation-text-size: clamp(20px, 1.7vw, 26px);
  --translation-line-height: 1.5;
  --translation-height: calc(var(--translation-text-size) * var(--translation-line-height) * 3 + 2px);
  --translation-bottom: 36px;
}

:root[data-theme="light"] {
  --selected-cell: #DEDBD4;
  --translation-background: #F5F4ED;
  --translation-border: #E8E6DC;
  --translation-foreground: #3D3D3A;
}

.toc {
  padding-bottom: calc(var(--translation-height) + var(--translation-bottom) + 24px);
}

.kana-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.kana-table th,
.kana-table td {
  width: calc(100% / 11);
  height: var(--cell);
  padding: 0;
  border: 0.5px solid var(--foreground);
  color: var(--foreground);
  text-align: center;
  vertical-align: middle;
  font-weight: 400;
}

.kana-table thead th,
.kana-table tbody th {
  font-size: clamp(14px, 1.9vw, 26px);
  letter-spacing: 0.04em;
}

.kana-table td.is-selected {
  background: var(--selected-cell);
}

.kana-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.kana-pair {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
  white-space: nowrap;
}

.kana-button:hover .kana-hira,
.kana-button:hover .kana-kata,
.kana-button:focus-visible .kana-hira,
.kana-button:focus-visible .kana-kata {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.12em;
  text-decoration-skip-ink: none;
}

.kana-button:focus-visible {
  outline: 1px solid var(--foreground);
  outline-offset: -4px;
}

.kana-hira {
  font-size: clamp(16px, 2.2vw, 30px);
  line-height: 1;
}

.kana-kata {
  font-size: clamp(10px, 1.25vw, 17px);
  line-height: 1;
}

.translation {
  position: fixed;
  z-index: 1;
  left: 50%;
  bottom: max(var(--translation-bottom), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% / 3);
  height: var(--translation-height);
  padding: calc(0.5em * var(--translation-line-height));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  scrollbar-width: none;
  border: 1px solid var(--translation-border);
  border-radius: 6px;
  box-shadow: var(--translation-shadow);
  background: var(--translation-background);
  color: var(--translation-foreground);
  font-size: var(--translation-text-size);
  line-height: var(--translation-line-height);
  text-align: center;
}

.translation p {
  margin: 0;
  text-align: center;
}

.translation #translation {
  font-size: 1.35em;
  letter-spacing: 0.04em;
}

.translation::-webkit-scrollbar,
.translation::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

@media (max-width: 900px) {
  :root {
    --cell: calc(min(calc(100vw - 64px), 650px) / 11);
    --translation-bottom: 24px;
  }

  .translation {
    width: min(calc(100% - 80px), 634px);
  }
}

@media (max-width: 540px) {
  :root {
    --cell: calc((100vw - 40px) / 11);
    --translation-bottom: 20px;
  }

  .translation {
    width: calc(100% - 56px);
  }
}

@media (max-width: 340px) {
  .kana-hira {
    font-size: 12px;
  }

  .kana-kata {
    font-size: 7px;
  }

  .kana-table thead th,
  .kana-table tbody th {
    font-size: 7px;
  }

  .kana-pair {
    gap: 0.15em;
  }
}
