:root {
  --bg: #fbf5ee;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-border: rgba(138, 101, 60, 0.18);
  --ink: #2d241d;
  --muted: #796552;
  --delete-soft: rgba(242, 210, 94, 0.36);
  --delete-strong: rgba(242, 210, 94, 0.62);
  --insert-soft: rgba(156, 220, 160, 0.34);
  --insert-strong: rgba(156, 220, 160, 0.58);
  --spell-soft: rgba(236, 163, 202, 0.34);
  --spell-strong: rgba(236, 163, 202, 0.6);
  --sentence-row: rgba(255, 248, 240, 0.36);
  --sentence-row-changed: rgba(230, 177, 111, 0.08);
  --sentence-connector: rgba(182, 123, 58, 0.18);
  --sentence-connector-changed: rgba(218, 139, 54, 0.28);
  --shadow: 0 18px 45px rgba(83, 55, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(236, 188, 126, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 217, 181, 0.34), transparent 32%),
    linear-gradient(180deg, #fffaf4 0%, var(--bg) 100%);
}

.app-shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 16px 0 48px;
}

.hero {
  margin-bottom: 14px;
}

.hero-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hero-topbar .header-account {
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  font-size: 0.85rem;
  text-align: right;
}

.header-account button {
  padding: 8px 12px;
}

/* Show the horizontal wordmark from the supplied logo presentation sheet. */
.app-logo {
  position: relative;
  width: 180px;
  flex-shrink: 0;
  aspect-ratio: 900 / 210;
  overflow: hidden;
  margin-bottom: 0;
  mix-blend-mode: multiply;
}

.app-logo img {
  position: absolute;
  width: 139.333333%;
  height: auto;
  max-width: none;
  left: -20%;
  top: -366.666667%;
}

.eyebrow {
  margin: 0 0 6px;
  color: #9f6b2d;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(1.25rem, 2.5vw, 1.5rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.intro {
  margin: 4px 0 0;
  max-width: 85ch;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

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

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary-button {
  background: #2d241d;
  color: #fff9f1;
  box-shadow: var(--shadow);
}

.secondary-button {
  background: rgba(255, 248, 240, 0.92);
  color: var(--ink);
  border: 1px solid rgba(117, 84, 50, 0.14);
}

.status-text {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.95rem;
}

.date-control {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.date-control input {
  min-height: 42px;
  border: 1px solid rgba(117, 84, 50, 0.14);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 248, 240, 0.92);
  color: var(--ink);
  font: inherit;
}

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

.results-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: 14px;
  align-items: start;
  margin-top: 18px;
}

.results-grid {
  margin-top: 0;
  position: relative;
}

.results-grid--sentences .result-panel {
  overflow: visible;
  position: relative;
  z-index: 1;
}

.learned-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(117, 84, 50, 0.1);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-header span {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.panel-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.panel-action-button {
  padding: 9px 14px;
  font-size: 0.92rem;
}

.panel-action-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.panel-action-button--active {
  background: #2d241d;
  color: #fff9f1;
  box-shadow: var(--shadow);
}

.text-input,
.diff-output {
  width: 100%;
  min-height: 320px;
  padding: 20px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  line-height: 1.7;
}

.text-input {
  resize: vertical;
}

.text-input:read-only {
  color: rgba(45, 36, 29, 0.72);
  cursor: default;
}

.text-input:focus {
  outline: 2px solid rgba(230, 177, 111, 0.45);
  outline-offset: -2px;
}

.diff-output {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-output--sentences {
  padding: 0;
  overflow: visible;
  white-space: normal;
}

.sentence-row {
  position: relative;
  min-height: 48px;
  padding: 14px 20px;
  border-top: 1px solid rgba(117, 84, 50, 0.1);
  background: var(--sentence-row);
  white-space: pre-wrap;
  word-break: break-word;
}

.sentence-row:first-child {
  border-top: 0;
}

.sentence-row--changed {
  background: var(--sentence-row-changed);
}

.sentence-row--empty {
  min-height: 42px;
  background:
    linear-gradient(
      90deg,
      transparent 0,
      transparent 18px,
      rgba(117, 84, 50, 0.18) 18px,
      rgba(117, 84, 50, 0.18) calc(100% - 18px),
      transparent calc(100% - 18px)
    )
    center / 100% 1px no-repeat,
    rgba(255, 248, 240, 0.52);
}

.sentence-row--paragraph-break::before {
  content: "^^^^^^^^^^^^^^^^";
  position: absolute;
  left: 20px;
  right: 20px;
  top: 50%;
  overflow: hidden;
  color: rgba(117, 84, 50, 0.48);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1;
  text-align: center;
  transform: translateY(-50%);
  white-space: nowrap;
}

.sentence-connectors {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

.sentence-connector {
  fill: var(--sentence-connector);
}

.sentence-connector--changed {
  fill: var(--sentence-connector-changed);
}

.sentence-row > * {
  position: relative;
  z-index: 1;
}

.diff-placeholder {
  color: var(--muted);
}

.diff-mark {
  border-radius: 0.3em;
}

.diff-mark--delete {
  background: var(--delete-soft);
  box-shadow: inset 0 -0.08em 0 var(--delete-strong);
}

.diff-mark--insert {
  background: var(--insert-soft);
  box-shadow: inset 0 -0.08em 0 var(--insert-strong);
}

.diff-mark--spell {
  background: var(--spell-soft);
  box-shadow: inset 0 -0.08em 0 var(--spell-strong);
}

.diff-mark--strong {
  font-weight: 600;
}

.diff-char-emphasis {
  font-weight: 700;
}

.diff-segment {
  border-radius: 0.45em;
  outline: 1px solid transparent;
  outline-offset: 1px;
  transition: outline-color 120ms ease, background-color 120ms ease;
}

.diff-segment--interactive {
  cursor: pointer;
  user-select: none;
}

.diff-segment--selected {
  outline-color: rgba(130, 130, 130, 0.75);
}

.learned-panel {
  margin-top: 18px;
}

.history-panel {
  margin-bottom: 18px;
}

.history-panel[hidden] {
  display: none;
}

.history-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 16px 20px 0;
}

.history-list {
  min-height: 82px;
  padding: 16px 20px 20px;
  display: grid;
  gap: 10px;
}

.history-placeholder {
  color: var(--muted);
}

.history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  width: 100%;
  padding: 13px 15px;
  border: 1px solid rgba(117, 84, 50, 0.12);
  border-radius: 16px;
  background: rgba(255, 248, 240, 0.78);
  color: inherit;
  text-align: left;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.history-entry--selected {
  border-color: rgba(130, 130, 130, 0.78);
  background: rgba(240, 235, 229, 0.96);
}

.history-entry__meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.history-entry__preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.history-entry__button {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.history-entry__button--delete {
  color: #7c2d20;
}

.history-arrow {
  color: var(--muted);
}

.learned-list {
  min-height: 96px;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}

.learned-placeholder {
  color: var(--muted);
}

.learned-entry {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid rgba(117, 84, 50, 0.12);
  border-radius: 999px;
  background: rgba(255, 248, 240, 0.78);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.learned-entry--selected {
  border-color: rgba(130, 130, 130, 0.78);
  background: rgba(240, 235, 229, 0.96);
}

.learned-arrow {
  color: var(--muted);
}

.learned-note-indicator {
  position: absolute;
  top: -7px;
  right: -5px;
  min-width: 22px;
  padding: 2px 6px;
  border: 1px solid rgba(117, 84, 50, 0.18);
  border-radius: 999px;
  background: #2d241d;
  color: #fff9f1;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.learned-note-panel {
  padding: 0 20px 20px;
}

.learned-note-panel[hidden] {
  display: none;
}

.learned-note-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.learned-note-input {
  width: 100%;
  min-height: 110px;
  padding: 14px 16px;
  border: 1px solid rgba(117, 84, 50, 0.14);
  border-radius: 16px;
  background: rgba(255, 248, 240, 0.72);
  color: inherit;
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

.learned-note-input:focus {
  outline: 2px solid rgba(230, 177, 111, 0.45);
  outline-offset: 2px;
}

.learned-note-input:read-only {
  color: rgba(45, 36, 29, 0.72);
  cursor: default;
}

@media (max-width: 900px) {
  .panel-grid {
    grid-template-columns: 1fr;
  }

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

  .learned-controls {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .results-grid--sentences .result-panel {
    overflow: hidden;
  }

  .sentence-connectors {
    display: none;
  }

  .status-text {
    width: 100%;
    margin-left: 0;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-header span {
    text-align: left;
  }

  .panel-actions,
  .panel-buttons {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .history-entry {
    grid-template-columns: 1fr;
  }

  .history-entry__actions {
    justify-content: flex-start;
  }
}

[hidden] { display: none !important; }
.account-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.account-bar > span { color: var(--muted); }
#authDialog { max-width: min(460px, calc(100vw - 32px)); border: 1px solid var(--panel-border); border-radius: 16px; background: #fffaf4; color: var(--ink); padding: 24px; }
#authDialog::backdrop { background: #0006; }
#authForm label { display: grid; gap: 6px; margin: 14px 0; }
#authForm input { font: inherit; padding: 10px; border: 1px solid var(--panel-border); border-radius: 6px; }
#authError { color: #a12e2e; }
