/* Sestina Composer — unique bits only. Tokens, body, top-bar, header,
   kicker and note live in /lib/composer-base.css. */
:root {
  --lineage-0: #8b2f1d;
  --lineage-1: #a47215;
  --lineage-2: #355e3b;
  --lineage-3: #2a4d69;
  --lineage-4: #6a2f78;
  --lineage-5: #c0641e;
}

.compose-root {
  min-height: calc(100vh - 48px);
  padding: 0 24px 120px;
}

.compose-page {
  max-width: 820px;
  margin: 0 auto;
  padding: 56px 0 40px;
}

/* Versions panel */
.versions-panel {
  margin-top: 24px;
  padding: 18px;
  background: var(--bg-card);
  border: 1px solid rgba(26, 23, 20, 0.12);
  border-radius: 3px;
}

.versions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.versions-head h3 {
  font-family: 'EB Garamond', serif;
  font-size: 1.3rem;
}

.versions-close {
  background: transparent;
  border: 0;
  color: rgba(26, 23, 20, 0.55);
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
}

.versions-close:hover { color: #1a1714; }

.versions-empty {
  color: rgba(26, 23, 20, 0.55);
  font-size: 0.95rem;
}

.versions-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.versions-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid rgba(26, 23, 20, 0.08);
  border-radius: 2px;
  padding: 10px 12px;
  flex-wrap: wrap;
}

.versions-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.versions-meta strong {
  font-weight: 500;
  font-size: 1rem;
}

.versions-date {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: rgba(26, 23, 20, 0.5);
}

.versions-mode {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.4);
}

.versions-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.versions-actions button {
  background: transparent;
  border: 1px solid rgba(26, 23, 20, 0.2);
  border-radius: 2px;
  padding: 4px 10px;
  font-family: 'Space Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #4a453e;
  cursor: pointer;
}

.versions-actions button:hover {
  background: rgba(26, 23, 20, 0.06);
  color: #1a1714;
}

.versions-actions button.danger {
  color: #8b2f1d;
  border-color: rgba(139, 47, 29, 0.25);
}

.versions-actions button.danger:hover {
  background: #fdecea;
}

.sestina-root {
  min-height: calc(100vh - 48px);
  padding: 0 24px 140px;
}

.sestina-page {
  max-width: 680px;
  margin: 0 auto;
  padding: 56px 0 40px;
}

.sestina-page {
  position: relative;
}

/* Stanzas + envoi + sections sit above the ribbon layer */
.stanza,
.stanza-envoi,
.trail-wrap,
.sestina-section,
.sestina-head {
  position: relative;
  z-index: 1;
}

.sestina-head {
  margin-bottom: 48px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(26, 23, 20, 0.12);
}

/* Reading-mode toggle — sits inside the header, right of the byline */
.reading-mode {
  margin-top: 14px;
  display: inline-flex;
  background: rgba(26, 23, 20, 0.04);
  border: 1px solid rgba(26, 23, 20, 0.12);
  border-radius: 3px;
  padding: 2px;
}

.reading-mode button {
  background: transparent;
  border: 0;
  padding: 5px 14px;
  font-family: 'EB Garamond', serif;
  font-size: 0.9rem;
  color: #4a453e;
  cursor: pointer;
  border-radius: 2px;
}

.reading-mode button.is-on {
  background: #8b2f1d;
  color: #f4efe6;
}

/* Ribbon layer */
.ribbon-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: multiply;
}

.ribbon {
  transition: opacity 0.2s ease;
}

.ribbon.is-dim {
  opacity: 0.12;
}

.ribbon-main {
  fill: none;
  stroke-width: 18;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.18;
  filter: url(#ribbon-soft);
}

.ribbon-highlight {
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0.65;
}

.ribbon-node {
  opacity: 0.85;
}

.ribbon-0 .ribbon-main,
.ribbon-0 .ribbon-highlight { stroke: var(--lineage-0); }
.ribbon-0 .ribbon-node { fill: var(--lineage-0); }

.ribbon-1 .ribbon-main,
.ribbon-1 .ribbon-highlight { stroke: var(--lineage-1); }
.ribbon-1 .ribbon-node { fill: var(--lineage-1); }

.ribbon-2 .ribbon-main,
.ribbon-2 .ribbon-highlight { stroke: var(--lineage-2); }
.ribbon-2 .ribbon-node { fill: var(--lineage-2); }

.ribbon-3 .ribbon-main,
.ribbon-3 .ribbon-highlight { stroke: var(--lineage-3); }
.ribbon-3 .ribbon-node { fill: var(--lineage-3); }

.ribbon-4 .ribbon-main,
.ribbon-4 .ribbon-highlight { stroke: var(--lineage-4); }
.ribbon-4 .ribbon-node { fill: var(--lineage-4); }

.ribbon-5 .ribbon-main,
.ribbon-5 .ribbon-highlight { stroke: var(--lineage-5); }
.ribbon-5 .ribbon-node { fill: var(--lineage-5); }

/* Ribbons view: let end-word text breathe over the ribbons */
.mode-ribbons .end-word {
  background: rgba(244, 239, 230, 0.72);
  padding: 1px 4px;
  margin: -1px -4px;
  border-radius: 2px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.mode-ribbons .end-word .ch-morph {
  background: transparent;
  border-bottom-color: transparent;
}

.sestina-head h1 {
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 500;
  font-size: 2.4rem;
  letter-spacing: -0.5px;
}

.sestina-head .numeral {
  font-variant-numeric: oldstyle-nums;
  color: rgba(26, 23, 20, 0.45);
  font-style: normal;
}

.sestina-head .byline {
  margin-top: 8px;
  font-size: 0.95rem;
  color: rgba(26, 23, 20, 0.55);
}

.stanza {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 20px;
  margin-bottom: 36px;
}

.stanza-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.35);
  padding-top: 6px;
}

.stanza-body .line {
  font-size: 1.15rem;
  line-height: 1.75;
}

.line-lead {
  color: rgba(26, 23, 20, 0.85);
}

/* End-word */
.end-word {
  display: inline-flex;
  cursor: pointer;
  font-style: italic;
  color: var(--lineage, #1a1714);
  position: relative;
  transition: opacity 0.2s;
}

.end-word .ch {
  display: inline-block;
  transition: color 0.3s ease, transform 0.3s ease;
}

.end-word .ch-morph {
  font-weight: 500;
  color: var(--lineage, #1a1714);
  border-bottom: 1px dotted currentColor;
}

.end-word.lineage-0 { --lineage: var(--lineage-0); }
.end-word.lineage-1 { --lineage: var(--lineage-1); }
.end-word.lineage-2 { --lineage: var(--lineage-2); }
.end-word.lineage-3 { --lineage: var(--lineage-3); }
.end-word.lineage-4 { --lineage: var(--lineage-4); }
.end-word.lineage-5 { --lineage: var(--lineage-5); }

.end-word.is-active {
  font-weight: 600;
}

.end-word.is-active .ch-morph {
  background: var(--lineage);
  color: #f4efe6;
  border-bottom: none;
  padding: 0 2px;
  border-radius: 2px;
}

.end-word.is-dim {
  opacity: 0.35;
  color: rgba(26, 23, 20, 0.55);
}

/* Envoi */
.stanza-envoi {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid rgba(26, 23, 20, 0.12);
}

/* Trail — morph lineage callout */
.trail-wrap {
  margin-top: 56px;
  padding: 28px 0 20px;
  border-top: 1px solid rgba(26, 23, 20, 0.12);
}

.trail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 1.25rem;
  font-style: italic;
}

.trail-empty {
  color: rgba(26, 23, 20, 0.4);
  font-size: 0.9rem;
  font-family: 'Space Mono', monospace;
  letter-spacing: 0.5px;
}

.trail-word {
  color: var(--lineage, #1a1714);
  display: inline-flex;
}

.trail-word .ch-morph {
  color: var(--lineage, #1a1714);
  font-weight: 600;
  background: rgba(139, 47, 29, 0.08);
  padding: 0 2px;
  border-radius: 2px;
}

.trail.lineage-0 { --lineage: var(--lineage-0); }
.trail.lineage-1 { --lineage: var(--lineage-1); }
.trail.lineage-2 { --lineage: var(--lineage-2); }
.trail.lineage-3 { --lineage: var(--lineage-3); }
.trail.lineage-4 { --lineage: var(--lineage-4); }
.trail.lineage-5 { --lineage: var(--lineage-5); }

.trail-arrow {
  color: rgba(26, 23, 20, 0.35);
  font-size: 0.9rem;
  font-style: normal;
}

/* Controls */
.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(244, 239, 230, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(26, 23, 20, 0.12);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 50;
}

.controls-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.45);
  margin-right: 8px;
}

.lineage-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid rgba(26, 23, 20, 0.2);
  border-radius: 16px;
  color: var(--chip-color, #1a1714);
  font-family: 'EB Garamond', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.lineage-chip em {
  font-style: italic;
  opacity: 0.7;
  font-size: 0.85rem;
}

.lineage-chip:hover {
  border-color: var(--chip-color, #1a1714);
}

.lineage-chip.is-on {
  background: var(--chip-color);
  color: #f4efe6;
  border-color: var(--chip-color);
}

.lineage-chip.is-on em {
  color: #f4efe6;
  opacity: 0.9;
}

.lineage-chip.lineage-0 { --chip-color: var(--lineage-0); }
.lineage-chip.lineage-1 { --chip-color: var(--lineage-1); }
.lineage-chip.lineage-2 { --chip-color: var(--lineage-2); }
.lineage-chip.lineage-3 { --chip-color: var(--lineage-3); }
.lineage-chip.lineage-4 { --chip-color: var(--lineage-4); }
.lineage-chip.lineage-5 { --chip-color: var(--lineage-5); }

.clear {
  background: transparent;
  border: none;
  color: rgba(26, 23, 20, 0.55);
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  padding: 6px 8px;
}

.clear:hover { color: #1a1714; }

/* Sections: traditional + compose */
.sestina-section {
  margin-top: 72px;
  padding-top: 40px;
  border-top: 1px solid rgba(26, 23, 20, 0.12);
}

.section-head {
  margin-bottom: 24px;
}

.section-head h2 {
  font-family: 'EB Garamond', serif;
  font-weight: 500;
  font-size: 1.8rem;
  letter-spacing: -0.5px;
}

.section-head h2 em {
  font-style: normal;
}

.section-sub {
  margin-top: 4px;
  color: rgba(26, 23, 20, 0.6);
  font-size: 0.95rem;
}

/* Rotation grid */
.rot-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid rgba(26, 23, 20, 0.1);
  border-radius: 3px;
  padding: 14px 14px;
}

.rot-stanza {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 10px;
}

.rot-stanza-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.4);
}

.rot-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

/* Color tokens — indexed by stanza-1 line position */
.rot-row .pos-0, .rot-envoi .pos-0 { --c: var(--lineage-0); }
.rot-row .pos-1, .rot-envoi .pos-1 { --c: var(--lineage-1); }
.rot-row .pos-2, .rot-envoi .pos-2 { --c: var(--lineage-2); }
.rot-row .pos-3, .rot-envoi .pos-3 { --c: var(--lineage-3); }
.rot-row .pos-4, .rot-envoi .pos-4 { --c: var(--lineage-4); }
.rot-row .pos-5, .rot-envoi .pos-5 { --c: var(--lineage-5); }

.rot-cell {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--c, #1a1714);
  background: rgba(244, 239, 230, 0.6);
  border: 1px solid rgba(26, 23, 20, 0.08);
  border-left: 3px solid var(--c, #ccc);
  border-radius: 2px;
  padding: 6px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}

.rot-cell.is-empty {
  color: rgba(26, 23, 20, 0.3);
  font-style: normal;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
}

.rot-cell .ch {
  display: inline;
}

.rot-cell .ch-morph {
  font-weight: 600;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border-radius: 2px;
  padding: 0 2px;
}

/* Editable cell */
.rot-cell--edit {
  padding: 0;
  background: #fff;
  display: flex;
  align-items: stretch;
  position: relative;
}

.rot-cell--edit input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--c, #1a1714);
  outline: none;
  font-style: italic;
}

.rot-cell--edit input::placeholder {
  color: rgba(26, 23, 20, 0.3);
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  font-style: normal;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.rot-cell--edit .rot-cell-diff {
  display: none;
  /* Diff renders on hover for editable cells — keeps the input clean by default */
}

.rot-cell--edit:focus-within {
  border-color: var(--c, rgba(26, 23, 20, 0.4));
}

.rot-cell--edit.is-warn {
  border-left-color: #b03a2e;
  background: #fff4ee;
}

.rot-cell--drag {
  padding-left: 0;
}

.rot-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  cursor: grab;
  user-select: none;
  color: rgba(26, 23, 20, 0.28);
  font-size: 0.85rem;
  letter-spacing: -1px;
  background: rgba(26, 23, 20, 0.03);
  border-right: 1px solid rgba(26, 23, 20, 0.06);
  transition: color 0.12s, background 0.12s;
}

.rot-drag-handle:hover {
  color: var(--c, rgba(26, 23, 20, 0.7));
  background: color-mix(in srgb, var(--c) 8%, transparent);
}

.rot-drag-handle:active {
  cursor: grabbing;
}

.rot-cell--edit.is-drag-source {
  opacity: 0.35;
}

.rot-cell--edit.is-drag-over {
  background: color-mix(in srgb, var(--c) 10%, #fff);
  outline: 2px dashed var(--c, rgba(26, 23, 20, 0.4));
  outline-offset: -2px;
}

.rot-warn {
  position: absolute;
  top: 2px;
  right: 4px;
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #b03a2e;
  background: #ffd8c9;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
}

/* Envoi row in the grid */
.rot-stanza--envoi {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(26, 23, 20, 0.15);
}

.rot-envoi {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rot-envoi-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rot-envoi .rot-cell {
  background: rgba(244, 239, 230, 0.6);
  padding: 4px 8px;
  font-size: 0.95rem;
}

/* Editable envoi cells — compact, white like stanza cells */
.rot-envoi .rot-cell--edit {
  flex: 0 1 auto;
  background: #fff;
  padding: 0;
}

.rot-envoi .rot-cell--edit input {
  padding: 4px 7px;
  width: 6.5em;
  font-size: 0.92rem;
}

.rot-envoi-sep {
  color: rgba(26, 23, 20, 0.35);
  font-family: 'Space Mono', monospace;
}

/* Compose bar — mode switch + start-from presets on one line */
.compose-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  margin-bottom: 32px;
}

.mode-switch {
  display: inline-flex;
  background: rgba(26, 23, 20, 0.04);
  border: 1px solid rgba(26, 23, 20, 0.14);
  border-radius: 3px;
  padding: 2px;
}

.mode-switch button {
  background: transparent;
  border: 0;
  padding: 6px 14px;
  font-family: 'EB Garamond', serif;
  font-size: 0.95rem;
  color: #4a453e;
  cursor: pointer;
  border-radius: 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mode-switch button.is-on {
  background: #8b2f1d;
  color: #f4efe6;
}

.plus-one {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  opacity: 0.7;
  font-style: normal;
}

.view-switch {
  /* Visually distinguish from the primary mode switch */
  background: transparent;
  border-color: rgba(26, 23, 20, 0.08);
}

.view-switch button.is-on {
  background: #8b2f1d;
  color: #f4efe6;
}

/* Body editor — full-poem writing surface */
.body-editor {
  background: var(--bg-card);
  border: 1px solid rgba(26, 23, 20, 0.1);
  border-radius: 3px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.body-gate {
  background: #fff4ee;
  border-left: 3px solid #8b2f1d;
  padding: 10px 14px;
  color: #4a453e;
  font-size: 0.9rem;
  border-radius: 2px;
}

/* Spine row: stanza-1 end-words above the body editor, draggable for reorder */
.body-spine {
  display: grid;
  grid-template-columns: 60px 1fr;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px dashed rgba(26, 23, 20, 0.15);
}

.body-spine-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.45);
}

.body-spine .rot-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.body-spine .rot-cell--edit input {
  padding: 5px 7px;
  font-size: 0.9rem;
}

.body-stanza {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.body-stanza-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.45);
  margin-bottom: 4px;
}

.body-stanza--envoi {
  padding-top: 14px;
  border-top: 1px dashed rgba(26, 23, 20, 0.15);
}

.body-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid rgba(26, 23, 20, 0.1);
  border-left: 3px solid var(--lineage-0);
  border-radius: 2px;
  padding: 0;
  transition: border-color 0.15s, background 0.15s;
}

.body-line.pos-0 { border-left-color: var(--lineage-0); }
.body-line.pos-1 { border-left-color: var(--lineage-1); }
.body-line.pos-2 { border-left-color: var(--lineage-2); }
.body-line.pos-3 { border-left-color: var(--lineage-3); }
.body-line.pos-4 { border-left-color: var(--lineage-4); }
.body-line.pos-5 { border-left-color: var(--lineage-5); }

.body-line input {
  border: 0;
  background: transparent;
  padding: 10px 12px;
  font-family: 'EB Garamond', serif;
  font-size: 1.05rem;
  color: #1a1714;
  outline: none;
  min-width: 0;
  width: 100%;
}

.body-line input::placeholder {
  color: rgba(26, 23, 20, 0.35);
  font-style: italic;
}

.body-line input:disabled {
  background: rgba(26, 23, 20, 0.03);
  color: rgba(26, 23, 20, 0.4);
  cursor: not-allowed;
}

.body-line:focus-within {
  border-color: rgba(26, 23, 20, 0.4);
}

.body-line--ok {
  background: #f7fbf5;
}

.body-line--mismatch {
  background: #fff4ee;
}

.body-expect {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 0 0;
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--lineage-0);
  white-space: nowrap;
}

.body-line.pos-0 .body-expect { color: var(--lineage-0); }
.body-line.pos-1 .body-expect { color: var(--lineage-1); }
.body-line.pos-2 .body-expect { color: var(--lineage-2); }
.body-line.pos-3 .body-expect { color: var(--lineage-3); }
.body-line.pos-4 .body-expect { color: var(--lineage-4); }
.body-line.pos-5 .body-expect { color: var(--lineage-5); }

.ok-tick {
  color: #2a7a3e;
  font-weight: 700;
  font-style: normal;
}

.expect-word {
  font-weight: 500;
}

.expect-word.is-miss {
  opacity: 0.45;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.expect-word.is-pending {
  opacity: 0.55;
}

.expect-word.is-ok {
  opacity: 1;
}

/* Inline editable end-word — editable from the body view too. The
   .body-line input rule above is more specific than .expect-word-input
   alone, so we scope here to win the cascade. */
.body-line .expect-word-input {
  border: 0;
  background: transparent;
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--c, var(--lineage-0));
  outline: none;
  padding: 3px 5px;
  margin: 0;
  width: auto;
  min-width: 3.2em;
  text-align: center;
  border-radius: 2px;
  transition: background 0.12s, opacity 0.15s;
  field-sizing: content;
}

.body-line .expect-word-input::placeholder {
  color: rgba(26, 23, 20, 0.3);
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  font-style: normal;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.body-line .expect-word-input:hover,
.body-line .expect-word-input:focus {
  background: rgba(26, 23, 20, 0.05);
}

.body-line .expect-word-input.is-miss {
  opacity: 0.5;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.body-line .expect-word-input.is-pending {
  opacity: 0.6;
}

.body-line .expect-word-input.is-ok {
  opacity: 1;
}

/* Color tokens for body inline inputs (mid + end may have different lineages
   on envoi lines, so each input carries its own pos- class). */
.body-line .expect-word-input.pos-0 { --c: var(--lineage-0); }
.body-line .expect-word-input.pos-1 { --c: var(--lineage-1); }
.body-line .expect-word-input.pos-2 { --c: var(--lineage-2); }
.body-line .expect-word-input.pos-3 { --c: var(--lineage-3); }
.body-line .expect-word-input.pos-4 { --c: var(--lineage-4); }
.body-line .expect-word-input.pos-5 { --c: var(--lineage-5); }

.expect-sep {
  color: rgba(26, 23, 20, 0.35);
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  margin: 0 3px;
  font-style: normal;
}

.body-clear {
  align-self: flex-start;
  margin-top: 4px;
}

.example-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(26, 23, 20, 0.5);
}

.example-row {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.example-row button {
  background: transparent;
  border: 1px solid rgba(26, 23, 20, 0.2);
  border-radius: 2px;
  color: #1a1714;
  font-family: 'EB Garamond', serif;
  font-size: 0.9rem;
  padding: 4px 10px;
  cursor: pointer;
}

.example-row button:hover {
  background: rgba(26, 23, 20, 0.06);
  border-color: rgba(26, 23, 20, 0.4);
}

.shuffle-btn {
  background: transparent;
  border: 1px dashed rgba(26, 23, 20, 0.3);
  border-radius: 2px;
  color: #1a1714;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 4px 10px;
  cursor: pointer;
}

.shuffle-btn:hover:not(:disabled) {
  background: rgba(26, 23, 20, 0.06);
  border-style: solid;
}

.shuffle-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Compose actions */
.compose-actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.share {
  background: #1a1714;
  color: #f4efe6;
  border: 0;
  border-radius: 2px;
  padding: 8px 14px;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}

.share:hover { background: #000; }
.share:disabled {
  background: rgba(26, 23, 20, 0.3);
  cursor: not-allowed;
}

.share-alt {
  background: transparent;
  color: #1a1714;
  border: 1px solid rgba(26, 23, 20, 0.4);
}

.share-alt:hover { background: rgba(26, 23, 20, 0.06); }
.share-alt:disabled {
  color: rgba(26, 23, 20, 0.3);
  border-color: rgba(26, 23, 20, 0.15);
}

.compose-url {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: rgba(26, 23, 20, 0.45);
  padding: 6px 8px;
  background: rgba(26, 23, 20, 0.03);
  border-radius: 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

@media (max-width: 640px) {
  .sestina-root { padding: 0 16px 160px; }
  .sestina-page { padding: 28px 0 80px; }
  .sestina-head h1 { font-size: 1.8rem; }
  .stanza { grid-template-columns: 28px 1fr; gap: 10px; margin-bottom: 24px; }
  .stanza-body .line { font-size: 1rem; line-height: 1.65; }
  .stanza-num { font-size: 0.6rem; padding-top: 4px; }

  /* Bottom lineage toolbar — stays reachable with one thumb */
  .controls { padding: 8px 10px; gap: 6px; }
  .controls-label { display: none; }
  .lineage-chip { padding: 4px 8px; font-size: 0.8rem; gap: 4px; }
  .lineage-chip em { font-size: 0.75rem; }

  /* Sections stack tighter on mobile */
  .sestina-section { margin-top: 48px; padding-top: 32px; }
  .section-head h2 { font-size: 1.4rem; }

  /* Compose bar wraps to multiple rows */
  .compose-bar { gap: 10px; }
  .mode-switch button { padding: 6px 10px; font-size: 0.9rem; }
  .example-row button { padding: 4px 8px; font-size: 0.85rem; }

  /* Rotation grid: cells move to a 3-column layout, which stays readable */
  .rot-grid { padding: 10px; }
  .rot-stanza { grid-template-columns: 36px 1fr; gap: 8px; }
  .rot-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .rot-cell { font-size: 0.88rem; padding: 5px 7px; }
  .rot-cell--edit input { font-size: 0.9rem; padding: 6px 8px; }

  /* Body editor: the expected-word chip moves below the input so each line
     keeps a usable tappable width */
  .body-editor { padding: 12px; }
  .body-line { grid-template-columns: 1fr; padding-bottom: 6px; }
  .body-line input { font-size: 1rem; padding: 8px 10px; }
  .body-expect {
    justify-content: flex-end;
    padding: 0 10px 6px;
    font-size: 0.82rem;
  }

  /* Compose actions / URL preview stack */
  .compose-actions { gap: 6px; }
  .compose-url {
    width: 100%;
    font-size: 0.65rem;
    flex-basis: 100%;
  }

  /* Trail wraps cleanly */
  .trail { font-size: 1rem; gap: 8px; }
}
