* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

main {
  flex: 1;
}

body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  padding-right: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  height: 100%;
}

.page-title {
  font-size: 1.5em;
  font-weight: 600;
  color: #1a1f36;
  margin: 0 0 16px 8px;
  letter-spacing: 0.5px;
  font-family: "Yu Mincho", "游明朝", "Hiragino Mincho ProN", "ヒラギノ明朝 ProN W3", "ＭＳ Ｐ明朝", serif;
  padding-bottom: 6px;
}

h2 {
  font-size: clamp(1.2rem, 3vw, 1.5em);
  margin-top: 1em;
  margin-bottom: 0.2em;
  position: relative;
  font-family: "Yu Mincho", "游明朝", "Hiragino Mincho ProN", "ヒラギノ明朝 ProN W3", "ＭＳ Ｐ明朝", serif;
}

.visually-hidden {
  position: absolute;
  left: -9999px;
}

.content {
  padding: 20px;
  margin: 0;
}

#toc {
  background: #fafafa;
  border: 1px solid #ccc;
  max-width: 300px;
  padding: 1em;
  margin-top: 2em;
  margin-bottom: 1em;
  border-radius: 8px;
}

#toc a:hover {
  text-decoration: underline;
}

.table-container {
  margin: 2rem 0;
  overflow-x: auto;
}

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

.table-wrapper {
  overflow-x: auto;
  width: 100%;
  box-sizing: border-box;
}

th,
td {
  padding: 8px;
  text-align: center;
}

table,
th,
td {
  border: calc(1.5px * var(--scale, 1)) solid #bbb;
}

#tables-container {
  font-size: calc(14px * var(--scale, 1));
}

.book-table th:nth-child(1),
.book-table td:nth-child(1) { width: calc(200px * var(--scale, 1)); }
.book-table th:nth-child(2),
.book-table td:nth-child(2) { width: calc(180px * var(--scale, 1)); }
.book-table th:nth-child(3),
.book-table td:nth-child(3) { width: calc(80px * var(--scale, 1)); }
.book-table th:nth-child(4),
.book-table td:nth-child(4) { width: calc(100px * var(--scale, 1)); }
.book-table th:nth-child(5),
.book-table td:nth-child(5) { width: calc(100px * var(--scale, 1)); }
.book-table th:nth-child(6),
.book-table td:nth-child(6) { width: calc(100px * var(--scale, 1)); }

th {
  background-color: #f2f4f7;
  font-weight: bold;
  border-bottom: calc(2px * var(--scale, 1)) solid #bbb;
}

.table-wrapper.scroll-mode th,
.table-wrapper.scroll-mode td {
  white-space: nowrap;
}

.table-wrapper.wrap-mode th,
.table-wrapper.wrap-mode td {
  white-space: normal;
  word-break: break-word;
}

.thin-line {
  border: none;
  border-top: 1px solid #ddd;
  margin: 6px 0;
}

#bonusModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

#bonusModal.hidden {
  display: none;
}

.modal-content {
  position: relative;
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  width: 95%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
  animation: fadeIn 0.2s ease-out;
  z-index: 1000;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

#closeModal {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1.6rem;
  cursor: pointer;
  color: #666;
  transition: color 0.2s;
  z-index: 1100;
}

#closeModal:hover {
  color: #000;
}

#modalTitle {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 1.3rem;
  text-align: center;
  border-bottom: 2px solid #eee;
  padding-bottom: 0.5rem;
  white-space: nowrap;
}

#modalTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  table-layout: auto;
}

#modalTable th,
#modalTable td {
  border: 1px solid #ccc;
  padding: 8px;
  text-align: center;
  word-wrap: break-word;
}

#modalTable th {
  background-color: #f6f8fa;
  font-weight: 600;
}

.char-cell {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.char-icon {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}

.book-name {
  cursor: pointer;
  user-select: none;
  color: #0078d4;
  transition: color 0.2s;
}

.book-name:hover {
  color: #005a9e;
}

.book-name:focus {
  outline: 2px solid rgba(0, 102, 204, 0.3);
  outline-offset: 2px;
}

@media (max-width: 930px) {
  table { font-size: calc(13px * var(--scale, 1)); }

  th, td { padding: calc(4px * var(--scale, 1)) calc(6px * var(--scale, 1)); }

  .book-table th:nth-child(1),
  .book-table td:nth-child(1) { width: calc(190px * var(--scale, 1)); }
  .book-table th:nth-child(2),
  .book-table td:nth-child(2) { width: calc(170px * var(--scale, 1)); }
  .book-table th:nth-child(3),
  .book-table td:nth-child(3) { width: calc(70px * var(--scale, 1)); }
  .book-table th:nth-child(4),
  .book-table td:nth-child(4) { width: calc(90px * var(--scale, 1)); }
  .book-table th:nth-child(5),
  .book-table td:nth-child(5) { width: calc(90px * var(--scale, 1)); }
  .book-table th:nth-child(6),
  .book-table td:nth-child(6) { width: calc(90px * var(--scale, 1)); }
}

@media (max-width: 520px) {
  #modalTitle {
    white-space: normal;
    line-height: 1.4;
  }

  #modalTitle .bonus-label {
    display: block;
    margin-top: 0.3em;
  }

  .char-icon {
    width: 28px;
    height: 28px;
  }

  .char-cell {
    gap: 0.4em;
  }

  .char-cell span {
    font-size: 0.9rem;
  }
}

@media (max-width: 460px) {
  .page-title {
    text-align: center;
  }
}