/* Coaching page — offline draft.
   Independent from the live site's home.css so we can iterate freely.
   On migration to /diy/write/, we'll swap colors/fonts to the site palette. */

:root {
  --ink: #2b1d12;
  --paper: #faf4e6;
  --accent: #ee0a14;
  --soft: #ece1c8;
  --muted: rgba(60, 40, 30, 0.55);
  --hairline: rgba(60, 40, 30, 0.14);
  --stress-bg: #f4ecd8;
  --syllable-bg: #ffffff;
  --syllable-border: rgba(60, 40, 30, 0.18);
  --stressed-bg: #fff3d6;
  --stressed-border: #d9b86b;
  --unknown-bg: #fbe8e8;
  --unknown-border: #d99c9c;
  /* Foot tier colors */
  --tier-green-bg: #e3f0d8;
  --tier-green-border: #8bbf6a;
  /* --tier-yellow-* removed in the 2-tier rewrite. Feet are green or red. */
  --tier-red-bg: #fbe0e0;
  --tier-red-border: #d97070;
  --font-display: Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

.coach {
  max-width: 920px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.coach-header {
  text-align: center;
  margin-bottom: 2rem;
}

.page-back-stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
  margin: 0 0 1rem;
}
.page-back {
  display: inline-block;
  font-family: var(--font-display, 'Caveat', cursive);
  font-size: 1.1rem;
  color: #1a2348;
  text-decoration: none;
}
.page-back--secondary { font-size: 0.95rem; opacity: 0.9; }
.page-back:hover { text-decoration: underline; }

.coach-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}

.coach-sub {
  font-size: 1.05rem;
  opacity: 0.75;
  margin: 0;
}

/* Each line: input on the left, stats column on the right. */
.line {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 1rem;
  margin-bottom: 0.5rem;
  align-items: stretch;
}

.line-input-wrap {
  display: flex;
  flex-direction: column;
}

/* Per-line Clear text button — small, understated, right-aligned. */
.line-clear {
  align-self: flex-end;
  margin-top: 0.35rem;
  padding: 0;
  background: transparent;
  border: none;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: #c8102e;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  line-height: 1.2;
}
.line-clear:hover,
.line-clear:focus-visible {
  color: var(--ink);
  outline: none;
}
.line-clear[hidden] { display: none; }

.line-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.line-input {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.3;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  resize: vertical;
  min-height: 2.2rem;
  height: 2.4rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.line-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.12);
}

/* Whole input goes red when no template fits well */
.line-input--red {
  border-color: var(--tier-red-border);
  background: #fff7f7;
}
.line-input--red:focus {
  border-color: var(--tier-red-border);
  box-shadow: 0 0 0 3px rgba(217, 112, 112, 0.18);
}

.line-stats {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.4rem;
  padding-bottom: 0.15rem;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.stat-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  flex-shrink: 0;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--ink);
  font-weight: 600;
}

.stat-value--empty {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

/* ---------- Stress box ---------- */
/* Sits below the input. Spans the full width (under input AND stats column)
   so syllable boxes have room to breathe for long lines. */
.stress-box {
  grid-column: 1 / -1;
  background: var(--stress-bg);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  margin-top: 0.4rem;
  margin-bottom: 1.1rem;
  min-height: 4.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.35rem 0.5rem;
}

.stress-box--empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
}

.stress-box--loading {
  opacity: 0.5;
}

/* ---------- Candidate templates ---------- */
/* All three canonical patterns are always shown, stacked in fixed order.
   Force each onto its own row inside the stress-box flex container. */
.candidate {
  margin-bottom: 0.55rem;
  width: 100%;
  flex: 0 0 100%;
}

.candidate:last-child {
  margin-bottom: 0;
}

.candidate-header {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
}

.candidate-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  background: rgba(60, 40, 30, 0.08);
  border-radius: 50%;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--ink);
  flex-shrink: 0;
}

.candidate--best .candidate-letter {
  background: var(--tier-green-border);
  color: white;
}

.candidate-name {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink);
}

.candidate-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

/* .candidate-badge removed: in the 2-tier UI only the best-fit pattern is
   rendered, so the "best fit" badge is no longer needed. */

.candidate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: center;
}

/* A foot groups 1-3 syllable boxes into a colored container.
   The color indicates how well it matches the template's expected pattern. */
.foot {
  display: flex;
  gap: 0.15rem;
  padding: 0.22rem 0.3rem;
  border-radius: 7px;
  border: 1.5px solid transparent;
  position: relative;
}

.foot--green {
  background: var(--tier-green-bg);
  border-color: var(--tier-green-border);
}

.foot--red {
  background: var(--tier-red-bg);
  border-color: var(--tier-red-border);
}

/* A single syllable box */
.syllable {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  padding: 0.2rem 0.45rem 0.18rem;
  background: var(--syllable-bg);
  border: 1px solid var(--syllable-border);
  border-radius: 5px;
  min-width: 2.5rem;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  position: relative;
}

.syllable:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(60, 40, 30, 0.15);
}

.syllable--unknown {
  background: var(--unknown-bg);
  border-color: var(--unknown-border);
}

.syllable--overridden {
  border-style: dashed;
}

.syllable-text {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.1;
}

.syllable-stress {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  font-weight: 700;
  line-height: 1;
}

.syllable--unknown .syllable-stress {
  color: #b03030;
}

/* Mismatch indicator: the user's actual stress doesn't fit the template */
.syllable--mismatch {
  background: #fff8e8;
}

/* Reset cursor: clicking restores CMU value */
.reset-overrides {
  margin-left: auto;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.reset-overrides:hover {
  background: rgba(60, 40, 30, 0.08);
  color: var(--ink);
}
.reset-overrides[hidden] {
  display: none;
}

/* Mobile: stack stats under the input */
@media (max-width: 640px) {
  .line {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .line-stats {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.6rem 1.2rem;
    padding-bottom: 0;
  }
  .stress-box {
    grid-column: 1;
  }
}

/* -------- Instructions button + page -------- */

.coach-button {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.coach-button:hover,
.coach-button:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: none;
}

.coach-button:active { transform: translateY(1px); }

/* Destructive variant for Clear All Lines: red outline so it reads as a wipe,
   not just another navigation button. */
.coach-button--clear {
  border-color: #c8102e;
  color: #c8102e;
}
.coach-button--clear:hover,
.coach-button--clear:focus-visible {
  background: #c8102e;
  color: var(--paper);
}

/* Instructions page layout */
.coach.instructions {
  max-width: 780px;
}

.coach.instructions .coach-header h1 {
  font-size: clamp(1.6rem, 4.5vw, 2.4rem);
}

.instr-section {
  margin: 2rem 0;
  padding: 1.25rem 1.5rem;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--hairline);
  border-radius: 14px;
}

.instr-section h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 0 0 0.6rem;
  letter-spacing: -0.005em;
}

.instr-section p,
.instr-section li {
  font-size: 1rem;
  line-height: 1.55;
}

.instr-section ul,
.instr-section ol {
  padding-left: 1.25rem;
}

.instr-section li { margin: 0.3rem 0; }

.ex {
  font-family: var(--font-mono);
  background: var(--stress-bg);
  border: 1px solid var(--syllable-border);
  border-radius: 6px;
  padding: 0 0.35rem;
  font-size: 0.92em;
  white-space: nowrap;
}

.color-key { list-style: none; padding-left: 0; }

.color-key li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.45rem 0;
}

.swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
}

.swatch-green  { background: var(--tier-green-bg);  border: 1px solid var(--tier-green-border); }
.swatch-red    { background: var(--tier-red-bg);    border: 1px solid var(--tier-red-border); }

.instr-foot {
  font-style: italic;
  opacity: 0.75;
  margin-top: 1rem;
}

.instr-back {
  text-align: center;
  margin: 2.5rem 0 0;
}

/* -------- Analysis toggle + control row -------- */

.coach-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.coach-controls .coach-button { margin-top: 0; }

.analysis-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
}

.analysis-toggle input {
  /* Hide the native checkbox but keep it focusable for a11y */
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.analysis-toggle-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.analysis-toggle-track {
  position: relative;
  width: 42px;
  height: 24px;
  /* Default (unchecked) = OFF = red */
  background: #ee0a14;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  transition: background 160ms ease;
  flex-shrink: 0;
}

.analysis-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 160ms ease;
}

/* Checked = ON = green */
.analysis-toggle input:checked + .analysis-toggle-state--off + .analysis-toggle-track {
  background: #2e8b57;
}

.analysis-toggle input:checked + .analysis-toggle-state--off + .analysis-toggle-track .analysis-toggle-thumb {
  transform: translateX(18px);
}

.analysis-toggle input:focus-visible + .analysis-toggle-state--off + .analysis-toggle-track {
  box-shadow: 0 0 0 3px rgba(46, 139, 87, 0.30);
}
.analysis-toggle input:not(:checked):focus-visible + .analysis-toggle-state--off + .analysis-toggle-track {
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.30);
}

.analysis-toggle-state {
  min-width: 1.7em;
  font-variant: small-caps;
  font-weight: 700;
  opacity: 0.32;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
  transition: opacity 160ms ease, color 160ms ease;
}

.analysis-toggle-state--off { text-align: right; }
.analysis-toggle-state--on  { text-align: left; }

/* When checkbox is ON (checked), highlight the "ON" label in green */
.analysis-toggle input:checked ~ .analysis-toggle-state--on {
  opacity: 1;
  color: #2e8b57;
  font-weight: 800;
}

/* When checkbox is OFF (unchecked), highlight the "OFF" label in red */
.analysis-toggle input:not(:checked) ~ .analysis-toggle-state--off {
  opacity: 1;
  color: #ee0a14;
  font-weight: 800;
}

/* -------- Analysis-off mode: hide the feedback chrome -------- */

body.analysis-off .stress-box,
body.analysis-off .line-stats,
body.analysis-off .reset-overrides {
  display: none !important;
}

body.analysis-off .line {
  /* No more side-column for stats; let the textarea use the full width */
  grid-template-columns: 1fr;
  margin-bottom: 0.85rem;
}

body.analysis-off .line-input--red {
  /* Defensive — toggle handler already strips this, but make sure */
  border-color: var(--syllable-border);
  background: var(--syllable-bg);
}

/* -------- Post Limerick button -------- */

.post-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  margin-top: 2.5rem;
  padding-bottom: 2rem;
}

.congrats-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 38rem;
  padding: 0.75rem 1.15rem;
  border-radius: 10px;
  background: #e8f5ec;
  border: 1px solid #2e8b57;
  color: #1b5a37;
  font-family: var(--font-body);
  font-size: 0.98rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  animation: congrats-fade-in 220ms ease-out;
}

.congrats-banner[hidden] {
  display: none;
}

.congrats-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  color: #2e8b57;
}

.congrats-text {
  flex: 1;
}

@keyframes congrats-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 430px) {
  .congrats-banner {
    font-size: 0.9rem;
    padding: 0.65rem 0.95rem;
  }
}

.post-btn-prompt {
  margin: 0 0 0.25rem 0;
  max-width: 38rem;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--ink);
  text-align: center;
}

/* Inline POST reference in the prompt sentence: plain text, same font/size
   as the surrounding sentence (Caveat 1.05rem regular ink). The class is
   kept for HTML stability but contributes no visual styling. */
.post-btn-prompt-pill {
  display: inline;
  padding: 0;
  background: transparent;
  border-radius: 0;
  color: inherit;
  font-weight: inherit;
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
}

/* Bottom POST button — matches the top red banner (.explain-pill--wide) in
   font, size, color, and pill geometry. */
.post-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.05rem 2.4rem;
  border: 1px solid #437A22;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  background: #437A22;
  box-shadow: 0 1px 2px rgba(0, 40, 10, 0.18);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.post-btn:not(:disabled):hover,
.post-btn:not(:disabled):focus-visible {
  background: #365f1a;
  border-color: #365f1a;
  color: #ffffff;
  outline: none;
  transform: translateY(-1px);
}

.post-btn:not(:disabled):active { transform: translateY(1px); }

.post-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.post-btn-icon {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
}

/* -------- Submission modal -------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 29, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 2rem 2rem 1.75rem;
  max-width: 540px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(43, 29, 18, 0.22);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}

.modal-close:hover { background: rgba(60, 40, 30, 0.08); color: var(--ink); }

.modal-title {
  font-family: var(--font-display);
  font-size: 1.55rem;
  margin: 0 0 1.1rem;
  padding-right: 2rem;
}

.modal-preview {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
}

.modal-preview-line {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  margin: 0;
}

.modal-preview-num {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 0.4rem;
  user-select: none;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* HTML `hidden` attribute has lower specificity than the .modal-field
   display:flex rule above. Restore the browser default so cartoon-desc
   and cartoon-file (both hidden until the flow is wired up) stay hidden. */
.modal-field[hidden] { display: none; }

.modal-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.modal-req { color: var(--accent); }

.modal-input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.12);
}

.modal-input.input-error {
  border-color: var(--tier-red-border);
  background: #fff7f7;
}

.modal-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.modal-error {
  font-size: 0.85rem;
  color: #b03030;
  line-height: 1.35;
}

.modal-error[hidden] { display: none; }

.modal-server-error {
  background: var(--tier-red-bg);
  border: 1px solid var(--tier-red-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #7a1515;
}

.modal-server-error[hidden] { display: none; }

.modal-server-error ul {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
}

.modal-server-error li { margin: 0.2rem 0; }

.modal-success {
  background: var(--tier-green-bg);
  border: 1px solid var(--tier-green-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #2a5a10;
  font-weight: 500;
}

.modal-success[hidden] { display: none; }

.modal-submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.6rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
  align-self: flex-start;
}

.modal-submit-btn:hover,
.modal-submit-btn:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: none;
}

.modal-submit-btn:active { transform: translateY(1px); }

.modal-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 560px) {
  .modal-box { padding: 1.5rem 1.25rem 1.5rem; }
  .modal-submit-btn { align-self: stretch; justify-content: center; }
}

/* -------- New headline + subhead sizing -------- */

.coach-header h1.coach-headline {
  font-family: var(--font-display);
  font-weight: 700;
  /* Headline sized to match the rendered width of the subhead. */
  font-size: clamp(1.59rem, 4.6vw, 3.36rem);
  line-height: 1.0;
  /* Remove negative letter-spacing entirely. Negative tracking causes the
     trailing character's spacing to push the visible glyphs toward the
     right edge of the centered box, especially on mobile Safari which
     handles trailing letter-spacing differently than other browsers. */
  letter-spacing: 0;
  /* Defensive centering: explicit auto margins + 100% width + center text
     so the headline is centered even if a parent layout context overrides
     text-align. */
  margin: 0 auto;
  width: 100%;
  display: block;
  text-align: center;
  white-space: nowrap;
  /* Optical correction: serif uppercase letters like "L" have heavy weight
     on the left and trailing "h" extends right, making the visible mass
     appear right-shifted even when geometrically centered. A small left
     translate compensates. */
  transform: translateX(-0.04em);
}

.coach-subhead {
  font-family: var(--font-display);
  /* Italic display serif glyphs are wider than upright, so the subhead's
     ratio is lower than the literal 22/27 char ratio. Tuned visually so
     the subhead sits just inside the headline width on desktop. */
  font-size: clamp(0.95rem, 2.4vw, 1.85rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 2.25rem auto 0;
  width: 100%;
  display: block;
  text-align: center;
  white-space: nowrap;
  font-style: italic;
  color: var(--ink);
  opacity: 0.78;
}

/* On narrow screens, allow both to wrap rather than overflow.
   430px covers iPhone Pro Max and large phones. */
@media (max-width: 430px) {
  .coach-header h1.coach-headline {
    /* Keep one line on mobile. With letter-spacing: 0, the text needs
       slightly more room, so we cap font-size lower. */
    white-space: nowrap;
    font-size: clamp(1.48rem, 7.27vw, 2.1rem);
    /* Smaller optical correction on mobile */
    transform: translateX(-0.03em);
  }
  .coach-subhead  {
    white-space: nowrap;
    font-size: clamp(0.85rem, 3.6vw, 1.15rem);
  }
}

/* On very narrow screens (older iPhone SE, Galaxy Fold), allow wrapping. */
@media (max-width: 340px) {
  .coach-header h1.coach-headline { white-space: normal; font-size: 1.59rem; }
  .coach-subhead  { white-space: normal; font-size: 1.1025rem; }
}

/* =====================================================================
   Show Rhymes button + modal
   ===================================================================== */

.show-rhymes-btn {
  /* Full-width row inside .line-stats so the long dynamic label fits on one line */
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  border: 1.5px solid var(--accent);
  background: white;
  color: var(--accent);
  font: 600 0.9rem/1.15 'Space Grotesk', system-ui, sans-serif;
  letter-spacing: 0.01em;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, color 120ms, opacity 120ms;
  text-align: center;
}
.show-rhymes-btn__label {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.show-rhymes-btn__word {
  font-weight: 700;
  font-style: italic;
}
.show-rhymes-btn:hover:not(:disabled),
.show-rhymes-btn:focus-visible:not(:disabled) {
  background: var(--accent);
  color: white;
  outline: none;
}
.show-rhymes-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
@media (max-width: 380px) {
  .show-rhymes-btn { padding: 0.55rem 0.75rem; font-size: 0.82rem; }
}

/* Anchored popover: positioned by JS just below (or above) the rhyme pill
   the user tapped. No full-viewport overlay, no backdrop — the panel is
   attached to the trigger like a tooltip. JS sets these CSS variables on
   the element each time it opens.
   !important on position/top/left/z-index is needed to beat a higher-
   specificity selector in the page's inline parchment styles
   (body > *:not(.scroll-bg)...) that otherwise forces position:relative. */
.rhymes-modal,
body > .rhymes-modal {
  position: fixed !important;
  top: var(--popover-top, 0px) !important;
  left: var(--popover-left, 0px) !important;
  z-index: 1000 !important;
  width: var(--popover-width, 360px);
  max-height: var(--popover-max-height, 60vh);
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  border: 1px solid rgba(60, 40, 30, 0.18);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 1000;
  animation: rhymes-pop 140ms cubic-bezier(0.2, 0.7, 0.2, 1);
  padding: 0;
  display: block;
}
.rhymes-modal[hidden] { display: none; }

@keyframes rhymes-pop {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.rhymes-modal__box {
  position: relative;
  width: 100%;
  background: transparent;
  color: var(--ink);
  border-radius: 14px;
  padding: 1rem 1rem 1.25rem;
  overflow: visible;
}

.rhymes-modal__close {
  position: sticky;
  top: 0;
  float: right;
  margin: -0.5rem -0.25rem 0.5rem 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1.5px solid var(--ink);
  background: white;
  color: var(--ink);
  font: 600 0.95rem/1 'Space Grotesk', system-ui, sans-serif;
  padding: 0.55rem 0.95rem 0.55rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
  z-index: 2;
}
.rhymes-modal__close:hover,
.rhymes-modal__close:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline: none;
}

.rhymes-modal__title {
  margin: 0 0 0.25rem;
  font: 700 1.4rem/1.2 'Fraunces', Georgia, serif;
  color: var(--ink);
  padding-right: 5.5rem;          /* leaves room for the close pill */
}
.rhymes-modal__sub {
  margin: 0 0 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.rhymes-modal__hint {
  margin: 0 0 1rem;
  font: 500 0.88rem/1.3 'Space Grotesk', system-ui, sans-serif;
  color: var(--brand-red, #ee0a14);
}
.rhymes-modal__hint[hidden] { display: none; }

.rhymes-modal__loading,
.rhymes-modal__empty {
  margin: 1.25rem 0;
  font-style: italic;
  color: var(--muted);
}

.rhymes-section {
  margin-top: 1.25rem;
  border-top: 1px solid rgba(60, 40, 30, 0.12);
  padding-top: 1rem;
}
.rhymes-section:first-of-type { border-top: 0; padding-top: 0; }

.rhymes-section__title {
  margin: 0 0 0.6rem;
  font: 700 0.9rem/1 'Space Grotesk', system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}
.rhymes-section__count {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0;
  text-transform: none;
}

.rhymes-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.5rem;
}
.rhymes-chip {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: white;
  border: 1px solid rgba(60, 40, 30, 0.18);
  color: var(--ink);
  font: 500 0.9rem/1.2 'Space Grotesk', system-ui, sans-serif;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
  -webkit-tap-highlight-color: transparent;
}
.rhymes-chip:hover {
  background: #fff7f3;
  border-color: rgba(60, 40, 30, 0.32);
}
.rhymes-chip:active {
  transform: scale(0.97);
}
.rhymes-chip--active {
  background: var(--brand-red, #ee0a14);
  border-color: var(--brand-red, #ee0a14);
  color: white;
}
.rhymes-syl-group {
  margin-top: 0.75rem;
}
.rhymes-syl-group:first-child { margin-top: 0; }
.rhymes-syl-group__title {
  font: 600 0.78rem/1.2 'Space Grotesk', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(60, 40, 30, 0.62);
  margin: 0 0 0.4rem;
}

/* ---- Definition popup (appears under a chip row) ---- */
.define-pop {
  position: relative;
  margin: 0.5rem 0 0.75rem;
  padding: 0.85rem 2.2rem 0.85rem 0.95rem;
  border-radius: 12px;
  background: #fffaf3;
  border: 1px solid rgba(60, 40, 30, 0.18);
  box-shadow: 0 6px 18px rgba(60, 40, 30, 0.08);
  font: 400 0.92rem/1.4 'Space Grotesk', system-ui, sans-serif;
  color: var(--ink, #3a2a22);
  animation: defineFadeIn 140ms ease-out;
}
.define-pop--anchored {
  position: absolute;
  margin: 0;
  z-index: 30;
  box-shadow: 0 10px 28px rgba(60, 40, 30, 0.18), 0 2px 6px rgba(60, 40, 30, 0.10);
}
@keyframes defineFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.define-pop__close {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 0;
  color: rgba(60, 40, 30, 0.55);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.define-pop__close:hover {
  background: rgba(60, 40, 30, 0.08);
  color: var(--ink);
}
.define-pop__header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.define-pop__word {
  font: 700 1.05rem/1.2 'Space Grotesk', system-ui, sans-serif;
  color: var(--brand-red, #ee0a14);
}
.define-pop__phonetic {
  font: 400 0.85rem/1.2 'Space Grotesk', system-ui, sans-serif;
  color: rgba(60, 40, 30, 0.55);
}
.define-pop__pos {
  font: 600 0.75rem/1.2 'Space Grotesk', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(60, 40, 30, 0.6);
  margin-top: 0.55rem;
}
.define-pop__pos:first-of-type { margin-top: 0.15rem; }
.define-pop__defs {
  margin: 0.2rem 0 0;
  padding-left: 1.25rem;
}
.define-pop__defs li {
  margin: 0.1rem 0;
}
.define-pop__loading,
.define-pop__empty {
  margin: 0;
  color: rgba(60, 40, 30, 0.65);
  font-style: italic;
}
.define-pop__source {
  margin-top: 0.55rem;
  font: 400 0.78rem/1.2 'Space Grotesk', system-ui, sans-serif;
  color: rgba(60, 40, 30, 0.55);
}
.define-pop__source a {
  color: inherit;
  text-decoration: underline;
}

/* ---------- Rhyme scheme analyzer ----------------------------------------
   Lives just below the 5 lines, above the Post Limerick button. A single
   bordered box: 5 stacked "Line N : [box]" rows on the left, short
   explanation on the right, left-justified against the right edge of the
   symbol boxes (with one full character-width of breathing room).
   ------------------------------------------------------------------------- */
.rhyme-scheme {
  /* Two columns: rows on the left at an explicit width that matches the
     visible content of `Line N : [box]`, explanation fills the rest.
     Using `min-content` / `auto` lets the intrinsic max-content (inflated
     by the inter-<li> whitespace text nodes when rows have white-space:
     nowrap) collapse the explainer to a single-word column. Lock it. */
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  align-items: start;
  column-gap: 0.7rem;    /* tight breathing room between boxes and copy */
  background: var(--stress-bg, rgba(255, 255, 255, 0.55));
  border: 1px solid var(--hairline, rgba(60, 40, 30, 0.22));
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin: 0.8rem 0 1.1rem;
  font-family: var(--font-body, 'Space Grotesk', system-ui, sans-serif);
  color: var(--ink, #2a1c10);
}
.rhyme-scheme__rows {
  list-style: none;       /* no 1. 2. 3. 4. 5. numbering */
  margin: 0;
  padding: 0;
  width: 6.5rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.rhyme-scheme__row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font: 600 0.95rem/1.1 var(--font-mono, ui-monospace, 'SF Mono', Menlo, monospace);
  white-space: nowrap;
}
.rhyme-scheme__num {
  color: var(--ink, #2a1c10);
  letter-spacing: 0.01em;
}
.rhyme-scheme__colon {
  color: var(--ink, #2a1c10);
  margin-right: 0.3rem;
}
.rhyme-scheme__box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6em;           /* sized to the widest symbol (X) */
  height: 1.6em;
  border: 1px solid var(--hairline, rgba(60, 40, 30, 0.45));
  border-radius: 4px;
  background: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--ink, #2a1c10);
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
/* Color-code the verdicts so the strip is glanceable */
.rhyme-scheme__box[data-state="A"],
.rhyme-scheme__box[data-state="B"] {
  background: #e8f4ea;
  border-color: #2e7d32;
  color: #1b5e20;
}
.rhyme-scheme__box[data-state="X"] {
  background: #fdecea;
  border-color: #c8102e;
  color: #c8102e;
}
.rhyme-scheme__box[data-state="empty"] {
  /* No symbol — just a soft grey-filled box until the line is started */
  background: #eceae6;
  border-color: rgba(60, 40, 30, 0.22);
  color: transparent;
}
.rhyme-scheme__explain {
  margin: 0;
  /* Snug serif explanation; line-height tight so 5 short rows of rhyme
     rows align roughly with 4-5 lines of explanation text. */
  font: 500 0.88rem/1.28 var(--font-body, 'Space Grotesk', system-ui, sans-serif);
  color: var(--ink, #2a1c10);
  align-self: stretch;
  padding-right: 0.4rem;  /* matches the visual "two spaces" of right margin */
}

/* ----- Allow-one-X rhyme override toggle ----- */
/* Lives inside the rhyme-scheme section, below the explainer paragraph.
   Same toggle ships on Submit. Defaults OFF; flipping ON tells the server
   to permit exactly one X in the AABBA pattern. */
.allow-one-x-toggle {
  /* Inside the .rhyme-scheme grid: span both columns so the label,
     toggle states, and track lay out on a single full-width row
     instead of being squeezed into the narrow left rows column. */
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-body);
  font-size: 1.05rem;
  color: var(--ink);
  margin-top: 0.85rem;
}

.allow-one-x-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.allow-one-x-toggle-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.allow-one-x-toggle-track {
  position: relative;
  width: 42px;
  height: 24px;
  /* Default (unchecked) = OFF = neutral gray (both states are valid). */
  background: #c8c8c8;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  transition: background 160ms ease;
  flex-shrink: 0;
}

.allow-one-x-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 160ms ease;
}

.allow-one-x-toggle input:checked + .allow-one-x-toggle-state--off + .allow-one-x-toggle-track {
  background: #2e8b57;
}

.allow-one-x-toggle input:checked + .allow-one-x-toggle-state--off + .allow-one-x-toggle-track .allow-one-x-toggle-thumb {
  transform: translateX(18px);
}

.allow-one-x-toggle input:focus-visible + .allow-one-x-toggle-state--off + .allow-one-x-toggle-track {
  box-shadow: 0 0 0 3px rgba(46, 139, 87, 0.30);
}
.allow-one-x-toggle input:not(:checked):focus-visible + .allow-one-x-toggle-state--off + .allow-one-x-toggle-track {
  box-shadow: 0 0 0 3px rgba(120, 120, 120, 0.30);
}

.allow-one-x-toggle-state {
  min-width: 1.7em;
  font-variant: small-caps;
  font-weight: 700;
  opacity: 0.32;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
  transition: opacity 160ms ease, color 160ms ease;
}

.allow-one-x-toggle-state--off { text-align: right; }
.allow-one-x-toggle-state--on  { text-align: left; }

.allow-one-x-toggle input:checked ~ .allow-one-x-toggle-state--on {
  opacity: 1;
  color: #2e8b57;
  font-weight: 800;
}

.allow-one-x-toggle input:not(:checked) ~ .allow-one-x-toggle-state--off {
  opacity: 1;
  color: #6b6b6b;
  font-weight: 800;
}
