:root{
  --ivory:#f5efe2; --paper:#ece5d6; --paper-2:#ddd5c4; --paper-3:#c9c0ad;
  --ink:#2a2826; --ink-soft:#5d5952; --red:#c4473b; --green:#4a8858;
  /* darker shades for signed numbers set as text: >=5:1 on panel, receipt and ivory */
  --red-text:#ad3a30; --green-text:#3a7148; --sweat:#9fbfd6;
  --panel:#f8f3e8; --shadow:0 2px 0 var(--ink);
  /* paper stocks and state tints (DESIGN.md names them; the canvas draws its own) */
  --sheet:#fffdf7; --note:#fbf6e6; --receipt:#fbf8ef;
  --sell-tint:#f5d9d3; --buy-tint:#d9eadb; --pending-tint:#fff7dc; --live-tint:#e6f1e6;
  --hand:"Patrick Hand","Comic Sans MS","Segoe Print",cursive;
  --display:"Bowlby One","Arial Black",Impact,sans-serif;
  box-sizing:border-box;
  padding-top:env(safe-area-inset-top,0px); padding-bottom:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){ --ivory:#e9e2d3; --panel:#f1ebde; }
}
:root[data-theme="dark"]{ --ivory:#e9e2d3; --panel:#f1ebde; }
*,*::before,*::after{box-sizing:inherit}
html{height:100%; scroll-padding-top:env(safe-area-inset-top,0px)}
body{margin:0; height:100%; overflow:hidden; background:var(--ivory); color:var(--ink);
  font-family:var(--hand); font-size:19px; line-height:1.35; -webkit-tap-highlight-color:transparent; overscroll-behavior:none}
#world{position:fixed; inset:0; width:100%; height:100%; display:block; touch-action:none; cursor:grab; outline:none}
#world.dragging{cursor:grabbing}
#world.pointing{cursor:pointer}
button,a{font:inherit; color:inherit}
:focus-visible{outline:3px solid var(--ink); outline-offset:2px; border-radius:6px}

/* paper chip: the shared look for every control, slightly crooked like a cut-out */
.chip{display:inline-flex; align-items:center; gap:.35em; background:var(--panel); border:2.5px solid var(--ink);
  border-radius:12px 9px 13px 8px; padding:.28em .7em; box-shadow:var(--shadow); cursor:pointer; text-decoration:none;
  font-size:18px; line-height:1.1; white-space:nowrap; min-height:40px; transition:transform .12s}
.chip:hover{transform:translateY(-1px) rotate(-.6deg)}
.chip:active{transform:translateY(1px); box-shadow:0 1px 0 var(--ink)}
.chip[aria-pressed="true"]{background:var(--ink); color:var(--panel)}
.chip svg{width:20px; height:20px; flex:none}
.chip.icon{padding:.28em .5em; min-width:40px; justify-content:center}

/* wordmark */
#brand{position:fixed; left:calc(14px + env(safe-area-inset-left,0px)); top:calc(12px + env(safe-area-inset-top,0px)); z-index:5;
  display:flex; flex-direction:column; gap:4px; pointer-events:none}
#brand .mark{font-family:var(--display); font-size:34px; font-weight:400; line-height:.9; letter-spacing:.01em; position:relative; margin:0; padding:0 14px; align-self:flex-start}
#brand .mark::before,#brand .mark::after{content:""; position:absolute; top:6px; width:9px; height:18px;
  border-left:3px solid var(--ink); border-right:3px solid var(--ink); border-radius:2px}
#brand .mark::before{left:-2px; transform:skewX(22deg)} #brand .mark::after{right:-2px; transform:skewX(-22deg)}
#brand .tag{font-size:16px; color:var(--ink-soft); background:color-mix(in srgb,var(--ivory) 80%,transparent); border-radius:6px; padding:0 4px; align-self:flex-start}
#status{pointer-events:auto; align-self:flex-start; margin-top:4px; font-size:16px; min-height:34px; padding:.2em .6em}
#status .dot{width:9px; height:9px; border-radius:50%; background:var(--ink-soft); flex:none}
#status .dot.live{background:var(--green)} #status .dot.err{background:var(--red)}

/* controls */
#controls{position:fixed; right:calc(12px + env(safe-area-inset-right,0px)); top:calc(12px + env(safe-area-inset-top,0px)); z-index:6;
  display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; max-width:min(720px,calc(100vw - 260px))}
#zoom{position:fixed; right:calc(12px + env(safe-area-inset-right,0px)); bottom:calc(14px + env(safe-area-inset-bottom,0px)); z-index:6; display:flex; gap:6px}
.sr{position:absolute!important; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap}

/* hint */
#hint{position:fixed; left:50%; bottom:calc(26px + env(safe-area-inset-bottom,0px)); transform:translateX(-50%) rotate(-1deg); z-index:6;
  background:var(--ink); color:var(--panel); padding:.45em 1em; border-radius:14px 10px 15px 11px; font-size:21px; pointer-events:none;
  transition:opacity .4s, transform .4s}
#hint.gone{opacity:0; transform:translateX(-50%) translateY(12px)}

/* speech bubbles */
#bubbles{position:fixed; inset:0; pointer-events:none; z-index:4; overflow:hidden}
.bubble{position:absolute; left:0; top:0; max-width:250px; width:max-content; background:var(--sheet); border:2.5px solid var(--ink);
  border-radius:16px 13px 17px 12px; padding:.35em .7em; font-size:18px; line-height:1.25; box-shadow:var(--shadow);
  transform-origin:50% 100%; animation:pop .18s ease-out}
.bubble::after{content:""; position:absolute; left:var(--tail,50%); bottom:-11px; width:16px; height:16px; background:var(--sheet);
  border-right:2.5px solid var(--ink); border-bottom:2.5px solid var(--ink); transform:translateX(-50%) rotate(45deg) skew(8deg,8deg)}
.bubble.note{max-width:270px; background:var(--note)}
.bubble.note::after{background:var(--note)}
.bubble.out{opacity:0; transition:opacity .25s}
/* `scale`, not `transform`: the bubble's position lives in its transform, and the pop must not move it */
@keyframes pop{from{scale:.6; opacity:0}}

/* stamp */
#stamp{position:fixed; left:50%; top:42%; z-index:7; transform:translate(-50%,-50%) rotate(-8deg); pointer-events:none;
  border:4px solid var(--red); color:var(--red); font-family:var(--display); font-size:clamp(22px,4vw,38px); padding:.2em .6em;
  background:color-mix(in srgb,var(--panel) 85%,transparent); border-radius:10px; opacity:0; text-align:center; line-height:1.05}
#stamp small{display:block; font-family:var(--hand); font-size:.55em; color:var(--ink)}
#stamp.show{animation:stamp 3.2s ease-out forwards}
@keyframes stamp{0%{opacity:0; transform:translate(-50%,-50%) rotate(-8deg) scale(2.2)}10%{opacity:1; transform:translate(-50%,-50%) rotate(-8deg) scale(1)}80%{opacity:1}100%{opacity:0}}

/* panels: side sheet on desktop, bottom sheet on phones */
.scrim{position:fixed; inset:0; background:rgba(42,40,38,.18); z-index:8; opacity:0; pointer-events:none; transition:opacity .2s}
.scrim.on{opacity:1; pointer-events:auto}
.panel{position:fixed; z-index:9; top:calc(12px + env(safe-area-inset-top,0px)); right:12px; bottom:calc(12px + env(safe-area-inset-bottom,0px));
  width:min(440px,calc(100vw - 24px)); background:var(--panel); border:3px solid var(--ink); border-radius:18px 14px 20px 15px;
  box-shadow:0 4px 0 var(--ink); display:flex; flex-direction:column; transform:translateX(calc(100% + 30px)); transition:transform .28s cubic-bezier(.2,.9,.3,1.1); visibility:hidden}
.panel.open{transform:none; visibility:visible}
.panel header{display:flex; align-items:center; justify-content:space-between; gap:10px; padding:14px 16px 8px}
.panel h2{font-family:var(--display); font-size:24px; margin:0; font-weight:400; line-height:1.05}
.panel .body{overflow:auto; padding:4px 18px 18px; flex:1; overscroll-behavior:contain}
.panel .handle{display:none}
.panel h3{font-family:var(--display); font-weight:400; font-size:17px; margin:18px 0 6px}
.panel p{margin:.4em 0 .7em; max-width:62ch}
.panel ol{padding-left:1.3em; margin:.3em 0} .panel ol li{margin:.25em 0}
@media (max-width:700px){
  .panel{top:auto; left:0; right:0; bottom:0; width:100%; max-height:80vh; border-radius:20px 20px 0 0; border-bottom:none;
    transform:translateY(105%); padding-bottom:env(safe-area-inset-bottom,0px)}
  .panel .handle{display:block; width:52px; height:5px; border-radius:3px; background:var(--paper-3); margin:8px auto 0}
  #controls{top:auto; bottom:calc(10px + env(safe-area-inset-bottom,0px)); left:10px; right:10px; max-width:none; justify-content:center; gap:6px}
  #controls .chip{font-size:16px; min-height:40px; padding:.25em .55em}
  #controls .label-wide{display:none}
  #zoom{bottom:calc(128px + env(safe-area-inset-bottom,0px)); flex-direction:column}
  #zoom .zin,#zoom .zout{display:none}
  #hint{bottom:calc(132px + env(safe-area-inset-bottom,0px)); font-size:18px; left:calc(12px + env(safe-area-inset-left,0px)); right:auto;
    transform:rotate(-1deg); max-width:calc(100vw - 80px); text-align:left}
  #hint.gone{transform:translateY(12px) rotate(-1deg)}
  #brand .mark{font-size:28px}
}

/* activity */
.source{display:flex; gap:8px; align-items:flex-start; background:var(--pending-tint); border:2px dashed var(--ink); border-radius:10px; padding:.45em .7em; font-size:17px}
.source.live{background:var(--live-tint); border-style:solid}
.source.err{background:var(--sell-tint)} .source + .source{margin-top:8px}
.chip.small{min-height:32px; font-size:15px}
.statuscard{margin-top:12px; border:2.5px solid var(--ink); border-radius:12px; padding:.6em .8em; background:var(--sheet)}
.statuscard .state{font-family:var(--display); font-size:19px}
.meta{color:var(--ink-soft); font-size:16px}
.pill{display:inline-block; border:2px solid var(--ink); border-radius:999px; padding:0 .55em; font-size:15px; line-height:1.4; background:var(--panel)}
.pill.sell{background:var(--sell-tint)} .pill.buy{background:var(--buy-tint)} .pill.err{background:var(--sell-tint)}
.tabs{display:flex; gap:6px; margin:16px 0 8px}
.tabs button{border:2.5px solid var(--ink); background:var(--panel); border-radius:10px 8px 11px 7px; padding:.15em .7em; cursor:pointer; font-size:17px}
.tabs button[aria-selected="true"]{background:var(--ink); color:var(--panel)}
.feed{list-style:none; margin:0; padding:0}
.feed li{border-bottom:2px dotted var(--paper-3); padding:.55em 0}
.feed .top{display:flex; gap:8px; align-items:baseline; flex-wrap:wrap}
.feed .title{font-size:18px}
.feed details{margin-top:4px}
.feed summary{cursor:pointer; color:var(--ink-soft); font-size:16px; min-height:32px}
.panel .body a{padding-block:.3em} /* a taller target for inline links; inline padding does not move the text */
.feed details p{background:var(--sheet); border-left:3px solid var(--ink); margin:.3em 0; padding:.3em .6em; font-size:17px}
.empty{color:var(--ink-soft); padding:1em 0}
.addr{display:block; user-select:all; -webkit-user-select:all; font-family:ui-monospace,Menlo,Consolas,monospace; font-size:14px; word-break:break-all;
  background:var(--sheet); border:2px solid var(--ink); border-radius:8px; padding:.4em .6em; margin:.3em 0}
.row{display:flex; gap:8px; flex-wrap:wrap; align-items:center}
.poke{display:grid; gap:8px; grid-template-columns:1fr 1fr; margin-top:6px}
.poke button{justify-content:flex-start; white-space:normal; text-align:left; min-height:44px}
@media (max-width:420px){.poke{grid-template-columns:1fr}}
@media (prefers-reduced-motion: reduce){.chip,.panel,#hint,.bubble{transition:none!important; animation:none!important}}
:root.calm .bubble,:root.calm .panel,:root.calm #hint{transition:none!important; animation:none!important}

/* ---------- the receipt tape: his books at a glance, fed from the sell-station printer ---------- */
#tape{position:fixed; z-index:5; left:calc(14px + env(safe-area-inset-left,0px)); bottom:calc(14px + env(safe-area-inset-bottom,0px));
  max-width:calc(100vw - 200px); display:flex; align-items:stretch; padding:9px 6px 7px 12px;
  background:var(--receipt); border:2.5px solid var(--ink); border-top:none; border-radius:0 0 12px 9px; box-shadow:var(--shadow);
  transform:rotate(-.35deg); transform-origin:0 100%}
#tape::before{content:""; position:absolute; left:-2.5px; right:-2.5px; top:-8px; height:9px;
  background:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='9'%3E%3Cpath d='M-1 9.5L8 1.2 17 9.5' fill='%23fbf8ef' stroke='%232a2826' stroke-width='2.4' stroke-linejoin='round'/%3E%3C/svg%3E") repeat-x left bottom/16px 9px}
#tape .stamp-mode{align-self:center; flex:none; margin:0 10px 0 2px; font-family:var(--display); font-size:15px; line-height:1; letter-spacing:.04em;
  color:var(--red); border:2.5px solid var(--red); border-radius:6px 4px 7px 3px; padding:.28em .45em .2em; transform:rotate(-7deg)}
#tape .stub{display:flex; flex-direction:column; justify-content:center; align-items:flex-start; gap:1px; min-height:44px; padding:0 12px; margin:0;
  background:none; border:none; border-left:2px dashed var(--paper-3); border-radius:0; text-align:left; cursor:pointer; color:var(--ink)}
#tape .stub .k{font-size:14px; line-height:1; color:var(--ink-soft)}
#tape .stub .v{font-size:19px; line-height:1.15; white-space:nowrap; font-variant-numeric:tabular-nums}
#tape .stub.pos .v{color:var(--green-text)} #tape .stub.neg .v{color:var(--red-text)}
#tape .stub.last{min-width:0; flex:1 1 auto} #tape .stub.last .v{max-width:34ch; overflow:hidden; text-overflow:ellipsis}
#tape .stub:hover .v{text-decoration:underline; text-decoration-thickness:2px; text-underline-offset:4px; text-decoration-color:var(--paper-3)}
#tape .stub:focus-visible{outline-offset:-2px}
#tape .stub.printed{animation:feed .6s cubic-bezier(.2,.9,.3,1)}
@keyframes feed{from{transform:translateY(-12px); clip-path:inset(0 0 100% 0)} to{transform:none; clip-path:inset(0 0 0 0)}}
#hint{bottom:calc(98px + env(safe-area-inset-bottom,0px))}

/* ---------- the books and the decisions ---------- */
.ledger{margin:.2em 0 .5em; display:grid; gap:3px}
.ledger div{display:flex; align-items:baseline; gap:6px}
.ledger dt{flex:1; display:flex; align-items:baseline; color:var(--ink-soft); min-width:0}
.ledger dt::after{content:""; flex:1; min-width:12px; margin:0 0 .28em 8px; border-bottom:2px dotted var(--paper-3)}
.ledger dd{margin:0; text-align:right; font-variant-numeric:tabular-nums}
.ledger dd.pos{color:var(--green-text)} .ledger dd.neg{color:var(--red-text)}
.source b{font-weight:400; font-family:var(--display); font-size:16px; letter-spacing:.01em}
.concerns{margin:.3em 0 0; padding-left:1.2em} .concerns li{margin:.25em 0}
.feed .why{margin:.25em 0 0}
.bars{display:grid; gap:5px; margin:.45em 0 .2em}
.bar{display:grid; grid-template-columns:6.6em 1fr 3.4em; align-items:center; gap:8px; font-size:16px}
.bar .track{height:13px; border:2px solid var(--ink); border-radius:7px 5px 8px 4px; background:var(--sheet); overflow:hidden}
.bar .fill{display:block; height:100%; background:var(--ink)}
.bar .num{text-align:right; font-variant-numeric:tabular-nums}
.panel a{text-decoration-thickness:2px; text-underline-offset:3px}
::selection{background:var(--ink); color:var(--panel)}
.panel .body{scrollbar-color:var(--paper-3) transparent; scrollbar-width:thin}

@media (max-width:700px){
  /* phones: the stamp and the latest decision on top, the five numbers below */
  #tape{left:8px; right:8px; bottom:auto; top:calc(120px + env(safe-area-inset-top,0px)); max-width:none;
    display:grid; grid-template-columns:auto repeat(4,minmax(0,1fr)); row-gap:4px;
    border-top:2.5px solid var(--ink); border-bottom:none; border-radius:10px 7px 0 0; transform:none; padding:6px 4px 7px 6px}
  /* on phones the tape hangs under the status chip, so it tears at the bottom */
  #tape::before{top:auto; bottom:-8px; transform:scaleY(-1)}
  #tape .stub .k{white-space:normal; line-height:1.05}
  #tape .stub{justify-content:flex-end} /* a two-line label never pushes its number out of line */
  #tape .stamp-mode{grid-row:1; grid-column:1; justify-self:start; font-size:12px; margin:0 6px 0 4px}
  #tape .stub.last{grid-row:1; grid-column:2 / -1; min-height:36px}
  #tape .stub.last .v{max-width:100%}
  #tape .stub{min-height:38px; padding:0 6px; min-width:0} #tape .stub .k{font-size:13px} #tape .stub .v{font-size:16px; max-width:100%; overflow:hidden; text-overflow:ellipsis}
  #tape .stub[data-k="price"]{border-left:none; border-top:2px dashed var(--paper-3); padding-top:3px}
  #tape .stub[data-k="watch"],#tape .stub[data-k="cash"],#tape .stub[data-k="result"],#tape .stub[data-k="hold"]{border-top:2px dashed var(--paper-3); padding-top:3px}
  #hint{bottom:calc(132px + env(safe-area-inset-bottom,0px))}
}
@media (prefers-reduced-motion: reduce){ #tape .stub.printed{animation:none} }
:root.calm #tape .stub.printed{animation:none}

/* an ink-drawn disclosure arrow for the receipts (the browser's triangle belongs to no world) */
.feed summary{list-style:none; display:inline-flex; align-items:center; gap:.35em}
.feed summary::-webkit-details-marker{display:none}
.feed summary::before{content:""; flex:none; width:.62em; height:.62em; transition:transform .15s ease-out;
  background:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3.2 1.6 9.4 6.3 3 10.4' fill='none' stroke='%232a2826' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center/contain}
.feed details[open] > summary::before{transform:rotate(90deg)}
:root.calm .feed summary::before{transition:none}

/* touch screens: every control at least 44px, the comfortable size for a thumb */
@media (pointer: coarse){
  .chip,#controls .chip,.chip.small,#status{min-height:44px}
  .chip.icon,#controls .chip{min-width:44px; justify-content:center}
  .tabs button,.feed summary{min-height:44px}
}
