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

  :root {
    --bg:            #0d1117;
    --surface:       #161b22;
    --surface2:      #1c2230;
    --border:        #2a3347;
    --accent:        #4a9eff;
    --accent-dim:    #1e3a5f;
    --text:          #c9d1d9;
    --text-dim:      #6e7d91;
    --text-mono:     'Courier New', monospace;
    --tooltip-bg:    #0d1525;
    --tooltip-border:#3d5068;
    --popover-bg:    #0d1525;
  }

  body.light {
    --bg:            #f0f4f8;
    --surface:       #ffffff;
    --surface2:      #f0f4f8;
    --border:        #d0d8e4;
    --accent:        #1a6ec0;
    --accent-dim:    #d0e4f8;
    --text:          #1a2030;
    --text-dim:      #5a6880;
    --tooltip-bg:    #ffffff;
    --tooltip-border:#c0cad8;
    --popover-bg:    #f8fafc;
  }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 740px;
    overflow: auto;
  }

  /* ── Top header bar ── */
  #header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
  }
  #header h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: -0.01em;
  }
  #header h1 .accent { color: var(--accent); }
  #header h1 .kip    { font-size: 11px; font-weight: 400; color: var(--text-dim); margin-left: 4px; }

  .sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
  .spacer { flex: 1; }

  /* Playback buttons */
  .btn {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
  }
  .btn:hover { background: #243040; border-color: #3d5068; }
  .btn.running { background: #1a3a5c; border-color: var(--accent); color: #7ec8ff; }
  .btn.paused  { background: #3a2800; border-color: #f6ad55; color: #fbd38d; }
  .btn.danger  { border-color: #e05252; color: #fc8181; }
  .btn.danger:hover { background: #3a1515; }

  .speed-wrap { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); }
  .speed-wrap input[type=range] { width: 80px; accent-color: var(--accent); }
  .speed-wrap #speedVal { color: var(--accent); font-weight: 600; min-width: 32px; font-family: var(--text-mono); }

  /* ── Main body: sidebar + canvas ── */
  #body {
    display: flex;
    flex: 1;
    min-height: 480px;
  }

  /* ── Sidebar ── */
  #sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
  }
  #sidebar::-webkit-scrollbar { width: 4px; }
  #sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  .sidebar-section {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-section:last-child { border-bottom: none; }

  .section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 12px;
  }

  /* Control row */
  .ctrl {
    margin-bottom: 14px;
  }
  .ctrl:last-child { margin-bottom: 0; }

  .ctrl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
  }
  .ctrl-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    font-family: var(--text-mono);
  }
  .ctrl-val {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    font-family: var(--text-mono);
    background: var(--accent-dim);
    padding: 1px 6px;
    border-radius: 3px;
    min-width: 28px;
    text-align: center;
  }

  /* Slider */
  .ctrl input[type=range] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
  }
  .slider-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 2px;
  }
  .slider-ticks span {
    font-size: 9px;
    color: var(--text-dim);
    font-family: var(--text-mono);
  }

  /* Select */
  .ctrl select {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-family: var(--text-mono);
    cursor: pointer;
    appearance: auto;
  }
  .ctrl select:focus { outline: 1px solid var(--accent); }

  /* Toggle (checkbox styled) */
  .ctrl-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
  }
  .ctrl-toggle input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
  .ctrl-toggle span { font-size: 11px; color: var(--text); font-family: var(--text-mono); }

  /* Info icon + popover */
  .info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 9px;
    font-weight: 700;
    font-style: italic;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.1s, color 0.1s;
    font-family: Georgia, serif;
    line-height: 1;
  }
  .info-btn:hover { border-color: var(--accent); color: var(--accent); }

  .info-popover {
    display: none;
    margin-top: 6px;
    background: var(--popover-bg);
    border: 1px solid var(--accent-dim);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.55;
  }
  .info-popover.open { display: block; }
  .info-popover a { color: var(--accent); font-size: 10px; }
  .info-popover strong { color: var(--text); }

  /* Status strip */
  #statusBar {
    padding: 10px 14px 6px;
  }
  .status-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 8px;
  }
  .stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
  }
  .stat {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-dim);
  }
  .stat .dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
  .stat .count { color: var(--text); font-weight: 700; margin-left: auto; font-family: var(--text-mono); font-size: 12px; }

  /* Keyboard hint */
  .kbd-hint {
    padding: 8px 14px;
    font-size: 10px;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    font-family: var(--text-mono);
  }

  /* About + How to use */
  .about-text {
    font-size: 11.5px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 8px;
  }
  .about-text:last-child { margin-bottom: 0; }
  .about-text strong { color: var(--text); }
  .about-text em { color: #90b8e0; font-style: normal; }

  .how-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 7px;
  }
  .how-list li {
    font-size: 11.5px;
    color: var(--text-dim);
    line-height: 1.5;
    padding-left: 12px;
    position: relative;
  }
  .how-list li::before {
    content: '›';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 700;
  }
  .how-list li strong { color: var(--text); }
  .how-list li code {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 3px;
    font-size: 10px;
    font-family: var(--text-mono);
    color: #90b8e0;
  }
  .how-list li kbd {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 10px;
    font-family: var(--text-mono);
    color: var(--text);
  }

  /* Learn more links */
  .learn-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .learn-list li {}
  .learn-list a {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    transition: color 0.1s;
  }
  .learn-list a:hover { color: #7ec8ff; text-decoration: underline; }
  .link-icon {
    flex-shrink: 0;
    font-size: 10px;
    margin-top: 2px;
    color: var(--accent);
    opacity: 0.7;
  }
  .link-meta {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 1px;
    padding-left: 17px;
  }

  /* ── Main panel (about banner + canvas) ── */
  #mainPanel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
  }

  /* ── About banner ── */
  #aboutBanner {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
    align-items: start;
  }
  #aboutBanner .about-text {
    margin-bottom: 0;
    font-size: 13px;
    line-height: 1.6;
  }

  /* ── Canvas area ── */
  #canvasWrap {
    flex: 1;
    min-width: 0;
    min-height: 0;
    position: relative;
    background: var(--bg);
  }
  canvas { display: block; width: 100%; height: 100%; }

  /* ── Right sidebar ── */
  #rightSidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
  }
  #rightSidebar::-webkit-scrollbar { width: 4px; }
  #rightSidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  /* record tooltip */
  #tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--tooltip-bg);
    border: 1px solid var(--tooltip-border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 12px;
    font-family: var(--text-mono);
    color: var(--text);
    line-height: 1.7;
    display: none;
    z-index: 200;
    min-width: 190px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  }
  #tooltip .tt-head { font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--text-dim); margin-bottom: 6px; padding-bottom: 5px;
    border-bottom: 1px solid var(--border); }
  #tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
  #tooltip .tt-key { color: var(--text-dim); }
  #tooltip .tt-val { color: var(--text); font-weight: 600; }
  #tooltip .tt-val.state-available  { color: #63b3ed; }
  #tooltip .tt-val.state-acquired   { color: #FF9800; }
  #tooltip .tt-val.state-ack-accept { color: #4CAF50; }
  #tooltip .tt-val.state-ack-release{ color: #9C27B0; }
  #tooltip .tt-val.state-ack-reject { color: #F44336; }
  #tooltip .tt-val.state-archived   { color: #607D8B; }
  #tooltip .tt-val.dc-warn          { color: #fc8181; }

  /* pause overlay */
  #pauseHint {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.78);
    border: 1px solid #f6ad55;
    color: #fbd38d;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    display: none;
    letter-spacing: 0.04em;
    backdrop-filter: blur(2px);
  }

  /* ── Light mode overrides ── */
  body.light .btn { background: var(--surface2); color: var(--text); }
  body.light .btn:hover { background: #dce8f4; border-color: #9cb8d8; }
  body.light .btn.running { background: #d0e4f8; border-color: var(--accent); color: #1a6ec0; }
  body.light .btn.paused  { background: #fef3e2; border-color: #c8a04a; color: #7a5010; }
  body.light .btn.danger:hover { background: #fde8e8; }
  body.light #tooltip .tt-val.dc-warn { color: #c04040; }

  /* ── Lag box (sidebar status strip) ── */
  #lagBox {
    margin-top: 8px; padding: 6px 8px;
    background: #1a1e0e; border: 1px solid #3a3010;
    border-radius: 4px; display: flex;
    justify-content: space-between; align-items: center;
  }
  body.light #lagBox { background: #fef8e6; border-color: #d8b840; }

  #lagBox .lag-label {
    font-size: 10px; color: #c9a84c; font-weight: 600; letter-spacing: .03em;
  }
  body.light #lagBox .lag-label { color: #8a6010; }

  #lagBox .lag-kip { font-weight: 400; color: #6e7d91; }
  body.light #lagBox .lag-kip { color: var(--text-dim); }

  #cntLag { font-size: 14px; font-weight: 700; color: #e2a83a; font-family: var(--text-mono); }
  body.light #cntLag { color: #b07020; }

  /* ── Welcome Modal ── */
  #welcomeModal {
    display: none;
    position: fixed; inset: 0; z-index: 1000;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.82);
    backdrop-filter: blur(3px);
  }

  #welcomeContent {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 40px 44px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  }

  .welcome-logo {
    font-size: 48px;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 16px;
  }

  #welcomeContent h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px;
    letter-spacing: 0.01em;
  }

  .welcome-sub {
    font-size: 11px;
    color: var(--text-dim);
    margin: 0 0 20px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .welcome-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.6;
    margin: 0 0 28px;
  }

  .welcome-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
  }

  .welcome-actions .btn {
    padding: 8px 20px;
    font-size: 13px;
  }

  .welcome-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
  .welcome-primary:hover { opacity: 0.88; }

  /* ── Tour Spotlight ── */
  #tourSpotlight {
    display: none;
    position: fixed;
    z-index: 900;
    pointer-events: none;
    border-radius: 5px;
    transition: top 0.22s ease, left 0.22s ease, width 0.22s ease, height 0.22s ease;
  }

  /* ── Tour Card ── */
  #tourCard {
    display: none;
    position: fixed;
    z-index: 950;
    width: 300px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 14px 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.55);
    transition: top 0.22s ease, left 0.22s ease;
  }

  #tourCardHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
  }

  #tourStepLabel {
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  #tourExit {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
  }
  #tourExit:hover { color: var(--text); background: var(--surface2); }

  #tourTitle {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
  }

  #tourBody {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 14px;
  }

  #tourBody strong { color: var(--text); }
  #tourBody code {
    font-family: var(--text-mono);
    font-size: 11px;
    background: var(--surface2);
    padding: 1px 4px;
    border-radius: 3px;
  }

  #tourNav {
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }

  #tourNav .btn {
    flex: 1;
    font-size: 11px;
    padding: 5px 8px;
  }

  #tourPrev:disabled {
    opacity: 0.35;
    cursor: default;
  }

  /* ── Playback controls wrapper ── */
  #playbackControls {
    display: flex;
    gap: 4px;
    align-items: center;
  }
