:root {
  --bg: #f7f5f2;
  --bg2: #efebe6;
  --card: #ffffff;
  --fg: #1c1917;
  --muted: #6b635c;
  --line: #e3ddd6;
  --red: #c0262d;
  --red-soft: rgba(192, 38, 45, .14);
  --green: #1f8a4c;
  --green-soft: rgba(31, 138, 76, .14);
  --accent: #b45309;
  --link: #9a3412;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --bg2: #1a1917;
    --card: #1e1c1a;
    --fg: #ece8e3;
    --muted: #a39b93;
    --line: #34302c;
    --red: #f0565c;
    --red-soft: rgba(240, 86, 92, .16);
    --green: #3fbf74;
    --green-soft: rgba(63, 191, 116, .14);
    --accent: #f59e0b;
    --link: #fb923c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--link); }
img, svg { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); margin: 0 0 .4em; }
h2 { font-size: clamp(1.4rem, 3.6vw, 1.9rem); margin: 2.2em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1.4em 0 .3em; }
p, li { max-width: 68ch; }
small, .muted { color: var(--muted); }
strong.red, .red { color: var(--red); }
.green { color: var(--green); }
hr { border: 0; border-top: 1px solid var(--line); margin: 3em 0; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 10; }
.top .wrap { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 800; text-decoration: none; color: var(--fg); letter-spacing: -0.02em; white-space: nowrap; }
.brand span { color: var(--red); }
.nav { display: flex; gap: 4px 14px; flex-wrap: wrap; font-size: .95rem; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 4px 0; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--fg); }
.nav a[aria-current="page"] { border-bottom: 2px solid var(--red); }
@media (max-width: 640px) {
  .top { position: static; }
  .nav { margin-left: 0; width: 100%; padding-bottom: 8px; }
}

/* hero */
.hero { padding: 56px 0 24px; }
.hero .kicker { color: var(--red); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.hero p.lead { font-size: 1.2rem; color: var(--muted); }
.quote {
  border-left: 4px solid var(--red);
  padding: 8px 0 8px 18px;
  margin: 28px 0;
  font-size: 1.25rem;
  font-weight: 600;
  max-width: 60ch;
}
.quote small { display: block; font-weight: 400; margin-top: 6px; font-size: .9rem; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin: 24px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 2rem; line-height: 1.1; color: var(--red); font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 6px; font-size: .95rem; }
.stat small { display: block; margin-top: 6px; font-size: .8rem; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 18px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
a.card { text-decoration: none; color: var(--fg); display: block; transition: border-color .15s; }
a.card:hover { border-color: var(--red); }
.card h3 { margin-top: 0; }
.card p { margin: .4em 0 0; color: var(--muted); font-size: .95rem; }

/* tools */
.tool { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 20px 0; box-shadow: var(--shadow); }
.tool h3 { margin-top: 0; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; margin: 12px 0 16px; }
.controls label { display: flex; flex-direction: column; font-size: .82rem; color: var(--muted); gap: 4px; }
.controls input, .controls select {
  font: inherit; font-size: 1rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
.controls input[type="range"] { padding: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.seg button {
  font: inherit; font-size: .9rem; border: 1px solid var(--line); background: var(--bg);
  color: var(--fg); border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  background: var(--red); color: #fff;
}
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }

.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; margin-top: 14px; }
.readout div { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.readout small { display: block; font-size: .78rem; }
.readout b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--red-soft); font-weight: 600; }

.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis { stroke: var(--line); }
.chart .zero { stroke: var(--muted); stroke-width: 1; }
.chart .profit { fill: var(--green-soft); }
.chart .loss { fill: var(--red-soft); }
.chart .line { fill: none; stroke: var(--fg); stroke-width: 2; }
.chart .t0 { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .spot { stroke: var(--accent); stroke-dasharray: 2 3; }
.chart .pdf { fill: var(--muted); opacity: .12; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .tip { fill: var(--fg); font-weight: 600; font-size: 12px; }
.chart .path { fill: none; stroke-width: 1; opacity: .35; }
.chart .path.up { stroke: var(--green); }
.chart .path.down { stroke: var(--red); }
.chart .path.hl { stroke-width: 2.2; opacity: 1; stroke: var(--fg); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: .95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }

/* bias list */
.bias { border-top: 1px solid var(--line); padding: 18px 0; }
.bias h3 { margin: 0 0 4px; }
.bias .how { margin: 6px 0; }
.bias .fix { color: var(--green); font-weight: 500; }

.note { font-size: .85rem; color: var(--muted); }
.callout { background: var(--bg2); border-radius: 12px; padding: 16px 18px; margin: 20px 0; }
.callout.red { background: var(--red-soft); color: var(--fg); }

ol.steps { padding-left: 1.2em; }
ol.steps li { margin: .6em 0; }

/* footer */
.foot { border-top: 1px solid var(--line); margin-top: 64px; padding: 28px 0 40px; font-size: .88rem; color: var(--muted); }
.foot p { max-width: 80ch; }

/* follow button */
.follow {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: .85rem; font-weight: 600; text-decoration: none;
  color: var(--bg); background: var(--fg); border-radius: 999px; padding: 5px 12px;
}
.follow svg { width: 13px; height: 13px; fill: currentColor; }
@media (max-width: 640px) { .follow { margin-left: auto; order: 2; } .nav { order: 3; } }

/* diary quotes from @trading_horror */
.diary { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 18px 0; }
.tweet {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow); margin: 0; display: flex; flex-direction: column; gap: 8px;
}
.tweet p { margin: 0; font-size: .98rem; }
.tweet footer { font-size: .8rem; color: var(--muted); margin-top: auto; }
.tweet footer a { color: var(--muted); }
.tweet.big { grid-column: 1 / -1; }
.tweet.big p { font-size: 1.15rem; font-weight: 600; }
.follow-band {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg2); border-radius: 14px; padding: 18px 20px; margin: 28px 0;
}
.follow-band p { margin: 0; max-width: 60ch; }

/* dropdown menus in the header */
.nav { align-items: center; }
.dd { position: relative; }
.dd summary {
  list-style: none; cursor: pointer; color: var(--muted); padding: 4px 0; user-select: none;
  display: inline-flex; align-items: center; gap: 4px;
}
.dd summary::-webkit-details-marker { display: none; }
.dd summary::after { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.dd[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.dd summary:hover, .dd[open] summary { color: var(--fg); }
.dd summary.on { color: var(--fg); border-bottom: 2px solid var(--red); }
.dd-menu {
  position: absolute; top: calc(100% + 8px); left: -12px; z-index: 20; min-width: 240px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14); display: flex; flex-direction: column;
}
.nav .dd-menu a { color: var(--fg); padding: 9px 12px; border-radius: 8px; border-bottom: 0; white-space: nowrap; }
.nav .dd-menu a:hover { background: var(--bg2); }
.nav .dd-menu a[aria-current="page"] { background: var(--bg2); font-weight: 600; border-bottom: 0; }
@media (max-width: 640px) {
  .nav { gap: 4px 18px; }
  .dd:last-of-type .dd-menu { left: auto; right: -40px; }
}
.jump { font-size: .9rem; color: var(--muted); margin: 8px 0 0; }
h2[id] { scroll-margin-top: 72px; }

/* wiki-style linking */
[id] { scroll-margin-top: 76px; }
main p a, main li a, .gloss dd a { text-underline-offset: 2px; text-decoration-thickness: 1px; }
:target { animation: target-flash 2.4s ease-out; }
@keyframes target-flash { 0%, 30% { background: var(--red-soft); } 100% { background: transparent; } }
.seealso { border-top: 1px solid var(--line); margin: 36px 0 0; padding-top: 4px; }
.seealso h2 { font-size: 1.15rem; margin: 16px 0 8px; }
.seealso ul { margin: 0; padding-left: 1.2em; columns: 2 240px; column-gap: 32px; }
.seealso li { margin: .3em 0; break-inside: avoid; }
.toc { line-height: 1.9; }
.letters a { display: inline-block; min-width: 1.8em; text-align: center; padding: 2px 0; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; margin: 2px 1px; }
.gloss { margin: 0; }
.gloss dt { font-weight: 700; margin-top: 18px; font-size: 1.05rem; border-radius: 6px; }
.gloss dd { margin: 4px 0 0; color: var(--fg); max-width: 72ch; }
.myth h3 { font-style: italic; }

/* figures */
.fig { margin: 22px 0; }
.fig svg { width: 100%; height: auto; display: block; }
.fig figcaption { font-size: .85rem; color: var(--muted); margin-top: 8px; }
.fig .f-red { fill: var(--red); }
.fig .f-green { fill: var(--green); }
.fig .f-muted { fill: var(--muted); opacity: .35; }
.fig .f-track { fill: var(--bg2); }
.fig .f-card { fill: var(--card); stroke: var(--line); }
.fig .s-line { stroke: var(--line); fill: none; }
.fig .s-fg { stroke: var(--fg); fill: none; }
.fig .s-red { stroke: var(--red); fill: none; }
.fig text { fill: var(--fg); font-family: inherit; font-size: 17px; }
.fig text.m { fill: var(--muted); font-size: 15px; }
.fig text.b { font-weight: 700; }
.fig text.big { font-size: 28px; font-weight: 800; }
.fig text.red { fill: var(--red); }
.fig text.green { fill: var(--green); }
.fig text.on { fill: #fff; }

/* four menus: keep one row on phones */
.nav { position: relative; }
@media (max-width: 640px) {
  .nav .home { display: none; }
  .nav { gap: 4px 16px; }
  .dd { position: static; }
  .dd-menu, .dd:last-of-type .dd-menu { left: 0; right: 0; min-width: 0; }
  .nav .dd-menu a { white-space: normal; }
}

/* quitting tools */
.crisis { background: var(--red-soft); border-radius: 10px; padding: 10px 14px; margin: 14px 0; font-size: .95rem; }
.crisis a { margin-left: 8px; font-weight: 600; white-space: nowrap; }
.quitbar { background: var(--bg2); border-left: 4px solid var(--green); border-radius: 8px; padding: 12px 16px; margin: 32px 0 0; font-size: .95rem; line-height: 1.8; }
.cards.tools .card { border-left: 4px solid var(--green); }
.quiz ol { padding-left: 1.4em; }
.quiz li { margin: 0 0 14px; }
.quiz li p { margin: 0 0 6px; }
.yn { display: inline-flex; gap: 8px; }
.yn label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; cursor: pointer; background: var(--card); }
.yn label:has(input:checked) { border-color: var(--fg); font-weight: 600; }
.yn input { accent-color: var(--red); margin: 0; }
.result { border-radius: 14px; padding: 4px 20px 12px; margin: 24px 0; background: var(--bg2); border-left: 5px solid var(--muted); }
.result.high { border-left-color: var(--red); }
.result.mid { border-left-color: var(--accent); }
.result.low { border-left-color: var(--green); }
.result h2 { margin-top: .8em; }
.urge-timer { text-align: center; }
.clock { font-size: clamp(3.5rem, 16vw, 6rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; line-height: 1.1; margin: 8px 0 14px; }
.clock.small { font-size: 2.6rem; margin: 6px 0; }
.clock.done { color: var(--green); }
label.block { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
textarea { font: inherit; width: 100%; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: vertical; }
cite { font-style: italic; }

/* comments */
.comments { border-top: 1px solid var(--line); margin-top: 40px; padding-top: 4px; }
.c-intro { color: var(--muted); }
.c-form { display: grid; gap: 6px; max-width: 680px; }
.c-form label { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.c-form input, .c-form textarea { font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; }
.c-form textarea { resize: vertical; min-height: 110px; }
.c-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.c-trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.c-msg:empty { display: none; }
.c-msg { border-radius: 10px; padding: 10px 14px; margin-top: 8px; font-size: .95rem; }
.c-msg.good { background: var(--green-soft); }
.c-msg.bad { background: var(--red-soft); }
.c-crisis { margin: 8px 0 0; }
.c-rules { margin: 14px 0; font-size: .9rem; color: var(--muted); max-width: 680px; }
.c-rules summary { cursor: pointer; }
.c-count { margin-top: 28px; }
.c-list { list-style: none; padding: 0; margin: 0; }
.c-item { border-top: 1px solid var(--line); padding: 14px 0; }
.c-item.mine { background: var(--green-soft); border-radius: 10px; padding: 14px; border-top: 0; }
.c-meta { font-size: .9rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px; }
.c-body { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch; }
.c-report { margin-left: auto; background: none; border: 0; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; }
.c-report:disabled { cursor: default; text-decoration: none; }

/* the diary timeline */
.timeline { list-style: none; padding: 0; margin: 20px 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 20px 22px; max-width: 72ch; }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); border: 2px solid var(--bg); }
.timeline li.vow::before { background: var(--green); }
.timeline li.loss::before { background: var(--red); }
.timeline li.urge::before { background: var(--accent); }
.timeline .when { font-size: .82rem; color: var(--muted); font-weight: 600; }
.timeline .tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; margin-left: 8px; background: var(--bg2); }
.timeline .vow .tag { background: var(--green-soft); color: var(--green); }
.timeline .loss .tag { background: var(--red-soft); color: var(--red); }
.timeline .urge .tag { color: var(--accent); }
.timeline blockquote { margin: 4px 0 0; font-size: 1.02rem; }
.timeline .after { font-size: .9rem; color: var(--muted); margin: 6px 0 0; }

/* videos */
.vids { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin: 18px 0 8px; }
.vid { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.vid-play, .vid-frame { position: relative; display: block; aspect-ratio: 16 / 9; background: #000; }
.vid-play img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vid-btn { position: absolute; inset: 0; margin: auto; width: 64px; height: 44px; border-radius: 12px; background: rgba(0,0,0,.72); color: #fff; display: grid; place-items: center; font-size: 1.2rem; }
.vid-play:hover .vid-btn, .vid-play:focus-visible .vid-btn { background: var(--red); }
.vid-ext .vid-btn { width: auto; padding: 0 12px; font-size: .85rem; font-weight: 700; }
.vid-len { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.8); color: #fff; font-size: .75rem; padding: 1px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.vid-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.vid-body { padding: 14px 16px 16px; }
.vid-body h3 { margin: 0 0 4px; font-size: 1rem; line-height: 1.35; }
.vid-meta { font-size: .82rem; color: var(--muted); margin: 0 0 8px; }
.vid-body p { margin: .35em 0 0; font-size: .94rem; }
p.watch { margin: 12px 0; font-size: .95rem; }
p.watch::before { content: "▶"; color: var(--red); margin-right: 6px; font-size: .8em; }
