/* cache.css: shared styles for the Week 7 walkthroughs.
   Part 1 is the shared engine theme (byte-identical to the KERNEL block in ../../worksheet6/sched/sched.css, ../../worksheet5/pipe/pipe.css and ../../worksheet4/cpu/cpu.css).
   Part 2 is specific to these pages: the program listing, stats, the file strip, cache frames, the storage layers, verdict cards. */
  /* === 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: cache walkthroughs ---------- */
  main { padding: .6rem 1.2rem .5rem; }
  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; }
  .call:empty { display: none; }
  .narr p { max-width: 125ch; }
  .narr .r { color: var(--gone); font-weight: 700; }
  .narr .g { color: var(--new); font-weight: 700; }
  .narr mark { background: #fff1b8; padding: 0 .2rem; border-radius: .2rem; }
  .mono { font-family: "SF Mono", Menlo, Consolas, monospace; }

  /* the program, as a listing */
  .prog { background: #fff; border: 2px solid var(--line); border-radius: .7rem; position: relative; }
  .prog .ph { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .74rem; font-weight: 700; padding: .22rem .6rem; background: #fbfaf6; border-bottom: 1px solid var(--line); border-radius: .5rem .5rem 0 0; display: flex; justify-content: space-between; gap: .6rem; white-space: nowrap; }
  .prog .ph small { font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
  .prog ol { list-style: none; margin: 0; padding: .18rem .3rem .25rem; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .72rem; line-height: 1.4; }
  .prog li { display: grid; grid-template-columns: 1.2rem 1fr; gap: .3rem; align-items: start; white-space: pre-wrap; padding: 0 .25rem; border-radius: .3rem; color: #6d6a63; }
  .prog li .tx { padding-left: var(--ind, 0); text-indent: calc(-1 * var(--ind, 0)); }
  .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); }

  /* key/value stats */
  .kv { display: grid; grid-template-columns: 1fr; gap: .25rem; }
  .kvr { display: flex; justify-content: space-between; gap: .8rem; align-items: baseline; background: #fff; border: 1.5px solid var(--line); border-radius: .45rem; padding: .2rem .6rem; font-size: .82rem; }
  .kvr .k { color: var(--muted); }
  .kvr .v { font-family: "SF Mono", Menlo, Consolas, monospace; font-weight: 800; }
  .kvr.good .v { color: var(--new); } .kvr.bad .v { color: var(--gone); }

  /* the file, one cell per 4 KiB page */
  .strip { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; background: #fff; border: 2px solid var(--line); border-radius: .7rem; padding: .5rem; }
  .pg { position: relative; aspect-ratio: 1.25; border-radius: .3rem; border: 2px solid #cfcbc2; background: #f3f2ee; display: flex; align-items: center; justify-content: center; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .7rem; color: #8d8a83; }
  .pg.flight { background: #fff7d6; border-color: #e2b500; border-style: dashed; color: var(--hot-ink); }
  .pg.cached { background: #dbe6f7; border-color: var(--py); color: var(--py); font-weight: 700; }
  .pg.read { background: var(--py); border-color: var(--py); color: #fff; font-weight: 800; }
  .pg.now { box-shadow: 0 0 0 3px var(--hot-ink); z-index: 1; }
  .pg.mark::after { content: "⚑"; position: absolute; top: -.55rem; right: -.3rem; font-size: .8rem; color: var(--gone); text-shadow: 0 0 2px #fff; }
  .legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .72rem; color: var(--muted); margin-top: .1rem; }
  .legend i { display: inline-block; width: .9rem; height: .7rem; border-radius: .2rem; border: 2px solid; vertical-align: -1px; margin-right: .25rem; }

  /* a log of requests */
  .log { display: flex; flex-direction: column; gap: .25rem; }
  .req { background: #fff; border: 1.5px solid var(--line); border-left: 5px solid var(--c, var(--kernel)); border-radius: .4rem; padding: .2rem .55rem; font-size: .78rem; display: flex; justify-content: space-between; gap: .6rem; }
  .req b { font-family: "SF Mono", Menlo, Consolas, monospace; }
  .req small { color: var(--muted); }
  .req.sync { --c: var(--gone); } .req.async { --c: var(--new); } .req.one { --c: #8d8a83; }

  /* cache frames and lists */
  .frames { display: flex; flex-direction: column; gap: .3rem; background: #fff; border: 2px solid var(--line); border-radius: .7rem; padding: .45rem .55rem .55rem; }
  .frames .fh { display: flex; justify-content: space-between; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .frames .row { display: flex; gap: .35rem; align-items: center; min-height: 2.4rem; }
  .frames .end { font-size: .64rem; color: var(--muted); width: 3.2rem; text-align: center; line-height: 1.15; flex: none; }
  .fr { flex: 1; min-width: 0; height: 2.3rem; border-radius: .4rem; border: 2px solid var(--c, #cfcbc2); background: var(--t, #fbfaf6); display: flex; align-items: center; justify-content: center; font-family: "SF Mono", Menlo, Consolas, monospace; font-weight: 800; font-size: .95rem; color: var(--c, #b8b4ab); position: relative; }
  .fr.empty { border-style: dashed; font-weight: 500; font-size: .7rem; }
  .fr.hot-set { --c: var(--py); --t: #dbe6f7; }
  .fr.scan { --c: #8d8a83; --t: #efede6; }
  .fr.hit { box-shadow: 0 0 0 3px var(--new); }
  .fr.in { box-shadow: 0 0 0 3px var(--hot-ink); }
  .fr.ref::after { content: "R"; position: absolute; top: -.5rem; right: -.35rem; background: var(--new); color: #fff; font-size: .58rem; border-radius: .3rem; padding: 0 .25rem; }
  .fr.out { opacity: .45; text-decoration: line-through; border-style: dashed; --c: var(--gone); --t: #fff3f1; }
  .seq { display: flex; flex-wrap: wrap; gap: .25rem; background: #fff; border: 2px solid var(--line); border-radius: .7rem; padding: .45rem; }
  .acc { min-width: 2rem; padding: .15rem .3rem; text-align: center; border-radius: .35rem; border: 2px solid #cfcbc2; font-family: "SF Mono", Menlo, Consolas, monospace; font-weight: 800; font-size: .85rem; color: #8d8a83; background: #fbfaf6; }
  .acc.hs { color: var(--py); border-color: #a9c2ea; }
  .acc.sc { color: #8d8a83; }
  .acc.h { background: #e6f4ea; border-color: var(--new); color: var(--new); }
  .acc.m { background: #fbe3df; border-color: var(--gone); color: var(--gone); }
  .acc.now { box-shadow: 0 0 0 3px var(--hot-ink); }

  /* storage layers, top (fast, volatile) to bottom (slow, persistent) */
  .layers { display: flex; flex-direction: column; gap: .5rem; }
  .layer { background: #fff; border: 2px solid var(--line); border-radius: .7rem; padding: .35rem .65rem .45rem; position: relative; }
  .layer .lh { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; }
  .layer .lh b { font-size: .88rem; }
  .layer .lh small { color: var(--muted); font-size: .7rem; }
  .layer .tag { font-size: .58rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: .02rem .4rem; border-radius: 1rem; color: #fff; }
  .layer .tag.vol { background: var(--cat); } .layer .tag.per { background: var(--new); }
  .layer .items { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .3rem; min-height: 1.7rem; }
  .blk { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .74rem; font-weight: 700; padding: .12rem .5rem; border-radius: .35rem; border: 2px solid var(--line); background: #fbfaf6; }
  .blk.dirty { border-color: var(--cat); background: #fbe3d6; color: #8a3a12; }
  .blk.dirty::before { content: "dirty · "; font-weight: 500; }
  .blk.clean { border-color: var(--py); background: #dbe6f7; color: var(--py); }
  .blk.meta { border-style: dashed; }
  .blk.newv { border-color: var(--new); background: #e6f4ea; color: #17603a; }
  .blk.oldv { color: var(--muted); }
  .blk.zero { border-color: var(--gone); background: #fff3f1; color: var(--gone); }
  .layer .none { color: var(--muted); font-style: italic; font-size: .74rem; }

  /* verdict cards */
  .verdicts { display: grid; grid-template-columns: 1fr; gap: .5rem; }
  .verdict { border: 2px solid var(--line); border-radius: .7rem; background: #fff; padding: .35rem .65rem .45rem; }
  .verdict .vh { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .verdict .vb { display: flex; align-items: center; gap: .5rem; margin: .1rem 0; }
  .verdict .vb b { font-size: 1.35rem; width: 1.7rem; text-align: center; }
  .verdict .vb span { font-weight: 800; font-size: 1rem; }
  .verdict .vw { font-size: .78rem; color: #444; line-height: 1.35; }
  .verdict.v-safe { border-color: var(--new); background: #eef8f1; } .verdict.v-safe .vb { color: var(--new); }
  .verdict.v-old { border-color: #b8860b; background: #fbf6e6; } .verdict.v-old .vb { color: #8a6500; }
  .verdict.v-lost, .verdict.v-empty { border-color: var(--gone); background: #fff3f1; } .verdict.v-lost .vb, .verdict.v-empty .vb { color: var(--gone); }
  .verdict.v-maybe { border-color: var(--cat); background: #fdf1ea; } .verdict.v-maybe .vb { color: var(--cat); }
