/* cpu.css: shared styles for the Week 4 CPU walkthroughs.
   Part 1 is the shared engine theme (byte-identical to the KERNEL block in ../../worksheet3/proc/proc.css).
   Part 2 is specific to these pages: the CPU, the trap table, the address-space maps, the queues, the terminal. */
  /* === KERNEL-START === */
  /* ---------- theme ---------- */
  :root {
    --bg: #f6f5f1;
    --panel: #ffffff;
    --ink: #1c1c1c;
    --muted: #6b6b6b;
    --line: #d9d6cf;
    --hot: #ffcf33;
    --hot-ink: #6b4d00;
    --new: #1e9e5a;
    --gone: #c0392b;
    --lookup: #7b3fe4;
    --cat: #e0662a;
    --py: #2266d3;
    --kernel: #555;
    font-size: 17px;
  }
  @media (min-width: 1500px) { :root { font-size: 19px; } }
  @media (max-width: 1200px) { :root { font-size: 14px; } }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    background: var(--bg); color: var(--ink);
    font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
    display: flex; flex-direction: column; height: 100vh; overflow: hidden;
  }
  code, .mono { font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
  b { font-weight: 700; }

  /* ---------- header ---------- */
  header {
    display: flex; align-items: center; gap: 1.2rem;
    padding: .55rem 1.2rem; background: #fff; border-bottom: 2px solid var(--line);
  }
  header .title { font-weight: 800; font-size: 1.15rem; letter-spacing: .01em; }
  header .title span { color: var(--muted); font-weight: 500; margin-left: .6rem; font-size: .95rem; }
  header .stepno { margin-left: auto; color: var(--muted); font-size: .95rem; white-space: nowrap; }
  header .stepno b { color: var(--ink); }
  header .part { color: var(--ink); font-weight: 600; }
  nav { display: flex; gap: .4rem; }
  nav button {
    font: inherit; font-weight: 700; padding: .4rem .9rem; border-radius: .5rem;
    border: 2px solid var(--ink); background: #fff; cursor: pointer;
  }
  nav button:hover { background: #f0efe9; }
  nav button:disabled { opacity: .35; cursor: default; }
  .progress { height: 4px; background: #e8e6df; }
  .progress i { display: block; height: 100%; background: var(--ink); transition: width .25s; }

  /* ---------- main grid ---------- */
  main {
    flex: 1; display: grid; gap: 1rem; padding: 1rem 1.2rem; min-height: 0;
  }
  .col { min-width: 0; display: flex; flex-direction: column; gap: .7rem; overflow-y: auto; overflow-x: hidden; padding: .3rem .35rem; }
  .col > h2 {
    margin: 0; font-size: 1rem; text-transform: uppercase; letter-spacing: .06em;
    display: flex; flex-direction: column; gap: .1rem;
  }
  .col > h2 small {
    text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted);
    font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .8rem;
  }
  .empty { color: var(--muted); font-style: italic; padding: .4rem .2rem; }

  /* ---------- generic boxes ---------- */
  .box { background: var(--panel); border: 2px solid var(--line); border-radius: .7rem; padding: .45rem .7rem; position: relative; }
  .proc { background: var(--panel); border: 2px solid var(--c); border-radius: .7rem; overflow: hidden; position: relative; }
  .proc .phead {
    background: var(--c); color: #fff; padding: .35rem .7rem; font-weight: 700;
    display: flex; justify-content: space-between; align-items: baseline; gap: .6rem;
  }
  .proc .phead small { font-weight: 500; opacity: .9; }
  .chip {
    display: inline-block; font-size: .75rem; font-weight: 700; padding: .05rem .45rem; border-radius: 1rem;
    border: 1px solid var(--line); background: #fafaf7; color: #333; white-space: nowrap;
  }
  .badge { font-size: .75rem; font-weight: 700; padding: .05rem .45rem; border-radius: 1rem; background: var(--gone); color: #fff; }

  /* ---------- states ---------- */
  .hot { box-shadow: 0 0 0 4px var(--hot); animation: pulse 1.1s ease-in-out 2; position: relative; z-index: 1; }
  @keyframes pulse { 0%,100% { box-shadow: 0 0 0 4px var(--hot); } 50% { box-shadow: 0 0 0 8px #ffe28a; } }
  .new { border-color: var(--new) !important; position: relative; }
  .new::after {
    content: "NEW"; position: absolute; top: -.6rem; right: .6rem; background: var(--new); color: #fff;
    font-size: .65rem; font-weight: 800; padding: .05rem .4rem; border-radius: .3rem; letter-spacing: .05em; z-index: 1;
  }
  .gone { opacity: .5; border-style: dashed !important; border-color: var(--gone) !important; position: relative; }
  .gone::after {
    content: "FREED"; position: absolute; top: -.6rem; right: .6rem; background: var(--gone); color: #fff;
    font-size: .65rem; font-weight: 800; padding: .05rem .4rem; border-radius: .3rem; letter-spacing: .05em; z-index: 1;
  }
  .gone.lost::after { content: "LOST"; }

  /* ---------- footer ---------- */
  footer {
    background: #fff; border-top: 2px solid var(--line); padding: .7rem 1.2rem .9rem;
    display: grid; grid-template-columns: 1fr; gap: .5rem; min-height: 9.5rem;
  }
  .call {
    display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; min-height: 2rem;
    font-family: Menlo, monospace; font-size: 1.05rem;
  }
  .call .who {
    background: var(--c, var(--kernel)); color: #fff; padding: .15rem .6rem; border-radius: .4rem;
    font-family: -apple-system, "Segoe UI", sans-serif; font-weight: 700; font-size: .9rem;
  }
  .call .sys { font-weight: 700; }
  .call .ret { color: var(--new); font-weight: 800; }
  .call .bytes { background: var(--hot); color: var(--hot-ink); padding: 0 .4rem; border-radius: .3rem; font-weight: 700; }
  .call .note { color: var(--muted); font-family: -apple-system, "Segoe UI", sans-serif; font-size: .9rem; }
  .crumbs { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; font-size: .95rem; }
  .crumb { border: 2px solid var(--line); border-radius: .4rem; padding: .05rem .5rem; color: var(--muted); }
  .crumb.done { border-color: var(--lookup); color: var(--lookup); font-weight: 700; }
  .crumb.cur { background: var(--lookup); border-color: var(--lookup); color: #fff; font-weight: 800; }
  .crumb small { font-weight: 500; opacity: .8; }
  .narr h3 { margin: 0 0 .25rem; font-size: 1.1rem; }
  .narr p { margin: 0; font-size: 1.05rem; line-height: 1.45; max-width: 95ch; }
  .narr ul { margin: .2rem 0 0; padding-left: 1.3rem; font-size: 1rem; line-height: 1.4; columns: 2; column-gap: 2.5rem; }
  .narr li { break-inside: avoid; margin-bottom: .25rem; }
  .narr code { background: #f0efe9; padding: 0 .3rem; border-radius: .25rem; font-size: .95em; }
  .narr table { border-collapse: collapse; font-size: .95rem; margin-top: .3rem; }
  .narr th, .narr td { border: 1px solid var(--line); padding: .15rem .6rem; text-align: left; }
  .narr .k { color: var(--lookup); font-weight: 700; }
  .narr .cat { color: var(--cat); font-weight: 700; }
  .narr .py { color: var(--py); font-weight: 700; }
  nav button#explain { border-color: var(--line); font-weight: 600; color: var(--muted); }
  nav button#explain[aria-pressed="true"] { background: var(--hot); border-color: var(--hot-ink); color: var(--hot-ink); }
  footer.collapsed { min-height: 0; }
  footer.collapsed .narr > :not(h3) { display: none; }
  footer.collapsed .narr h3 { cursor: pointer; }
  footer.collapsed .narr h3::after { content: ": explanation hidden · press E or “Explain”"; color: var(--muted); font-weight: 500; font-size: .85rem; }

  /* ---------- arrow overlay ---------- */
  #arrows { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 2; }
  #arrows path { fill: none; stroke-width: 2.5; stroke: var(--kernel); }
  #arrows polygon { fill: var(--kernel); }
  #arrows path.lookup { stroke: var(--lookup); stroke-dasharray: 7 5; stroke-width: 3; }
  #arrows polygon.lookup { fill: var(--lookup); }
  #arrows path.new { stroke: var(--new); stroke-width: 3; }
  #arrows polygon.new { fill: var(--new); }
  #arrows path.gone { stroke: var(--gone); stroke-dasharray: 4 4; stroke-width: 3; }
  #arrows polygon.gone { fill: var(--gone); }
  #arrows path.hotarrow { stroke: var(--hot-ink); stroke-width: 3.5; }
  #arrows polygon.hotarrow { fill: var(--hot-ink); }
  #arrows .dim { opacity: .3; }
  /* === KERNEL-END === */

  /* ---------- page: CPU walkthroughs (system call, timer, keystroke) ---------- */
  main { padding: .6rem 1.2rem .5rem; }
  main.cols3 { grid-template-columns: 1fr 1fr 1.05fr; }
  main.cols4 { grid-template-columns: .9fr 1.1fr .9fr 1.1fr; }
  header .title { white-space: nowrap; }
  @media (max-width: 1400px) { header .title span { display: none; } }
  .col > h2 { font-size: .9rem; }
  .col > h2 small { font-size: .72rem; }
  .col > h2 + * { margin-top: -.15rem; }
  .call:empty { display: none; }
  .narr p { max-width: 125ch; }
  .narr th, .narr td { padding: .08rem .5rem; }
  .narr .u { color: var(--new); font-weight: 700; }
  .narr .kk { color: var(--gone); font-weight: 700; }
  .emp { color: var(--muted); font-style: italic; font-size: .7rem; padding: .1rem .2rem; }
  .box.hot, .as .hot { z-index: 1; }

  /* source listings */
  .prog { background: #fff; border: 2px solid var(--line); border-radius: .7rem; overflow: hidden; }
  .prog .ph { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .78rem; font-weight: 700; padding: .22rem .6rem; background: #fbfaf6; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: .6rem; }
  .prog .ph small { font-weight: 500; color: var(--muted); display: flex; gap: .25rem; align-items: center; }
  .prog .ph small i { font-style: normal; background: var(--c); color: #fff; font-size: .58rem; font-weight: 800; padding: 0 .32rem; border-radius: .6rem; line-height: 1.5; }
  .prog ol { list-style: none; margin: 0; padding: .18rem .3rem .25rem; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .7rem; line-height: 1.32; }
  .prog li { display: grid; grid-template-columns: minmax(2.4rem, auto) 1.4rem 1fr; gap: .3rem; align-items: center; white-space: pre; padding: 0 .25rem; border-radius: .3rem; color: #6d6a63; }
  .prog li .tx { overflow: hidden; text-overflow: ellipsis; }
  .prog li .mk { display: flex; gap: .15rem; justify-content: flex-end; min-height: 1rem; }
  .prog li .mk i { font-style: normal; background: var(--c); color: #fff; font-size: .58rem; font-weight: 800; padding: 0 .32rem; border-radius: .6rem; line-height: 1.5; letter-spacing: .02em; }
  .prog li .mk i.saved { background: #fff; color: var(--c); border: 1px dashed var(--c); line-height: 1.3; }
  .prog li .ln { color: #c2bfb7; text-align: right; }
  .prog li .tx .c { color: #9a978f; }
  .prog li.cur { background: var(--hot); color: var(--ink); font-weight: 700; }
  .prog li.cur .ln { color: var(--hot-ink); }
  .prog li.cur .tx .c { color: #7d6a2a; }
  .prog.kernel { border-color: var(--kernel); }
  .prog.kernel .ph { background: #ecebe7; }

  /* the CPU */
  .cpu { padding: .4rem .6rem .5rem; border-color: var(--ink); }
  .cpu .ch { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-weight: 800; font-size: .9rem; margin-bottom: .25rem; }
  .mode { display: inline-block; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .72rem; font-weight: 800; padding: .08rem .55rem; border-radius: 1rem; color: #fff; letter-spacing: .02em; white-space: nowrap; }
  .mode.m0 { background: var(--new); }
  .mode.m1 { background: var(--gone); }
  .cpu .rows { display: grid; grid-template-columns: auto 1fr; gap: .05rem .5rem; align-items: baseline; }
  .cpu .k, .pcb .k, .qs .k { color: var(--muted); font-size: .62rem; text-transform: uppercase; letter-spacing: .05em; }
  .cpu .v, .pcb .v { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .regs { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
  .reg { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .68rem; border: 1px solid var(--line); border-radius: .35rem; padding: .04rem .4rem; background: #fafaf7; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .reg b { color: var(--muted); font-weight: 700; margin-right: .15rem; }
  .reg.bad { border-color: var(--gone); background: #fff0ee; color: var(--gone); font-weight: 700; }
  .reg.bad s { color: var(--muted); font-weight: 400; }
  .cpu.hung { border-color: var(--gone); }
  .hungtag { margin-top: .35rem; font-size: .72rem; font-weight: 800; color: #fff; background: var(--gone); border-radius: .35rem; padding: .1rem .5rem; display: inline-block; }

  /* the timeline strip */
  .tl { display: flex; align-items: center; gap: 2px; min-height: 1.1rem; padding: .1rem .2rem; }
  .tl i { flex: 1 1 0; min-width: 3px; max-width: .7rem; height: .9rem; border-radius: 2px; border-bottom: 3px solid var(--c); }
  .tl i.u { background: #bfe5cf; }
  .tl i.k { background: #f0a89f; }
  .tl i.thin { flex: 0 0 3px; max-width: 3px; }
  .tl span { color: var(--muted); font-size: .62rem; margin-left: .3rem; white-space: nowrap; }
  .tl .emp { margin-left: 0; }
  .tl.hot { border-radius: .3rem; }

  /* the trap table and the system call table */
  .tt { padding: 0; overflow: hidden; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .68rem; }
  .tt .th, .tt .r { display: grid; grid-template-columns: 3rem 7.5rem 1fr; gap: .3rem; padding: .1rem .55rem; border-top: 1px solid var(--line); white-space: nowrap; align-items: center; }
  .tt.sc .th, .tt.sc .r { grid-template-columns: 3rem 1fr; }
  .tt .th { border-top: 0; font-weight: 700; background: #fbfaf6; text-transform: uppercase; font-size: .58rem; letter-spacing: .05em; color: var(--muted); }
  .tt .r span:last-child { overflow: hidden; text-overflow: ellipsis; }
  .tt .r.hit { background: var(--hot); font-weight: 700; }
  .tt .r.more { color: var(--muted); font-style: italic; }
  .tt.unset { border-style: dashed; color: var(--muted); }
  .tt .r.hot { z-index: 1; }

  /* the devices */
  .dev { padding: .3rem .6rem; }
  .dev .d { font-size: .74rem; padding: .12rem .3rem; border-radius: .35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dev .d b { margin-right: .3rem; }
  .dev .d.firing { background: var(--hot); font-weight: 700; }

  /* the address space: high addresses at the top */
  .as { display: flex; flex-direction: column; gap: .22rem; border: 2px solid var(--c); border-radius: .7rem; padding: 0 .4rem .4rem; background: #fff; }
  .as .ah { background: var(--c); color: #fff; margin: 0 -.4rem .1rem; padding: .22rem .6rem; border-radius: .5rem .5rem 0 0; font-weight: 800; font-size: .85rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
  .seg { border: 1.5px solid var(--line); border-radius: .4rem; padding: .12rem .35rem .2rem; background: #fff; display: flex; flex-direction: column; gap: .12rem; min-width: 0; }
  .seg.k { background: #efedea; border-color: #bdb9b1; }
  .seg.thin { padding-bottom: .18rem; }
  .seg.free { flex: 1 0 1.1rem; border-style: dashed; color: var(--muted); font-size: .68rem; font-style: italic; justify-content: center; text-align: center; padding: .1rem; min-height: 1.4rem; }
  .sl { display: flex; justify-content: space-between; gap: .4rem; font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
  .sl span:last-child { text-transform: none; letter-spacing: 0; font-weight: 500; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .62rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bound { border-top: 2px dashed var(--gone); color: var(--gone); font-size: .64rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; text-align: center; padding-top: .08rem; margin: .05rem 0; }
  .bound.reject { background: #fff0ee; border-radius: .3rem; border: 2px dashed var(--gone); padding: .15rem; }
  .ke, .fr, .dat, .kbuf { position: relative; border: 1.5px solid var(--line); border-radius: .35rem; background: #fff; padding: .05rem .4rem .05rem .45rem; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .68rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .15rem; }
  .ke small, .fr small, .dat small, .kbuf small { color: var(--muted); font-family: -apple-system, "Segoe UI", sans-serif; font-size: .62rem; }
  .ke.tf { border-color: var(--gone); background: #fff7f5; white-space: normal; padding-right: 3rem; }
  .ke .tfr { font-size: .6rem; color: #6d6a63; white-space: normal; }
  .ke.fr { border-color: #bdb9b1; background: #fbfaf7; }
  .fr { border-color: var(--c); }
  .fr span { color: #6d6a63; }
  .ke.top, .fr.top { box-shadow: inset 3px 0 0 var(--hot-ink); }
  .sp { position: absolute; right: .3rem; top: .05rem; font-style: normal; font-size: .58rem; font-weight: 800; color: var(--hot-ink); background: var(--hot); padding: 0 .3rem; border-radius: .3rem; }
  .ke.gone, .fr.gone { opacity: .55; }
  /* frames clip overflow (for the ellipsis), so their NEW/FREED badges sit inside, at the right */
  .ke.new::after, .fr.new::after, .dat.new::after, .kbuf.new::after,
  .ke.gone::after, .fr.gone::after, .dat.gone::after, .kbuf.gone::after { top: 50%; transform: translateY(-50%); right: .3rem; font-size: .58rem; padding: 0 .3rem; }
  .ke.new, .fr.new, .dat.new, .kbuf.new, .ke.gone, .fr.gone, .dat.gone, .kbuf.gone { padding-right: 2.9rem; }
  .ke.new.top, .fr.new.top { padding-right: 5.4rem; }
  .ke.new .sp, .fr.new .sp { right: 2.9rem; }
  .ke.tf.new::after, .ke.tf.gone::after { top: .15rem; transform: none; }
  .ke.tf.new .sp { top: 1.25rem; right: .3rem; }
  .dat { border-color: #c9c3d8; background: #f7f5fb; }
  .kbuf { border-color: var(--new); background: #eef8f1; margin-top: .25rem; }
  .pcb { position: relative; border: 1.5px solid var(--c); border-radius: .4rem; background: #fff; margin-top: .15rem; }
  .pcb .pt { font-weight: 800; font-size: .7rem; padding: .1rem .45rem; background: var(--c); color: #fff; border-radius: .25rem .25rem 0 0; }
  .pcb .pt small { font-weight: 500; opacity: .9; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .6rem; margin-left: .3rem; }
  .pcb .rows { padding: .1rem .45rem .18rem; display: grid; grid-template-columns: auto 1fr; gap: .02rem .45rem; align-items: baseline; }
  .pcb .v { font-size: .66rem; }
  .pcb .v.sv { overflow: visible; display: flex; align-items: center; gap: .3rem; line-height: 1.6; }
  .pcb .v.sv .wt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .pcb .v.new { border: 1.5px solid var(--new); border-radius: .3rem; padding: 0 .3rem; white-space: normal; }
  .pcb .v.new { padding-right: 2.6rem; }
  .pcb .v.new::after { top: .1rem; right: .2rem; font-size: .58rem; padding: 0 .3rem; }
  .st { display: inline-block; font-size: .6rem; font-weight: 800; padding: .02rem .45rem; border-radius: 1rem; letter-spacing: .04em; text-transform: uppercase; color: #fff; background: var(--kernel); font-family: -apple-system, "Segoe UI", sans-serif; }
  .st.running { background: var(--new); }
  .st.ready { background: #6c8; }
  .st.sleeping { background: #8d8a83; }
  .ah .st { background: rgba(255,255,255,.25); }

  /* the kernel's queues */
  .qs { padding: .3rem .6rem .4rem; display: flex; flex-direction: column; gap: .25rem; }
  .qr { display: grid; grid-template-columns: 6.2rem 1fr; gap: .4rem; align-items: center; font-size: .74rem; }
  .qc { position: relative; display: inline-block; font-style: normal; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .66rem; font-weight: 700; border: 1.5px solid var(--c); color: var(--c); border-radius: 1rem; padding: 0 .45rem; margin-right: .25rem; background: #fff; }
  .qc.ch { border-color: var(--hot-ink); color: var(--hot-ink); background: var(--hot); }
  .qc.new::after { top: -.8rem; }

  /* the terminal */
  .term { background: #1d1f21; color: #e6e6e6; border-radius: .7rem; padding: .45rem .7rem .5rem; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .74rem; line-height: 1.5; min-height: 3.6rem; }
  .term .l { display: flex; gap: .45rem; align-items: baseline; white-space: pre-wrap; border-radius: .25rem; padding: 0 .2rem; margin: 0 -.2rem; }
  .term .l .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--c); flex: none; position: relative; top: -.05rem; }
  .term .l.prompt { color: #8fd3a5; }
  .term .l.fresh { background: rgba(255, 207, 51, .22); }
  .term .cursor { display: inline-block; width: .5rem; height: .95rem; background: #e6e6e6; vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
  @keyframes blink { 50% { opacity: 0; } }
  .term.hot { box-shadow: 0 0 0 4px var(--hot); }
  #col-kernel .term { flex: 1; }
  /* four-column pages: the two short program listings sit side by side so the queues stay above the fold */
  main.cols4 #src { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
  main.cols4 #src .prog.kernel { grid-column: 1 / -1; }
  main.cols4 .col > h2 { margin-top: .1rem; }
