/* =====================================================================
 * CES-Alpha manual pages: shared style (assets/manual.css)
 *
 * Every page loads this file and assets/manual.js. A page's own <style>
 * keeps only what is specific to that page.
 *
 * Page skeleton:
 *   <nav class="ces-navbar"> brand › マニュアル / page </nav>
 *   <div class="manual-layout">
 *     <nav class="manual-toc"></nav>          (filled by manual.js)
 *     <main class="manual-main">
 *       <h1 class="manual-page-title">…</h1>
 *       <div class="manual-section" id="…">
 *         <div class="manual-section-header"><span class="manual-section-num">1</span> Title</div>
 *         <div class="manual-section-body"> … </div>
 *       </div>
 *     </main>
 *   </div>
 *   <div class="manual-footer">…</div>
 *
 * Hints: .manual-tip / .manual-info (and .manual-note) that are direct
 * children of .manual-section-body move to a right-hand column on wide
 * screens, next to the text they follow. .manual-warning stays in the text.
 * A hint with class "inline", or inside an element with data-notes="inline",
 * stays in the text.
 * Screenshots (.screenshot-frame img) open in a zoom viewer on click.
 * ===================================================================== */

:root {
  --ces-primary:    #4da6ff;
  --ces-primary-dk: #1f6fbf;
  --ces-primary-bg: #eef5ff;
  --ces-warning:    #f2b300;
  --ces-danger:     #e5484d;
  --ces-success:    #3f9a4a;
  --ces-bg:         #f3f5f8;
  --ces-surface:    #ffffff;
  --ces-ink:        #1f2933;
  --ces-ink-2:      #4b5866;
  --ces-ink-3:      #7b8794;
  --ces-line:       #e3e7ec;
  --ces-navbar-h:   56px;
  --ces-toc-w:      248px;
  --ces-note-w:     300px;
  --ces-note-gap:   36px;
  --ces-text-max:   52em;
}

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  font-family: 'Noto Sans JP', 'Noto Sans SC', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  background: var(--ces-bg);
  color: var(--ces-ink);
  font-size: 1rem;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ces-primary-dk); }
a:hover { color: var(--ces-primary); }

/* ---------- Top bar ---------- */
.ces-navbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--ces-navbar-h);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(1.4) blur(6px);
  border-bottom: 1px solid var(--ces-line);
  box-shadow: 0 1px 0 rgba(77, 166, 255, 0.35);
  padding: 8px 32px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  line-height: 1.4;
}
.ces-navbar .brand { font-weight: 700; font-size: 1.15rem; color: var(--ces-primary); text-decoration: none; }
.ces-navbar .brand:hover { color: var(--ces-primary-dk); }
.breadcrumb-sep { color: #b8c0c8; font-size: 0.9rem; }
.nav-link-manual { color: var(--ces-ink-2); text-decoration: none; font-size: 0.9rem; }
.nav-link-manual:hover { color: var(--ces-primary-dk); }
.current-page { color: var(--ces-ink-3); font-size: 0.9rem; }

/* ---------- Page grid: contents | main (text + hint column) ---------- */
.manual-layout {
  max-width: 1560px;
  margin: 0 auto;
  padding: 32px 32px 0;
  display: grid;
  grid-template-columns: var(--ces-toc-w) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}
.manual-layout.no-toc { grid-template-columns: minmax(0, 1fr); max-width: 1120px; }
.manual-layout.no-toc > .manual-toc { display: none; }
.manual-main { min-width: 0; }

.manual-page-title {
  font-size: 1.85rem; font-weight: 700; color: var(--ces-ink);
  line-height: 1.4; letter-spacing: 0.01em;
  margin: 0 0 0.6rem; padding: 0; border: 0;
}
.manual-page-title + * { margin-top: 0; }
.manual-main > .manual-page-title { margin-bottom: 1.75rem; }
.manual-main > .manual-page-title::after {
  content: ""; display: block; width: 56px; height: 4px; border-radius: 2px;
  background: var(--ces-primary); margin-top: 0.9rem;
}
.manual-lead { font-size: 1.05rem; color: var(--ces-ink-2); max-width: var(--ces-text-max); margin-bottom: 2.25rem; }

/* ---------- Contents (left) ---------- */
.manual-toc {
  position: sticky;
  top: calc(var(--ces-navbar-h) + 24px);
  max-height: calc(100vh - var(--ces-navbar-h) - 48px);
  overflow-y: auto;
  font-size: 0.9rem; line-height: 1.5;
  scrollbar-width: thin;
}
.manual-toc details > summary {
  list-style: none; cursor: default;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ces-ink-3); padding: 0 0 0.75rem 12px;
}
.manual-toc details > summary::-webkit-details-marker { display: none; }
.manual-toc ol { list-style: none; margin: 0; padding: 0; }
.manual-toc > details > ol { border-left: 2px solid var(--ces-line); }
.manual-toc li { margin: 0; }
.manual-toc a {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 12px; margin-left: -2px;
  border-left: 2px solid transparent;
  color: var(--ces-ink-2); text-decoration: none;
  transition: color .12s, border-color .12s, background .12s;
}
.manual-toc a:hover { color: var(--ces-primary-dk); background: rgba(77, 166, 255, 0.06); }
.manual-toc .toc-num {
  flex-shrink: 0; min-width: 1.6em; height: 1.6em; line-height: 1.6em;
  border-radius: 50%; text-align: center; font-size: 0.72rem; font-weight: 700;
  background: #e6eaef; color: var(--ces-ink-2);
}
.manual-toc li.active > a { color: var(--ces-primary-dk); font-weight: 700; border-left-color: var(--ces-primary); background: var(--ces-primary-bg); }
.manual-toc li.active > a .toc-num { background: var(--ces-primary); color: #fff; }
.manual-toc ol ol { display: none; padding: 2px 0 6px; }
.manual-toc li.active > ol { display: block; }
.manual-toc ol ol a { padding: 4px 12px 4px 46px; font-size: 0.84rem; color: var(--ces-ink-3); }
.manual-toc ol ol li.active > a { color: var(--ces-primary-dk); font-weight: 600; background: none; border-left-color: transparent; }

/* ---------- Sections ---------- */
.manual-section {
  display: flow-root;            /* holds the floated hints */
  background: var(--ces-surface);
  border: 1px solid var(--ces-line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  padding: 1.85rem 2.4rem 2rem;
  margin: 0 0 2.25rem;
  scroll-margin-top: calc(var(--ces-navbar-h) + 20px);
}
[id] { scroll-margin-top: calc(var(--ces-navbar-h) + 20px); }
.manual-section-header {
  display: flex; align-items: center; gap: 14px;
  font-size: 1.4rem; font-weight: 700; line-height: 1.45; color: var(--ces-ink);
  margin: 0 0 1.35rem; padding: 0 0 0.85rem;
  border-bottom: 1px solid var(--ces-line);
  background: none;
}
.manual-section-num {
  flex-shrink: 0;
  width: 36px; height: 36px; line-height: 36px; border-radius: 10px;
  background: var(--ces-primary); color: #fff;
  text-align: center; font-size: 1rem; font-weight: 700;
}
.manual-section-num:empty { display: none; }
.manual-section-body { padding: 0; overflow-wrap: break-word; }
.manual-section-body > :last-child { margin-bottom: 0; }

/* Text rhythm: generous spacing, readable line length */
.manual-section-body p { margin: 0 0 1em; }
.manual-section-body > p,
.manual-section-body > ul,
.manual-section-body > ol,
.manual-section-body > li { max-width: var(--ces-text-max); }
.manual-section-body ul, .manual-section-body ol { padding-left: 1.4em; margin: 0 0 1.25em; }
.manual-section-body li { margin-bottom: 0.45em; }
.manual-section-body li > ul, .manual-section-body li > ol { margin: 0.45em 0 0.2em; }

.manual-section-body h3,
.manual-section-body h4,
.manual-section-body h5,
.manual-section-body h6 {
  font-size: 1.12rem; font-weight: 700; line-height: 1.5; color: var(--ces-ink);
  margin: 2.1rem 0 0.85rem !important;
  padding-left: 12px; border-left: 4px solid var(--ces-primary);
}
.manual-section-body > h3:first-child,
.manual-section-body > h4:first-child,
.manual-section-body > h5:first-child,
.manual-section-body > h6:first-child { margin-top: 0 !important; }
.manual-section-body hr { margin: 2rem 0; border-color: var(--ces-line); opacity: 1; }

.manual-section-body code { color: #b4235a; background: #f4f5f7; padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.88em; }
.manual-section-body pre { background: #f6f8fa; border: 1px solid var(--ces-line); border-radius: 8px; padding: 0.9rem 1.1rem; font-size: 0.86rem; line-height: 1.6; margin: 0.75rem 0 1.5rem; }
.manual-section-body pre code { background: none; color: inherit; padding: 0; }

/* Tables */
.manual-section-body .table-responsive { margin: 0.85rem 0 1.4rem; }
.manual-section-body table.table { font-size: 0.93rem; line-height: 1.65; margin-bottom: 0; background: #fff; }
.manual-section-body .table-responsive > table.table { margin-bottom: 0; }
.manual-section-body > table.table { margin: 0.85rem 0 1.4rem; }
.manual-section-body table.table > :not(caption) > * > * { padding: 0.65rem 0.85rem; border-color: var(--ces-line); }
.manual-section-body table.table th { background: var(--ces-primary-bg); font-weight: 700; color: var(--ces-ink); }
.manual-section-body table.table td:first-child { font-weight: 500; }

/* Command blocks */
.manual-cmd {
  background: #1e2a33; color: #e8eef2; border-radius: 8px;
  padding: 0.85rem 1.1rem; margin: 0.5rem 0 1.25rem;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.86rem; line-height: 1.7; overflow-x: auto; white-space: pre;
}
.file-path {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  background: #f4f5f7; border: 1px solid var(--ces-line); border-radius: 4px;
  padding: 1px 7px; font-size: 0.86rem; color: #b4235a; word-break: break-all;
}

/* Numbered step list */
.manual-steps { list-style: none; padding: 0 !important; margin: 1rem 0 1.5rem; max-width: var(--ces-text-max); }
.manual-steps li {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 0.8rem 0; margin: 0; border-bottom: 1px dashed var(--ces-line);
}
.manual-steps li:last-child { border-bottom: none; }
.step-num {
  flex-shrink: 0; margin-top: 3px;
  width: 26px; height: 26px; line-height: 26px; border-radius: 50%;
  background: var(--ces-primary); color: #fff;
  text-align: center; font-size: 0.8rem; font-weight: 700;
}

/* ---------- Hints: tip / info / warning ---------- */
.manual-tip, .manual-info, .manual-warning, .manual-note {
  position: relative;
  font-size: 0.92rem; line-height: 1.75;
  padding: 0.9rem 1.1rem 0.9rem 1.15rem;
  margin: 1rem 0 1.4rem;
  border-radius: 10px;
  border: 1px solid transparent; border-left-width: 4px;
  max-width: var(--ces-text-max);
}
.manual-tip     { background: #fffaeb; border-color: #f7e3a6; border-left-color: var(--ces-warning); }
.manual-info,
.manual-note    { background: #f0f7ff; border-color: #cfe3fb; border-left-color: var(--ces-primary); }
.manual-warning { background: #fff2f2; border-color: #f6cccd; border-left-color: var(--ces-danger); }
.manual-tip > :last-child, .manual-info > :last-child,
.manual-warning > :last-child, .manual-note > :last-child { margin-bottom: 0; }
.manual-tip ul, .manual-info ul, .manual-warning ul, .manual-note ul { margin-bottom: 0.3em; }

/* Wide screens: hints sit in a column at the right of the text.
 * manual.js puts each hint just before the element it follows, so that its
 * top lines up with that element, and marks the section with .has-notes. */
@media (min-width: 1400px) {
  .manual-section.has-notes { padding-right: calc(2.4rem + var(--ces-note-w) + var(--ces-note-gap)); }
  .manual-section.has-notes > .manual-section-header {
    margin-right: calc(-1 * (var(--ces-note-w) + var(--ces-note-gap)));
  }
  .manual-section-body > .is-note {
    float: right; clear: right;
    width: var(--ces-note-w);
    margin: 0.2rem calc(-1 * (var(--ces-note-w) + var(--ces-note-gap))) 1rem 0;
    font-size: 0.88rem; line-height: 1.7;
  }
  .manual-section-body > .is-note.mt-3,
  .manual-section-body > .is-note.mt-1 { margin-top: 0.2rem !important; }
}

/* ---------- Screenshots ---------- */
.screenshot-frame {
  position: relative;
  border: 1px solid var(--ces-line); border-radius: 10px; overflow: hidden;
  margin: 0.85rem 0 1.6rem;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.07);
  background: #fff;
}
.screenshot-frame img { width: 100%; height: auto; display: block; }
/* Display width of a screenshot: style="--shot-w: 640px" on the frame.
 * Choose it so that the UI in the picture shows at about 0.9 of its real size:
 *   --shot-w = image width / (image px per CSS px of the captured UI) * 0.9,
 * and never more than the image width (it would be blurred). Without it the
 * screenshot fills the column. */
.screenshot-frame { width: min(100%, var(--shot-w, 100%)); margin-left: auto; margin-right: auto; }
.screenshot-frame.narrow,
.screenshot-frame.screenshot-narrow { --shot-w: 520px; }
@media (min-width: 1400px) {
  /* a large screenshot in a section with hints also uses the hint column (manual.js adds .shot-wide) */
  .manual-section-body > .screenshot-frame.shot-wide {
    clear: right;
    margin-left: 0;
    width: min(calc(100% + var(--ces-note-w) + var(--ces-note-gap)), var(--shot-w, 100vw));
  }
}
.screenshot-caption {
  background: #f8f9fb; border-top: 1px solid var(--ces-line);
  font-size: 0.84rem; line-height: 1.55; color: var(--ces-ink-2);
  padding: 0.55rem 0.9rem; text-align: center;
}
img.zoomable { cursor: zoom-in; }
.zoom-hint {
  position: absolute; top: 10px; right: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(20, 28, 36, 0.72); color: #fff;
  font-size: 0.76rem; line-height: 1; padding: 6px 10px; border-radius: 999px;
  opacity: 0; transform: translateY(-2px); transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.zoom-host:hover .zoom-hint,
.zoom-host:focus-within .zoom-hint { opacity: 1; transform: none; }
@media (hover: none) { .zoom-hint { opacity: 0.85; transform: none; } }
img.zoomable:focus-visible { outline: 3px solid var(--ces-primary); outline-offset: -3px; }

/* Zoom viewer */
.mlb {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10, 14, 18, 0.9);
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .15s;
}
.mlb.open { opacity: 1; }
.mlb[hidden] { display: none; }
.mlb-stage {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 56px 72px 12px;
  overscroll-behavior: contain;
}
.mlb-stage img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  background: #fff; border-radius: 6px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  cursor: zoom-in;
}
.mlb.actual .mlb-stage { align-items: flex-start; justify-content: flex-start; }
.mlb.actual .mlb-stage img { max-width: none; max-height: none; margin: auto; cursor: zoom-out; }
.mlb.no-zoom .mlb-stage img { cursor: default; }
.mlb-bar {
  display: flex; align-items: center; gap: 16px;
  color: #dfe6ec; font-size: 0.9rem; line-height: 1.5;
  padding: 10px 24px 16px; text-align: center; justify-content: center;
}
.mlb-caption { max-width: 900px; }
.mlb-count { color: #9aa7b2; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mlb-btn {
  position: absolute; z-index: 2;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.12); color: #fff;
  font-size: 1.25rem; cursor: pointer; transition: background .12s;
}
.mlb-btn:hover { background: rgba(255, 255, 255, 0.26); }
.mlb-btn:focus-visible { outline: 3px solid var(--ces-primary); }
.mlb-close { top: 12px; right: 16px; }
.mlb-toggle { top: 12px; right: 68px; }
.mlb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.mlb-next { right: 14px; top: 50%; transform: translateY(-50%); }
.mlb-btn[hidden] { display: none; }
body.mlb-lock { overflow: hidden; }

/* ---------- Back to top, footer ---------- */
.to-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 20;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--ces-line); background: #fff; color: var(--ces-ink-2);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.12);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; cursor: pointer;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.to-top.show { opacity: 1; pointer-events: auto; }
.to-top:hover { color: var(--ces-primary-dk); }

.manual-footer {
  text-align: center; color: var(--ces-ink-3); font-size: 0.84rem;
  padding: 1rem 0 4rem; line-height: 1.6;
}
.manual-footer a { color: var(--ces-ink-3); text-decoration: none; }
.manual-footer a:hover { color: var(--ces-primary-dk); }

/* ---------- Medium screens: contents + text, hints inline ---------- */
@media (max-width: 1199px) {
  :root { --ces-toc-w: 220px; }
  .manual-layout { gap: 32px; padding: 32px 24px 0; }
  .manual-section { padding: 1.7rem 1.9rem 1.9rem; }
}

/* ---------- Narrow screens: one column, contents fold at the top ---------- */
@media (max-width: 991px) {
  .ces-navbar { padding: 8px 16px; flex-wrap: nowrap; gap: 8px; }
  .ces-navbar > * { flex-shrink: 0; }
  .ces-navbar .current-page { flex: 1 1 auto; flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ces-navbar:has(.lang-switch) { flex-wrap: wrap; }
  /* a table that is not in .table-responsive scrolls by itself instead of widening the page */
  .manual-section-body table.table:not(.table-responsive table) { display: block; overflow-x: auto; }
  .manual-layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 20px 16px 0; }
  .manual-toc {
    position: static; max-height: none; overflow: visible;
    background: #fff; border: 1px solid var(--ces-line); border-radius: 12px;
    margin: 0 0 1.75rem; order: 0;
  }
  .manual-toc details > summary {
    cursor: pointer; padding: 0.85rem 1rem; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: space-between;
  }
  .manual-toc details > summary::after { content: "▾"; font-size: 0.9rem; transition: transform .15s; }
  .manual-toc details[open] > summary::after { transform: rotate(180deg); }
  .manual-toc > details > ol { border-left: 0; padding: 0 0 0.6rem; }
  .manual-toc a { border-left: 0; margin-left: 0; padding: 8px 16px; }
  .manual-toc ol ol { display: none !important; }
  .manual-main > .manual-page-title { font-size: 1.5rem; margin-bottom: 1.5rem; }
  .manual-section { padding: 1.3rem 1.15rem 1.5rem; border-radius: 12px; margin-bottom: 1.6rem; }
  .manual-section-header { font-size: 1.2rem; gap: 12px; margin-bottom: 1.1rem; }
  .manual-section-num { width: 30px; height: 30px; line-height: 30px; font-size: 0.9rem; border-radius: 8px; }
  .mlb-stage { padding: 56px 8px 8px; }
  .mlb-prev, .mlb-next { top: auto; bottom: 10px; transform: none; }
  .to-top { right: 14px; bottom: 14px; }
}

/* The layout row placeholder of the TOC must come first in DOM order on
 * narrow screens; it already does. */

@media print {
  .ces-navbar, .manual-toc, .to-top, .zoom-hint { display: none !important; }
  .manual-layout { display: block; padding: 0; }
  .manual-section { box-shadow: none; break-inside: auto; padding: 1rem 0; border: 0; }
  .manual-section.has-notes { padding-right: 0; }
  .manual-section-body > .is-note { float: none; width: auto; margin: 1rem 0; }
}
