/* The Outer Box tools — styles. Copyright Pkale S. Robinson. */
:root {
  --bg: #fbfaf7; --surface: #ffffff; --ink: #1d1d1f; --muted: #62646a; --line: #dedcd6;
  --accent: #8a3a28; --accent-ink: #ffffff; --soft: #f3efe8;
  --bull: #2f6b3a; --bull-soft: #e5f0e6; --bear: #8a3a28; --bear-soft: #f6e6e1;
  --ok: #2f6b3a; --ok-soft: #e5f0e6; --err: #9b2c1f; --err-soft: #fbe7e3;
  --band: rgba(138, 58, 40, 0.08); --price: #1f4f8a;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --surface: #1c1c1f; --ink: #ececec; --muted: #a2a3a8; --line: #34343a;
    --accent: #e08a6d; --accent-ink: #141416; --soft: #232327;
    --bull: #7cc58a; --bull-soft: #1f2d22; --bear: #e08a6d; --bear-soft: #33221d;
    --ok: #7cc58a; --ok-soft: #1f2d22; --err: #f09a88; --err-soft: #3a211c;
    --band: rgba(224, 138, 109, 0.10); --price: #7fb0f0;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 1.9rem; margin: 0 0 6px; }
h2 { font-size: 1.3rem; margin: 32px 0 12px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Header and footer */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand span { color: var(--accent); font-weight: 400; font-style: italic; }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav a, .nav .link { color: var(--ink); text-decoration: none; font-size: 0.95rem; }
.nav a:hover, .nav .link:hover { color: var(--accent); }
main.wrap { padding-top: 32px; padding-bottom: 48px; min-height: 60vh; }
.foot { color: var(--muted); font-size: 0.85rem; padding-top: 16px; padding-bottom: 32px; border-top: 1px solid var(--line); }
.foot a { color: var(--muted); }

/* Forms */
.narrow { max-width: 440px; margin: 24px auto; }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 0.92rem; }
.lbl .small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { font-family: var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn {
  display: inline-block; font: 600 0.95rem var(--sans); background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent); border-radius: 6px; padding: 10px 18px; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--err); }
.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.grow { flex: 1 1 260px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.hint { margin: -4px 0 0; min-height: 1.2em; font-size: 0.88rem; color: var(--muted); }
.hint.warn { color: var(--err); }

/* Messages */
.flash { border-radius: 6px; padding: 12px 14px; margin: 0 0 20px; border: 1px solid transparent; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-ok { background: var(--ok-soft); border-color: var(--ok); }
.flash-error { background: var(--err-soft); border-color: var(--err); }
.flash .copy { margin-top: 8px; font-family: var(--mono); font-size: 0.85rem; }

/* Cards, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.crumb { margin: 0 0 6px; font-size: 0.9rem; }
.table-wrap { overflow-x: auto; margin-top: 16px; }
table { border-collapse: collapse; width: 100%; }
.list th, .list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.list .num { text-align: right; }
.list a { text-decoration: none; }
.clip { max-width: 34ch; }
.tag { display: inline-block; font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.code { font-family: var(--mono); letter-spacing: 0.08em; }
.empty-state { text-align: center; padding: 40px 20px; }
.row-actions { white-space: nowrap; }
.row-actions form + form { margin-left: 12px; }
.code-block { display: flex; gap: 24px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.big-code { font-family: var(--mono); font-size: 1.9rem; letter-spacing: 0.14em; font-weight: 700; }
.copy { font-family: var(--mono); font-size: 0.88rem; }

/* Ladder page */
.ladder-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.ladder-head p { margin: 0; }
.mode { display: inline-flex; border: 1px solid var(--accent); border-radius: 6px; overflow: hidden; }
.mode-btn { font: 600 0.9rem var(--sans); background: transparent; color: var(--accent); border: 0; padding: 8px 16px; cursor: pointer; }
.mode-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.ladder-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
.results { padding: 16px 20px 12px; }

.position { display: flex; gap: 16px; align-items: center; padding: 12px 14px; border-radius: 6px; margin-bottom: 14px; background: var(--soft); border-left: 4px solid var(--muted); }
.position[data-bias="bull"] { background: var(--bull-soft); border-left-color: var(--bull); }
.position[data-bias="bear"] { background: var(--bear-soft); border-left-color: var(--bear); }
.pos-pct { flex: 0 0 auto; font-family: var(--serif); font-size: 1.7rem; font-weight: 700; line-height: 1; text-align: center; min-width: 5.2ch; font-variant-numeric: tabular-nums; }
.pos-pct small { display: block; font: 400 0.7rem var(--sans); color: var(--muted); margin-top: 4px; }
.pos-zone { font-weight: 700; }
.pos-text { font-size: 0.92rem; color: var(--muted); }

.ladder-body { display: grid; grid-template-columns: 1fr 112px; gap: 18px; }
.levels th, .levels td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.levels thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.levels thead th.num { text-align: right; }
.levels tbody th { font-weight: 400; }
.levels .num { text-align: right; }
.lvl-name { display: inline-block; min-width: 3.4em; font-weight: 700; }
.lvl-note { display: block; font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.levels .kind-edge .lvl-name { color: var(--accent); }
.levels .kind-center td:nth-child(2) { font-weight: 700; }
.levels .empty td { color: var(--muted); text-align: center; padding: 28px 8px; }
.price-row th, .price-row td { color: var(--price); font-weight: 700; background: color-mix(in srgb, var(--price) 8%, transparent); }
.adv { display: none; }
.mode-advanced .adv { display: table-row; }

.scale { position: relative; min-height: 380px; border-left: 2px solid var(--line); margin: 6px 0 6px 6px; }
.scale .band { position: absolute; left: 0; right: 0; background: var(--band); }
.scale .tick, .scale .marker { position: absolute; left: -2px; right: 0; height: 0; border-top: 1px solid var(--muted); }
.scale .tick span, .scale .marker span { position: absolute; left: 8px; top: -0.72em; font-size: 0.78rem; background: var(--surface); padding: 0 4px; line-height: 1.4; }
.scale .tick.kind-edge { border-top: 2px solid var(--accent); }
.scale .tick.kind-edge span { color: var(--accent); font-weight: 700; }
.scale .tick.kind-center { border-top-style: dashed; }
.scale .tick.kind-inner, .scale .tick.kind-outer { border-top-style: dotted; }
.scale .marker { border-top: 2px solid var(--price); }
.scale .marker span { left: auto; right: 0; color: var(--price); font-weight: 700; }
.delete-form { margin-top: 20px; }

@media (max-width: 820px) {
  .ladder-grid { grid-template-columns: 1fr; }
  .ladder-body { grid-template-columns: 1fr 84px; gap: 10px; }
  .lvl-note { display: none; }
}
@media (max-width: 480px) {
  .row2 { grid-template-columns: 1fr; }
  .ladder-body { grid-template-columns: 1fr; }
  .scale { display: none; }
  h1 { font-size: 1.6rem; }
}

/* ---- Book and lessons ---------------------------------------------------- */
.book-cover { max-width: 680px; margin: 8px auto 36px; }
.book-cover .rule { height: 2px; width: 56px; background: var(--accent); margin: 0 0 22px; }
.book-title { font-size: 2.6rem; margin: 0 0 6px; }
.book-sub { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 1.15rem; margin: 0 0 6px; }
.book-note { margin: 18px 0; }
.toc { max-width: 680px; margin: 0 auto; }
.toc-list { list-style: none; margin: 0 0 8px; padding: 0; }
.toc-list li { display: flex; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.toc-list a { color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 1.08rem; flex: 1; }
.toc-list a:hover { color: var(--accent); }
.toc-num { min-width: 1.8em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-part { font-size: 1rem; margin: 30px 0 4px; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.toc-part span { color: var(--accent); margin-right: 6px; }
.toc-back { margin-top: 30px; }
.lock { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }

.reader { max-width: 720px; margin: 0 auto; }
.reader-head { margin: 4px 0 28px; }
.reader-label { color: var(--accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; margin-bottom: 6px; }
.reader-head h1 { font-size: 2.2rem; }
.prose { font-family: var(--serif); font-size: 1.12rem; line-height: 1.7; }
.prose p { margin: 0 0 1.05em; }
.prose h2 { font-size: 1.45rem; margin: 2em 0 0.6em; }
.prose h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; font-family: var(--serif); }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.prose li { margin: 0.3em 0; }
.prose strong { font-weight: 700; }
.prose a { text-underline-offset: 2px; }
.prose figure { margin: 1.8em 0; }
.prose img { max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: 6px; background: #fff; }
.prose figcaption { font-family: var(--sans); font-size: 0.86rem; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.prose table { font-family: var(--sans); font-size: 0.92rem; margin: 1.4em 0; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.prose thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.prose code { font-family: var(--mono); font-size: 0.9em; }
.prose blockquote { margin: 1.8em 0; padding: 16px 20px; background: var(--soft); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; font-size: 1.02rem; }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose .aside-label { font-family: var(--sans); font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 8px; }
.prose .footnote-ref { font-family: var(--sans); font-size: 0.72em; text-decoration: none; padding: 0 1px; }
.prose .footnotes { margin-top: 3em; padding-top: 1em; border-top: 1px solid var(--line); font-family: var(--sans); font-size: 0.86rem; color: var(--muted); line-height: 1.55; }
.prose .footnotes hr { display: none; }
.prose .footnotes a { word-break: break-word; }
.prose-locked { position: relative; max-height: 22em; overflow: hidden; }
.prose-locked::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 9em; background: linear-gradient(to bottom, transparent, var(--bg)); }
.paywall { text-align: center; margin: 8px 0 28px; }
.paywall h2 { margin-top: 0; }
.paywall .actions { justify-content: center; }
.pager { display: flex; justify-content: space-between; gap: 16px; margin: 40px 0 8px; padding-top: 20px; border-top: 1px solid var(--line); }
.pager a { text-decoration: none; color: var(--ink); max-width: 48%; font-family: var(--serif); }
.pager a span { display: block; font-family: var(--sans); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 2px; }
.pager-next { text-align: right; margin-left: auto; }
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; }
.lesson-list h2 { margin: 6px 0 6px; }
.lesson-list h2 a { color: var(--ink); text-decoration: none; }
.lesson-list p { margin: 0; color: var(--muted); }
.lvl-ch { font-size: 0.78rem; white-space: nowrap; }
@media (max-width: 480px) {
  .book-title { font-size: 2rem; }
  .reader-head h1 { font-size: 1.7rem; }
  .prose { font-size: 1.05rem; }
}
.prose .align-right { text-align: right; }
.prose .align-center { text-align: center; }
.prose .align-left { text-align: left; }
