/* =========================================================================
   YOSHIMITSU SYSTEMS  ·  技術ノート  Engineering Notes
   Long-form reading layout, loaded after styles.css on notes/ pages only.
   ========================================================================= */

/* chart palette: the brand hues re-stepped into the dark-mode lightness band
   (OKLCH L 0.48–0.67) so marks pass the CVD checks on --panel. Text never
   wears these; they are for marks only. */
:root {
  --series-1: #c18600;   /* amber  · slot 1 */
  --series-2: #707ed4;   /* violet · slot 2 */
  --series-3: #db6148;   /* coral  · slot 3 */
  --grid:     #262b3b;
  --measure:  68ch;
}

/* ---- 1. NOTE HEADER ---------------------------------------------------- */
.note-head { padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(1.5rem, 3vw, 2.5rem); border-bottom: 1px solid var(--line); }
.note-head h1 {
  font-size: clamp(2.1rem, 1.3rem + 3.2vw, 3.6rem);
  max-width: 22ch;
  margin: 0.9rem 0 1.1rem;
}
.note-head .dek { color: var(--mist); font-size: 1.15rem; max-width: 60ch; }
.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.6rem;
  margin-top: 1.8rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--slate);
}
.note-meta b { color: var(--periwinkle); font-weight: 500; }
.note-meta a { color: var(--mist); }
.note-meta a:hover { color: var(--fortune); }

/* ---- 2. LAYOUT: CONTENTS RAIL + PROSE ---------------------------------- */
.note-body {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  padding-block: clamp(2rem, 5vw, 3.5rem);
}
.toc { position: sticky; top: calc(68px + 1.5rem); align-self: start; font-size: 0.86rem; }
.toc h2 {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fortune);
  margin-bottom: 0.9rem;
}
.toc ol { list-style: none; padding: 0; display: grid; gap: 0.15rem; counter-reset: toc; }
.toc li { counter-increment: toc; }
.toc a {
  display: grid;
  grid-template-columns: 2.1em 1fr;
  padding: 0.3rem 0 0.3rem 0.7rem;
  border-left: 1px solid var(--line);
  color: var(--mist);
  line-height: 1.35;
  transition: color 0.2s, border-color 0.2s;
}
.toc a::before { content: counter(toc, decimal-leading-zero); font-family: var(--mono); font-size: 0.7rem; color: var(--slate); padding-top: 0.12em; }
.toc a:hover, .toc a[aria-current="true"] { color: var(--fortune); border-left-color: var(--fortune); }

/* ---- 3. PROSE ---------------------------------------------------------- */
.prose { max-width: var(--measure); min-width: 0; }
.prose > * + * { margin-top: 1.15em; }
.prose h2 {
  font-size: clamp(1.55rem, 1.2rem + 1.3vw, 2.1rem);
  margin-top: 2.6em;
  scroll-margin-top: calc(68px + 1rem);
  counter-increment: sec;
}
.prose { counter-reset: sec; }
.prose h2::before {
  content: counter(sec, decimal-leading-zero) " · ";
  font-family: var(--mono);
  font-size: 0.55em;
  letter-spacing: 0.2em;
  color: var(--fortune);
  vertical-align: 0.3em;
}
.prose h2.unnumbered::before { content: none; }
.prose h2.unnumbered { counter-increment: none; }
.prose h3 { font-size: 1.25rem; margin-top: 2em; scroll-margin-top: calc(68px + 1rem); }
.prose p, .prose li { color: #dcd8d0; }
.prose strong { color: var(--ivory); font-weight: 600; }
.prose a { text-decoration: underline; text-decoration-color: rgba(154, 167, 230, 0.4); text-underline-offset: 0.2em; }
.prose a:hover { color: var(--fortune); text-decoration-color: var(--fortune); }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.45em; }
.prose li::marker { color: var(--fortune-dim); }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.prose sup, .figures sup { line-height: 0; }
.prose sup a { text-decoration: none; font-family: var(--mono); font-size: 0.75em; padding-inline: 0.1em; }
.prose blockquote {
  padding: 0.2rem 0 0.2rem 1.3rem;
  border-left: 2px solid var(--coral);
  color: var(--mist);
  font-style: italic;
}
.prose blockquote cite { display: block; margin-top: 0.5rem; font-style: normal; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; color: var(--slate); }

.lede { font-size: 1.12rem; }
.lede::first-letter { font-family: var(--display); font-weight: 600; color: var(--fortune); }

/* abstract / key-result panels */
.abstract, .callout {
  padding: 1.3rem 1.5rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--fortune);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--void-2));
}
.abstract > * + *, .callout > * + * { margin-top: 0.8em; }
.abstract h2, .callout h4 {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fortune);
  margin: 0;
}
.abstract h2::before { content: none; }
.prose .abstract h2 { counter-increment: none; margin-top: 0; }
.callout--coral { border-left-color: var(--coral); }
.callout--coral h4 { color: var(--coral); }
.callout p, .abstract p { font-size: 0.98rem; }

/* key numbers strip */
.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.figures > div { padding: 1.1rem 1.2rem; background: var(--panel); }
.figures b { display: block; font-family: var(--body); font-weight: 600; font-size: 1.85rem; line-height: 1.1; color: var(--ivory); }
.figures span { display: block; margin-top: 0.4rem; font-size: 0.82rem; line-height: 1.4; color: var(--mist); }

/* ---- 4. FIGURES -------------------------------------------------------- */
.fig {
  margin-block: 2.2em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.prose .fig { margin-top: 2.2em; }
/* figures may run wider than the text column on large screens */
@media (min-width: 1240px) { .fig--wide { margin-right: -8rem; } }
.fig > .media__bar { margin: 0; padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--line); }
.fig__plot { position: relative; padding: 1rem 1.1rem 0.4rem; }
.fig__plot svg { width: 100%; height: auto; overflow: visible; }
.fig__img img { width: 100%; }
.fig figcaption { padding: 0.6rem 1.1rem 1.1rem; font-size: 0.9rem; color: var(--mist); line-height: 1.55; }
.fig figcaption b { color: var(--ivory); font-weight: 600; }
.fig details { border-top: 1px solid var(--line); }
.fig summary {
  cursor: pointer;
  padding: 0.65rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--slate);
}
.fig summary:hover { color: var(--fortune); }
.fig details[open] summary { color: var(--fortune); }
.fig .data { margin: 0 1.1rem 1.1rem; }
.fig .data { font-size: 0.82rem; }
.fig .data th, .fig .data td { padding: 0.5rem 0.55rem; }
.fig__plot > .table-scroll .data { margin: 0; }

/* svg chart parts */
.ch text { font-family: var(--mono); font-size: 11px; fill: var(--mist); }
.ch .muted { fill: var(--slate); }
.ch .ink { fill: var(--ivory); paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.ch .title { font-family: var(--body); font-size: 12.5px; fill: var(--ivory); }
.ch .grid line, .ch line.grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.ch .axis { stroke: #3a4157; stroke-width: 1; shape-rendering: crispEdges; }
.ch .s1 { stroke: var(--series-1); fill: var(--series-1); }
.ch .s2 { stroke: var(--series-2); fill: var(--series-2); }
.ch .s3 { stroke: var(--series-3); fill: var(--series-3); }
.ch .s0 { stroke: var(--slate); fill: var(--slate); }
.ch path.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch circle.dot { stroke: var(--panel); stroke-width: 2; }
.ch .area { stroke: none; opacity: 0.12; }
.ch .hit { fill: transparent; stroke: none; cursor: crosshair; }
.ch .cursor { stroke: var(--slate); stroke-width: 1; opacity: 0; pointer-events: none; }
.ch.hover .cursor { opacity: 1; }
.ch .hl { opacity: 0; pointer-events: none; }
.ch .hl.on { opacity: 1; }
.ch .lead { stroke: var(--slate); stroke-width: 1; fill: none; }
/* diagram parts */
.dg text { font-family: var(--mono); font-size: 11px; fill: var(--mist); paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.dg .lbl { font-family: var(--body); font-size: 12.5px; fill: var(--ivory); }
.dg .box { fill: var(--panel-2); stroke: #3a4157; stroke-width: 1; }
.dg .rule { stroke: #3a4157; stroke-width: 1; }
.dg .msg { stroke: var(--mist); stroke-width: 1.5; fill: none; }
.dg .msg.s1, .dg .msg.s2, .dg .msg.s3 { fill: none; stroke-width: 2; }
.dg .s1 { stroke: var(--series-1); }
.dg .s2 { stroke: var(--series-2); }
.dg .s3 { stroke: var(--series-3); }
.dg .f1 { fill: var(--series-1); }
.dg .f2 { fill: var(--series-2); }
.dg .f3 { fill: var(--series-3); }
.dg .s0 { stroke: var(--mist); }
.dg .f0 { fill: var(--mist); }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; padding: 0 1.1rem; margin-top: 0.2rem; font-family: var(--mono); font-size: 0.72rem; color: var(--mist); }
.legend span { display: inline-flex; align-items: center; gap: 0.5em; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; background: currentColor; }
.legend .k1 i { background: var(--series-1); }
.legend .k2 i { background: var(--series-2); }
.legend .k3 i { background: var(--series-3); }
.legend .k0 i { background: var(--slate); }

/* tooltip (one per page, positioned by notes.js) */
.tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  min-width: 9rem;
  padding: 0.55rem 0.75rem;
  background: var(--panel-2);
  border: 1px solid #3a4157;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--mist);
  opacity: 0;
  transition: opacity 0.12s;
}
.tip.on { opacity: 1; }
.tip b { color: var(--ivory); font-weight: 500; }
.tip .row { display: flex; align-items: center; gap: 0.5em; }
.tip .row i { width: 10px; height: 3px; border-radius: 2px; }
.tip .row em { margin-left: auto; padding-left: 1em; font-style: normal; color: var(--ivory); }

/* ---- 5. TABLES --------------------------------------------------------- */
.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table-scroll { overflow-x: auto; }
.data caption { caption-side: top; text-align: left; padding-bottom: 0.6rem; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--slate); }
.data th, .data td { padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data thead th { font-family: var(--mono); font-size: 0.7rem; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fortune); border-bottom-color: #3a4157; }
.data td { color: #dcd8d0; }
.data td.n, .data th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data tbody th { font-weight: 500; color: var(--ivory); }

/* ---- 6. EQUATIONS ------------------------------------------------------ */
.eq {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.2rem;
  background: var(--void-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
.eq math { font-size: 1.18rem; color: var(--ivory); }
.eq__n { font-family: var(--mono); font-size: 0.75rem; color: var(--slate); }
math { font-family: "STIX Two Math", "Cambria Math", "Latin Modern Math", math; }

/* ---- 7. CODE ----------------------------------------------------------- */
.code {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--void-2);
}
.code__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.6rem 0.45rem 1rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--slate);
}
.code pre { margin: 0; padding: 1rem 1.1rem; overflow-x: auto; font-family: var(--mono); font-size: 0.82rem; line-height: 1.6; color: #dcd8d0; }
.code pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.code .c { color: var(--slate); }
.code .k { color: var(--periwinkle); }
.code .s { color: var(--jade); }
.copy {
  padding: 0.25rem 0.7rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist);
  cursor: pointer;
}
.copy:hover { color: var(--void); background: var(--fortune); border-color: var(--fortune); }

/* ---- 8. REFERENCES / CHANGELOG ---------------------------------------- */
.refs { font-size: 0.9rem; padding-left: 2.2em; }
.refs li { color: var(--mist); padding-left: 0.3em; scroll-margin-top: calc(68px + 1rem); }
.refs li::marker { font-family: var(--mono); font-size: 0.8em; color: var(--fortune-dim); }
.refs li:target { color: var(--ivory); }
.refs a { word-break: break-word; }
.changelog { list-style: none; padding: 0; font-family: var(--mono); font-size: 0.8rem; }
.changelog li { color: var(--mist); }
.changelog time { color: var(--fortune); margin-right: 0.8em; }

/* ---- 9. NOTES INDEX ---------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.6rem; }
.filters button {
  padding: 0.45rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mist);
  cursor: pointer;
}
.filters button:hover { color: var(--fortune); border-color: var(--fortune-dim); }
.filters button[aria-pressed="true"] { color: var(--fortune); border-color: var(--fortune-dim); background: rgba(255, 194, 75, 0.08); }
.note-list { display: grid; gap: 1.4rem; }
.note-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--void-2));
  overflow: hidden;
  transition: border-color 0.3s;
}
.note-card:hover { border-color: #3a4157; }
.note-card[hidden] { display: none; }
.note-card__art { position: relative; min-height: 13rem; background: var(--void-2); border-right: 1px solid var(--line); }
.note-card__art img, .note-card__art svg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.note-card__body { padding: 1.6rem 1.8rem 1.8rem; }
.note-card h2 { font-size: 1.55rem; margin: 0.8rem 0 0.7rem; }
.note-card h2 a { color: var(--ivory); }
.note-card h2 a::before { content: ""; position: absolute; inset: 0; z-index: 1; }
.note-card:hover h2 a { color: var(--fortune); }
.note-card p { color: var(--mist); font-size: 0.98rem; }
.note-card .note-meta { margin-top: 1.2rem; }

/* ---- 10. RESPONSIVE ---------------------------------------------------- */
@media (max-width: 1100px) {
  .note-body { grid-template-columns: 1fr; }
  .toc { position: static; padding: 1rem 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
}
@media (max-width: 760px) {
  .note-card { grid-template-columns: 1fr; }
  .note-card__art { min-height: 11rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .fig__plot { padding-inline: 0.5rem; overflow-x: auto; }
  /* keep chart text legible: scroll sideways rather than shrink */
  .fig__plot > svg { min-width: 600px; }
}
@media print {
  .rail, .topbar, .toc, .footer, .copy { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; color: #000; }
}

/* ---- 11. NOTE HERO IMAGE ---------------------------------------------- */
.note-hero { margin-top: 2.2rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.note-hero img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; object-position: 50% 40%; }
.note-hero figcaption { padding: 0.65rem 1.1rem; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--slate); }
@media (max-width: 760px) { .note-hero img { aspect-ratio: 4 / 3; } }

/* encoding gallery (YS-EN-0003 Figure 1): a label column and six square images per row */
.enc-grid { display: grid; gap: 6px; padding: 1rem 1.1rem 0.4rem; overflow-x: auto; }
.enc-grid > div { display: grid; grid-template-columns: 8.5rem repeat(6, minmax(72px, 1fr)); gap: 6px; align-items: center; min-width: 560px; }
.enc-grid img { width: 100%; height: auto; aspect-ratio: 1; border-radius: 3px; }
.enc-grid__head span { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--slate); text-align: center; }
.enc-grid [role="rowheader"] { display: inline-flex; align-items: center; gap: 0.5em; font-size: 0.86rem; color: var(--ivory); }
.enc-grid [role="rowheader"] i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.enc-grid .k1 i { background: var(--series-1); }
.enc-grid .k2 i { background: var(--series-2); }
.enc-grid .k3 i { background: var(--series-3); }

/* ---- 12. CALCULATOR (YS-EN-0004) -------------------------------------- */
.calc { padding: 1.2rem 1.1rem 1rem; }
.calc__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.calc .field { margin-bottom: 0.9rem; }
.calc .data { margin: 0; }
.calc .field input { padding: 0.6rem 0.75rem; font-family: var(--mono); font-size: 0.9rem; }
.calc__parts { width: 100%; border-collapse: collapse; margin: 0.4rem 0 1rem; font-size: 0.86rem; }
.calc__parts th, .calc__parts td { padding: 0.3rem 0.4rem; text-align: left; }
.calc__parts thead th { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--periwinkle); font-weight: 500; }
.calc__parts input { width: 100%; padding: 0.45rem 0.6rem; background: var(--void-2); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ivory); font-family: var(--mono); font-size: 0.86rem; }
.calc__parts input:focus { outline: none; border-color: var(--fortune); box-shadow: 0 0 0 3px rgba(255, 194, 75, 0.15); }
.calc__cmp { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; margin-top: 1rem; }
.calc__cmp div { padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--void-2); }
.calc__cmp b { display: block; font-family: var(--display); font-size: 1.6rem; color: var(--fortune); line-height: 1.1; }
.calc__cmp span { font-size: 0.8rem; color: var(--mist); }
.calc__warn { color: var(--coral); font-family: var(--mono); font-size: 0.8rem; }
.calc__foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 0.4rem; }
.calc__foot p { font-size: 0.8rem; color: var(--slate); margin: 0; }
@media (max-width: 760px) {
  .calc__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc__cmp { grid-template-columns: 1fr; }
}
