:root {
  --kbv-page-padding: clamp(0.5rem, 0.85vw, 1rem);
  --kbv-floor-height: 34px;
  --kbv-bg: #f7f8fc;
  --kbv-card: #ffffff;
  --kbv-border: #d8dee9;
  --kbv-text: #1f2a37;
  --kbv-muted: #5b6878;
  --kbv-primary: #1f4fd1;
  --kbv-primary-soft: #e7edff;
  --kbv-danger: #b31942;
  --kbv-danger-soft: #ffe7ef;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--kbv-bg);
}

.kbv-page {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  align-items: stretch;
  gap: 1.2rem;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: var(--kbv-page-padding);
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #f8faff 0%, #f5f6fa 45%, #f8f8fb 100%);
  color: var(--kbv-text);
}

.kbv-panel {
  background: var(--kbv-card);
  border: 1px solid var(--kbv-border);
  border-radius: 1rem;
  box-shadow: 0 10px 22px rgba(38, 53, 86, 0.08);
  padding: 1rem;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.kbv-panel-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.kbv-panel-header p {
  margin: 0.4rem 0 0;
  color: var(--kbv-muted);
  font-size: 0.9rem;
}

.kbv-panel-nav {
  margin-bottom: 0.55rem;
}

.kbv-home-button {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8d4ef;
  border-radius: 0.55rem;
  background: #fff;
  color: var(--kbv-primary);
  text-decoration: none;
  padding: 0.34rem 0.68rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.kbv-home-button:hover {
  background: var(--kbv-primary-soft);
  text-decoration: none;
}

.kbv-card {
  border: 1px solid var(--kbv-border);
  border-radius: 0.9rem;
  padding: 0.85rem;
  background: #fcfdff;
}

.kbv-card h2 {
  margin: 0 0 0.55rem;
  font-size: 0.92rem;
}

.kbv-card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.kbv-card-title-row h2 {
  margin: 0;
}

.kbv-book-title-row {
  margin-bottom: 0.55rem;
}

.kbv-detail-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #4f5f78;
  font-size: 0.78rem;
  user-select: none;
}

.kbv-detail-toggle input {
  margin: 0;
  accent-color: var(--kbv-primary);
}

.kbv-link-button {
  border: 0;
  background: transparent;
  color: var(--kbv-primary);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}

.kbv-link-button:hover {
  text-decoration: underline;
}

.kbv-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.kbv-chip {
  border: 1px solid var(--kbv-border);
  border-radius: 0.6rem;
  background: #fff;
  color: var(--kbv-muted);
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.kbv-chip:hover {
  border-color: #9fb3e7;
  color: var(--kbv-text);
}

.kbv-chip.is-active {
  background: var(--kbv-primary-soft);
  color: var(--kbv-primary);
  border-color: #9ab1ec;
}

.kbv-chip-hidden {
  display: none;
}

.kbv-option-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.kbv-option {
  border: 1px solid var(--kbv-border);
  border-radius: 0.7rem;
  background: #fff;
  color: var(--kbv-muted);
  text-align: left;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
}

.kbv-option small {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color: #7a8593;
}

.kbv-option.is-active {
  background: var(--kbv-primary-soft);
  color: var(--kbv-primary);
  border-color: #9ab1ec;
}

.kbv-book-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 260px;
  overflow: auto;
}

.kbv-book-item {
  border: 1px solid var(--kbv-border);
  border-radius: 0.7rem;
  background: #fff;
  color: var(--kbv-text);
  text-align: left;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: all 0.2s ease;
}

.kbv-book-item strong {
  font-size: 0.88rem;
}

.kbv-book-item span {
  font-size: 0.78rem;
  color: #6c788a;
}

.kbv-book-title-cn {
  line-height: 1.3;
}

.kbv-book-title-en {
  font-size: 0.75rem;
  color: #717d91;
  font-style: italic;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-size {
  margin-top: 0.08rem;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-intro {
  margin-top: 0.18rem;
  font-size: 0.73rem;
  color: #607089;
  line-height: 1.38;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-item:hover {
  border-color: #f3a5bf;
}

.kbv-book-item.is-active {
  border-color: #dc5f88;
  background: var(--kbv-danger-soft);
}

.kbv-tip {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #4966a8;
  background: #eaf2ff;
  border-radius: 0.8rem;
  border: 1px solid #c7d7ff;
  padding: 0.65rem 0.75rem;
}

.kbv-stage-wrap {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.kbv-stage {
  position: relative;
  border-radius: 1.2rem;
  border: 1px solid var(--kbv-border);
  background: linear-gradient(180deg, #eff4ff 0%, #dbe5f8 100%);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.kbv-grid-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(#a8bad8 1px, transparent 1px),
    linear-gradient(90deg, #a8bad8 1px, transparent 1px);
  background-size: 48px 48px;
}

.kbv-visual {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 1rem 1rem calc(var(--kbv-floor-height) + 0.9rem);
  z-index: 2;
}

#kbv-character-container {
  position: relative;
  display: flex;
  align-items: flex-end;
}

.kbv-character-box {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.kbv-character-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 16px 20px rgba(15, 23, 42, 0.25));
}

.kbv-custom-character {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 16px 20px rgba(15, 23, 42, 0.25));
}

.kbv-height-line {
  position: absolute;
  left: -12px;
  top: 0;
  bottom: 0;
  width: 1px;
  border-left: 1px dashed #60708a;
}

.kbv-height-label {
  position: absolute;
  left: -56px;
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: center;
  font-size: 0.75rem;
  color: #55627a;
  font-weight: 700;
  white-space: nowrap;
}

.kbv-paper-wrap {
  position: absolute;
  line-height: 0;
  transition: all 0.45s ease;
  z-index: 4;
}

.kbv-paper-anchor,
.kbv-paper-anchor:visited {
  color: inherit;
  text-decoration: none;
}

.kbv-paper-shell {
  position: relative;
  display: inline-block;
}

.kbv-paper-face {
  position: relative;
  line-height: normal;
  border: 1px solid #d6deea;
  background: linear-gradient(135deg, #ffffff 0%, #f8fbff 60%, #ecf1fa 100%);
  box-shadow: 0 16px 26px rgba(20, 30, 50, 0.22);
  overflow: hidden;
}

.kbv-paper-face::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, rgba(112, 128, 160, 0.65), rgba(112, 128, 160, 0));
}

.kbv-paper-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.kbv-paper-anchor:hover .kbv-paper-cover {
  transform: scale(1.03);
}

.kbv-paper-cover-fallback {
  background: linear-gradient(135deg, #fde7f0 0%, #f9cadd 100%);
}

.kbv-paper-plain {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #334155;
}

.kbv-paper-kai {
  font-size: clamp(1rem, 2.4vw, 2.2rem);
  line-height: 1.1;
  font-weight: 700;
}

.kbv-paper-size {
  margin-top: 0.25rem;
  font-size: clamp(0.7rem, 1.2vw, 1rem);
  line-height: 1.2;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid #dde6f5;
  border-radius: 0.45rem;
  padding: 0.1rem 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
}

.kbv-paper-outside-label {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: max-content;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid #e2e7f0;
  border-radius: 0.5rem;
  box-shadow: 0 8px 16px rgba(41, 51, 72, 0.08);
  padding: 0.3rem 0.55rem;
}

.kbv-paper-outside-label strong {
  font-size: 1rem;
  line-height: 1.1;
  white-space: nowrap;
}

.kbv-paper-outside-label small {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  line-height: 1.1;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.kbv-book-label {
  position: absolute;
  top: calc(100% + 0.9rem);
  left: 0.5rem;
  width: max-content;
  max-width: min(26rem, 72vw);
  line-height: normal;
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #f4bfce;
  border-radius: 0.6rem;
  box-shadow: 0 8px 20px rgba(52, 34, 41, 0.15);
  padding: 0.4rem 0.55rem;
}

.kbv-book-label strong {
  color: var(--kbv-danger);
  font-size: 0.88rem;
  line-height: 1.32;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-label-en {
  display: block;
  font-size: 0.72rem;
  color: #6e7787;
  line-height: 1.35;
  font-style: italic;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-label span {
  font-size: 0.72rem;
  color: #5a6477;
  line-height: 1.32;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-label-intro {
  display: block;
  margin-top: 0.08rem;
  font-size: 0.7rem;
  color: #5c677c;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.kbv-book-label-intro :where(p, div, blockquote, ul, ol, h1, h2, h3, h4, h5, h6) {
  margin: 0 0 0.35rem;
}

.kbv-book-label-intro :where(p, div, blockquote, ul, ol, h1, h2, h3, h4, h5, h6):last-child {
  margin-bottom: 0;
}

.kbv-book-label-intro :where(ul, ol) {
  padding-left: 1.1rem;
}

.kbv-book-label-intro a {
  color: var(--kbv-danger);
  text-decoration: underline;
}

.kbv-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--kbv-floor-height);
  background: #fefefe;
  border-top: 1px solid #bdcadc;
  z-index: 1;
}

.kbv-stage-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.78rem;
  color: #657187;
  justify-content: center;
}

.kbv-empty {
  margin: 0;
  font-size: 0.82rem;
  color: #6b778b;
}

@media (max-width: 1100px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .kbv-page {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .kbv-panel {
    height: auto;
    overflow: visible;
  }

  .kbv-stage-wrap {
    height: clamp(430px, 68vh, 760px);
    min-height: 430px;
  }
}

@media (max-width: 720px) {
  :root {
    --kbv-floor-height: 28px;
  }

  .kbv-page {
    padding: 0.75rem;
  }

  .kbv-panel,
  .kbv-stage {
    border-radius: 0.95rem;
  }

  .kbv-height-label {
    left: -42px;
    font-size: 0.68rem;
  }
}
