:root {
  color-scheme: light;
  --page: #f4f6f7;
  --surface: #ffffff;
  --surface-subtle: #edf1f2;
  --text: #172126;
  --muted: #657178;
  --border: #cfd7da;
  --border-strong: #aab6ba;
  --left: #2165b5;
  --left-soft: #e6f0fb;
  --right: #7a4eb3;
  --right-soft: #f0eafb;
  --add: #13795b;
  --add-soft: #e2f3ec;
  --delete: #b5473d;
  --delete-soft: #fae9e7;
  --replace-soft: #fff5d9;
  --milestone: #c17a16;
  --focus: #126f86;
  --shadow: 0 10px 28px rgba(18, 33, 39, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #121617;
    --surface: #1a2022;
    --surface-subtle: #232b2e;
    --text: #e8edef;
    --muted: #9aa7ac;
    --border: #354145;
    --border-strong: #516064;
    --left: #6daaf0;
    --left-soft: #1c3348;
    --right: #bf98ef;
    --right-soft: #362849;
    --add: #61c7a4;
    --add-soft: #173b31;
    --delete: #ef8c82;
    --delete-soft: #472825;
    --replace-soft: #44391e;
    --milestone: #efb75f;
    --focus: #6dc3d5;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button,
select,
input {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 0 20px 24px;
}

.app-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark svg,
.icon-link svg,
.icon-button svg,
.empty-state svg {
  width: 18px;
  height: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 600;
}

h2 {
  font-size: 13px;
  font-weight: 600;
}

.brand-block p,
.section-heading p,
.pane-header p,
.diff-title-block p,
.whole-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.icon-link,
.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.icon-link {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.icon-link:hover,
.icon-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
}

.comparison-toolbar {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) 36px minmax(210px, 1fr) minmax(280px, auto);
  align-items: end;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.version-field {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.side-key {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
}

.side-left {
  color: var(--left);
  background: var(--left-soft);
}

.side-right {
  color: var(--right);
  background: var(--right-soft);
}

select {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 11px;
  font-family: var(--mono);
  cursor: pointer;
}

.swap-button {
  margin-bottom: 1px;
}

.comparison-stats {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  white-space: nowrap;
  font-size: 12px;
}

.comparison-stats strong {
  margin-right: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
}

.comparison-stats .addition strong {
  color: var(--add);
}

.comparison-stats .deletion strong {
  color: var(--delete);
}

.timeline-band {
  padding: 10px 0 8px;
  border-bottom: 1px solid var(--border);
}

.section-heading,
.timeline-footer,
.pane-header,
.diff-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.segmented-control {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-subtle);
}

.segmented-control button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented-control button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.segmented-control button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.timeline-wrap {
  position: relative;
  width: 100%;
  margin-top: 5px;
}

#timelineCanvas {
  display: block;
  width: 100%;
  height: 72px;
  cursor: crosshair;
}

.timeline-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 128px;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.timeline-footer {
  min-height: 22px;
  padding-top: 3px;
}

#releaseNote {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.timeline-legend {
  display: flex;
  flex: 0 0 auto;
  gap: 14px;
  color: var(--muted);
  font-size: 11px;
}

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

.view-toolbar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
}

.view-tabs button {
  min-width: 92px;
}

.display-mode button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.display-mode svg {
  width: 14px;
  height: 14px;
}

.whole-view {
  height: calc(100vh - 326px);
  min-height: 520px;
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.whole-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.aggregate-editor {
  min-width: 0;
  min-height: 0;
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface);
}

.aggregate-editor > .monaco-diff-editor {
  width: 100%;
  height: 100%;
}

.legend-bar {
  width: 10px;
  height: 8px;
  display: inline-block;
  background: var(--border-strong);
}

.legend-dot {
  width: 7px;
  height: 7px;
  display: inline-block;
  border-radius: 50%;
  background: var(--milestone);
}

.compare-workspace {
  height: calc(100vh - 286px);
  min-height: 520px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.file-browser,
.diff-viewer {
  min-width: 0;
  min-height: 0;
}

.file-browser {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.pane-header,
.diff-header {
  min-height: 72px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-control {
  width: 156px;
  height: 34px;
  position: relative;
  display: block;
}

.search-control svg {
  width: 15px;
  height: 15px;
  position: absolute;
  top: 9px;
  left: 9px;
  color: var(--muted);
  pointer-events: none;
}

.search-control input {
  width: 100%;
  height: 34px;
  padding: 0 9px 0 30px;
}

.file-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
}

.file-filters {
  display: grid;
  gap: 8px;
  padding: 9px 12px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.scope-filter {
  width: 100%;
}

.scope-filter button {
  flex: 1;
}

.scope-filter span,
.status-filters span {
  margin-left: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.status-filters {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 5px;
}

.status-filters button {
  min-width: 0;
  height: 27px;
  padding: 0 5px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.status-filters button:hover {
  border-color: var(--border);
  background: var(--surface);
}

.status-filters button[aria-pressed="true"] {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(18, 33, 39, 0.08);
}

.file-group {
  border-bottom: 1px solid var(--border);
}

.file-group > summary {
  height: 34px;
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

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

.file-group > summary::before {
  width: 14px;
  content: ">";
  color: var(--muted);
  font-family: var(--mono);
  font-size: 16px;
  transform: rotate(0deg);
}

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

.file-group > summary > span:first-child {
  flex: 1;
}

.group-count {
  font-family: var(--mono);
  font-weight: 400;
}

.file-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 12px 8px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: auto 54px;
}

.file-item:hover {
  background: var(--surface-subtle);
}

.file-item[aria-selected="true"] {
  background: var(--left-soft);
  box-shadow: inset 3px 0 0 var(--left);
}

.status-badge {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 24px;
  border-radius: 4px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}

.status-a {
  color: var(--add);
  background: var(--add-soft);
}

.status-d {
  color: var(--delete);
  background: var(--delete-soft);
}

.status-m,
.status-r {
  color: var(--milestone);
  background: var(--replace-soft);
}

.file-main {
  min-width: 0;
}

.file-name {
  display: block;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.file-detail {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.file-detail .counts {
  flex: 0 0 auto;
  font-family: var(--mono);
}

.plus {
  color: var(--add);
}

.minus {
  margin-left: 5px;
  color: var(--delete);
}

.diff-viewer {
  display: flex;
  flex-direction: column;
}

.diff-title-block {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.diff-title-block > div {
  min-width: 0;
}

#diffTitle {
  overflow: hidden;
  font-family: var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.diff-options {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  gap: 12px;
}

.toggle-control input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--focus);
}

.diff-table {
  min-height: 0;
  flex: 1;
  overflow: auto;
  background: var(--surface);
}

.diff-grid {
  width: 100%;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
}

.diff-column-header,
.diff-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px minmax(0, 1fr);
}

.diff-column-header {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--muted);
}

.diff-column-header > span {
  min-width: 0;
  padding: 7px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diff-column-header .left-label {
  grid-column: 1 / 3;
  border-right: 1px solid var(--border-strong);
}

.diff-column-header .right-label {
  grid-column: 3 / 5;
}

.diff-row {
  min-height: 24px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  content-visibility: auto;
  contain-intrinsic-size: auto 24px;
}

.line-no,
.line-code {
  min-width: 0;
  padding: 3px 8px;
}

.line-no {
  border-right: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--muted);
  text-align: right;
  user-select: none;
}

.line-code {
  overflow: visible;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-table.is-nowrap .diff-grid {
  width: max-content;
  min-width: 100%;
}

.diff-table.is-nowrap .diff-column-header,
.diff-table.is-nowrap .diff-row {
  grid-template-columns: 52px var(--left-code-width) 52px var(--right-code-width);
}

.diff-table.is-nowrap .line-code {
  overflow-wrap: normal;
  white-space: pre;
  word-break: normal;
}

.line-code.left-code {
  border-right: 1px solid var(--border-strong);
}

.diff-row.row-insert .right-no,
.diff-row.row-insert .right-code,
.diff-row.row-replace .right-no,
.diff-row.row-replace .right-code {
  background: var(--add-soft);
}

.diff-row.row-delete .left-no,
.diff-row.row-delete .left-code,
.diff-row.row-replace .left-no,
.diff-row.row-replace .left-code {
  background: var(--delete-soft);
}

.diff-skip {
  width: 100%;
  height: 28px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}

.diff-skip:hover {
  color: var(--text);
}

.empty-state,
.loading-state,
.error-state {
  min-height: 260px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: var(--delete);
}

@media (max-width: 960px) {
  .comparison-toolbar {
    grid-template-columns: minmax(180px, 1fr) 36px minmax(180px, 1fr);
  }

  .comparison-stats {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .compare-workspace {
    grid-template-columns: 310px minmax(0, 1fr);
  }

  .pane-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .search-control {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0 14px 24px;
  }

  .app-header {
    min-height: 70px;
  }

  h1 {
    font-size: 16px;
  }

  .comparison-toolbar {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  .version-field:first-child {
    grid-column: 1;
  }

  .swap-button {
    grid-column: 2;
  }

  .version-field:nth-of-type(2) {
    grid-column: 1 / -1;
  }

  .comparison-stats {
    gap: 12px;
  }

  .timeline-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  #releaseNote {
    width: 100%;
  }

  .whole-view {
    height: calc(100svh - 24px);
    min-height: 560px;
    max-height: 800px;
  }

  .compare-workspace {
    height: calc(100svh - 24px);
    min-height: 620px;
    max-height: 820px;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 42%) minmax(0, 1fr);
  }

  .file-browser {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .pane-header {
    flex-direction: row;
    align-items: center;
  }

  .search-control {
    width: 150px;
  }

  .diff-viewer {
    min-height: 0;
  }

  .diff-grid {
    min-width: 0;
  }

  .diff-column-header {
    grid-template-columns: 1fr 1fr;
  }

  .diff-column-header .left-label {
    grid-column: 1;
  }

  .diff-column-header .right-label {
    grid-column: 2;
  }

  .diff-row {
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .left-no,
  .left-code {
    grid-row: 1;
  }

  .right-no,
  .right-code {
    grid-row: 2;
  }

  .left-no,
  .right-no {
    grid-column: 1;
  }

  .left-code,
  .right-code {
    grid-column: 2;
  }

  .line-code.left-code {
    border-right: 0;
  }

  .row-equal .right-no,
  .row-equal .right-code,
  .row-insert .left-no,
  .row-insert .left-code,
  .row-delete .right-no,
  .row-delete .right-code {
    display: none;
  }

  .diff-table.is-nowrap .diff-column-header,
  .diff-table.is-nowrap .diff-row {
    grid-template-columns: 52px var(--left-code-width) 52px var(--right-code-width);
  }

  .diff-table.is-nowrap .left-no,
  .diff-table.is-nowrap .left-code,
  .diff-table.is-nowrap .right-no,
  .diff-table.is-nowrap .right-code {
    display: block;
    grid-column: auto;
    grid-row: auto;
  }

  .diff-header {
    align-items: flex-start;
  }

  .diff-options {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .icon-link,
  .icon-button,
  select {
    min-height: 44px;
  }

  .segmented-control button {
    min-height: 38px;
  }

  .status-filters button {
    min-height: 36px;
  }
}

@media (max-width: 420px) {
  .brand-block p,
  .timeline-legend {
    display: none;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .comparison-stats {
    flex-wrap: wrap;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .view-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .view-tabs,
  .display-mode {
    width: 100%;
  }

  .view-tabs button,
  .display-mode button {
    flex: 1;
  }

  .pane-header {
    align-items: stretch;
    flex-direction: column;
  }

  .search-control {
    width: 100%;
  }
}
