:root {
  --ink: #1d2430;
  --muted: #5c6675;
  --line: #d5d5d5;
  --panel: #ffffff;
  --accent: #0f6a5d;
  --accent-soft: rgba(15, 106, 93, 0.1);
  --empty: #e8e8e8;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.06);
  --panel-width: 240px;
  /* 23 columns (row label + 22 onsets) preserve the previous 1500px total. */
  --table-column-width: calc(1500px / 23);
  /* A 1.3× centered tile extends 15% of one column past either edge. */
  --tile-hover-overhang: calc(var(--table-column-width) * 0.15);
  --font-ui: "IBM Plex Sans", sans-serif;
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --font-han: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: #ffffff;
  font-family: var(--font-ui);
}

body {
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-width);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app.panel-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.workspace {
  padding: 1.5rem 1.5rem 2.5rem;
  overflow: auto;
}

.page-header {
  margin-bottom: 1.25rem;
  max-width: 60rem;
}

.page-header h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font-ui);
  font-size: clamp(1.8rem, 2.4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.about {
  margin-top: 0.85rem;
}

.about > summary {
  width: fit-content;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.about > summary::-webkit-details-marker {
  display: none;
}

.about > summary::before {
  content: "▾";
  display: inline-block;
  width: 1em;
  transition: transform 140ms ease;
}

.about:not([open]) > summary::before {
  transform: rotate(-90deg);
}

.about-body {
  margin-top: 0.75rem;
  max-width: 60rem;
  font-family: var(--font-serif);
  font-size: 0.9rem;
}

.about-body p {
  margin: 0;
  color: var(--ink);
  line-height: 1.65;
  text-indent: 1.5em;
}

.about-body p:last-child {
  margin-bottom: 0;
}

.tables {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.tone-block {
  align-self: flex-start;
  width: fit-content;
  max-width: 100%;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 0.85rem 0.85rem 1rem;
  animation: rise 420ms ease both;
}

.tone-block:nth-child(2) {
  animation-delay: 60ms;
}
.tone-block:nth-child(3) {
  animation-delay: 120ms;
}
.tone-block:nth-child(4) {
  animation-delay: 180ms;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.tone-block > summary {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  user-select: none;
}

.tone-block > summary::-webkit-details-marker {
  display: none;
}

.tone-block > summary::before {
  content: "▾";
  display: inline-block;
  width: 1em;
  color: var(--muted);
  transition: transform 140ms ease;
}

.tone-block:not([open]) > summary {
  margin-bottom: 0;
}

.tone-block:not([open]) > summary::before {
  transform: rotate(-90deg);
}

.table-scroll {
  overflow: auto;
  max-width: 100%;
  padding-right: var(--tile-hover-overhang);
  border-top: 1px solid var(--line);
}

table.pinyin-table {
  border-collapse: collapse;
  font-size: 0.78rem;
  width: max-content;
}

.pinyin-table th,
.pinyin-table td {
  width: var(--table-column-width);
  min-width: var(--table-column-width);
  max-width: var(--table-column-width);
  border: 1px solid #d8d8d8;
  text-align: center;
  vertical-align: middle;
  padding: 0;
}

.pinyin-table th {
  height: 2.1rem;
  padding: 0.15rem;
}

.pinyin-table td {
  height: auto;
}

.pinyin-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f3f3;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: clip;
}

.pinyin-table tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f3f3f3;
  font-weight: 600;
  color: var(--muted);
}

.pinyin-table thead th.corner {
  z-index: 3;
  left: 0;
}

.pinyin-table td.empty {
  background: var(--empty);
}

.pinyin-table .axis-hidden {
  display: none;
}

html.hide-lowest-freq .pinyin-table td.filled[data-freq-step="0"] {
  background: var(--empty) !important;
  color: inherit;
  cursor: default;
}

html.hide-lowest-freq .pinyin-table td.filled[data-freq-step="0"] .cell {
  display: none;
}

html.hide-lowest-freq .pinyin-table td.filled[data-freq-step="0"]:hover {
  filter: none;
  transform: none;
}

.pinyin-table td.filled {
  cursor: default;
  transition: filter 140ms ease, transform 140ms ease;
}

.pinyin-table td.filled:hover {
  filter: brightness(1.08);
  transform: scale(1.30);
  z-index: 4;
  position: relative;
}

.cell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 4.4rem;
}

.cell-top {
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr;
  align-items: stretch;
  flex: 2 1 0;
  min-height: 0;
  border-bottom: 1px solid rgba(29, 36, 48, 0.12);
  container-type: inline-size;
}

.cell-char,
.cell-pinyin,
.cell-gloss {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0.1rem 0.15rem;
  line-height: 1.1;
}

.cell-char {
  position: relative;
  overflow: hidden;
  height: 100%;
  width: 100%;
  border-right: 1px solid rgba(29, 36, 48, 0.12);
}

.cell-char-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-han);
  font-size: 2.5rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.cell-pinyin {
  padding: 0 1px;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: clamp(0.35rem, 18cqi, 0.72rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  line-height: 1;
}

.cell-gloss {
  flex: 1 1 0;
  min-height: 0;
  padding: 0.1rem 0.25rem;
  font-size: 0.58rem;
  line-height: 1.15;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: keep-all;
  line-break: strict;
}

.gloss-zh {
  white-space: nowrap;
}

.panel {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 1.35rem 1.1rem;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 30px rgba(40, 32, 18, 0.04);
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  overflow-y: auto;
}

.app.panel-hidden .panel {
  display: none;
}

.panel-toolbar {
  display: flex;
  justify-content: flex-start;
  margin: -0.25rem 0 0.15rem;
}

.panel-toggle,
.panel-show {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.panel-toggle:hover,
.panel-show:hover {
  background: var(--accent-soft);
  border-color: rgba(15, 106, 93, 0.25);
  color: var(--accent);
}

.panel-show {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 20;
  box-shadow: var(--shadow);
}

.panel-section h2 {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.radio {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.radio:hover {
  background: rgba(15, 106, 93, 0.06);
}

.radio:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(15, 106, 93, 0.25);
}

.radio input {
  accent-color: var(--accent);
}

.radio span {
  font-size: 0.95rem;
}

.radio-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
}

.radio-grid .radio {
  gap: 0.3rem;
  padding: 0.35rem;
}

.radio-grid .radio-wide {
  grid-column: span 3;
}

.panel-footer {
  margin-top: auto;
}

.panel-attribution {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.load-status {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  margin: 0;
  padding: 0.35rem 0.55rem;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.load-status[hidden] {
  display: none;
}

.panel-attribution {
  margin-top: 0.65rem;
  font-size: 0.68rem;
}

.panel-attribution a {
  color: inherit;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .app.panel-hidden {
    grid-template-columns: 1fr;
  }

  .panel {
    position: relative;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--line);
    box-shadow: none;
  }
}
