/* ==========================================================================
   What is a TLE? — prototype stylesheet
   Self-contained, but the tokens mirror shared/css/base.css and the orbit
   visualizer so the two tools read as one family.

   1. Tokens and base
   2. Header and footer
   3. Prose sections
   4. Callouts and gotchas
   5. Decoder — input
   6. Decoder — raw record
   7. Decoder — field table
   8. Decoder — derived values
   9. Reference tables
   10. Responsive
   ========================================================================== */

/* ---------- 1. Tokens and base ------------------------------------------ */

:root {
  --ink: #162033;
  --muted: #5d6878;
  --paper: #fbfaf7;
  --surface: #ffffff;
  --line: #dce2ea;
  --blue: #155eef;
  --orbit: #087f8c;
  --orbit-dark: #075d68;
  --orbit-pale: #e9f7f6;
  --sand: #c77720;
  --sand-pale: #fff8e8;
  --red: #b42318;
  --red-pale: #fff1f0;
  --green: #167653;
  --green-pale: #eaf8f1;
  /* Shared with the orbit visualizer so the same object is the same colour
     in both tools: amber is the satellite, red is the ground track. */
  --sat: #ffb000;
  --track: #c43b43;
  --radius: 14px;
  --shadow: 0 14px 34px rgba(31, 50, 81, .08);
  --mono: "Cascadia Code", ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --content: 1100px;
  --reading: 760px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.65;
}

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -.02em; margin: 0; }
p { margin: 0 0 1em; }
a { color: var(--blue); text-underline-offset: .2em; }
button { font: inherit; cursor: pointer; }
code { font-family: var(--mono); font-size: .92em; background: #eef2f6; padding: .1em .35em; border-radius: 4px; }
:focus-visible { outline: 3px solid #7ab4ff; outline-offset: 2px; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: #fff; padding: .7rem 1rem; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.eyebrow {
  text-transform: uppercase; letter-spacing: .14em;
  font-weight: 800; font-size: .7rem; margin: 0 0 .35rem;
}

/* ---------- 2. Header and footer ---------------------------------------- */

.tool-header {
  padding: clamp(1.6rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) clamp(1.4rem, 3vw, 2rem);
  background: linear-gradient(120deg, #0b2441 0%, #174f69 100%);
  color: #eaf4f7;
}
.tool-header__inner { max-width: var(--content); margin: 0 auto; }
.tool-header .eyebrow { color: #8fe2dc; }
.tool-header h1 { font-size: clamp(1.9rem, 5vw, 3rem); }
/* Left edge stays flush with the heading; only the measure is limited. */
.tool-header__lede { max-width: 62ch; margin: .7rem 0 0; color: #c9dfe6; font-size: 1.02rem; }

.tool-footer { padding: 1.5rem clamp(1rem, 4vw, 2rem) 3rem; color: var(--muted); font-size: .82rem; }
.tool-footer p { max-width: var(--reading); margin: 0 auto; }

/* ---------- 3. Prose sections ------------------------------------------- */

.prose {
  max-width: var(--reading);
  margin: 0 auto;
  padding: clamp(1.6rem, 4vw, 2.6rem) clamp(1rem, 4vw, 2rem) 0;
}
.prose h2 { font-size: clamp(1.3rem, 2.6vw, 1.75rem); margin-bottom: .6rem; }
.prose h3 { font-size: 1.03rem; margin: 1.4rem 0 .4rem; }
.prose .aside { color: var(--muted); font-size: .92rem; }

.math-block, .element-block {
  font-family: var(--mono); font-size: .86rem; line-height: 1.6;
  background: #0f2233; color: #d7e7ee;
  padding: .9rem 1.1rem; border-radius: 10px;
  overflow-x: auto; margin: 0 0 1em;
}

/* Reference tables sit wider than the reading column when they need to. */
.table-scroll { overflow-x: auto; margin: 0 0 1.4em; }

/* ---------- 4. Callouts and gotchas ------------------------------------- */

.callout {
  margin: 1.4rem 0; padding: 1rem 1.15rem;
  border-radius: 10px; border-left: 4px solid var(--orbit);
  background: var(--orbit-pale);
}
.callout h3 { margin: 0 0 .4rem; font-size: 1rem; }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }
.callout--key { border-left-color: var(--orbit); background: var(--orbit-pale); }
.callout--warn { border-left-color: var(--sand); background: var(--sand-pale); }
.callout ul { margin: 0 0 1em; padding-left: 1.1rem; }
.callout li { margin-bottom: .45rem; }

.gotchas { margin: 1.2rem 0 0; padding: 0; list-style: none; counter-reset: gotcha; }
.gotchas > li {
  counter-increment: gotcha;
  position: relative; padding: 0 0 1.1rem 2.6rem; margin-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}
.gotchas > li:last-child { border-bottom: 0; }
.gotchas > li::before {
  content: counter(gotcha);
  position: absolute; left: 0; top: .1rem;
  display: grid; place-items: center;
  width: 1.85rem; height: 1.85rem; border-radius: 50%;
  background: var(--orbit-dark); color: #fff;
  font-size: .82rem; font-weight: 800;
}
.gotchas h3 { margin: .15rem 0 .4rem; font-size: 1.03rem; }
.gotchas p:last-child { margin-bottom: 0; }

/* ---------- 4b. Pipeline diagram ---------------------------------------- *
   Five stage cards. Horizontal on a wide screen so the whole chain reads at a
   glance; stacked below 1040px, with the connector arrow turning to point
   down. Glyph colours match the two tools on purpose: amber is the satellite
   and red is the ground track in the visualizer as well.
   ------------------------------------------------------------------------ */

.pipeline-section {
  max-width: var(--content);
  margin: 0 auto;
  padding: clamp(1.6rem, 4vw, 2.6rem) clamp(1rem, 4vw, 2rem) 0;
}
.pipeline-section__intro, .pipeline-section__notes { max-width: var(--reading); }
.pipeline-section__intro h2 { font-size: clamp(1.3rem, 2.6vw, 1.75rem); margin-bottom: .6rem; }
.pipeline-section__notes { margin-top: 1.6rem; }
.pipeline-section__caption { font-size: .85rem; color: var(--muted); margin: 1rem 0 0; }

.pipeline {
  list-style: none;
  margin: 1.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 2.4rem 0;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0 .2rem;
}

/* The connector. Points down when the cards are stacked. */
.stage::before {
  content: "↓";
  position: absolute;
  left: 50%;
  top: -1.75rem;
  transform: translateX(-50%);
  font-size: 1.35rem;
  line-height: 1;
  color: var(--orbit);
}
.stage:first-child::before { content: none; }

/* "How you get here" chip. Step 1 says "start" so every card lines up. */
.stage__via {
  align-self: center;
  margin: 0 0 .7rem;
  padding: .2rem .6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--orbit-pale);
  color: var(--orbit-dark);
  font-size: .72rem;
  font-weight: 800;
  white-space: nowrap;
}

.stage__glyph {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: .4rem;
  margin-bottom: .7rem;
}
.stage__glyph svg { display: block; width: 100%; height: auto; }

.stage__step {
  margin: 0 0 .15rem;
  font-size: .68rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted);
}
.stage h3 { font-size: 1rem; margin: 0 0 .35rem; }
.stage__text { font-size: .85rem; color: var(--muted); margin: 0 0 .6rem; }
.stage__frame {
  margin: auto 0 0;
  padding-top: .5rem;
  border-top: 1px dashed var(--line);
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--orbit-dark);
}

/* 1100px is where five cards still get ~175px each; below it they stack
   rather than squeeze the captions into two-word lines. */
@media (min-width: 1100px) {
  .pipeline { grid-template-columns: repeat(5, 1fr); gap: 0 2.6rem; }
  /* Hang the arrow off the glyph rather than the card, so it stays centred on
     the artwork whatever height the cards' captions push them to. */
  .stage::before { content: none; }
  .stage__glyph { position: relative; }
  .stage__glyph::before {
    content: "→";
    position: absolute;
    left: -1.85rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.35rem;
    line-height: 1;
    color: var(--orbit);
  }
  .stage:first-child .stage__glyph::before { content: none; }
}

/* ---- Glyph internals --------------------------------------------------- */

.stage__glyph .g-earth { fill: var(--orbit-pale); stroke: var(--orbit); stroke-width: 1.2; }
.stage__glyph .g-station { fill: var(--orbit-dark); }
.stage__glyph .g-beam { fill: none; stroke: var(--sand); stroke-width: 1.1; stroke-dasharray: 3 2.6; }
.stage__glyph .g-orbit { fill: none; stroke: var(--orbit); stroke-width: 1.7; }
.stage__glyph .g-satbody { fill: var(--ink); }
.stage__glyph .g-sat { fill: var(--sat); }
.stage__glyph .g-satdot { fill: var(--sat); stroke: #7a4a00; stroke-width: 1.2; }

.stage__glyph .g-panel { fill: #0f2233; }
.stage__glyph .g-ruler { stroke: #5f7d8f; stroke-width: 1.4; stroke-dasharray: 1 3.9; }
.stage__glyph .g-chars { stroke: #8fb8c9; stroke-width: 3.4; stroke-dasharray: 2.4 1.6; }
.stage__glyph .g-check { stroke: #ffd166; stroke-width: 3.4; }
.stage__glyph .g-num { fill: #8fb8c9; font-family: var(--mono); font-size: 9px; font-weight: 700; }

.stage__glyph .g-chips rect { fill: var(--orbit-pale); stroke: var(--orbit); stroke-width: 1.2; }
.stage__glyph .g-chip-t text {
  fill: var(--orbit-dark); font-size: 14px; font-weight: 800;
  text-anchor: middle; font-style: italic;
}
.stage__glyph .g-epoch { fill: var(--sand-pale); stroke: var(--sand); stroke-width: 1.2; }
.stage__glyph .g-epoch-t { fill: #7a4a00; font-size: 11px; font-weight: 800; text-anchor: middle; }

.stage__glyph .g-plane { fill: none; stroke: var(--line); stroke-width: 1.2; stroke-dasharray: 3 3; }
.stage__glyph .g-globe { fill: var(--orbit-pale); stroke: var(--orbit); stroke-width: 1.2; }
.stage__glyph .g-equator { fill: none; stroke: var(--orbit); stroke-width: 1; opacity: .55; }

.stage__glyph .g-map { fill: #eef4f7; stroke: var(--line); stroke-width: 1.2; }
.stage__glyph .g-equator-flat { stroke: var(--orbit); stroke-width: 1; opacity: .4; }
.stage__glyph .g-track { fill: none; stroke: var(--track); stroke-width: 2.2; stroke-linecap: round; }
.stage__glyph .g-track--old { opacity: .3; stroke-width: 1.8; }

/* ---------- 5. Decoder — input ------------------------------------------ */

.decoder {
  max-width: var(--content);
  margin: clamp(1.8rem, 4vw, 2.8rem) auto 0;
  padding: clamp(1rem, 3vw, 1.6rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.decoder__intro { max-width: var(--reading); }
.decoder__intro h2 { font-size: clamp(1.3rem, 2.6vw, 1.75rem); margin-bottom: .4rem; }

.decoder__input { margin-top: 1.1rem; }

.sample-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .7rem; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--orbit-dark);
  font-size: .8rem; font-weight: 700; padding: .42rem .75rem; border-radius: 999px;
}
.chip:hover { border-color: var(--orbit); background: var(--orbit-pale); }
.chip[aria-pressed="true"] { background: var(--orbit-dark); border-color: var(--orbit-dark); color: #fff; }
.chip--warn { color: #8f2119; }
.chip--warn:hover { border-color: var(--red); background: var(--red-pale); }
.chip--warn[aria-pressed="true"] { background: #8f2119; border-color: #8f2119; color: #fff; }

.sample-note {
  font-size: .8rem; color: var(--muted);
  background: var(--sand-pale); border-left: 3px solid var(--sand);
  padding: .55rem .8rem; border-radius: 0 6px 6px 0; margin-bottom: 1rem;
}

.input-label { display: block; font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .35rem; }
textarea[data-tle-input] {
  width: 100%; font-family: var(--mono); font-size: .8rem; line-height: 1.7;
  padding: .7rem .8rem; border: 1px solid #aebbc8; border-radius: 8px;
  background: #fff; color: var(--ink); resize: vertical; white-space: pre; overflow-x: auto;
}

.status { margin: .9rem 0 .3rem; font-weight: 750; font-size: .9rem; }
.status[data-state="valid"] { color: var(--green); }
.status[data-state="invalid"] { color: var(--red); }
.status[data-state="empty"] { color: var(--muted); }

.issue-list { margin: 0 0 .6rem; padding: 0; list-style: none; }
.issue-list li {
  font-size: .84rem; padding: .5rem .75rem; margin-bottom: .35rem; border-radius: 6px;
  background: var(--red-pale); color: #8f2119; border-left: 3px solid var(--red);
}
.issue-list li[data-kind="warning"] { background: var(--sand-pale); color: #7a4a00; border-left-color: var(--sand); }

/* Hide the output panels until there is something to show. */
.decoder:not(.has-fields) .raw,
.decoder:not(.has-fields) .breakdown,
.decoder:not(.has-fields) .derived { display: none; }

.raw h3, .breakdown h3, .derived h3 { font-size: .95rem; margin: 1.4rem 0 .5rem; }

/* ---------- 6. Decoder — raw record ------------------------------------- */

.raw__scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #0f2233; }
.raw__block {
  margin: 0; padding: .85rem 1rem;
  font-family: var(--mono); font-size: .82rem; line-height: 1.75;
  color: #d7e7ee; white-space: pre; font-variant-ligatures: none;
}
.raw__ruler { color: #5f7d8f; }
.raw__name { color: #9fd8c8; }

.raw__block .f { border-radius: 3px; padding: .1em 0; transition: background-color .12s, color .12s; }
.raw__block .f.is-even { background: rgba(255, 255, 255, .07); }
.raw__block .f.is-odd { background: rgba(255, 255, 255, .015); }
.raw__block .f.is-active { background: #ffd166; color: #10222f; font-weight: 700; }
.raw__block .f.is-bad { background: rgba(230, 90, 80, .38); color: #ffe9e7; }

.raw__hint { font-size: .8rem; color: var(--muted); margin: .5rem 0 0; }

/* ---------- 7. Decoder — field table ------------------------------------ */

.breakdown__scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }

.field-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.field-table th, .field-table td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.field-table thead th { background: #f2f6f8; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; position: sticky; top: 0; }
.field-table tbody tr { cursor: default; }
.field-table tbody tr:hover, .field-table tbody tr.is-active { background: #fff6da; }
.field-table tbody tr:focus-visible { background: #fff6da; }
.field-table td:nth-child(1), .field-table td:nth-child(2) { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.field-table .raw-cell { font-family: var(--mono); white-space: pre; background: #f4f7f9; border-radius: 4px; }
.field-table .value-cell { font-weight: 700; font-variant-numeric: tabular-nums; }
.field-table .value-cell .unit { font-weight: 500; color: var(--muted); }
.field-table .value-cell .note { display: block; font-weight: 500; font-size: .78rem; color: var(--muted); }
.field-table .value-cell .note.is-bad { color: var(--red); font-weight: 700; }
.field-table .meaning { display: block; font-weight: 400; color: var(--muted); font-size: .79rem; margin-top: .1rem; }

/* ---------- 8. Decoder — derived values --------------------------------- */

.derived-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem; margin: 0 0 1.2rem; }
.derived-grid > div { padding: .5rem .65rem; border-top: 2px solid var(--orbit); background: #f8fcfc; border-radius: 0 0 6px 6px; }
.derived-grid > div.is-warn { border-top-color: var(--sand); background: var(--sand-pale); }
.derived-grid > div.is-bad { border-top-color: var(--red); background: var(--red-pale); }
.derived-grid dt { font-size: .7rem; color: var(--muted); }
.derived-grid dd { margin: .1rem 0 0; font-weight: 800; font-variant-numeric: tabular-nums; font-size: .9rem; }

.element-handoff { border-top: 1px solid var(--line); padding-top: 1rem; }
.element-handoff h4 { font-size: .88rem; margin-bottom: .5rem; }
.element-note { font-size: .8rem; color: var(--muted); margin: 0; }

/* ---------- 9. Reference tables ----------------------------------------- */

.reference-table { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 560px; }
.reference-table th, .reference-table td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.reference-table thead th { background: #f2f6f8; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.reference-table td:first-child { font-family: var(--mono); color: var(--orbit-dark); font-weight: 700; white-space: nowrap; }
.reference-table td:nth-child(2) { font-weight: 650; }
.reference-table td:nth-child(3) { color: var(--muted); }

/* ---------- 10. Responsive ---------------------------------------------- */

@media (max-width: 900px) {
  .derived-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .derived-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
  .field-table { font-size: .78rem; }
  .field-table .meaning { display: none; }
  .gotchas > li { padding-left: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .raw__block .f { transition: none; }
}
