/*
 * haiku.to — "constellation lineage"
 * A sumi-black void lit from within: poems glow soft-white in negative space,
 * lineage runs as luminous indigo light-trails, vermilion is reserved for the
 * remix "cut" + the author seal. Mono terminal chrome. Motion + glow over a
 * drifting starfield (assets/starfield.js). Cinematic depth, haiku calm.
 */

:root {
  --void:   #0a0d13;  /* near-black, cool indigo tint — the night */
  --void-2: #10151f;  /* raised panels */
  --ink:    #eae7f0;  /* soft near-white — poem text */
  --ai:     #6ea8ff;  /* electric indigo — the lineage light (glows) */
  --ai-dim: #3f6fd1;
  --cut:    #ff4a35;  /* vermilion glow — the remix "cut" + the hanko seal */
  --mist:   #6b7688;  /* dim mono chrome, meta */
  --line:   rgba(110, 168, 255, 0.16); /* hairlines / faint structure */

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans:  "Helvetica Neue", Inter, -apple-system, system-ui, "Segoe UI", sans-serif;
  --mono:  "SF Mono", ui-monospace, "Cascadia Code", "JetBrains Mono", Menlo, monospace;

  --measure: 33rem;
  --glow-ai:  0 0 22px rgba(110, 168, 255, 0.35);
  --glow-cut: 0 0 20px rgba(255, 74, 53, 0.45);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--void);
  /* a faint indigo aurora bleeding up from the horizon, like remix.run's valley */
  background-image:
    radial-gradient(120% 60% at 50% 118%, rgba(63, 111, 209, 0.22) 0%, transparent 60%),
    radial-gradient(90% 50% at 50% -10%, rgba(110, 168, 255, 0.08) 0%, transparent 55%);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* the starfield canvas (assets/starfield.js) mounts here, behind everything */
#starfield { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* ---- masthead — mono terminal chrome -------------------------------------*/

header[role="banner"] {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 1rem;
  border-bottom: 1px solid var(--line);
}
header[role="banner"] h1 {
  margin: 0;
  font: 700 1.1rem/1 var(--sans);
  letter-spacing: 0.38em;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(110, 168, 255, 0.25);
}
header[role="banner"] h1 a { color: var(--ink); text-decoration: none; }
header[role="banner"] h1 a::first-letter { color: var(--cut); text-shadow: var(--glow-cut); }

header[role="banner"] nav { display: flex; gap: 1.1rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; }
header[role="banner"] nav a { color: var(--ai); text-decoration: none; opacity: 0.85; }
header[role="banner"] nav a::before { content: "["; color: var(--mist); }
header[role="banner"] nav a::after  { content: "]"; color: var(--mist); }
header[role="banner"] nav a:hover { opacity: 1; text-shadow: var(--glow-ai); }

/* ---- main column ---------------------------------------------------------*/

main { position: relative; z-index: 1; max-width: var(--measure); margin: 0 auto; padding: 4rem 1.5rem 7rem; }
main#feed { max-width: 38rem; }

/* ---- the poem (hero) — glowing in the dark -------------------------------*/

[data-testid="poem"], .haiku-card { position: relative; margin: 0 0 3rem; padding-left: 1.6rem; }
/* the lineage spine: a luminous indigo thread with bloom */
[data-testid="poem"]::before, .haiku-card::before {
  content: ""; position: absolute; left: 0; top: 0.3rem; bottom: 0.3rem; width: 2px;
  background: linear-gradient(to bottom, var(--ai) 0%, var(--ai-dim) 82%, transparent 100%);
  box-shadow: var(--glow-ai);
  border-radius: 2px;
}
.haiku, [data-testid="poem-lines"] {
  white-space: pre-line; margin: 0;
  font-family: var(--serif); font-size: 1.65rem; line-height: 2.1; letter-spacing: 0.005em;
  color: var(--ink); text-shadow: 0 0 26px rgba(234, 231, 240, 0.14);
}
.haiku-card .haiku, .haiku-card [data-testid^="haiku-poem"] { font-size: 1.32rem; line-height: 1.95; }

@media (prefers-reduced-motion: no-preference) {
  [data-testid="poem-lines"] { animation: rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(0.6rem); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }
}

/* ---- spine roots — glowing depth by descendant_count ---------------------*/
/* `data-roots` (haiku.js/library.js, bucketed via the shared
   `lineage-depth.js#bucketRoots` from `descendant_count` -- the haiku page
   reads it off `getHaikuLive()`, the feed reads it directly off each feed
   row, which already carries the count: 0 -> childless/no remixes, 1-2,
   3-6, 7+) grows a small root system off the spine's lower terminus -- the
   more a poem has been remixed, the deeper its roots. Applies to both the
   poem hero spine AND each `.haiku-card` in the library feed, so the feed
   reads as a field of poems with visible lineage depth too.
   `data-roots="0"` is the plain spine, no ::after at all. Each root is an
   SVG data-URI used purely as an alpha mask (the stroke value inside it is
   irrelevant to the final render) painted via `background-color`, so the
   glow color always comes from --ai -- never a baked hex. */
[data-testid="poem"][data-roots="1"]::after,
[data-testid="poem"][data-roots="2"]::after,
[data-testid="poem"][data-roots="3"]::after,
.haiku-card[data-roots="1"]::after,
.haiku-card[data-roots="2"]::after,
.haiku-card[data-roots="3"]::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0.15rem;
  transform: translate(-50%, 55%);
  transform-origin: top center;
  background-color: var(--ai);
  box-shadow: var(--glow-ai);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: top center;
  mask-position: top center;
  -webkit-mask-size: contain;
  mask-size: contain;
  pointer-events: none;
}
[data-testid="poem"][data-roots="1"]::after,
.haiku-card[data-roots="1"]::after {
  width: 1.3rem; height: 1.3rem; opacity: 0.55;
  -webkit-mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q14 16 11 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q26 16 29 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/></svg>");
  mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q14 16 11 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q26 16 29 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/></svg>");
}
[data-testid="poem"][data-roots="2"]::after,
.haiku-card[data-roots="2"]::after {
  width: 1.6rem; height: 1.6rem; opacity: 0.7;
  -webkit-mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q11 16 7 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q20 20 20 34' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q29 16 33 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/></svg>");
  mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q11 16 7 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q20 20 20 34' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/><path d='M20 4 Q29 16 33 30' stroke='currentColor' stroke-width='2.5' fill='none' stroke-linecap='round'/></svg>");
}
[data-testid="poem"][data-roots="3"]::after,
.haiku-card[data-roots="3"]::after {
  width: 2rem; height: 2rem; opacity: 0.85;
  -webkit-mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q9 15 4 27' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q14 18 11 35' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q20 22 20 38' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q26 18 29 35' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q31 15 36 27' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/></svg>");
  mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 4 Q9 15 4 27' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q14 18 11 35' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q20 22 20 38' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q26 18 29 35' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/><path d='M20 4 Q31 15 36 27' stroke='currentColor' stroke-width='2.25' fill='none' stroke-linecap='round'/></svg>");
}
@media (prefers-reduced-motion: no-preference) {
  [data-testid="poem"][data-roots="1"]::after,
  [data-testid="poem"][data-roots="2"]::after,
  [data-testid="poem"][data-roots="3"]::after,
  .haiku-card[data-roots="1"]::after,
  .haiku-card[data-roots="2"]::after,
  .haiku-card[data-roots="3"]::after {
    animation: rootsGrow 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }
  @keyframes rootsGrow {
    from { transform: translate(-50%, 55%) scaleY(0); }
    to   { transform: translate(-50%, 55%) scaleY(1); }
  }
}

/* ---- byline / seal / meta — mono -----------------------------------------*/

.counts, [data-testid="byline"], [data-testid^="haiku-meta"], [data-testid="lineage-summary"] {
  font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.02em; color: var(--mist); margin: 0.7rem 0 0;
}
[data-testid="byline"]::before, [data-testid^="haiku-meta"]::before {
  content: ""; display: inline-block; width: 0.6em; height: 0.6em; margin-right: 0.6em;
  background: var(--cut); box-shadow: var(--glow-cut); border-radius: 1px; vertical-align: 0.02em;
}
[data-testid="lineage-summary"] { margin-top: 1.9rem; color: var(--ai); }

.haiku-card a, [data-testid^="haiku-card"] a { color: inherit; text-decoration: none; }
.haiku-card { border-bottom: 1px solid var(--line); padding-bottom: 2.5rem; }

/* ---- born-from -----------------------------------------------------------*/

[data-testid="born-from"] { margin: 2.75rem 0 0; }
[data-testid="born-from"] h2 { font: 400 0.7rem/1 var(--mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--mist); margin: 0 0 0.75rem; }
[data-testid="born-from-list"] { list-style: none; margin: 0; padding: 0; }
[data-testid="born-from-list"] li { margin: 0 0 0.4rem; padding-left: 1.2rem; position: relative; }
[data-testid="born-from-list"] li::before { content: "\21B3"; position: absolute; left: 0; color: var(--ai); text-shadow: var(--glow-ai); }
[data-testid="born-from-list"] a { color: var(--ai); text-decoration: none; font-family: var(--serif); }
[data-testid="born-from-list"] a:hover { text-shadow: var(--glow-ai); }

/* ---- remix bar — the "cut" -----------------------------------------------*/

[data-testid="remix-bar"] { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 2.75rem 0 0; padding-top: 1.9rem; border-top: 1px solid var(--line); }
[data-testid="remix-bar"] a {
  font: 400 0.72rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ai); text-decoration: none; padding: 0.55rem 0.9rem;
  border: 1px solid var(--line); border-radius: 2px; background: rgba(110, 168, 255, 0.03);
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
[data-testid="remix-bar"] a:hover { color: var(--cut); border-color: var(--cut); box-shadow: var(--glow-cut); background: rgba(255, 74, 53, 0.06); }

/* ---- forms (compose / remix) ---------------------------------------------*/

form { margin: 0; }
label { display: block; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--mist); margin: 1.4rem 0 0.4rem; }
input[type="text"], textarea, select {
  font: 1.3rem/1.9 var(--serif); color: var(--ink); width: 100%;
  background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 0.4rem 0; border-radius: 0;
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--mist); opacity: 0.5; }
input[type="text"]:focus, textarea:focus, select:focus { outline: none; border-bottom-color: var(--ai); box-shadow: 0 1px 0 0 var(--ai), var(--glow-ai); }
select { font-size: 1rem; }
select option { background: var(--void-2); color: var(--ink); }
textarea { resize: vertical; }
input[type="checkbox"] { accent-color: var(--ai); margin-right: 0.5rem; }

/* ---- settings (save confirmation / guarded delete) -----------------------*/

[data-testid="settings-success"] {
  color: var(--ai); font-family: var(--mono); font-size: 0.82rem; margin: 1.6rem 0 0;
  padding-left: 0.9rem; border-left: 2px solid var(--ai); box-shadow: -1px 0 12px -6px var(--ai);
}
[data-testid="delete-section"] { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
[data-testid="delete-panel"] { margin-top: 1rem; }
[data-testid="delete-account"], [data-testid="delete-confirm"] { background: var(--cut); box-shadow: var(--glow-cut); }
[data-testid="delete-account"]:hover, [data-testid="delete-confirm"]:hover { filter: brightness(1.15); box-shadow: 0 0 30px rgba(255, 74, 53, 0.6); }

[data-testid="syllable-counter"] { font-family: var(--mono); font-size: 0.85rem; letter-spacing: 0.12em; color: var(--mist); margin: 1.4rem 0; }
[data-testid="syllable-counter"][data-valid="true"]  { color: var(--ai); text-shadow: var(--glow-ai); }
[data-testid="syllable-counter"][data-valid="false"] { color: var(--cut); }

button, [type="submit"] {
  font: 400 0.75rem/1 var(--mono); letter-spacing: 0.18em; text-transform: uppercase; cursor: pointer;
  color: var(--void); background: var(--ai); border: none; border-radius: 2px; padding: 0.8rem 1.6rem; margin-top: 1.9rem;
  box-shadow: var(--glow-ai); transition: background 0.15s, box-shadow 0.15s;
}
button:hover, [type="submit"]:hover { background: #8bbaff; box-shadow: 0 0 30px rgba(110, 168, 255, 0.6); }
button:disabled { background: var(--mist); box-shadow: none; cursor: not-allowed; }

/* ---- stats (author) — a glowing ledger -----------------------------------*/

dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); gap: 1.6rem 1rem; margin: 2.25rem 0; }
dt { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mist); }
dd { margin: 0.25rem 0 0; font-family: var(--mono); font-size: 1.9rem; color: var(--ink); text-shadow: 0 0 20px rgba(110, 168, 255, 0.2); }

[data-testid^="author-node"] { font-family: var(--serif); }
main ul { list-style: none; margin: 0; padding: 0; }
main li { margin: 0 0 0.5rem; }
main li a { color: var(--ai); text-decoration: none; }
main li a:hover { text-shadow: var(--glow-ai); }

/* ---- lineage tree — the river of light ------------------------------------*/

[data-testid="lineage-tree"] { margin: 1.5rem 0 0; }
.lineage-tree { display: block; width: 100%; height: auto; }
.lineage-node { cursor: pointer; }
.lineage-node text { font-family: var(--mono); pointer-events: none; }
.lineage-node:hover .lineage-node-dot,
.lineage-node:focus-visible .lineage-node-dot { filter: url(#lineage-glow) brightness(1.3); }
.lineage-node:focus-visible { outline: none; }
/* One intentional focus-glow opacity (0.75) used everywhere the focus ring
   glow's brightness is set -- the static base below, the reduced-motion
   fallback, and the animated pulse's peak all agree on 0.75 (was previously
   three slightly different values: 0.8 base / 0.75 reduced / 0.35<->0.75
   pulse -- now the base and the pulse's resting/peak state read the same
   under every motion preference). */
.lineage-node:focus-visible .lineage-node-glow { stroke: var(--ink); opacity: 0.75; }

/* the draw-in (stroke-dashoffset via JS) and the node fade/scale-in are set
   up in lineage-tree.js only when the user has no reduced-motion preference
   (see `prefersReducedMotion()`); the trail/glow strength itself (below) is
   not motion, so it always applies. */
@media (prefers-reduced-motion: no-preference) {
  /* a gentle "breathing" glow on hover/focus -- purely decorative, gated
     alongside the rest of the motion in this file. */
  .lineage-node:hover .lineage-node-glow,
  .lineage-node:focus-visible .lineage-node-glow {
    animation: lineage-node-pulse 1.6s ease-in-out infinite;
  }
  @keyframes lineage-node-pulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.75; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .lineage-node:hover .lineage-node-glow,
  .lineage-node:focus-visible .lineage-node-glow {
    opacity: 0.75;
  }
}

/* ---- errors --------------------------------------------------------------*/

[role="alert"], .err {
  color: var(--cut); font-family: var(--mono); font-size: 0.82rem; margin: 1.6rem 0 0;
  padding-left: 0.9rem; border-left: 2px solid var(--cut); box-shadow: -1px 0 12px -6px var(--cut);
}
[data-testid="rate-limit-claim"] { color: var(--ai); }

/* ---- responsive ----------------------------------------------------------*/

@media (max-width: 480px) {
  .haiku, [data-testid="poem-lines"] { font-size: 1.4rem; line-height: 1.95; }
  header[role="banner"] { flex-direction: column; gap: 0.6rem; align-items: flex-start; }
  main { padding-top: 2.75rem; }
}

:focus-visible { outline: 2px solid var(--ai); outline-offset: 3px; }
