:root {
  --paper: #f5f2ea;
  --ink: #1d2430;
  --muted: #667085;
  --line: rgba(29, 36, 48, 0.14);
  --tile: 24px;
  --gap: 2px;
  --hsk1: #f0ae1d;
  --hsk2: #2d8398;
  --hsk3: #fd5423;
  --hsk4: #be2021;
  --hsk5: #25467b;
  --hsk6: #6f3b8d;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
}

button,
input {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  min-height: 48px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

h1 {
  margin: 0;
  line-height: 1;
  letter-spacing: 0;
}

.brand-logo {
  display: block;
  width: min(230px, 42vw);
  height: auto;
}

.byline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.search {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.search input {
  width: min(280px, 42vw);
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fffaf0;
}

.levels {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.level-toggle,
.zoom-controls button,
#resetButton {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fffaf0;
  cursor: pointer;
  font-size: 14px;
}

.level-toggle[aria-pressed="true"] {
  color: white;
  border-color: transparent;
  background: var(--level-color);
}

.zoom-controls {
  display: inline-flex;
  gap: 4px;
}

.zoom-controls button {
  width: 30px;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 10px;
  height: calc(100vh - 59px);
  padding: 8px 12px 10px;
}

.detail-panel {
  position: sticky;
  top: 8px;
  align-self: start;
  min-height: 0;
  max-height: calc(100vh - 78px);
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: 0 18px 40px rgba(47, 38, 28, 0.09);
}

.panel-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.selected-hanzi {
  margin-top: 6px;
  font-family: "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 52px;
  line-height: 1;
  word-break: break-word;
}

.selected-meta {
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

dt {
  margin-top: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1.35;
}

.chart-shell {
  min-width: 0;
  min-height: 0;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 18px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  background: var(--level-color);
}

.chart-scroll {
  position: relative;
  height: calc(100vh - 96px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: inset 0 0 0 8px white;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.chart-scroll.is-panning {
  cursor: grabbing;
}

.chart-map {
  position: relative;
  width: 2617px;
  height: 1317px;
  background: white;
  transform: translate3d(var(--pan-x, 0px), var(--pan-y, 0px), 0);
  transform-origin: 0 0;
  will-change: transform;
}

.chart-content {
  position: relative;
  width: 2617px;
  height: 1317px;
  padding: 8px;
  zoom: var(--css-zoom, 1);
  transform: scale(var(--transform-scale, 0.58));
  transform-origin: 0 0;
  backface-visibility: hidden;
  contain: layout paint style;
  will-change: transform;
}

.level-section {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile));
  grid-auto-rows: var(--tile);
  gap: var(--gap);
  align-content: start;
  justify-content: start;
  background: var(--level-color);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.level-section[data-level="1"] {
  left: 8px;
  top: 8px;
  --cols: 25;
  --level-color: var(--hsk1);
}

.level-section[data-level="2"] {
  left: 8px;
  top: 164px;
  --cols: 25;
  --level-color: var(--hsk2);
}

.level-section[data-level="3"] {
  left: 8px;
  top: 320px;
  --cols: 25;
  --level-color: var(--hsk3);
}

.level-section[data-level="4"] {
  left: 658px;
  top: 8px;
  --cols: 25;
  --level-color: var(--hsk4);
}

.level-section[data-level="5"] {
  left: 8px;
  top: 632px;
  --cols: 50;
  --level-color: var(--hsk5);
}

.level-section[data-level="6"] {
  left: 1308px;
  top: 8px;
  --cols: 50;
  --level-color: var(--hsk6);
}

.word-tile {
  display: grid;
  place-items: center;
  width: var(--tile);
  height: var(--tile);
  border: 0;
  padding: 0;
  overflow: hidden;
  color: white;
  background: var(--level-color);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    inset -1px -1px 0 rgba(0, 0, 0, 0.1);
  font-family: "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  cursor: pointer;
}

.word-tile:hover,
.word-tile:focus-visible,
.word-tile.is-selected {
  color: var(--level-color);
  background: white;
  outline: 0;
}

.word-tile.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

.credits {
  display: none;
  padding: 0 clamp(14px, 2.5vw, 32px) 18px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .app-header {
    align-items: end;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .brand-logo {
    width: min(190px, 64vw);
  }

  .toolbar {
    flex: 1 1 360px;
  }

  .search input {
    width: min(280px, 55vw);
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    padding: 8px 12px;
    overflow: auto;
  }

  .detail-panel {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    column-gap: 10px;
    position: relative;
    top: 0;
    min-height: 0;
    height: 132px;
    max-height: none;
    padding: 8px 10px;
    overflow: hidden;
  }

  .panel-kicker,
  .selected-hanzi,
  .selected-meta {
    grid-column: 1;
  }

  .panel-kicker {
    font-size: 9px;
  }

  .selected-hanzi {
    margin-top: 2px;
    font-size: 36px;
  }

  .selected-meta {
    margin: 2px 0 0;
    font-size: 10px;
  }

  .detail-panel dl {
    grid-column: 2;
    grid-row: 1 / span 3;
    margin: 0;
    overflow: auto;
  }

  dt {
    margin-top: 5px;
    font-size: 9px;
  }

  dt:first-child {
    margin-top: 0;
  }

  dd {
    margin-top: 1px;
    font-size: 11px;
    line-height: 1.25;
  }

  .chart-head {
    align-items: start;
    gap: 4px 8px;
    font-size: 10px;
  }

  .legend-item {
    gap: 3px;
  }

  .chart-map {
    min-width: 0;
  }
}
