:root {
  --ink: #1e2329;
  --muted: #667085;
  --line: #d8dde6;
  --paper: #fbfcfd;
  --panel: #ffffff;
  --accent: #2364aa;
  --accent-strong: #174a80;
  --danger: #a23b3b;
  --source: #f1f5f9;
  --row-a: #fff2cc;
  --row-b: #dbeafe;
  --row-c: #dcfce7;
  --row-d: #fce7f3;
  --row-e: #ede9fe;
  --source-head: #d8e0ea;
  --row-a-head: #e9d27c;
  --row-b-head: #a9c7f6;
  --row-c-head: #9fdcb0;
  --row-d-head: #efb7d4;
  --row-e-head: #cbc1f4;
  --llm: #6d5bd0;
  --llm-strong: #5544ad;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 36px;
  padding: 7px 12px;
}

button:hover {
  border-color: #aab4c2;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.actions,
.alignment-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

#alignButton {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#alignButton:hover {
  background: var(--accent-strong);
}

#llmAlignButton {
  border-color: var(--llm);
  background: var(--llm);
  color: #fff;
}

#llmAlignButton:hover {
  background: var(--llm-strong);
}

#llmAlignButton.is-loading {
  cursor: wait;
  opacity: 0.72;
}

main {
  padding: 20px 28px 36px;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: stretch;
  --version-edge-offset: 22px;
}

.source-panel {
  width: calc(100% - (var(--version-edge-offset) * 2));
  margin: 0 var(--version-edge-offset);
}

.version-inputs {
  display: flex;
  align-items: stretch;
  gap: 14px;
  min-width: 0;
  padding: 0 var(--version-edge-offset);
  position: relative;
}

.version-inputs .version-panel {
  flex: 1 1 280px;
  min-width: 260px;
}

.insert-version-slot {
  min-height: 260px;
  width: 42px;
  flex: 0 0 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 -28px;
  z-index: 2;
  pointer-events: none;
}

.insert-version-slot.edge-slot {
  margin: 0 -35px;
}

.insert-version-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 999px;
  color: var(--accent);
  background: #fff;
  box-shadow: 0 8px 22px rgba(30, 35, 41, 0.14);
  opacity: 0;
  transform: scale(0.82);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: auto;
  font-size: 22px;
  line-height: 1;
}

.insert-version-slot:hover .insert-version-button,
.insert-version-button:focus {
  opacity: 1;
  transform: scale(1);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-height: 260px;
  display: flex;
  flex-direction: column;
}

.panel.is-hidden {
  display: none;
}

.panel label,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 650;
  min-height: 48px;
}

.panel-heading label {
  border-bottom: 0;
  padding: 0;
  min-height: 0;
  flex: 1;
}

.panel label span {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

.version-title {
  width: 100%;
  border: 0;
  font-weight: 650;
  color: var(--ink);
  padding: 3px 0;
}

.version-title:focus {
  outline: 2px solid #bfdbfe;
}

.remove-version {
  color: var(--danger);
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 0;
  padding: 12px;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
}

textarea:focus {
  outline: 2px solid #bfdbfe;
  outline-offset: -2px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 10px;
  flex-wrap: wrap;
}

.hint {
  color: var(--muted);
  font-size: 14px;
  flex: 1 1 520px;
}

.alignment-actions {
  justify-content: flex-end;
}

.option-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}

.option-toggle input {
  margin: 0;
}

.status-message {
  color: var(--muted);
  font-size: 14px;
  min-height: 20px;
}

.status-message.error {
  color: var(--danger);
}

.alignment-shell {
  overflow-x: auto;
  border: 0;
  background: transparent;
}

.alignment-table {
  min-width: 780px;
  --alignment-text-size: 16px;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 58px repeat(var(--columns), minmax(220px, 1fr));
  gap: 6px;
}

.cell {
  border: 0;
  border-radius: 6px;
  padding: 8px;
  min-height: 54px;
}

.head {
  font-weight: 700;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.source-head {
  background: var(--source-head);
}

.tone-head-0 {
  background: var(--row-a-head);
}

.tone-head-1 {
  background: var(--row-b-head);
}

.tone-head-2 {
  background: var(--row-c-head);
}

.tone-head-3 {
  background: var(--row-d-head);
}

.tone-head-4 {
  background: var(--row-e-head);
}

.row-number {
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

.row-number.head {
  background: #e9edf3;
}

.row-index {
  line-height: 1;
}

.insert-row-cell {
  grid-column: 2 / -1;
  min-height: 6px;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: -3px 0;
}

.insert-row-button {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  color: var(--accent);
  background: #fff;
  opacity: 0;
  transform: scale(0.88);
  transition: opacity 140ms ease, transform 140ms ease;
}

.insert-row-cell:hover .insert-row-button,
.insert-row-button:focus {
  opacity: 1;
  transform: scale(1);
}

.aligned-text {
  width: 100%;
  min-height: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  resize: none;
  overflow: hidden;
  padding: 8px;
  font-size: var(--alignment-text-size);
  line-height: 1.45;
  background: transparent;
}

.aligned-text:focus {
  outline: 2px solid rgba(35, 100, 170, 0.24);
  background: rgba(255, 255, 255, 0.62);
}

.source-cell {
  background: var(--source);
}

.tone-0 {
  background: var(--row-a);
}

.tone-1 {
  background: var(--row-b);
}

.tone-2 {
  background: var(--row-c);
}

.tone-3 {
  background: var(--row-d);
}

.tone-4 {
  background: var(--row-e);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.row-actions button {
  min-height: 29px;
  padding: 3px 8px;
  font-size: 13px;
}

.delete-row {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
  color: var(--danger);
  font-size: 18px;
  line-height: 1;
}

.text-size-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.text-size-controls button {
  min-width: 40px;
  padding: 7px 9px;
  font-weight: 700;
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 20px 28px 28px;
  color: var(--muted);
  font-size: 14px;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

@media print {
  .topbar,
  .workspace,
  .controls,
  .row-actions,
  .remove-version {
    display: none;
  }

  main {
    padding: 0;
  }

  .alignment-shell {
    border: 0;
    overflow: visible;
  }

  .head {
    position: static;
  }

  .aligned-text {
    border: 0;
    resize: none;
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    flex-direction: column;
    padding: 18px;
  }

  main {
    padding: 16px;
  }

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