@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;1,9..144,400&family=Inter:wght@400;500&display=swap');

:root {
  --bg: #faf8f3;
  --magic: #597b47;
  --ink: #1b1a17;
  --muted: #8a8377;
  --faint: #a99f8c;
  --hair: #e7e1d4;
  --hair-soft: #eadfce;
  --chip: #efe9dc;
  --chip-ink: #7a7364;
  --accent-bg: #f3e2d8;
  --accent: #a0512c;
  --accent-line: #b0532e;
  --dim-1: #b3a690;
  --dim-2: #8f8672;
  --warn: #b0762e;
  --danger: #b3402e;
}

html[data-theme="dark"] {
  --bg: #141319;
  --magic: #597b47;
  --ink: #ece7dd;
  --muted: #8f887d;
  --faint: #756f66;
  --hair: #2c2a30;
  --hair-soft: #2c2a30;
  --chip: #26242b;
  --chip-ink: #b3ac9f;
  --accent-bg: #3a2820;
  --accent: #d98b5f;
  --accent-line: #d98b5f;
  --dim-1: #6b665d;
  --dim-2: #948d81;
  --warn: #d9a05f;
  --danger: #e07a5f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  line-height: 1.6;
  transition: background .35s ease, color .35s ease;
}

.wrap {
  max-width: 620px;
  margin: 0 auto;
  padding: 48px 26px 96px;
}

/* Header */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.home-link {
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 4px;
  transition: color .2s;
}
.home-link:hover { color: var(--accent); }
.theme-toggle {
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: border-color .2s, color .2s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent-line); }

h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-size: 40px;
  letter-spacing: -.015em;
  margin: 6px 0 6px;
  line-height: 1.05;
}
.subtitle {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 16px;
  color: var(--muted);
  margin: 0 0 34px;
}

/* Section labels */
.label {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 12px;
}
.label .action {
  float: right;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.label .action:hover { color: var(--accent); }

/* Poem input */
textarea#poem {
  width: 100%;
  height: 300px;
  resize: vertical;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-left: 2px solid var(--hair-soft);
  padding: 4px 0 4px 16px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 18px;
  line-height: 1.55;
  outline: none;
  overflow-y: auto;
}
textarea#poem::placeholder { color: var(--faint); font-style: italic; }
.counter { text-align: right; font-size: 11px; color: var(--faint); margin-top: 6px; }

/* Chain builder */
.chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
}
.pill {
  font-size: 12.5px;
  padding: 6px 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pill.fixed { background: var(--chip); color: var(--chip-ink); }
.arrow { color: var(--faint); display: inline-flex; }

.lang-pill {
  background: var(--accent-bg);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  padding-right: 4px;
}
.lang-pill select {
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: transparent;
  border: 0;
  padding: 6px 6px 6px 13px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.lang-pill select option { color: #1b1a17; }
.lang-pill .remove {
  border: 0;
  background: transparent;
  color: var(--accent);
  opacity: .6;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 13px;
  line-height: 1;
  border-radius: 999px;
}
.lang-pill .remove:hover { opacity: 1; }

.pill.ghost {
  background: transparent;
  border: 1px dashed var(--hair);
  color: var(--faint);
  cursor: pointer;
}
.pill.ghost:hover { color: var(--accent); border-color: var(--accent-line); }
.pill.outline {
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--muted);
  cursor: pointer;
}
.pill.outline:hover { color: var(--accent); border-color: var(--accent-line); }

/* Translate button */
.go-row { margin: 28px 0 4px; }
button#go {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 17px;
  color: var(--bg);
  background: var(--magic);
  border: 0;
  border-radius: 999px;
  padding: 11px 30px;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
button#go:hover { opacity: .88; }
button#go:active { transform: scale(.98); }
button#go:disabled { opacity: .45; cursor: default; }

/* Status / errors */
.status { font-style: italic; font-family: 'Fraunces', serif; color: var(--muted); margin: 22px 0; }
.status.error { color: var(--accent); }
.hidden { display: none !important; }

/* Divider */
hr.rule { border: 0; height: 1px; background: var(--hair-soft); margin: 34px 0; }

/* Journey — a horizontal route of clickable languages */
.route {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.step-chip {
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color .2s, transform .1s;
}
.step-chip:hover { border-color: var(--accent-line); }
.step-chip:active { transform: scale(.97); }
.step-chip.active { border-color: var(--accent-line); }
.step-chip.final { background: var(--chip); color: var(--chip-ink); }
.step-chip.final.active { border-color: var(--accent-line); }

.route-hint {
  font-size: 11px;
  font-style: italic;
  color: var(--faint);
  margin: 12px 0 0;
}
.reveal {
  margin-top: 16px;
  padding-left: 16px;
  border-left: 2px solid var(--hair-soft);
  font-family: 'Fraunces', Georgia, serif;
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-line;
  animation: fade .4s ease;
}

@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* Comparison — original (left) vs found (right), paired line-by-line so rows
   always align. Both columns share one font size and line height. */
.compare-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 30px;
  margin-bottom: 10px;
}
.compare-head .label { margin: 0; }

.compare-lines {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 30px;
  font-family: 'Fraunces', Georgia, serif;
}
.cl {
  font-size: 16px;
  line-height: 1.6;
  min-height: 1.6em;           /* preserves blank lines / stanza breaks */
  white-space: pre-wrap;       /* keep indentation, wrap long lines */
  overflow-wrap: anywhere;
}
.cl-orig { color: var(--muted); }
.cl-found {
  color: var(--ink);
  padding-left: 16px;
  border-left: 2px solid var(--accent-line);   /* rows stack into one accent line */
}

@media (max-width: 560px) {
  .compare-head, .compare-lines { gap: 0 14px; }
  .cl { font-size: 14px; }
  .cl-found { padding-left: 10px; }
}

/* Character counter states */
.counter.warn { color: var(--warn); }
.counter.over { color: var(--danger); }

/* Pending hop — the poem is mid-translation */
.step-chip.pending {
  background: var(--chip);
  cursor: default;
  padding: 8px 14px;
}
.dots { display: inline-flex; align-items: center; gap: 4px; }
.dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: dot 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .dots i { opacity: 1; }
}

/* ---- In-place morph stage (desktop) + view management ---- */
#composer { animation: fade .3s ease; }

#stage {
  border: 1px solid var(--hair);
  border-radius: 16px;
  padding: 30px 32px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  animation: fade .4s ease;
}
.stage-lang {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0;
  transition: opacity .3s ease;
}
.stage-lang.show { opacity: 1; }
.stage-text {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 22px;
  line-height: 1.6;
  white-space: pre-line;
  color: var(--ink);
  opacity: 0;
  transition: opacity .3s ease;
}
.stage-text.show { opacity: 1; }
.stage-dots { display: none; }
#stage.loading .stage-dots { display: inline-flex; }

/* Results ordering: mobile keeps the live journey first, then the comparison.
   Desktop leads with the comparison and tucks the revisit-route beneath it. */
#results { display: flex; flex-direction: column; }
#journey-section { order: 1; }
#final-block { order: 2; }
.reset {
  order: 0;
  align-self: flex-end;
  display: none;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 5px 13px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.reset:hover { color: var(--accent); border-color: var(--accent-line); }
#results.settle { animation: settleIn .45s ease; }
@keyframes settleIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (min-width: 700px) {
  .reset { display: inline-block; }
  #final-block { order: 1; }
  #journey-section { order: 2; }
}
