:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #667384;
  --line: #d9e2ec;
  --soft-line: #e9eef4;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-hover: #1d4ed8;
  --add: #087f5b;
  --add-soft: #e8f7f0;
  --remove: #b42318;
  --remove-soft: #fff0ed;
  --change: #9a6700;
  --change-soft: #fff7d6;
  --shadow: 0 18px 50px rgba(26, 37, 55, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell > * {
  min-width: 0;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

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

.brand > div {
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
  box-shadow: inset 0 -8px 20px rgba(0, 0, 0, 0.12);
}

.home-link,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.home-link {
  flex: 0 0 auto;
  min-width: max-content;
  height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

.secondary-action {
  width: 100%;
  padding: 0 12px;
}

.home-link:hover,
.home-link:focus-visible,
.secondary-action:hover:not(:disabled),
.secondary-action:focus-visible:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.secondary-action:hover:not(:disabled) {
  transform: translateY(-1px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
  word-break: keep-all;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

.brand p,
.toolbar p,
.status,
.text-card small,
.metric-card span,
.preview-actions span {
  color: var(--muted);
}

.input-panel,
.control-group,
.file-actions {
  display: grid;
  gap: 12px;
}

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

.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 680;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.status {
  min-height: 44px;
  font-size: 13px;
}

.copyright {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.toolbar > div {
  min-width: 0;
}

.toolbar-action {
  width: auto;
  min-width: 104px;
  height: 40px;
  flex: 0 0 auto;
}

.text-input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.text-card,
.metric-card,
.diff-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.text-card {
  display: grid;
  min-width: 0;
  overflow: hidden;
}

.text-card > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--soft-line);
}

.text-card strong,
.text-card small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-width: 0;
  min-height: 230px;
  resize: vertical;
  border: 0;
  background: #fbfcfe;
  color: var(--ink);
  padding: 16px;
  outline: none;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  tab-size: 4;
}

textarea:focus {
  box-shadow: inset 0 0 0 3px rgba(37, 99, 235, 0.16);
}

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

.metric-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 16px;
}

.metric-card strong {
  min-width: 0;
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.diff-panel {
  display: grid;
  min-width: 0;
  overflow: hidden;
}

.output-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.tab-button:hover,
.tab-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.tab-button.is-active {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--accent);
}

.empty-state {
  min-height: 360px;
  padding: 32px;
  color: var(--muted);
}

.side-by-side-view,
.unified-view {
  min-width: 0;
  max-height: min(58vh, 640px);
  overflow: auto;
  background: #fbfcfe;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.side-by-side-view[hidden],
.unified-view[hidden],
.empty-state[hidden] {
  display: none;
}

.diff-table {
  display: grid;
  min-width: 820px;
}

.diff-row {
  display: grid;
  grid-template-columns: 58px minmax(280px, 1fr) 58px minmax(280px, 1fr);
  min-width: 0;
  border-bottom: 1px solid var(--soft-line);
}

.diff-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f2f5f9;
  color: var(--muted);
  font: 12px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 800;
}

.diff-cell {
  min-width: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.diff-line-number {
  border-right: 1px solid var(--soft-line);
  background: #f6f8fb;
  color: #7a8797;
  text-align: right;
  user-select: none;
}

.diff-line-original {
  border-right: 1px solid var(--line);
}

.diff-row.is-added .diff-line-changed,
.unified-line.is-added {
  background: var(--add-soft);
}

.diff-row.is-removed .diff-line-original,
.unified-line.is-removed {
  background: var(--remove-soft);
}

.diff-row.is-changed .diff-line-original,
.diff-row.is-changed .diff-line-changed,
.unified-line.is-changed {
  background: var(--change-soft);
}

.diff-line-empty {
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(103, 115, 132, 0.08) 0,
    rgba(103, 115, 132, 0.08) 8px,
    transparent 8px,
    transparent 16px
  );
}

.inline-added,
.inline-removed,
.inline-changed {
  border-radius: 4px;
  padding: 1px 2px;
}

.inline-added {
  background: rgba(8, 127, 91, 0.18);
  color: #075f46;
}

.inline-removed {
  background: rgba(180, 35, 24, 0.18);
  color: #92221a;
}

.inline-changed {
  background: rgba(154, 103, 0, 0.2);
  color: #7a5200;
}

.unified-view {
  display: grid;
}

.unified-line {
  display: grid;
  grid-template-columns: 54px 34px minmax(0, 1fr);
  min-width: 720px;
  border-bottom: 1px solid var(--soft-line);
}

.unified-number,
.unified-sign {
  padding: 8px 10px;
  background: #f6f8fb;
  color: #7a8797;
  text-align: right;
  user-select: none;
}

.unified-sign {
  border-right: 1px solid var(--soft-line);
  text-align: center;
  font-weight: 850;
}

.unified-content {
  min-width: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-top: 1px solid var(--soft-line);
}

.preview-actions span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

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

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .controls,
  .workspace {
    padding: 22px;
  }

  .copyright {
    margin-top: 0;
  }
}

@media (max-width: 720px) {
  .brand-row,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .home-link,
  .toolbar-action {
    width: 100%;
  }

  .action-grid,
  .text-input-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 180px;
  }
}
