  :root {
    /* Light theme (default) */
    --bg:         #ffffff;
    --surface:    #f8fafc;
    --border:     #e2e8f0;
    --accent:     #6366f1;
    --accent-hover: #4f46e5;
    --text:       #1e293b;
    --muted:      #64748b;
    --ok:         #16a34a;
    --err:        #dc2626;
    --canvas-bg:  #ffffff;
    --shadow:     rgba(0,0,0,0.12);

    /* Trace colors - light */
    --tc-call-node: #dbeafe; --tc-call-edge: #3b82f6;
    --tc-delegatecall-node: #fef3c7; --tc-delegatecall-edge: #f59e0b;
    --tc-staticcall-node: #ede9fe; --tc-staticcall-edge: #8b5cf6;
    --tc-create-node: #d1fae5; --tc-create-edge: #10b981;
    --tc-selfdestruct-node: #fee2e2; --tc-selfdestruct-edge: #dc2626;
    --tc-callcode-node: #f4f4f5; --tc-callcode-edge: #71717a;

    --node-fill: #f8fafc;
    --node-stroke: #94a3b8;
    --node-glow: #cbd5e1;
    --grid-color: #e2e8f0;
    --edge-color: #cbd5e1;
    --path-color: #64748b;
    --hl-color: #475569;
    --tip-bg: #f8fafc;
    --tip-border: #cbd5e1;
  }

  html.dark {
    --bg:         #0f172a;
    --surface:    #1e293b;
    --border:     #334155;
    --accent:     #818cf8;
    --accent-hover: #a5b4fc;
    --text:       #f1f5f9;
    --muted:      #94a3b8;
    --ok:         #22c55e;
    --err:        #ef4444;
    --canvas-bg:  #0f172a;
    --shadow:     rgba(0,0,0,0.5);

    /* Trace colors - dark */
    --tc-call-node: #1e3a8a; --tc-call-edge: #60a5fa;
    --tc-delegatecall-node: #78350f; --tc-delegatecall-edge: #fbbf24;
    --tc-staticcall-node: #4c1d95; --tc-staticcall-edge: #a78bfa;
    --tc-create-node: #064e3b; --tc-create-edge: #34d399;
    --tc-selfdestruct-node: #7f1d1d; --tc-selfdestruct-edge: #f87171;
    --tc-callcode-node: #27272a; --tc-callcode-edge: #a1a1aa;

    --node-fill: #1e293b;
    --node-stroke: #94a3b8;
    --node-glow: #475569;
    --grid-color: #1e293b;
    --edge-color: #475569;
    --path-color: #94a3b8;
    --hl-color: #cbd5e1;
    --tip-bg: #1e293b;
    --tip-border: #475569;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  }

  /* ── Header ── */
  /*
   * CHANGE: border-bottom → box-shadow
   * Book: "Use a box shadow — do a great job of outlining an element
   * like a border would, but can be more subtle"
   */
  header {
    flex-shrink: 0;
    padding: 12px 20px;
    box-shadow: 0 1px 0 var(--border), 0 2px 8px var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: relative;
    z-index: 1;
  }
  .header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
  }
  header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    white-space: nowrap;
  }
  header .sub {
    font-size: 0.7rem;
    color: var(--muted);
    display: none;
  }
  @media (min-width: 640px) {
    header .sub { display: inline; }
    header { padding: 14px 28px; }
    header h1 { font-size: 1.35rem; }
  }

  /* ── Theme Toggle ── */
  #theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--muted);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    flex-shrink: 0;
  }
  #theme-toggle:hover {
    background: var(--border);
    color: var(--text);
  }
  #theme-toggle svg { width: 20px; height: 20px; }
  .dark #theme-toggle .icon-sun { display: block; }
  .dark #theme-toggle .icon-moon { display: none; }
  #theme-toggle .icon-sun { display: none; }
  #theme-toggle .icon-moon { display: block; }

  /* ── Input bar ── */
  .input-bar {
    flex-shrink: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    background: var(--surface);
  }
  @media (min-width: 640px) {
    .input-bar { padding: 12px 28px; flex-wrap: nowrap; }
  }
  .input-bar label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
    display: none;
  }
  @media (min-width: 480px) {
    .input-bar label { display: block; }
  }
  #tx-input {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  #tx-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
  #tx-input::placeholder { color: var(--muted); }
  #trace-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 9px 16px;
    cursor: pointer;
    transition: background 0.12s, transform 0.08s;
    white-space: nowrap;
  }
  #trace-btn:hover { background: var(--accent-hover); }
  #trace-btn:active { transform: scale(0.97); }
  #trace-btn:disabled { background: var(--muted); cursor: not-allowed; }
  #status {
    font-size: 0.7rem;
    color: var(--muted);
    white-space: nowrap;
  }
  #status.ok  { color: var(--ok); }
  #status.err { color: var(--err); }

  /* ── Main scroll area ── */
  .main-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
  }

  /* ── Panels ── */
  .panels {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  @media (min-width: 900px) {
    .panels {
      flex-direction: row;
      height: 50vh;
      min-height: 360px;
    }
  }
  .panel {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
  }
  @media (min-width: 900px) {
    .panel {
      flex: 1;
      min-height: 0;
      border-bottom: none;
      border-right: 1px solid var(--border);
    }
    .panel:last-child { border-right: none; }
  }
  .panel-head {
    flex-shrink: 0;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
  }
  @media (min-width: 640px) {
    .panel-head { padding: 10px 16px; gap: 12px; }
  }

  /*
   * CHANGE: accent pip on panel titles
   * Book: "Add color with accent borders — it doesn't take any graphic
   * design talent to add a colored rectangle to your UI, and it can go
   * a long way towards making something feel more 'designed'"
   */
  .panel-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    padding-left: 10px;
    position: relative;
  }
  .panel-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 13px;
    background: var(--accent);
    border-radius: 1px;
  }

  /*
   * CHANGE: de-emphasize panel hints
   * Book: "Emphasize by de-emphasizing — instead of trying to further
   * emphasize the element you want to draw attention to, figure out how
   * you can de-emphasize elements that are competing with it"
   */
  .panel-hint {
    font-size: 0.6rem;
    color: var(--muted);
    white-space: nowrap;
    margin-left: auto;
    opacity: 0.35;
    letter-spacing: 0.03em;
    display: none;
  }
  @media (min-width: 480px) {
    .panel-hint { display: block; }
  }

  /*
   * CHANGE: canvas dot grid background
   * Book: "Decorate your backgrounds — a great way to break up monotony
   * without drastically altering the design is to add some excitement
   * to a few of your backgrounds"
   */
  .canvas-wrap {
    flex: 1;
    min-height: 300px;
    overflow: hidden;
    position: relative;
    background-color: var(--canvas-bg);
    background-image: radial-gradient(circle, var(--grid-color) 1px, transparent 1px);
    background-size: 20px 20px;
  }
  .canvas-wrap svg {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
  }
  .canvas-wrap svg:active {
    cursor: grabbing;
  }

  /*
   * CHANGE: empty state — more descriptive, slightly more prominent
   * Book: "Don't overlook empty states — use them as an opportunity to be
   * interesting and exciting, don't settle for plain and boring"
   */
  .empty {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    color: var(--muted);
    text-align: center;
    line-height: 2;
    pointer-events: none;
    opacity: 0.55;
  }
  .empty strong {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    opacity: 0.5;
    margin-bottom: 2px;
    line-height: 1.4;
  }

  /* ── Results section ── */
  .results {
    display: none;
    border-top: 1px solid var(--border);
  }
  .results.visible {
    display: block;
  }

  /*
   * CHANGE: results head hierarchy — count is primary content, title is label
   * Book: "Not all elements are equal — when everything in an interface
   * is competing for attention, it feels noisy and chaotic. Deliberately
   * de-emphasize secondary and tertiary information"
   * Also: "Labels are a last resort — when you're able to present data
   * without labels, it's much easier to emphasize important information"
   */
  .results-head {
    padding: 14px 12px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: baseline;
    gap: 8px;
    background: var(--surface);
  }
  @media (min-width: 640px) {
    .results-head { padding: 16px 28px 12px; }
  }
  .results-count {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    line-height: 1;
  }
  .results-title {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* Grid shared by column headers and data rows */
  .results-columns,
  .tx-row {
    display: grid;
    grid-template-columns: 1fr 80px;
    gap: 0;
    padding: 0 12px;
    font-size: 0.72rem;
  }
  @media (min-width: 640px) {
    .results-columns,
    .tx-row {
      grid-template-columns: 90px 1fr 80px;
      padding: 0 28px;
    }
  }
  @media (min-width: 900px) {
    .results-columns,
    .tx-row {
      grid-template-columns: 90px 1fr 1fr 1fr 80px;
    }
  }

  .tx-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 10px 6px;
    min-width: 0;
  }

  /* Column headers */
  /*
   * CHANGE: column headers — heavily de-emphasized
   * Book: "Labels are secondary — add the label, but treat it as
   * supporting content. De-emphasize the label by making it smaller,
   * reducing the contrast, using a lighter font weight"
   */
  .results-columns {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .results-columns .tx-cell {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 5px 6px;
    opacity: 0.6;
  }

  /* Scrollable body */
  .results-body {
    max-height: 50vh;
    overflow-y: auto;
    padding: 0;
  }

  /*
   * CHANGE: table row separation — softer boundary, more breathing room
   * Book: "Use fewer borders — using too many of them can make your design
   * feel busy and cluttered. Add extra spacing — what better way to create
   * separation than to simply increase the separation?"
   */
  .tx-row {
    border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
    transition: background 0.1s;
  }
  .tx-row:first-child {
    border-top: none;
  }
  .tx-row:hover {
    background: var(--surface);
  }
  .tx-row.tx-error {
    background: color-mix(in srgb, var(--err) 6%, transparent);
  }

  .tx-block {
    color: var(--muted);
    font-size: 0.68rem;
    display: none;
  }
  @media (min-width: 640px) {
    .tx-block { display: block; }
  }

  /*
   * CHANGE: tx hash links — custom underline treatment
   * Book: "Supercharge the defaults — links are a great candidate for
   * special styling. You can do something as simple as changing the color
   * and font weight, or something as fancy as a thick and colorful custom
   * underline that partially overlaps the text"
   */
  .tx-hash {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.72rem;
    box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--accent) 30%, transparent);
    transition: box-shadow 0.12s, color 0.12s;
  }
  .tx-hash:hover {
    color: var(--accent-hover);
    box-shadow: inset 0 -2px 0 var(--accent-hover);
  }

  .tx-from,
  .tx-to {
    color: var(--text);
    font-size: 0.68rem;
    display: none;
  }
  @media (min-width: 900px) {
    .tx-from,
    .tx-to { display: block; }
  }

  .tx-value {
    color: var(--muted);
    font-size: 0.68rem;
    text-align: right;
  }

  .tx-empty {
    padding: 20px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted);
  }

  .results-footer {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  @media (min-width: 640px) {
    .results-footer { padding: 10px 28px; }
  }
  .results-footer:empty {
    display: none;
  }

  .page-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 0.7rem;
    font-weight: 500;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
  }
  .page-btn:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--accent);
  }
  .page-btn:disabled {
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.5;
  }

  .page-info {
    font-size: 0.68rem;
    color: var(--muted);
  }

  /* ── Footer ── */
  /*
   * CHANGE: promote footer stats slightly
   * Book: "Size isn't everything — try using font weight or color to
   * do the same job" — the structure count is important product data
   */
  footer {
    flex-shrink: 0;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--muted);
    background: var(--surface);
  }
  footer .footer-stat {
    font-variant-numeric: tabular-nums;
  }
  footer .footer-highlight {
    color: var(--text);
    font-weight: 500;
  }
  @media (min-width: 640px) {
    footer { padding: 8px 28px; font-size: 0.7rem; }
  }

  /* ── SVG Styles ── */
  .tree-edge {
    fill: none;
    stroke: var(--edge-color);
    stroke-width: 1.6;
    opacity: 0.6;
    transition: stroke 0.15s, stroke-width 0.15s, opacity 0.15s;
  }
  .tree-edge.highlighted {
    stroke: var(--path-color);
    stroke-width: 2.2;
    opacity: 1;
  }

  .tree-node-group { cursor: pointer; }

  .tree-node-shadow {
    fill: rgba(0,0,0,0.15);
  }
  .dark .tree-node-shadow {
    fill: rgba(0,0,0,0.3);
  }

  .tree-node-glow-group {
    opacity: 0;
    transition: opacity 0.15s;
  }
  .tree-node-group:hover .tree-node-glow-group,
  .tree-node-group.highlighted .tree-node-glow-group {
    opacity: 1;
  }

  .tree-node {
    stroke-width: 1.5;
    transition: stroke-width 0.15s;
  }
  .tree-node-group:hover .tree-node,
  .tree-node-group.highlighted .tree-node {
    stroke-width: 2.2;
  }
  .tree-node-group.root .tree-node {
    stroke-width: 2.5;
  }

  .tree-node-inner {
    fill: none;
    stroke-width: 0.6;
    opacity: 0.4;
  }

  .tree-node-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 8px;
    fill: var(--text);
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
  }
  .tree-node-group.root .tree-node-label {
    font-size: 9px;
  }

  .depth-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 8px;
    fill: var(--muted);
  }
  .depth-line {
    stroke: var(--muted);
    stroke-width: 0.5;
    stroke-dasharray: 2 5;
    opacity: 0.5;
  }
  .depth-rails {
    pointer-events: none;
  }

  /* Graph styles */
  .graph-edge {
    fill: none;
    stroke-width: 1.6;
    opacity: 0.55;
    transition: stroke-width 0.15s, opacity 0.15s;
  }
  .graph-edge-group.highlighted .graph-edge,
  .graph-edge-group.linked .graph-edge {
    stroke-width: 2.5;
    opacity: 1;
  }
  .graph-edge-group.linked .graph-edge {
    stroke-width: 3.5;
  }

  .graph-arrow {
    opacity: 0.7;
    transition: opacity 0.15s;
  }
  .graph-edge-group.highlighted .graph-arrow,
  .graph-edge-group.linked .graph-arrow {
    opacity: 1;
  }

  .graph-edge-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 9px;
    font-style: italic;
    opacity: 0.7;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
  }
  .graph-edge-group.highlighted .graph-edge-label,
  .graph-edge-group.linked .graph-edge-label {
    opacity: 1;
  }

  .graph-node-group { cursor: pointer; }

  .graph-node-shadow {
    fill: rgba(0,0,0,0.12);
  }
  .dark .graph-node-shadow {
    fill: rgba(0,0,0,0.25);
  }

  .graph-node-glow {
    fill: var(--node-glow);
    opacity: 0;
    transition: opacity 0.15s;
  }
  .graph-node-group:hover .graph-node-glow {
    opacity: 0.5;
  }

  .graph-node {
    fill: var(--node-fill);
    stroke: var(--node-stroke);
    stroke-width: 1.8;
    transition: stroke-width 0.15s;
  }
  .graph-node-group:hover .graph-node {
    stroke-width: 2.5;
  }

  .graph-node-inner {
    fill: none;
    stroke: var(--node-stroke);
    stroke-width: 0.6;
    opacity: 0.4;
  }

  .grid-dot {
    fill: var(--grid-color);
  }

  .tooltip-box {
    fill: var(--tip-bg);
    stroke: var(--tip-border);
    stroke-width: 1;
    filter: drop-shadow(0 2px 4px var(--shadow));
  }
  .tooltip-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    fill: var(--text);
    text-anchor: middle;
  }
  .tooltip-text.main {
    font-size: 9px;
    fill: var(--hl-color);
  }
  .tooltip-text.sub {
    font-size: 8px;
    fill: var(--muted);
  }

  /* Pulse animation */
  @keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
  }
  .tree-node-group:hover .tree-node,
  .graph-node-group:hover .graph-node {
    animation: pulse 0.8s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
  }
