/* ── Rhyme Finder · v2 Xuan Paper ─────────────────────────────────
   Warm xuan-paper canvas, ink-black calligraphy, vermilion seal accent.
   Minimal, but with the quiet weight of an old folio.
*/

:root {
  /* Warm xuan paper palette — keyed to the Wang Shimin reference */
  --paper: #dcc28e;
  --paper-warm: #d4b67a;
  --paper-deep: #c8a567;

  --ink: #1a140e;            /* sumi black, slightly warm */
  --ink-soft: #3a2e1f;
  --ink-faded: #6e5a3c;      /* aged ink */
  --ink-ghost: rgba(26, 20, 14, 0.14);
  --hair: rgba(26, 20, 14, 0.22);
  --hair-soft: rgba(26, 20, 14, 0.10);

  --vermilion: #b13b2c;      /* hanko / 朱印 red */
  --vermilion-deep: #8a2a1e;
  --jade: #4a5a3a;           /* deep painting green */
  --indigo: #2a3a4a;         /* deep painting blue */

  --serif: "Cormorant Garamond", "Songti SC", "STSong", "SimSun", "Times New Roman", serif;
  --display: "Cormorant Garamond", "Songti SC", "STSong", serif;
  --hand: "Ma Shan Zheng", "Cormorant Garamond", serif;
  --sans: "Inter", "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  background-color: var(--paper);
  background-image: url("./xuan-bg.png");
  background-size: 600px 600px;
  background-repeat: repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Vignette + paper-edge shadow framing the viewport */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 95% 75% at 50% 35%, rgba(255, 230, 180, 0.18), transparent 70%);
  box-shadow:
    inset 0 0 120px rgba(80, 50, 20, 0.18),
    inset 0 0 280px rgba(100, 70, 30, 0.10);
  z-index: 0;
}

/* ── Layout ──────────────────────────────────────────────────── */

.rf-app {
  position: relative;
  min-height: 100vh;
  width: min(880px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  z-index: 2;
}

/* Empty start state — fix the hero (title + input) dead-center of the
   viewport, like Google's homepage. Its position never moves when the
   active epigraph below changes height. */
.rf-app:not(:has(#results:not(:empty))):not(:has(#source-summary:not(:empty))) .rf-hero {
  position: fixed;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(880px, calc(100vw - 40px));
  z-index: 3;
}
.rf-app:not(:has(#results:not(:empty))):not(:has(#source-summary:not(:empty))) .rf-results-shell {
  display: none;
}
/* Footer pinned to viewport bottom on the empty start state. */
.rf-app:not(:has(#results:not(:empty))):not(:has(#source-summary:not(:empty))) .rf-epigraphs {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  border-top: none;
  padding-top: 0;
  z-index: 2;
}

/* ── Hero ────────────────────────────────────────────────────── */

.rf-hero {
  text-align: center;
  padding-top: 0;
  margin-bottom: 0;
  position: relative;
  transition: padding-top 0.3s ease, margin-bottom 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rf-app:has(#results:not(:empty)) .rf-hero,
.rf-app:has(#source-summary:not(:empty)) .rf-hero {
  padding-top: 56px;
  margin-bottom: 28px;
}

.rf-eyebrow {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 13px;
  color: var(--ink-faded);
  margin-bottom: 22px;
  letter-spacing: 0.04em;
}

.rf-title {
  font-family: var(--display);
  font-style: normal;
  font-weight: 500;
  font-size: clamp(44px, 6vw, 68px);
  line-height: 0.95;
  letter-spacing: 0.005em;
  color: var(--ink);
  margin: 0 0 8px;
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  white-space: nowrap;
}

/* "Rhyme" — italic, the leading voice */
.rf-title-rhyme {
  font-style: italic;
  font-weight: 500;
}

/* Middot between the two words — ink dot, smaller, mid-baseline */
.rf-title-amp {
  display: inline-block;
  font-style: normal;
  font-size: 0.42em;
  font-weight: 400;
  color: var(--ink-faded);
  margin: 0 0.32em;
  transform: translateY(-0.32em);
}

/* "Finder" — upright, smaller, letter-spaced —
   the quiet utility word beside the poetic one */
.rf-title-finder {
  font-style: normal;
  font-weight: 400;
  font-size: 0.62em;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  align-self: center;
  padding-top: 0.18em;
}

/* Vermilion seal — a small hanko-style stamp tucked beside the title */
.rf-seal {
  position: absolute;
  top: 2px;
  right: -54px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--vermilion);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
  /* the stamp ink is uneven — irregular borders + grainy mask */
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 240, 220, 0.18),
    inset 0 0 12px rgba(80, 10, 0, 0.45);
  transform: rotate(-6deg);
  mask-image: radial-gradient(ellipse at 30% 40%, black 60%, rgba(0,0,0,0.85) 80%, rgba(0,0,0,0.6) 95%);
  -webkit-mask-image: radial-gradient(ellipse at 30% 40%, black 60%, rgba(0,0,0,0.85) 80%, rgba(0,0,0,0.6) 95%);
}

.rf-seal-glyph {
  text-shadow: 0 0 1px rgba(255,255,255,0.10);
}

.rf-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 22px auto 0;
  max-width: 240px;
  color: var(--ink-faded);
}

.rf-divider-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--hair), transparent);
}

.rf-divider-mark {
  font-family: var(--display);
  font-size: 13px;
  color: var(--ink-faded);
  line-height: 1;
}

/* ── Epigraphs (footer rotator) ──────────────────────────────── */

/* One epigraph at a time — they cross-fade on a slow rotation.
   Berman speaks of the room a rhyme builds; Oliver of the discipline
   of answering the call. The footer holds both, only one visible. */
.rf-epigraphs {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 56px auto 0;
  padding: 24px 8px 0;
  border-top: 1px solid var(--hair-soft);
  /* Reserve enough space for the taller of the two so the page
     doesn't reflow as they swap. Mary Oliver's three-paragraph
     epigraph is the taller one. */
  min-height: 230px;
}

.rf-epigraph {
  position: absolute;
  inset: 36px 8px auto 8px;
  margin: 0;
  padding: 0;
  text-align: center;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 600ms ease;
}

.rf-epigraph.is-active {
  opacity: 0.55 !important;
  pointer-events: auto;
  position: relative !important;
  inset: auto !important;
}

/* Berman: short verse, italic centered */
.rf-epigraph-berman {
  font-family: "Spectral", "Songti SC", serif;
  font-style: italic;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.65;
}

.rf-epigraph-line {
  margin: 0;
  text-wrap: balance;
}

/* Mary Oliver: prose, three paragraphs — must fit fully without truncation */
.rf-epigraph-oliver {
  font-family: "Spectral", "Songti SC", serif;
  font-style: normal;
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.6;
  text-align: left;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.rf-epigraph-prose {
  margin: 0 0 8px;
  text-wrap: pretty;
  hyphens: auto;
}
.rf-epigraph-prose:last-of-type { margin-bottom: 0; }

/* Decorative vermilion mark — sits centered above each epigraph */
.rf-epigraph-mark {
  display: block;
  width: 28px;
  height: 28px;
  margin: 0 auto 18px;
}

/* Hide footer once results appear — workspace mode. */
.rf-app:has(#results:not(:empty)) .rf-epigraphs,
.rf-app:has(#source-summary:not(:empty)) .rf-epigraphs {
  display: none;
}

.rf-epigraph-attr {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 10px;
  margin-top: 18px;
  font-family: var(--mono);
  font-style: normal;
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faded);
  white-space: nowrap;
}

/* Oliver's attribution sits flush left under the prose */
.rf-epigraph-oliver .rf-epigraph-attr {
  justify-content: flex-start;
}

.rf-epigraph-dash {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0;
  color: var(--ink-faded);
}

.rf-epigraph-dates,
.rf-epigraph-source {
  opacity: 0.7;
  font-feature-settings: "tnum";
}

.rf-epigraph-source {
  font-style: italic;
  text-transform: none;
  letter-spacing: 0.04em;
  font-size: 10px;
}

/* Two dots beneath the epigraphs — manual switcher.
   Vermilion ink-stamp dots, the active one filled. */
.rf-epigraph-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
  position: relative;
  z-index: 1;
}

.rf-epigraph-dot {
  appearance: none;
  border: 1px solid var(--vermilion);
  background: transparent;
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 200ms ease, transform 160ms ease, opacity 200ms ease;
  opacity: 0.55;
}

.rf-epigraph-dot:hover { opacity: 0.9; transform: scale(1.15); }

.rf-epigraph-dot[aria-pressed="true"] {
  background: var(--vermilion);
  opacity: 1;
}

@media (max-width: 720px) {
  .rf-epigraphs {
    margin: 40px auto 32px;
    min-height: auto;
  }
  .rf-epigraph-berman { font-size: 13px; }
  .rf-epigraph-oliver { font-size: 12px; }

  /* On mobile the viewport is too short to fix the hero in the center
     and pin the footer to the bottom without overlap — fall back to
     normal document flow: hero near the top, then the epigraph below. */
  .rf-app:not(:has(#results:not(:empty))):not(:has(#source-summary:not(:empty))) .rf-hero {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    width: 100%;
    margin-top: 6vh;
  }
  .rf-app:not(:has(#results:not(:empty))):not(:has(#source-summary:not(:empty))) .rf-epigraphs {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    border-top: 1px solid var(--hair-soft);
    padding-top: 24px;
  }
  /* Shrink the shanshui painting so the hero takes less vertical space
     on small screens. */
  .rf-title-row .rf-mg-shanshui {
    width: 200px;
    height: 120px;
  }
}

/* ── Marginalia: literary motifs in the corners ───────────────── */

.rf-marginalia {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.rf-mg {
  position: absolute;
}

/* Shanshui sits directly above the title, snug — its water-line and pine-dotted
   ridge form a banner overhead, the red sail and 韵 seal each providing one
   vermilion accent that mirrors across the wordmark. */
.rf-title-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Override .rf-mg's absolute positioning since the painting now lives in
   normal flow as part of the title row. */
.rf-title-row .rf-mg-shanshui {
  position: static;
  width: 240px;
  height: 145px;
  opacity: 0.92;
}

@media (max-width: 980px) {
  .rf-mg-shanshui {
    width: 260px;
    height: 160px;
    opacity: 0.8;
  }
}

.rf-mg-seal-only {
  position: absolute;
  top: calc(8vh + 165px);
  left: max(60px, calc(50vw - 448px));
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--vermilion);
  color: var(--paper);
  font-family: var(--display);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  border-radius: 1.5px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 240, 220, 0.18),
              inset 0 0 8px rgba(80, 10, 0, 0.4);
  transform: rotate(-3deg);
  opacity: 0.92;
}

@media (max-width: 980px) {
  .rf-mg-seal-only { display: none; }
}

/* ── Search ──────────────────────────────────────────────────── */

.rf-panel {
  width: 100%;
  max-width: 460px;
  margin: 28px auto 0;
  position: relative;
}

.rf-form { margin: 0; }

.rf-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  transition: border-color 160ms ease;
  position: relative;
}

/* A small ink-brush-stroke shadow under the line */
.rf-input-row::after {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -3px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ink-ghost) 30%, var(--ink-ghost) 70%, transparent);
  opacity: 0.7;
}

.rf-input-row:focus-within {
  border-bottom-color: var(--vermilion);
}

input[type="text"] {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 400;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 4px;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.005em;
}

/* While the user is actively typing, slide text to the left so the
   cursor sits at the natural reading start. The empty/placeholder
   state stays centered. */
/* (Input text stays centered at all times.) */

input[type="text"]::placeholder {
  color: rgba(107, 94, 74, 0.55);
  font-style: italic;
}

.rf-go-btn {
  font-family: var(--display);
  font-size: 22px;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 160ms ease, transform 160ms ease;
}

.rf-go-btn:hover { color: var(--vermilion); }
.rf-go-btn:hover .rf-go-btn-arrow { transform: translateX(4px); }
.rf-go-btn-arrow { display: inline-block; transition: transform 160ms ease; }

.rf-go-btn:disabled { opacity: 0.5; cursor: wait; }
.rf-go-btn[data-busy="true"] .rf-go-btn-arrow {
  animation: rf-spin 700ms linear infinite;
}

@keyframes rf-spin { to { transform: rotate(360deg); } }

.rf-status {
  margin-top: 14px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-faded);
  min-height: 1.2em;
  text-transform: uppercase;
}

.rf-status[data-state="error"] { color: var(--vermilion-deep); }

/* ── Results ─────────────────────────────────────────────────── */

.rf-results-shell {
  width: 100%;
  max-width: 760px;
  margin: 56px auto 0;
  padding-bottom: 96px;
}

.rf-results-shell:has(#source-summary:empty):has(#results:empty) {
  display: none;
}

.rf-source-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 18px;
  padding: 26px 0 22px;
  margin-bottom: 36px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--hair);
  position: relative;
}

.rf-source-summary:empty { display: none; }

.rf-source-word {
  font-family: var(--display);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(34px, 4.5vw, 48px);
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.rf-source-tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
}

.rf-source-tag::before { content: "·  "; color: var(--vermilion); opacity: 0.7; }
.rf-source-tag:first-of-type::before { content: ""; }
.rf-source-tag:first-of-type {
  color: var(--paper);
  background: var(--ink);
  padding: 4px 9px;
  letter-spacing: 0.2em;
}

/* Highlight the phonetic kernel — the vowel & coda values */
.rf-source-tag .rf-tag-val {
  color: var(--vermilion);
  font-weight: 600;
}

.rf-results { display: grid; gap: 44px; }

.rf-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-faded);
  text-transform: uppercase;
}

.rf-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--hair);
  border-top-color: var(--vermilion);
  border-radius: 50%;
  animation: rf-spin 700ms linear infinite;
}

/* Tier — each tier card sits behind a vermilion vertical bar */
.rf-tier {
  position: relative;
  padding: 4px 0 8px 22px;
  border-left: 3px solid var(--vermilion);
}

.rf-tier-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 18px;
  row-gap: 6px;
  margin-bottom: 22px;
}

.rf-tier-titlebox {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
  flex-wrap: wrap;
}

.rf-tier-title {
  font-family: var(--display);
  font-style: italic;
  font-weight: 600;
  font-size: 30px;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.rf-tier-rule {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.rf-spectrum {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faded);
}

.rf-spectrum-end { display: none; }

.rf-cells { display: inline-flex; gap: 3px; align-items: flex-end; }

.rf-cell {
  display: inline-block;
  width: 5px;
  height: 12px;
  background: var(--hair-soft);
}

.rf-cells .rf-cell:nth-child(1) { height: 5px; }
.rf-cells .rf-cell:nth-child(2) { height: 7px; }
.rf-cells .rf-cell:nth-child(3) { height: 9px; }
.rf-cells .rf-cell:nth-child(4) { height: 11px; }
.rf-cells .rf-cell:nth-child(5) { height: 13px; }

.rf-tier-head .rf-cell-on { background: var(--vermilion); }

.rf-tier-count {
  font-family: var(--display);
  font-style: italic;
  font-weight: 600;
  font-size: 26px;
  line-height: 1;
  color: var(--vermilion);
  white-space: nowrap;
  justify-self: end;
}

.rf-tier-count::before {
  content: "n. ";
  font-family: var(--mono);
  font-style: normal;
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faded);
  margin-right: 4px;
  vertical-align: 0.18em;
}

.rf-subgroup { margin-top: 20px; }
.rf-subgroup:first-of-type { margin-top: 0; }

.rf-subgroup-label {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
  padding: 3px 8px;
  margin-bottom: 14px;
}

.rf-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  align-items: baseline;
}

.rf-word {
  display: inline-block;
  font-family: "Spectral", "Songti SC", "STSong", serif;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--ink);
  cursor: default;
  transition: color 120ms ease;
}

/* Hover: just turn the word vermilion. No underline — underlines read
   as 'clickable' on the web, and right now there's nothing to click. */
.rf-word:hover {
  color: var(--vermilion);
}

/* Very-common words: bold + ink color, no underline. Weight contrast
   alone is enough to make them pop against the italic non-bold rest. */
.rf-word.rf-c-very-common {
  font-weight: 700;
  font-style: normal;
  color: var(--ink);
}
.rf-word.rf-c-common { font-weight: 500; font-style: normal; color: var(--ink); }
.rf-word.rf-c-uncommon { font-weight: 400; font-style: italic; color: var(--ink-faded); }

.rf-word.rf-mismatch {
  color: var(--ink-faded);
  text-decoration: underline dotted;
  text-decoration-color: var(--hair);
  text-underline-offset: 4px;
}

.rf-word.rf-cliche {
  color: var(--ink);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  opacity: 0.45;
}

.rf-word-flag {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  color: var(--vermilion);
  margin-left: 2px;
  vertical-align: super;
  text-transform: uppercase;
  font-style: normal;
}

.rf-empty {
  padding: 40px 24px;
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  color: var(--ink-faded);
}

@media (max-width: 640px) {
  .rf-hero { padding-top: 12vh; }
  .rf-tier-head { gap: 8px; }
  .rf-tier-count { margin-left: 0; }
  .rf-seal { right: -42px; width: 36px; height: 36px; font-size: 18px; }
}
