:root {
  --bg: #faf8f3;
  --ink: #1c1b19;
  --muted: #6a6560;
  --rule: #d9d4cc;
  --violation: #c44c4c;
  --accent: #2a2826;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

.site-header {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1.5rem;
  text-align: center;
}

.title {
  margin: 0;
  font-weight: 600;
  font-size: clamp(3rem, 10vw, 4.5rem);
  letter-spacing: 0.35em;
  text-transform: lowercase;
  font-variant: small-caps;
}

.lede {
  margin: 1rem 0 0;
  font-size: 1rem;
  color: var(--muted);
}

.lede a {
  color: var(--accent);
}

.prompt-box {
  margin-top: 0.85rem;
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fffef9;
}

.prompt-box summary {
  cursor: pointer;
  list-style: none;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.prompt-box[open] summary {
  border-bottom: 1px solid var(--rule);
}

.prompt-box pre {
  margin: 0;
  padding: 0.65rem 0.7rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #3e3a35;
}

.gap {
  display: inline-block;
  min-width: 0.5em;
  border-bottom: 2px solid var(--ink);
  color: transparent;
  user-select: none;
}

.controls {
  margin-top: 1.25rem;
}

.check-french {
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  justify-content: stretch;
  margin-top: 1.5rem;
  text-align: left;
}

.legend-card {
  display: flex;
  flex-direction: column;
  gap: 0.33rem;
  border: 1px solid var(--rule);
  background: linear-gradient(180deg, #fffef9 0%, #f7f3eb 100%);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  padding: 0.65rem 0.7rem;
  border-radius: 9px;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

.legend-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.09);
}

.legend-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.legend-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 10px 22px rgba(0, 0, 0, 0.12);
}

.legend-card.failure-mode {
  border-color: #8f6b3a;
  box-shadow: 0 0 0 1px #8f6b3a, 0 8px 18px rgba(143, 107, 58, 0.2);
}

.legend-card-top {
  display: flex;
  align-items: center;
  gap: 0.42rem;
}

.legend-name {
  font-weight: 600;
}

.legend-rank {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}

.legend-k {
  font-size: 0.77rem;
  color: var(--muted);
  text-transform: lowercase;
}

.legend-v {
  font-size: 0.82rem;
}

.legend-failures-v {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.legend-chip {
  width: fit-content;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  text-transform: lowercase;
  border: 1px solid var(--rule);
  color: #4f4a44;
  background: #f4efe4;
}

.legend-chip.good {
  color: #305f3a;
  border-color: #9bc6a5;
  background: #ecf6ee;
}

.legend-chip.warn {
  color: #7a4a26;
  border-color: #d8b291;
  background: #fcf2e8;
}

.legend-chip.neutral {
  color: #4f4a44;
  border-color: var(--rule);
  background: #f4efe4;
}

.legend-tip {
  display: inline-flex;
  position: relative;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-left: 0.15rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  font-size: 0.7rem;
  line-height: 1;
  color: var(--muted);
  cursor: help;
}

.legend-tip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 340px;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fffef9;
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 30;
}

.legend-tip:hover::after,
.legend-tip:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

.reader {
  max-width: 640px;
  margin: 0 auto 4rem;
  padding: 0 1.25rem;
}

.para {
  position: relative;
  margin: 0 0 1.35rem;
  --band-width: 8px;
  --band-gap: 2px;
  padding-left: calc((var(--band-count) * (var(--band-width) + var(--band-gap))) + 0.8rem);
}

.para-bands {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  display: flex;
  gap: var(--band-gap);
}

.para-band-btn {
  width: var(--band-width);
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: var(--band-color, #999);
  cursor: pointer;
  opacity: 0.75;
}

.para-band-btn:hover {
  opacity: 1;
}

.para-band-btn.active {
  opacity: 1;
  outline: 1px solid var(--ink);
  outline-offset: 1px;
}

.para-band-btn.missing {
  opacity: 0.2;
}

.french-line {
  display: none;
  font-size: 14px;
  line-height: 1.5;
  color: #999;
  margin-bottom: 0.5rem;
}

body.show-french .french-line {
  display: block;
}

.para-text {
  margin: 0;
}

.failure-highlight .para-text {
  background: rgba(184, 92, 58, 0.08);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(184, 92, 58, 0.16);
  padding: 0.12rem 0.3rem;
}

.chapter-break {
  text-align: center;
  margin: 2.5rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.chapter-break::before,
.chapter-break::after {
  content: "";
  display: block;
  height: 1px;
  background: var(--rule);
  margin: 0.75rem auto;
  max-width: 120px;
}

.e-bad {
  text-decoration: underline;
  text-decoration-color: var(--violation);
  text-underline-offset: 2px;
}

.popover {
  position: absolute;
  z-index: 20;
  left: 0;
  top: 100%;
  margin-top: 6px;
  min-width: 220px;
  max-width: min(320px, 90vw);
  background: #fffef9;
  border: 1px solid var(--rule);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  padding: 0.35rem 0;
  list-style: none;
  margin: 6px 0 0;
}

.popover li button {
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font: inherit;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.popover li button:hover {
  background: rgba(0, 0, 0, 0.04);
}

.para-wrap {
  position: relative;
}

@media (min-width: 640px) {
  .para-bar-hit:hover + .popover,
  .popover:hover {
    /* popover shown via JS on desktop */
  }
}

.bottom-sheet[hidden] {
  display: none;
}

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 16, 0.35);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fffef9;
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  max-height: 55vh;
  overflow: auto;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
}

.sheet-title {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.sheet-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sheet-list button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--rule);
  background: var(--bg);
  font: inherit;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
