:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --paper: #ffffff;
  --ink: #222426;
  --muted: #6f756f;
  --line: #d9d7ce;
  --accent: #9f2f2b;
  --accent-2: #2d6b61;
  --accent-3: #b57a2a;
  --accent-4: #5d5f8d;
  --soft: #eee9dc;
  --shadow: 0 10px 28px rgba(34, 36, 38, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Inter", "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei",
    system-ui, sans-serif;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfaf7;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.25;
}

h2 {
  font-size: 28px;
  line-height: 1.25;
}

h3 {
  font-size: 18px;
  line-height: 1.3;
}

.brand p,
.panel-head p,
.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.control-group,
.control-grid {
  margin-bottom: 20px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-grid label:first-child:nth-last-child(3),
.control-grid label:first-child:nth-last-child(3) ~ label {
  grid-column: span 1;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 650;
}

label > span,
.control-group > label {
  display: block;
  margin-bottom: 7px;
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 10px 11px;
}

select,
input {
  height: 40px;
}

.tag-input {
  min-height: 116px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px;
  cursor: text;
}

.tag-input.compact {
  min-height: 78px;
}

.tag-input.tall {
  min-height: 174px;
}

.tag-input:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(45, 107, 97, 0.12);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tag {
  flex: 0 0 auto;
  max-width: 100%;
  min-width: 0;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #c9d8d4;
  border-radius: 999px;
  background: #eef6f3;
  color: #203a35;
  padding: 4px 6px 4px 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

.tag-label {
  display: inline-block;
  flex: 0 0 auto;
  width: max-content;
  min-width: 1.5em;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #203a35;
}

.tag-remove {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #45615b;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.tag-remove:hover {
  background: rgba(45, 107, 97, 0.12);
  border-color: transparent;
}

.tag-entry {
  width: auto;
  min-width: 116px;
  flex: 1 1 128px;
  height: 28px;
  border: 0;
  border-radius: 0;
  padding: 3px 4px;
  outline: 0;
  background: transparent;
}

.tag-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.tag-tools button {
  width: auto;
  height: 32px;
  margin-top: 0;
  border-radius: 6px;
  background: #fbfaf7;
  color: var(--muted);
  font-size: 12px;
}

.tag-tools button:hover {
  color: var(--ink);
  border-color: var(--accent-2);
}

button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.actions.single {
  grid-template-columns: 1fr;
}

.period-presets {
  display: grid;
  gap: 6px;
}

.period-preset {
  width: 100%;
  min-height: 34px;
  height: auto;
  margin: 0;
  padding: 7px 9px;
  border-radius: 6px;
  text-align: left;
  font-size: 12px;
  line-height: 1.25;
  font-weight: 650;
}

.period-preset.active {
  border-color: var(--accent-2);
  background: #eef6f3;
  color: #203a35;
}

.control-group button {
  width: 100%;
  margin-top: 10px;
}

.control-group .period-preset {
  margin-top: 0;
}

.tag .tag-remove {
  width: 20px;
  min-width: 20px;
  max-width: 20px;
  height: 20px;
  min-height: 20px;
  margin-top: 0;
  padding: 0;
  flex: 0 0 20px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.view-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 14px;
}

.view-tab {
  height: 34px;
  border: 0;
  border-radius: 5px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.view-tab:hover {
  border-color: transparent;
  background: var(--soft);
}

.view-tab.active {
  background: var(--ink);
  color: #fff;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric .value {
  font-size: 22px;
  font-weight: 760;
  line-height: 1.2;
}

.metric .label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}

.panel-tools {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 8px;
  min-width: 260px;
}

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.segment {
  height: 30px;
  border: 0;
  border-radius: 5px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.segment:hover {
  border-color: transparent;
  background: var(--soft);
}

.segment.active {
  background: var(--ink);
  color: #fff;
}

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

.legend-item {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.chart {
  position: relative;
  min-height: 360px;
  padding: 12px 16px 18px;
}

.chart.small {
  min-height: 300px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.split.single-panel {
  grid-template-columns: 1fr;
}

svg {
  display: block;
  width: 100%;
  height: auto;
}

.axis text {
  fill: var(--muted);
  font-size: 11px;
}

.axis line,
.axis path,
.grid-line {
  stroke: #e2dfd5;
  stroke-width: 1;
}

.axis-line {
  stroke: #c9c5b9;
  stroke-width: 1;
}

.hover-capture {
  cursor: crosshair;
}

.hover-guide {
  stroke: #4d5656;
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.45;
  pointer-events: none;
}

.zoom-selection {
  fill: rgba(45, 107, 97, 0.14);
  stroke: rgba(45, 107, 97, 0.7);
  stroke-width: 1;
  pointer-events: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  width: max-content;
  max-width: 280px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 8px 10px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.tooltip-title {
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 750;
}

.samples,
.cooccurrence {
  padding: 8px 18px 18px;
}

.wordcloud-counts {
  padding: 14px 18px 18px;
}

.count-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.count-table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.count-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.count-table th,
.count-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.count-table th {
  position: sticky;
  top: 0;
  background: #fbfaf7;
  color: var(--muted);
  font-size: 12px;
  z-index: 1;
}

.count-table td:last-child,
.count-table th:last-child {
  width: 120px;
  text-align: right;
}

.wordcloud-chart {
  min-height: 460px;
  padding: 12px 16px 18px;
}

.cloud-word {
  cursor: default;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.84);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.sample {
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.sample:last-child {
  border-bottom: 0;
}

.sample h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.snippet {
  color: #383a3b;
  font-size: 13px;
  line-height: 1.65;
}

mark {
  background: #f3d36b;
  color: #1e1f20;
  padding: 0 2px;
  border-radius: 2px;
}

.empty,
.error {
  padding: 20px;
  color: var(--muted);
}

.error {
  color: var(--accent);
}

.notice {
  margin: 10px 0 12px;
  border: 1px solid #ead59e;
  border-radius: 6px;
  background: #fff8e3;
  color: #6d5520;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
}

.token-box {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
}

.token-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf7;
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.5;
}

.token-row strong {
  display: inline-block;
  min-width: 72px;
  margin-right: 8px;
}

.token-row span {
  color: #2d6b61;
  font-weight: 650;
}

.token-row em {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-style: normal;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .split,
  .metrics {
    grid-template-columns: 1fr;
  }

  .panel-head {
    display: block;
  }

  .panel-tools {
    justify-items: start;
    margin-top: 12px;
  }
}
