/* Cloak Tooling guide · Andrey Shtinov brandbook application */
:root {
  color-scheme: light;
  --page: 78rem;
  --reading: 66ch;
  --gutter: clamp(1.15rem, 5vw, 3rem);
  --section-gap: clamp(4rem, 8vw, 7rem);
  --block-gap: clamp(1.6rem, 3vw, 2.4rem);
  --radius: 1.35rem;
  --radius-small: .7rem;
  --shadow: 0 18px 50px -32px rgba(24, 28, 30, .45);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --shadow: 0 18px 50px -28px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--color-ink);
  background: var(--color-bg);
  font-family: var(--font-sans);
  font-size: var(--type-body-size);
  line-height: var(--type-body-leading);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-brand); text-underline-offset: .22em; text-decoration-thickness: .06em; }
a:hover { text-decoration-thickness: .12em; }
img { max-width: 100%; height: auto; }
button { font: inherit; cursor: pointer; }
code, pre { font-family: var(--font-code); }
::selection { color: var(--color-ink); background: var(--color-soft); }
:focus-visible { outline: 2px solid var(--color-brand); outline-offset: 4px; border-radius: 2px; }

.shell { width: min(100% - 2 * var(--gutter), var(--page)); margin-inline: auto; }
.reading { width: min(100% - 2 * var(--gutter), var(--reading)); margin-inline: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; z-index: 50; left: 1rem; top: -100%;
  padding: .7rem 1rem; background: var(--color-surface); border-radius: .4rem;
}
.skip-link:focus { top: 1rem; }

/* Header */
.masthead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1.2rem var(--gutter);
  max-width: var(--page); margin-inline: auto;
}
.byline { display: inline-flex; align-items: center; gap: .65rem; color: var(--color-ink); text-decoration: none; font-weight: 650; }
.byline img { width: 2.1rem; height: 2.1rem; border-radius: 50%; }
.byline span span { color: var(--color-muted); font-weight: 450; }
.theme-toggle {
  border: 1px solid var(--color-line); background: var(--color-surface);
  color: var(--color-brand); border-radius: .45rem; padding: .45rem .75rem;
  font-size: .92rem; font-weight: 650;
}
.theme-toggle:hover { border-color: var(--color-brand); }

/* Cover */
.cover {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: 1.15fr .85fr; align-items: end;
  min-height: 39rem; margin-top: .4rem;
  border-radius: var(--radius);
  background: var(--color-soft);
  box-shadow: var(--shadow);
}
.cover::after {
  content: ""; position: absolute; inset: auto -10% -35% 35%;
  height: 60%; background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.34), transparent 68%);
  z-index: 0; pointer-events: none;
}
.cover-copy { position: relative; z-index: 2; padding: clamp(2.2rem, 5.5vw, 4.6rem); padding-right: 0; align-self: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .45rem;
  margin: 0 0 1.1rem; color: var(--color-brand); font-size: var(--type-label-size);
  font-weight: var(--type-label-weight); letter-spacing: var(--type-label-tracking); text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 1.5rem; height: 2px; background: currentColor; }
.cover h1 {
  margin: 0; font-size: clamp(3.4rem, 6.8vw, 5.5rem); line-height: .92;
  letter-spacing: -.045em; font-weight: 780; text-wrap: balance;
}
.cover h1 em { font-style: normal; color: var(--color-brand); }
.cover-lede { max-width: 33ch; margin: 1.4rem 0 0; font-size: clamp(1.12rem, 2vw, 1.36rem); line-height: 1.35; }
.cover-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.7rem; }
.button {
  display: inline-flex; align-items: center; gap: .55rem; padding: .78rem 1rem;
  border-radius: .45rem; font-weight: 680; text-decoration: none; border: 1px solid transparent;
}
.button-primary { color: var(--color-on-brand); background: var(--color-brand); }
.button-primary:hover { text-decoration: underline; }
.button-quiet { color: var(--color-brand); background: var(--color-surface); border-color: var(--color-line); }
.button-quiet:hover { border-color: var(--color-brand); }
.cover-art { position: relative; z-index: 1; align-self: end; margin: 0 .8rem 0 0; }
.cover-art img { display: block; width: 100%; height: clamp(30rem, 52vw, 37rem); object-fit: contain; object-position: center bottom; }
.cover-art .dark-art { display: none; }
[data-theme="dark"] .cover-art .light-art { display: none; }
[data-theme="dark"] .cover-art .dark-art { display: block; }
.cover-meta {
  position: relative; z-index: 2; display: flex; flex-wrap: wrap; gap: .4rem .9rem;
  margin-top: 1.5rem; color: var(--color-muted); font-size: .88rem;
}
.cover-meta strong { color: var(--color-ink); }

/* Tile */
.tile-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1.4rem; margin-top: var(--block-gap); }
.tile-label { max-width: 30ch; color: var(--color-muted); font-size: .95rem; }
.cover-tile {
  width: 18rem; min-height: 11.5rem; border-radius: 1rem; padding: 1.2rem;
  background: var(--color-soft); display: grid; grid-template-columns: 1fr .7fr;
  align-items: end; overflow: hidden; text-decoration: none; color: var(--color-ink);
  border: 1px solid color-mix(in srgb, var(--color-brand) 18%, transparent);
}
.cover-tile h3 { margin: 0; font-size: 1.45rem; line-height: .98; letter-spacing: -.03em; }
.cover-tile p { margin: .5rem 0 0; font-size: .78rem; color: var(--color-muted); }
.cover-tile .tile-art { align-self: end; display: flex; align-items: end; }
.cover-tile img { max-height: 10.5rem; object-fit: contain; object-position: bottom; }
.cover-tile .tile-dark { display: none; }
[data-theme="dark"] .cover-tile .tile-light { display: none; }
[data-theme="dark"] .cover-tile .tile-dark { display: block; }

/* TOC */
.toc {
  margin: var(--section-gap) auto 0; padding: 1.1rem 0;
  border-block: 1px solid var(--color-line);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .25rem 1.4rem;
}
.toc a { padding: .28rem 0; color: var(--color-muted); text-decoration: none; font-size: .95rem; display: flex; gap: .55rem; }
.toc a span { color: var(--color-brand); font-variant-numeric: tabular-nums; font-weight: 700; min-width: 1.6rem; }
.toc a:hover { color: var(--color-brand); }

/* Sections */
.section { margin-top: var(--section-gap); scroll-margin-top: 1.2rem; }
.section-head { max-width: var(--reading); }
.section-head h2 {
  display: flex; align-items: center; gap: .55rem; margin: 0;
  font-size: var(--type-h2-size); line-height: var(--type-h2-leading);
  letter-spacing: var(--type-h2-tracking); font-weight: var(--type-h2-weight); text-wrap: balance;
}
.section-head h2 img { width: clamp(2.1rem, 4.4vw, 2.9rem); height: auto; flex: 0 0 auto; }
.section-head .lede { margin: .8rem 0 0; color: var(--color-muted); font-size: var(--type-lede-size); line-height: var(--type-lede-leading); max-width: 60ch; }
.section > p, .section > ul, .section > ol, .section > .table-wrap, .section > .terminal, .section > .note, .section > .figure { margin-top: var(--block-gap); }
.section h3 { margin: 2.2rem 0 .55rem; font-size: var(--type-h3-size); line-height: var(--type-h3-leading); font-weight: var(--type-h3-weight); letter-spacing: var(--type-h3-tracking); }
.section p { max-width: var(--reading); }
.section p + p { margin-top: 1rem; }
p, li, td, th, .note, .card p { overflow-wrap: break-word; }
code { overflow-wrap: anywhere; }
.section ul, .section ol { max-width: var(--reading); padding-left: 1.35rem; }
.section li { margin: .35rem 0; }
.section li::marker { color: var(--color-brand); font-weight: 700; }

/* Figures and evidence */
.figure { margin: var(--block-gap) 0 0; max-width: 100%; }
.figure img { display: block; width: 100%; border-radius: var(--radius-small); border: 1px solid var(--color-line); background: var(--color-surface); }
.figure figcaption { margin-top: .55rem; color: var(--color-muted); font-size: .86rem; display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: baseline; }
.figure figcaption strong { color: var(--color-ink); }
.figure .source { font-size: .86rem; }

/* Inline character moments */
.figure-inline {
  display: grid; grid-template-columns: 1fr 9rem; gap: 1rem; align-items: end;
  margin-top: var(--block-gap); max-width: var(--reading);
}
.figure-inline p { margin: 0; }
.figure-inline img { max-height: 12rem; object-fit: contain; justify-self: center; }
.result-note {
  display: grid; grid-template-columns: 1fr 8.5rem; gap: 1rem; align-items: center;
  margin-top: var(--block-gap); padding: 1.1rem 1.25rem; max-width: var(--reading);
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius-small);
}
.result-note p { margin: 0; }
.result-note img { max-height: 9.5rem; object-fit: contain; justify-self: center; }
.result-note .dark-art { display: none; }
[data-theme="dark"] .result-note .light-art { display: none; }
[data-theme="dark"] .result-note .dark-art { display: block; }

/* Notes */
.brand-note {
  position: relative; margin: var(--block-gap) 0 0; padding: 1.15rem 1.25rem 1.15rem 1.45rem;
  background: var(--color-soft); border-radius: 0 var(--radius-small) var(--radius-small) 0;
  border-left: 4px solid var(--color-brand); max-width: var(--reading);
}
.brand-note p { margin: 0; }
.brand-note p + p { margin-top: .55rem; }
.brand-note .note-label {
  display: block; margin-bottom: .35rem; color: var(--color-brand);
  font-size: .78rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase;
}
.brand-note.with-icon { display: grid; grid-template-columns: 2.1rem 1fr; gap: .8rem; align-items: start; }
.brand-note.with-icon img { width: 2.1rem; margin-top: .1rem; }
.note { max-width: var(--reading); color: var(--color-muted); font-size: .95rem; }
.note strong { color: var(--color-ink); }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; margin-top: var(--block-gap); }
.card {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius-small); padding: 1.15rem;
}
.card h3 { margin: 0 0 .4rem; font-size: 1.12rem; line-height: 1.2; }
.card p { margin: 0; color: var(--color-muted); font-size: .95rem; max-width: none; }
.card .icon { width: 2.2rem; margin-bottom: .7rem; }
.card ul { margin: .5rem 0 0; padding-left: 1.1rem; font-size: .92rem; color: var(--color-muted); }

/* Metrics */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1rem; margin-top: var(--block-gap); }
.metric { padding: 1.1rem 0; border-top: 2px solid var(--color-brand); }
.metric strong { display: block; font-size: clamp(2rem, 4vw, 3rem); line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.metric span { display: block; margin-top: .35rem; color: var(--color-muted); font-size: .86rem; }

/* Steps */
.steps { list-style: none; padding: 0; margin: var(--block-gap) 0 0; max-width: var(--reading); counter-reset: step; }
.steps li { position: relative; padding: 0 0 1.4rem 2.7rem; counter-increment: step; }
.steps li::before {
  content: counter(step, decimal-leading-zero); position: absolute; left: 0; top: .05rem;
  width: 1.9rem; height: 1.9rem; display: grid; place-items: center;
  border-radius: 50%; background: var(--color-soft); color: var(--color-brand);
  font-size: .74rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.steps li:not(:last-child)::after {
  content: ""; position: absolute; left: .95rem; top: 2.1rem; bottom: .1rem; width: 1px; background: var(--color-line);
}
.steps strong { display: block; margin-bottom: .2rem; }
.steps p { margin: 0; color: var(--color-muted); }

/* Terminal */
.terminal {
  position: relative; margin-top: var(--block-gap);
  border: 1px solid var(--color-line); border-radius: var(--radius-small);
  background: #1c2326; color: #e8eee6; overflow: hidden; box-shadow: var(--shadow);
}
[data-theme="dark"] .terminal { background: #111617; }
.terminal-head {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  padding: .55rem .8rem; border-bottom: 1px solid rgba(255,255,255,.12);
  color: #b9c5bd; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase;
}
.terminal-head button {
  border: 1px solid rgba(255,255,255,.22); background: transparent; color: #dfe8e1;
  border-radius: .3rem; padding: .25rem .55rem; font-size: .76rem; letter-spacing: 0; text-transform: none;
}
.terminal-head button:hover { border-color: #a9c5a4; color: #fff; }
.terminal pre { margin: 0; padding: .9rem 1rem 1.1rem; overflow-x: auto; font-size: var(--type-code-size); line-height: 1.6; }
.terminal code { color: inherit; }
.terminal .comment { color: #9fb3a5; }
.terminal .prompt { color: #a9c5a4; }
.terminal .ok { color: #b7e4b0; }

/* Tables */
.table-wrap { overflow-x: auto; margin-top: var(--block-gap); border: 1px solid var(--color-line); border-radius: var(--radius-small); background: var(--color-surface); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
caption { caption-side: top; text-align: left; padding: .75rem .9rem .2rem; color: var(--color-muted); font-size: .86rem; }
th, td { text-align: left; padding: .62rem .75rem; border-bottom: 1px solid var(--color-line); vertical-align: top; }
th { color: var(--color-brand); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td code { font-size: .86em; }
.table-wrap .empty { color: var(--color-muted); font-style: italic; }

/* UI mockup */
.ui-mock {
  margin-top: var(--block-gap); border: 1px solid var(--color-line); border-radius: var(--radius-small);
  background: var(--color-surface); overflow: hidden; box-shadow: var(--shadow);
}
.ui-mock-bar { display: flex; align-items: center; gap: .45rem; padding: .55rem .75rem; border-bottom: 1px solid var(--color-line); background: var(--color-soft); }
.ui-mock-bar i { width: .55rem; height: .55rem; border-radius: 50%; background: var(--color-line); display: block; }
.ui-mock-bar span { margin-left: .35rem; color: var(--color-muted); font-size: .78rem; }
.ui-mock-body { display: grid; grid-template-columns: 11rem 1fr; min-height: 16rem; }
.ui-mock-side { border-right: 1px solid var(--color-line); padding: .85rem; font-size: .82rem; color: var(--color-muted); }
.ui-mock-side b { display: block; color: var(--color-ink); margin: .6rem 0 .3rem; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
.ui-mock-side .active { color: var(--color-brand); font-weight: 700; }
.ui-mock-main { padding: 1rem; }
.ui-mock-main h4 { margin: 0 0 .7rem; font-size: 1rem; }
.model-row { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .6rem .7rem; border: 1px solid var(--color-line); border-radius: .45rem; margin-bottom: .45rem; font-size: .88rem; }
.model-row.selected { border-color: var(--color-brand); background: var(--color-soft); }
.model-row small { color: var(--color-muted); }
.badge { display: inline-block; border-radius: 999px; padding: .12rem .5rem; background: var(--color-soft); color: var(--color-brand); font-size: .72rem; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }

/* Field list */
.field-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .55rem 1rem; margin-top: var(--block-gap); padding: 0; list-style: none; max-width: none; }
.field-list li { background: var(--color-surface); border: 1px solid var(--color-line); border-radius: .5rem; padding: .65rem .75rem; font-size: .9rem; }
.field-list code { color: var(--color-brand); font-weight: 650; }

/* Details */
details { border-bottom: 1px solid var(--color-line); padding: .75rem 0; max-width: var(--reading); }
summary { color: var(--color-brand); cursor: pointer; font-weight: 650; }
details > *:not(summary) { margin-top: .6rem; }

/* Footer */
.footer {
  margin-top: var(--section-gap); padding: 1.5rem var(--gutter) 2.4rem;
  border-top: 1px solid var(--color-line); color: var(--color-muted);
}
.footer-inner { max-width: var(--page); margin-inline: auto; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; align-items: center; }
.footer .byline img { width: 2.4rem; height: 2.4rem; }
.footer p { margin: 0; font-size: .86rem; }

/* Responsive */
@media (max-width: 62rem) {
  .cover { grid-template-columns: 1fr; min-height: 0; }
  .cover-copy { padding: 2.2rem 1.4rem 0; }
  .cover-art { width: min(58%, 20rem); margin: .3rem .4rem 0 auto; }
  .cover-art img { height: min(62vw, 24rem); }
  .ui-mock-body { grid-template-columns: 1fr; }
  .ui-mock-side { border-right: 0; border-bottom: 1px solid var(--color-line); display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
  .ui-mock-side b { display: inline; margin: 0; }
}
@media (max-width: 42rem) {
  .masthead { padding-inline: 1.15rem; }
  .cover h1 { font-size: clamp(3rem, 13vw, 4.4rem); }
  .cover-copy { padding: 1.8rem 1.15rem 0; }
  .cover-art { width: min(64%, 17rem); }
  .cover-actions .button { width: 100%; justify-content: center; }
  .toc { grid-template-columns: 1fr 1fr; }
  .tile-row { display: block; }
  .cover-tile { width: 100%; margin-top: .8rem; }
  .section-head h2 { align-items: flex-start; }
  .section-head h2 img { width: 1.9rem; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .figure-inline, .result-note { grid-template-columns: 1fr 6rem; }
  .footer-inner { display: block; }
}
@media (max-width: 26rem) {
  .masthead { padding-inline: .9rem; gap: .5rem; }
  .byline { font-size: .86rem; gap: .45rem; }
  .byline img { width: 1.8rem; height: 1.8rem; }
  .theme-toggle { font-size: .78rem; padding: .35rem .55rem; }
}

@media print {
  :root { --color-bg: #fff; --color-surface: #fff; --color-ink: #111; --color-muted: #444; --color-line: #bbb; --color-soft: #f0f0ea; }
  .theme-toggle, .terminal-head button, .button, .skip-link { display: none; }
  .cover { min-height: 0; box-shadow: none; }
  .section { break-inside: auto; page-break-inside: auto; }
  a { color: #111; }
}
