:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --text: #242832;
  --muted: #69707d;
  --line: #d8d4ca;
  --accent: #b13d2b;
  --accent-2: #28635b;
  --accent-soft: #f6ded8;
  --focus: #1f6feb;
  --shadow: 0 12px 32px rgba(35, 39, 47, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181a1f;
  --surface: #22252c;
  --surface-2: #2c3038;
  --text: #f1efe9;
  --muted: #afb4be;
  --line: #3a3f49;
  --accent: #e16c54;
  --accent-2: #70b8ab;
  --accent-soft: #402821;
  --focus: #8ab4ff;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Microsoft YaHei",
    Arial, sans-serif;
  letter-spacing: 0;
}

.parallel-box-zh,
[lang="zh-Hans"] {
  font-family:
    "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Source Han Sans SC",
    "Microsoft JhengHei", Arial, sans-serif;
}

.boot-error {
  border-bottom: 1px solid rgba(180, 83, 9, 0.28);
  background: #fff7ed;
  color: #92400e;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 18px;
}

[data-theme="dark"] .boot-error {
  background: rgba(180, 83, 9, 0.18);
  border-bottom-color: rgba(251, 191, 36, 0.24);
  color: #fed7aa;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: 2rem;
  line-height: 1.18;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.app-shell.is-results-focused {
  padding-top: 12px;
  padding-bottom: 10px;
}

.app-shell.is-results-focused .topbar {
  padding-bottom: 8px;
}

.app-shell.is-results-focused .eyebrow {
  font-size: 0.72rem;
}

.app-shell.is-results-focused h1 {
  font-size: clamp(1.35rem, 2.2vw, 1.65rem);
}

.app-shell.is-results-focused .stats-grid,
.app-shell.is-results-focused .selection-summary {
  display: none;
}

.app-shell.is-results-focused .toolbar,
.app-shell.is-results-focused .results-head {
  margin-bottom: 8px;
}

.app-shell.is-results-focused .site-footer {
  display: none;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.sidebar,
.content {
  min-width: 0;
  min-height: 0;
}

.sidebar {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.control-block {
  display: grid;
  gap: 8px;
}

.candidate-block {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.mode-button,
.view-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.mode-button.is-active,
.view-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.label,
.sort-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.search-input,
.select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.search-input:focus,
.select:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--focus);
  outline: 2px solid color-mix(in srgb, var(--focus), transparent 70%);
  outline-offset: 2px;
}

.select-compact {
  width: 148px;
  min-height: 36px;
}

.multi-select {
  position: relative;
}

.multi-select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.multi-select-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 10px;
}

.book-menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.book-filter-list {
  display: grid;
  gap: 2px;
}

.book-filter-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 36px;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
}

.book-filter-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-filter-item:hover {
  background: var(--surface-2);
}

.usage-filter-item.is-empty {
  color: var(--muted);
  opacity: 0.58;
}

.usage-filter-item.is-empty .candidate-count {
  background: transparent;
}

.book-filter-item input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.small-button,
.text-button,
.icon-button,
.segment {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.small-button {
  min-height: 38px;
  padding: 0 10px;
}

.small-button:hover,
.text-button:hover,
.icon-button:hover,
.segment:hover {
  background: var(--surface-2);
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  color: var(--text);
  text-decoration: none;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  font-size: 1.2rem;
}

.candidate-list {
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.candidate-item,
.keitai-item,
.usage-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.candidate-item:last-child,
.keitai-item:last-child,
.usage-item:last-child {
  border-bottom: 0;
}

.candidate-item input,
.keitai-item input,
.usage-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.candidate-name {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.candidate-no {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.candidate-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.candidate-count {
  min-width: 34px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.keitai-meta {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.stats-grid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat strong {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.toolbar,
.results-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar {
  justify-content: flex-end;
}

.focus-button {
  min-width: 104px;
}

.results-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.view-button {
  min-width: 96px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segment {
  min-height: 36px;
  padding: 0 11px;
}

.segment.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.sort-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.selection-summary {
  flex: 0 0 auto;
  margin-bottom: 14px;
  min-height: 0;
}

.selection-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.selection-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selected-chip-list {
  max-height: 86px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-right: 4px;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 260px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface), var(--surface-2) 45%);
  padding: 3px 8px;
  font-size: 0.84rem;
}

.selected-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-chip strong {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.selected-chip em {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 1px 6px;
  font-style: normal;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

#pageInfo {
  min-width: 84px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.result-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 12px;
  padding-right: 4px;
}

.content {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.site-footer {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 18px;
  margin-top: 10px;
  padding: 9px 2px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.site-footer p {
  margin: 0;
}

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

.result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 0.78rem;
}

.tag-accent {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.tag-usage {
  background: color-mix(in srgb, var(--accent-2), transparent 82%);
  color: var(--accent-2);
  font-weight: 700;
}

.kwic {
  margin: 8px 0 10px;
  font-family:
    "Noto Serif JP", "Yu Mincho", "Hiragino Mincho ProN", "Times New Roman", serif;
  font-size: 1.02rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.kwic-left,
.kwic-right {
  color: var(--muted);
}

.kwic-key {
  color: var(--accent);
  font-weight: 800;
  padding: 0 2px;
}

.term-highlight {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 800;
}

.kwic-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kwic-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
  font-family:
    "Noto Serif JP", "Yu Mincho", "Hiragino Mincho ProN", "Times New Roman", serif;
}

.kwic-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--surface-2), var(--focus) 16%);
  color: var(--text);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-family:
    "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Microsoft YaHei",
    Arial, sans-serif;
  font-size: 0.88rem;
}

.kwic-table th:nth-child(1),
.kwic-table th:nth-child(3) {
  width: calc((100% - 142px) / 2);
}

.kwic-table th:nth-child(2) {
  width: 142px;
}

.kwic-table td {
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.kwic-table tr:last-child td {
  border-bottom: 0;
}

.kwic-table tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface), var(--surface-2) 36%);
}

.kwic-context {
  color: var(--text);
}

.kwic-context-left {
  text-align: right;
}

.kwic-table-key {
  background: color-mix(in srgb, var(--surface), var(--accent-soft) 35%);
  color: var(--accent);
  text-align: center;
  font-weight: 800;
}

.kwic-table-key strong {
  display: block;
}

.kwic-table-key small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family:
    "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Microsoft YaHei",
    Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
}

.parallel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.parallel-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--surface), var(--surface-2) 38%);
}

.parallel-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.parallel-text {
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.empty {
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    padding: 14px;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    max-height: none;
  }

  .candidate-list {
    max-height: min(360px, 46vh);
  }

  .content {
    height: auto;
    overflow: visible;
  }

  .result-list {
    max-height: none;
    overflow: visible;
  }

  .parallel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  h1 {
    font-size: 1.35rem;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .app-shell {
    padding: 10px;
  }

  .topbar,
  .toolbar,
  .results-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .results-controls,
  .pager {
    justify-content: flex-start;
  }

  .results-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .view-toggle {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat {
    padding: 10px;
  }

  .stat strong {
    font-size: 1.25rem;
  }

  .selected-chip-list {
    max-height: 68px;
  }

  .select-compact {
    width: 100%;
  }

  .sidebar {
    padding: 10px;
    gap: 10px;
  }

  .site-footer {
    display: block;
    font-size: 0.74rem;
  }

  .site-footer p + p {
    margin-top: 3px;
  }

  .control-grid {
    grid-template-columns: 1fr 74px;
  }

  .candidate-item,
  .keitai-item,
  .usage-item {
    min-height: 40px;
    padding: 6px 2px;
  }

  .result-card {
    padding: 11px;
  }

  .result-top {
    flex-direction: column;
  }

  .kwic {
    font-size: 0.96rem;
    line-height: 1.65;
  }

  .kwic-table {
    min-width: 760px;
  }

}

