:root {
  --color-bg: #f6f8fa;
  --color-surface: #ffffff;
  --color-border: #d0d7de;
  --color-text: #1f2328;
  --color-muted: #57606a;
  --color-primary: #0969da;
  --color-primary-hover: #0860c4;
  --color-added-bg: #e6ffed;
  --color-added-text: #22863a;
  --color-added-word-bg: #acf2bd;
  --color-removed-bg: #ffeef0;
  --color-removed-text: #b31d28;
  --color-removed-word-bg: #fdb8c0;
  --color-changed-bg: #fffbdd;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

.app {
  width: 100%;
  margin: 0;
  padding: 20px 24px 40px;
}

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

.brand-icon {
  display: block;
  flex: 0 0 auto;
}

.app-header h1 {
  margin: 0;
  font-size: 1.8rem;
}

.app-header .lead {
  margin: 0 0 20px;
  color: var(--color-muted);
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.9rem;
  cursor: pointer;
}

.btn:hover {
  background: #f3f4f6;
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

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

kbd {
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.8em;
  background: var(--color-surface);
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.stat {
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 600;
}

.stat-added {
  background: var(--color-added-bg);
  color: var(--color-added-text);
}

.stat-removed {
  background: var(--color-removed-bg);
  color: var(--color-removed-text);
}

.stat-changed {
  background: #fff8c5;
  color: #7d5c00;
}

.input-area {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.pane {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pane label {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.pane textarea {
  flex: 1;
  min-height: 260px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}

.pane textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

.diff-area {
  width: 100%;
  margin-bottom: 20px;
}

/* Both sides live in a single grid so a line's row height — and
   therefore its vertical position — is always shared by both sides,
   even when wrapped content makes a row taller. This is what keeps
   long, wrapping lines from pushing the two sides out of sync. */
.diff-grid {
  display: grid;
  grid-template-columns: 3.6em minmax(0, 1fr) 3.6em minmax(0, 1fr);
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--color-surface);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.diff-grid-header {
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f3f4f6;
  border-bottom: 1px solid var(--color-border);
}

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

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

.diff-cell {
  min-height: 1.6em;
  padding: 1px 8px;
}

.diff-cell.num {
  text-align: right;
  color: var(--color-muted);
  background: #f6f8fa;
  user-select: none;
}

.cell-left-num {
  border-right: 1px solid var(--color-border);
}

.cell-right-num {
  border-left: 1px solid var(--color-border);
}

.diff-cell.content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* "No-wrap" mode: long lines are clipped instead of wrapping, with no
   scrollbar and no scroll cursor — text past the edge is simply not
   shown. Rows stay aligned because with no wrapping every row is a
   single line tall on both sides. */
.diff-grid.nowrap .diff-cell.content {
  white-space: pre;
  overflow: hidden;
  text-overflow: clip;
}

.diff-cell.type-added {
  background: var(--color-added-bg);
}
.diff-cell.content.type-added {
  color: var(--color-added-text);
}

.diff-cell.type-removed {
  background: var(--color-removed-bg);
}
.diff-cell.content.type-removed {
  color: var(--color-removed-text);
}

.diff-cell.type-changed {
  background: var(--color-changed-bg);
}

.diff-cell.type-empty {
  background: #fafbfc;
}

.word-added {
  background: var(--color-added-word-bg);
  border-radius: 2px;
}

.word-removed {
  background: var(--color-removed-word-bg);
  border-radius: 2px;
  text-decoration: line-through;
}

.app-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.82rem;
  color: var(--color-muted);
}

.app-footer p + p {
  margin-top: 4px;
}

.footer-link {
  color: inherit;
  text-decoration: underline;
}

@media (max-width: 768px) {
  .input-area {
    flex-direction: column;
  }

  .pane {
    flex: 1 1 auto;
  }

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

  .btn,
  .checkbox-label {
    width: 100%;
  }

  .btn {
    text-align: center;
  }

  .diff-grid {
    font-size: 0.78rem;
    grid-template-columns: 2.6em minmax(0, 1fr) 2.6em minmax(0, 1fr);
  }
}
